Skip to content
Permalink
Browse files
feat(ontology): add property to res class that is in use (DSP-1631) (#…
…477)

* feat(ontology): add property to res class that is in use (DSP-1631)

* refactor(ontology): clean up imports

* test(ontology): bug fix in tests

* test(ontology): update test for new implementation
  • Loading branch information
kilchenmann committed Jun 30, 2021
1 parent 8be7e55 commit b18e6ecba2afb3059ef75fb20c3d5699468e8335
@@ -281,21 +281,21 @@
<div *ngSwitchCase="'updateCardinality'">
<app-dialog-header [title]="data.title" [subtitle]="data.subtitle">
</app-dialog-header>
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position" (closeDialog)="dialogRef.close()">
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position" [canSetFullCardinality]="data.canBeUpdated" (closeDialog)="dialogRef.close()">
</app-property-form>
</div>

<div *ngSwitchCase="'createProperty'">
<app-dialog-header [title]="data.title" [subtitle]="data.subtitle">
</app-dialog-header>
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position" (closeDialog)="dialogRef.close()">
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position" [canSetFullCardinality]="data.canBeUpdated" (closeDialog)="dialogRef.close()">
</app-property-form>
</div>

<div *ngSwitchCase="'editProperty'">
<app-dialog-header [title]="data.title" [subtitle]="data.subtitle">
</app-dialog-header>
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position" (closeDialog)="dialogRef.close()">
<app-property-form [propertyInfo]="data.propInfo" [resClassIri]="data.parentIri" [guiOrder]="data.position" [canSetFullCardinality]="data.canBeUpdated" (closeDialog)="dialogRef.close()">
</app-property-form>
</div>

@@ -12,6 +12,7 @@ export interface DialogData {
name?: string;
existing?: string[];
propInfo?: PropertyInfoObject;
canBeUpdated?: boolean;
position?: number;
parentIri?: string;
projectCode?: string;
@@ -25,7 +25,7 @@ import { PropertyFormComponent } from './property-form.component';
* Property is of type simple text
*/
@Component({
template: '<app-property-form #propertyForm [propertyInfo]="propertyInfo"></app-property-form>'
template: '<app-property-form #propertyForm [propertyInfo]="propertyInfo" [canSetFullCardinality]="false"></app-property-form>'
})
class SimpleTextHostComponent {

@@ -256,7 +256,6 @@ describe('PropertyFormComponent', () => {

});


it('expect link to other resource called "Thing"', () => {
expect(linkHostComponent.propertyFormComponent).toBeTruthy();
expect(linkHostComponent.propertyFormComponent.propertyInfo.propDef).toBeDefined();
@@ -267,4 +266,24 @@ describe('PropertyFormComponent', () => {
expect(form.controls['guiAttr'].value).toEqual('http://0.0.0.0:3333/ontology/0001/anything/v2#Thing');

});

it('expect "required" toggle switch (cardinality) to be disabled', () => {
expect(simpleTextHostComponent.propertyFormComponent).toBeTruthy();
expect(simpleTextHostComponent.propertyFormComponent.propertyInfo.propDef).toBeDefined();
expect(simpleTextHostComponent.propertyFormComponent.propertyInfo.propType).toBeDefined();

const form = simpleTextHostComponent.propertyFormComponent.propertyForm;
expect(form.controls['required'].disabled).toBeTruthy();

});

it('expect "required" toggle switch (cardinality) to be enabled', () => {
expect(linkHostComponent.propertyFormComponent).toBeTruthy();
expect(linkHostComponent.propertyFormComponent.propertyInfo.propDef).toBeDefined();
expect(linkHostComponent.propertyFormComponent.propertyInfo.propType).toBeDefined();

const form = linkHostComponent.propertyFormComponent.propertyForm;
expect(form.controls['required'].disabled).toBeFalsy();

});
});
@@ -41,6 +41,12 @@ export class PropertyFormComponent implements OnInit {
*/
@Input() resClassIri?: string;

/**
* info if the cardinality can be fully set or not
* (depending on canReplaceCardinalityOfResourceClass request)
*/
@Input() canSetFullCardinality?: boolean = true;

/**
* position of property in case of cardinality update
*/
@@ -148,8 +154,11 @@ export class PropertyFormComponent implements OnInit {
'guiAttr': new FormControl({
value: this.guiAttributes
}),
'multiple': new FormControl(),
'required': new FormControl()
'multiple': new FormControl(), // --> TODO: here we will check, if it can be updated; case updateCardinality: disabled if !canSetFullCardinality && multiple.value !== true
'required': new FormControl({
value: '',
disabled: !this.canSetFullCardinality
})
});

this.updateAttributeField(this.propertyInfo.propType);
@@ -6,10 +6,9 @@ import { MatMenuModule } from '@angular/material/menu';
import { MatTooltipModule } from '@angular/material/tooltip';
import { By } from '@angular/platform-browser';
import { CanDoResponse, ClassDefinition, Constants, MockOntology, OntologiesEndpointV2, ReadOntology } from '@dasch-swiss/dsp-js';
import { AppInitService, DspActionModule, DspApiConfigToken, DspApiConnectionToken, SortingService } from '@dasch-swiss/dsp-ui';
import { DspActionModule, DspApiConnectionToken, SortingService } from '@dasch-swiss/dsp-ui';
import { of } from 'rxjs';
import { CacheService } from 'src/app/main/cache/cache.service';
import { TestConfig } from 'test.config';
import { ResourceClassInfoComponent } from './resource-class-info.component';

/**
@@ -70,7 +69,7 @@ describe('ResourceClassInfoComponent', () => {
beforeEach(waitForAsync(() => {
const ontologyEndpointSpyObj = {
v2: {
onto: jasmine.createSpyObj('onto', ['replaceGuiOrderOfCardinalities', 'canDeleteResourceClass'])
onto: jasmine.createSpyObj('onto', ['replaceGuiOrderOfCardinalities', 'canDeleteResourceClass', 'canReplaceCardinalityOfResourceClass'])
}
};

@@ -125,6 +124,16 @@ describe('ResourceClassInfoComponent', () => {
}
);

(dspConnSpy.v2.onto as jasmine.SpyObj<OntologiesEndpointV2>).canReplaceCardinalityOfResourceClass.and.callFake(
() => {
const replaceCardinalityOfResClass: CanDoResponse = {
'canDo': false
};

return of(replaceCardinalityOfResClass);
}
);

hostFixture = TestBed.createComponent(HostComponent);
hostComponent = hostFixture.componentInstance;
hostFixture.detectChanges();
@@ -60,6 +60,8 @@ export class ResourceClassInfoComponent implements OnInit {

classCanBeDeleted: boolean;

classCanReplaceCardinality: boolean;

// list of properties that can be displayed (not all of the props should be displayed)
propsToDisplay: IHasProperty[] = [];

@@ -88,17 +90,14 @@ export class ResourceClassInfoComponent implements OnInit {
(response: ReadOntology) => {
this.ontology = response;
this.lastModificationDate = this.ontology.lastModificationDate;
// translate iris from "sub class of" array
this.translateSubClassOfIri(this.resourceClass.subClassOf);
// prepare list of properties to display
this.preparePropsToDisplay(this.resourceClass.propertiesList);
// check if the class can be deleted
this._dspApiConnection.v2.onto.canDeleteResourceClass(this.resourceClass.id).subscribe(
(res: CanDoResponse) => {
this.classCanBeDeleted = res.canDo;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
);
this.canBeDeleted();
// check if the cardinalities can be changed
this.canReplaceCardinality();
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
@@ -108,7 +107,7 @@ export class ResourceClassInfoComponent implements OnInit {
}

/**
* translates iri from "sub class of" array
* translates iris from "sub class of" array
* - display label from default resource classes (as part of DSP System Project)
* - in case the class is a subclass of another class in the same ontology: display this class label
* - in none of those cases display the name from the class IRI
@@ -230,6 +229,17 @@ export class ResourceClassInfoComponent implements OnInit {
);
}

canReplaceCardinality() {
this._dspApiConnection.v2.onto.canReplaceCardinalityOfResourceClass(this.resourceClass.id).subscribe(
(response: CanDoResponse) => {
this.classCanReplaceCardinality = response.canDo;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
);
}

addNewProperty(propType: DefaultProperty) {
const cardinality: CardinalityInfo = {
resClass: this.resourceClass,
@@ -329,7 +339,15 @@ export class ResourceClassInfoComponent implements OnInit {
position: {
top: '112px'
},
data: { propInfo: card.property, title: title, subtitle: 'Customize property and cardinality', mode: mode, parentIri: card.resClass.id, position: this.propsToDisplay.length }
data: {
propInfo: card.property,
title: title,
subtitle: 'Customize property and cardinality',
mode: mode,
parentIri: card.resClass.id,
position: this.propsToDisplay.length,
canBeUpdated: this.classCanReplaceCardinality
}
};

const dialogRef = this._dialog.open(
@@ -341,45 +359,10 @@ export class ResourceClassInfoComponent implements OnInit {
// update the view: list of properties in resource class
this.updateCardinality.emit(this.ontology.id);
});
} else {

}

}

/**
* opens property form
* @param mode
* @param propertyInfo (could be subClassOf (create mode) or resource class itself (edit mode))
*/
openPropertyForm(mode: 'createProperty' | 'editProperty', propertyInfo: PropertyInfoObject): void {

const title = (propertyInfo.propDef ? propertyInfo.propDef.label : propertyInfo.propType.group + ': ' + propertyInfo.propType.label);

const dialogConfig: MatDialogConfig = {
width: '640px',
maxHeight: '80vh',
position: {
top: '112px'
},
data: { propInfo: propertyInfo, title: title, subtitle: 'Customize property as part of ' + this.resourceClass.label, mode: mode, parentIri: this.resourceClass.id }
};

const dialogRef = this._dialog.open(
DialogComponent,
dialogConfig
);

dialogRef.afterClosed().subscribe(result => {
// update the view
// this.initOntologiesList();
this.ngOnInit();
});
}
// open dialog box with property-form
// create new property or add existing property
// form includes cardinality and gui-attribute


/**
* drag and drop property line

0 comments on commit b18e6ec

Please sign in to comment.