diff --git a/package-lock.json b/package-lock.json index a3d81e9ebf..73f097c42d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,7 +18,7 @@ "@angular/platform-browser-dynamic": "^11.2.9", "@angular/router": "^11.2.9", "@ckeditor/ckeditor5-angular": "^1.2.3", - "@dasch-swiss/dsp-js": "^2.3.0", + "@dasch-swiss/dsp-js": "^2.4.0", "@dasch-swiss/dsp-ui": "^1.4.0", "@ngx-translate/core": "^12.1.2", "@ngx-translate/http-loader": "5.0.0", @@ -2054,9 +2054,9 @@ } }, "node_modules/@dasch-swiss/dsp-js": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-2.3.0.tgz", - "integrity": "sha512-mjQh+sni9v3R0g/cQSZXbNgendrsx3ZmKXDih3DvBU2gSNabB9T32mgKDFb0MezbOo963+VpOSfPRwm0Kn/P/Q==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-2.4.0.tgz", + "integrity": "sha512-anHm+SP0qAqDpTcUHCSED37Wtalo1XWSLFFVcN2JYn7hMUFbXHGrdsw50UuK+RWMEDjEAbUwLomDxjxzry3opw==", "dependencies": { "@types/jsonld": "^1.5.0", "json2typescript": "1.4.1", @@ -21837,9 +21837,9 @@ } }, "@dasch-swiss/dsp-js": { - "version": "2.3.0", - "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-2.3.0.tgz", - "integrity": "sha512-mjQh+sni9v3R0g/cQSZXbNgendrsx3ZmKXDih3DvBU2gSNabB9T32mgKDFb0MezbOo963+VpOSfPRwm0Kn/P/Q==", + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-2.4.0.tgz", + "integrity": "sha512-anHm+SP0qAqDpTcUHCSED37Wtalo1XWSLFFVcN2JYn7hMUFbXHGrdsw50UuK+RWMEDjEAbUwLomDxjxzry3opw==", "requires": { "@types/jsonld": "^1.5.0", "json2typescript": "1.4.1", diff --git a/package.json b/package.json index 293613608e..d3636fee2d 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,7 @@ "@angular/platform-browser-dynamic": "^11.2.9", "@angular/router": "^11.2.9", "@ckeditor/ckeditor5-angular": "^1.2.3", - "@dasch-swiss/dsp-js": "^2.3.0", + "@dasch-swiss/dsp-js": "^2.4.0", "@dasch-swiss/dsp-ui": "^1.4.0", "@ngx-translate/core": "^12.1.2", "@ngx-translate/http-loader": "5.0.0", diff --git a/src/app/project/ontology/ontology-form/ontology-form.component.html b/src/app/project/ontology/ontology-form/ontology-form.component.html index b0cd1fe52a..57832f4527 100644 --- a/src/app/project/ontology/ontology-form/ontology-form.component.html +++ b/src/app/project/ontology/ontology-form/ontology-form.component.html @@ -1,6 +1,4 @@ - - -
+
diff --git a/src/app/project/ontology/ontology-form/ontology-form.component.ts b/src/app/project/ontology/ontology-form/ontology-form.component.ts index f4d77b6402..3b17464e1e 100644 --- a/src/app/project/ontology/ontology-form/ontology-form.component.ts +++ b/src/app/project/ontology/ontology-form/ontology-form.component.ts @@ -223,6 +223,7 @@ export class OntologyFormComponent implements OnInit { this._dspApiConnection.v2.onto.updateOntology(ontologyData).subscribe( (response: OntologyMetadata) => { this.updateParent.emit(response.id); + this.loading = false; this.closeDialog.emit(response.id); }, (error: ApiResponseError) => { @@ -246,6 +247,7 @@ export class OntologyFormComponent implements OnInit { this._dspApiConnection.v2.onto.createOntology(ontologyData).subscribe( (response: OntologyMetadata) => { this.updateParent.emit(response.id); + this.loading = false; this.closeDialog.emit(response.id); }, (error: ApiResponseError) => { diff --git a/src/app/project/ontology/ontology.component.html b/src/app/project/ontology/ontology.component.html index b5fa76a14f..ad638a4d23 100644 --- a/src/app/project/ontology/ontology.component.html +++ b/src/app/project/ontology/ontology.component.html @@ -109,8 +109,8 @@

- + [matTooltip]="((resClasses.length > 0) ? 'The property can\'t be removed because it\'s in use' : 'Remove property from resource class')"> + [matTooltip]="((resClasses.length > 0 || !propCanBeDeleted)? 'The property can\'t be deleted because it\'s used in a class' : 'Delete property')"> @@ -25,16 +25,17 @@ - - - + + + @@ -54,10 +55,8 @@ - @@ -80,15 +79,15 @@ - + - @@ -96,8 +95,7 @@ - diff --git a/src/app/project/ontology/resource-class-info/resource-class-info.component.spec.ts b/src/app/project/ontology/resource-class-info/resource-class-info.component.spec.ts index fbe60a7293..acea358c76 100644 --- a/src/app/project/ontology/resource-class-info/resource-class-info.component.spec.ts +++ b/src/app/project/ontology/resource-class-info/resource-class-info.component.spec.ts @@ -5,10 +5,11 @@ import { MatIconModule } from '@angular/material/icon'; import { MatMenuModule } from '@angular/material/menu'; import { MatTooltipModule } from '@angular/material/tooltip'; import { By } from '@angular/platform-browser'; -import { ClassDefinition, Constants, MockOntology, ReadOntology } from '@dasch-swiss/dsp-js'; -import { DspActionModule, DspApiConnectionToken, SortingService } from '@dasch-swiss/dsp-ui'; +import { CanDoResponse, ClassDefinition, Constants, MockOntology, OntologiesEndpointV2, ReadOntology } from '@dasch-swiss/dsp-js'; +import { AppInitService, DspActionModule, DspApiConfigToken, 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'; /** @@ -69,7 +70,7 @@ describe('ResourceClassInfoComponent', () => { beforeEach(waitForAsync(() => { const ontologyEndpointSpyObj = { v2: { - onto: jasmine.createSpyObj('onto', ['getOntology', 'replaceGuiOrderOfCardinalities']) + onto: jasmine.createSpyObj('onto', ['replaceGuiOrderOfCardinalities', 'canDeleteResourceClass']) } }; @@ -112,6 +113,18 @@ describe('ResourceClassInfoComponent', () => { } ); + const dspConnSpy = TestBed.inject(DspApiConnectionToken); + + (dspConnSpy.v2.onto as jasmine.SpyObj).canDeleteResourceClass.and.callFake( + () => { + const deleteResClass: CanDoResponse = { + 'canDo': false + }; + + return of(deleteResClass); + } + ); + hostFixture = TestBed.createComponent(HostComponent); hostComponent = hostFixture.componentInstance; hostFixture.detectChanges(); @@ -134,4 +147,18 @@ describe('ResourceClassInfoComponent', () => { expect(subtitle.nativeElement.innerText).toEqual('Thing'); }); + + it('expect delete res class button should be disabled', () => { + expect(hostComponent.resourceClassInfoComponent).toBeTruthy(); + expect(hostComponent.resourceClassInfoComponent.resourceClass).toBeDefined(); + + const hostCompDe = hostFixture.debugElement; + + const moreBtn: DebugElement = hostCompDe.query(By.css('.res-class-menu')); + moreBtn.nativeElement.click(); + + const deleteBtn: DebugElement = hostCompDe.query(By.css('.res-class-delete')); + expect(deleteBtn.nativeElement.disabled).toBeTruthy(); + + }); }); diff --git a/src/app/project/ontology/resource-class-info/resource-class-info.component.ts b/src/app/project/ontology/resource-class-info/resource-class-info.component.ts index b26493b5e4..9e1660a5e7 100644 --- a/src/app/project/ontology/resource-class-info/resource-class-info.component.ts +++ b/src/app/project/ontology/resource-class-info/resource-class-info.component.ts @@ -3,6 +3,7 @@ import { Component, EventEmitter, Inject, Input, OnInit, Output } from '@angular import { MatDialog, MatDialogConfig } from '@angular/material/dialog'; import { ApiResponseError, + CanDoResponse, ClassDefinition, IHasProperty, KnoraApiConnection, @@ -57,6 +58,8 @@ export class ResourceClassInfoComponent implements OnInit { cardinalityUpdateEnabled: boolean; + classCanBeDeleted: boolean; + // list of properties that can be displayed (not all of the props should be displayed) propsToDisplay: IHasProperty[] = []; @@ -87,11 +90,21 @@ export class ResourceClassInfoComponent implements OnInit { this.lastModificationDate = this.ontology.lastModificationDate; this.translateSubClassOfIri(this.resourceClass.subClassOf); 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); + } + ); }, (error: ApiResponseError) => { this._errorHandler.showMessage(error); } ); + } /** @@ -204,6 +217,19 @@ export class ResourceClassInfoComponent implements OnInit { } + canBeDeleted() { + + // check if the class can be deleted + this._dspApiConnection.v2.onto.canDeleteResourceClass(this.resourceClass.id).subscribe( + (response: CanDoResponse) => { + this.classCanBeDeleted = response.canDo; + }, + (error: ApiResponseError) => { + this._errorHandler.showMessage(error); + } + ); + } + addNewProperty(propType: DefaultProperty) { const cardinality: CardinalityInfo = { resClass: this.resourceClass,