From b9f56a84f254851110a924eb16c4c104af5bdc7b Mon Sep 17 00:00:00 2001 From: mdelez <60604010+mdelez@users.noreply.github.com> Date: Thu, 12 May 2022 16:39:35 +0200 Subject: [PATCH] feat(onto-editor) delete resource class and property comments (DEV-698) (#733) * feat(onto-editor): delete resource class comments * feat(onto-editor): add some comments * chore(deps): update js-lib package * feat(property-form): add support to delete a property comment * chore(property-form): small refactoring and clean up * chore(package-lock.json): remove yalc package * refactor(property-form): rename method --- package-lock.json | 14 +-- package.json | 2 +- .../project/ontology/ontology.component.ts | 1 - .../property-form/property-form.component.ts | 116 +++++++++++------- .../resource-class-form.component.ts | 46 +++++-- 5 files changed, 113 insertions(+), 66 deletions(-) diff --git a/package-lock.json b/package-lock.json index b09b98f071..a7f39b7e59 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@angular/platform-browser-dynamic": "^13.2.6", "@angular/router": "^13.2.6", "@ckeditor/ckeditor5-angular": "^2.0.2", - "@dasch-swiss/dsp-js": "^7.1.0", + "@dasch-swiss/dsp-js": "^7.2.1", "@datadog/browser-rum": "^3.11.0", "@ngx-translate/core": "^13.0.0", "@ngx-translate/http-loader": "6.0.0", @@ -2425,9 +2425,9 @@ } }, "node_modules/@dasch-swiss/dsp-js": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-7.1.0.tgz", - "integrity": "sha512-JhjoSdrlolaO+SoYpQdYbKxENbXpg0I5hyRIjutSZ5VfRm3fh5FVr4k6at+9bQwaNvutufvmW+yxoz5MCYKtSA==", + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-7.2.1.tgz", + "integrity": "sha512-rvHx0PBmVwwPOnk9E4Rui3obY6glWBXmsk74s8b0hNdVePyxPk69wC2lKBAyHx8aX9x96ebTP9+a1jXmb//cdg==", "dependencies": { "@babel/helper-compilation-targets": "^7.16.7", "@types/jsonld": "^1.5.6", @@ -17117,9 +17117,9 @@ } }, "@dasch-swiss/dsp-js": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-7.1.0.tgz", - "integrity": "sha512-JhjoSdrlolaO+SoYpQdYbKxENbXpg0I5hyRIjutSZ5VfRm3fh5FVr4k6at+9bQwaNvutufvmW+yxoz5MCYKtSA==", + "version": "7.2.1", + "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-7.2.1.tgz", + "integrity": "sha512-rvHx0PBmVwwPOnk9E4Rui3obY6glWBXmsk74s8b0hNdVePyxPk69wC2lKBAyHx8aX9x96ebTP9+a1jXmb//cdg==", "requires": { "@babel/helper-compilation-targets": "^7.16.7", "@types/jsonld": "^1.5.6", diff --git a/package.json b/package.json index 3aa4e6be40..0bccecafad 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@angular/platform-browser-dynamic": "^13.2.6", "@angular/router": "^13.2.6", "@ckeditor/ckeditor5-angular": "^2.0.2", - "@dasch-swiss/dsp-js": "^7.1.0", + "@dasch-swiss/dsp-js": "^7.2.1", "@datadog/browser-rum": "^3.11.0", "@ngx-translate/core": "^13.0.0", "@ngx-translate/http-loader": "6.0.0", diff --git a/src/app/project/ontology/ontology.component.ts b/src/app/project/ontology/ontology.component.ts index 87bc38b425..3e5549add4 100644 --- a/src/app/project/ontology/ontology.component.ts +++ b/src/app/project/ontology/ontology.component.ts @@ -276,7 +276,6 @@ export class OntologyComponent implements OnInit { } initOntoClasses(allOntoClasses: ClassDefinition[]) { - // reset the ontology classes this.ontoClasses = []; diff --git a/src/app/project/ontology/property-form/property-form.component.ts b/src/app/project/ontology/property-form/property-form.component.ts index 8e04eb8f3c..58a108b797 100644 --- a/src/app/project/ontology/property-form/property-form.component.ts +++ b/src/app/project/ontology/property-form/property-form.component.ts @@ -5,6 +5,7 @@ import { ClassDefinition, Constants, CreateResourceProperty, + DeleteResourcePropertyComment, IHasProperty, KnoraApiConnection, ListNodeInfo, @@ -417,60 +418,56 @@ export class PropertyFormComponent implements OnInit { const updateComment = new UpdateResourcePropertyComment(); updateComment.id = this.propertyInfo.propDef.id; - updateComment.comments = (this.comments.length ? this.comments : this.labels); + updateComment.comments = this.comments; onto4Comment.entity = updateComment; this._dspApiConnection.v2.onto.updateResourceProperty(onto4Label).subscribe( - (classLabelResponse: ResourcePropertyDefinitionWithAllLanguages) => { - this.lastModificationDate = classLabelResponse.lastModificationDate; + (propertyLabelResponse: ResourcePropertyDefinitionWithAllLanguages) => { + this.lastModificationDate = propertyLabelResponse.lastModificationDate; onto4Comment.lastModificationDate = this.lastModificationDate; - this._dspApiConnection.v2.onto.updateResourceProperty(onto4Comment).subscribe( - (classCommentResponse: ResourcePropertyDefinitionWithAllLanguages) => { - this.lastModificationDate = classCommentResponse.lastModificationDate; + if (updateComment.comments.length) { // if the comments array is not empty, send a request to update the comments + this._dspApiConnection.v2.onto.updateResourceProperty(onto4Comment).subscribe( + (propertyCommentResponse: ResourcePropertyDefinitionWithAllLanguages) => { + this.lastModificationDate = propertyCommentResponse.lastModificationDate; - if (!this.unsupportedPropertyType) { - const onto4guiEle = new UpdateOntology(); - onto4guiEle.id = this.ontology.id; - onto4guiEle.lastModificationDate = this.lastModificationDate; - - const updateGuiEle = new UpdateResourcePropertyGuiElement(); - updateGuiEle.id = this.propertyInfo.propDef.id; - updateGuiEle.guiElement = this.propertyForm.controls['propType'].value.guiEle; - - const guiAttr = this.propertyForm.controls['guiAttr'].value; - if (guiAttr) { - updateGuiEle.guiAttributes = this.setGuiAttribute(guiAttr); + if (!this.unsupportedPropertyType) { + this.replaceGuiElement(); + } else { + this.loading = false; + this.closeDialog.emit(); } - onto4guiEle.entity = updateGuiEle; - - this._dspApiConnection.v2.onto.replaceGuiElementOfProperty(onto4guiEle).subscribe( - (guiEleResponse: ResourcePropertyDefinitionWithAllLanguages) => { - this.lastModificationDate = guiEleResponse.lastModificationDate; - // close the dialog box - this.loading = false; - this.closeDialog.emit(); - }, - (error: ApiResponseError) => { - this.error = true; - this.loading = false; - this._errorHandler.showMessage(error); - } - ); - } else { + }, + (error: ApiResponseError) => { + this.error = true; this.loading = false; - this.closeDialog.emit(); + this._errorHandler.showMessage(error); } - - }, - (error: ApiResponseError) => { - this.error = true; - this.loading = false; - this._errorHandler.showMessage(error); - } - ); - + ); + } else { // if the comments array is empty, send a request to remove the comments + const deleteResourcePropertyComment = new DeleteResourcePropertyComment(); + deleteResourcePropertyComment.id = this.propertyInfo.propDef.id; + deleteResourcePropertyComment.lastModificationDate = this.lastModificationDate; + + this._dspApiConnection.v2.onto.deleteResourcePropertyComment(deleteResourcePropertyComment).subscribe( + (deleteCommentResponse: ResourcePropertyDefinitionWithAllLanguages) => { + this.lastModificationDate = deleteCommentResponse.lastModificationDate; + + if (!this.unsupportedPropertyType) { + this.replaceGuiElement(); + } else { + this.loading = false; + this.closeDialog.emit(); + } + }, + (error: ApiResponseError) => { + this.error = true; + this.loading = false; + this._errorHandler.showMessage(error); + } + ); + } }, (error: ApiResponseError) => { this.error = true; @@ -535,6 +532,37 @@ export class PropertyFormComponent implements OnInit { } } + replaceGuiElement() { + const onto4guiEle = new UpdateOntology(); + onto4guiEle.id = this.ontology.id; + onto4guiEle.lastModificationDate = this.lastModificationDate; + + const updateGuiEle = new UpdateResourcePropertyGuiElement(); + updateGuiEle.id = this.propertyInfo.propDef.id; + updateGuiEle.guiElement = this.propertyForm.controls['propType'].value.guiEle; + + const guiAttr = this.propertyForm.controls['guiAttr'].value; + if (guiAttr) { + updateGuiEle.guiAttributes = this.setGuiAttribute(guiAttr); + } + + onto4guiEle.entity = updateGuiEle; + + this._dspApiConnection.v2.onto.replaceGuiElementOfProperty(onto4guiEle).subscribe( + (guiEleResponse: ResourcePropertyDefinitionWithAllLanguages) => { + this.lastModificationDate = guiEleResponse.lastModificationDate; + // close the dialog box + this.loading = false; + this.closeDialog.emit(); + }, + (error: ApiResponseError) => { + this.error = true; + this.loading = false; + this._errorHandler.showMessage(error); + } + ); + } + setCardinality(prop: ResourcePropertyDefinitionWithAllLanguages) { const onto = new UpdateOntology(); diff --git a/src/app/project/ontology/resource-class-form/resource-class-form.component.ts b/src/app/project/ontology/resource-class-form/resource-class-form.component.ts index 337b762510..dccc5edf38 100644 --- a/src/app/project/ontology/resource-class-form/resource-class-form.component.ts +++ b/src/app/project/ontology/resource-class-form/resource-class-form.component.ts @@ -4,6 +4,7 @@ import { ApiResponseError, ClassDefinition, CreateResourceClass, + DeleteResourceClassComment, KnoraApiConnection, PropertyDefinition, ReadOntology, @@ -302,7 +303,7 @@ export class ResourceClassFormComponent implements OnInit, AfterViewChecked { const updateComment = new UpdateResourceClassComment(); updateComment.id = this.iri; - updateComment.comments = (this.resourceClassComments.length ? this.resourceClassComments : this.resourceClassLabels); + updateComment.comments = this.resourceClassComments; onto4Comment.entity = updateComment; this._dspApiConnection.v2.onto.updateResourceClass(onto4Label).subscribe( @@ -310,18 +311,37 @@ export class ResourceClassFormComponent implements OnInit, AfterViewChecked { this.lastModificationDate = classLabelResponse.lastModificationDate; onto4Comment.lastModificationDate = this.lastModificationDate; - this._dspApiConnection.v2.onto.updateResourceClass(onto4Comment).subscribe( - (classCommentResponse: ResourceClassDefinitionWithAllLanguages) => { - this.lastModificationDate = classCommentResponse.lastModificationDate; - - // close the dialog box - this.loading = false; - this.closeDialog.emit(); - }, - (error: ApiResponseError) => { - this._errorHandler.showMessage(error); - } - ); + if(updateComment.comments.length) { // if the comments array is not empty, send a request to update the comments + this._dspApiConnection.v2.onto.updateResourceClass(onto4Comment).subscribe( + (classCommentResponse: ResourceClassDefinitionWithAllLanguages) => { + this.lastModificationDate = classCommentResponse.lastModificationDate; + + // close the dialog box + this.loading = false; + this.closeDialog.emit(); + }, + (error: ApiResponseError) => { + this._errorHandler.showMessage(error); + } + ); + } else { // if the comments array is empty, send a request to remove the comments + const deleteResourceClassComment = new DeleteResourceClassComment(); + deleteResourceClassComment.id = this.iri; + deleteResourceClassComment.lastModificationDate = this.lastModificationDate; + + this._dspApiConnection.v2.onto.deleteResourceClassComment(deleteResourceClassComment).subscribe( + (deleteCommentResponse: ResourceClassDefinitionWithAllLanguages) => { + this.lastModificationDate = deleteCommentResponse.lastModificationDate; + + // close the dialog box + this.loading = false; + this.closeDialog.emit(); + }, + (error: ApiResponseError) => { + this._errorHandler.showMessage(error); + } + ); + } }, (error: ApiResponseError) => {