Skip to content

Commit

Permalink
feat(onto-editor) delete resource class and property comments (DEV-698)…
Browse files Browse the repository at this point in the history
… (#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
  • Loading branch information
mdelez committed May 12, 2022
1 parent 88b81bf commit b9f56a8
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 66 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/app/project/ontology/ontology.component.ts
Expand Up @@ -276,7 +276,6 @@ export class OntologyComponent implements OnInit {
}

initOntoClasses(allOntoClasses: ClassDefinition[]) {

// reset the ontology classes
this.ontoClasses = [];

Expand Down
116 changes: 72 additions & 44 deletions src/app/project/ontology/property-form/property-form.component.ts
Expand Up @@ -5,6 +5,7 @@ import {
ClassDefinition,
Constants,
CreateResourceProperty,
DeleteResourcePropertyComment,
IHasProperty,
KnoraApiConnection,
ListNodeInfo,
Expand Down Expand Up @@ -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<UpdateResourcePropertyGuiElement>();
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;
Expand Down Expand Up @@ -535,6 +532,37 @@ export class PropertyFormComponent implements OnInit {
}
}

replaceGuiElement() {
const onto4guiEle = new UpdateOntology<UpdateResourcePropertyGuiElement>();
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<UpdateResourceClassCardinality>();
Expand Down
Expand Up @@ -4,6 +4,7 @@ import {
ApiResponseError,
ClassDefinition,
CreateResourceClass,
DeleteResourceClassComment,
KnoraApiConnection,
PropertyDefinition,
ReadOntology,
Expand Down Expand Up @@ -302,26 +303,45 @@ 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(
(classLabelResponse: ResourceClassDefinitionWithAllLanguages) => {
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) => {
Expand Down

0 comments on commit b9f56a8

Please sign in to comment.