diff --git a/package-lock.json b/package-lock.json index 00a34f04ba..184f15af9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,7 @@ "requires": true, "packages": { "": { - "version": "4.0.0", + "version": "4.1.0", "dependencies": { "@angular/animations": "^9.1.12", "@angular/cdk": "^9.2.4", diff --git a/src/app/main/dialog/dialog.component.html b/src/app/main/dialog/dialog.component.html index 4d3d1d28c0..44bcfca612 100644 --- a/src/app/main/dialog/dialog.component.html +++ b/src/app/main/dialog/dialog.component.html @@ -216,12 +216,9 @@
-

- - - + +
@@ -243,7 +240,7 @@ + [showResourceClassForm]="false" [edit]="true" (closeDialog)="dialogRef.close()">
diff --git a/src/app/project/ontology/ontology.component.html b/src/app/project/ontology/ontology.component.html index 1a5ae96168..99bec80683 100644 --- a/src/app/project/ontology/ontology.component.html +++ b/src/app/project/ontology/ontology.component.html @@ -86,7 +86,7 @@

{{ontology?.label}}

Data model configuration

- + - + + 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 e87ae3241c..4dfa56e0f9 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 @@ -15,7 +15,9 @@ import { ResourcePropertyDefinitionWithAllLanguages, StringLiteral, UpdateOntology, - UpdateResourceClassCardinality + UpdateResourceClassCardinality, + UpdateResourceClassComment, + UpdateResourceClassLabel } from '@dasch-swiss/dsp-js'; import { StringLiteralV2 } from '@dasch-swiss/dsp-js/src/models/v2/string-literal-v2'; import { DspApiConnectionToken } from '@dasch-swiss/dsp-ui'; @@ -122,7 +124,8 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC // form errors on the following fields: formErrors = { - 'label': '' + 'label': '', + 'comment': '' }; // in case of form error: show message @@ -130,6 +133,9 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC 'label': { 'required': 'Label is required.' }, + 'comment': { + 'required': 'Comment is required.' + } }; lastModificationDate: string; @@ -202,26 +208,43 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC this._resourceClassFormService.resetProperties(); if (this.edit) { - // edit mode - // get resource class and property definition first - - // get list of ontology properties - const ontoProperties: PropertyDefinition[] = this.ontology.getAllPropertyDefinitions(); - // find prop cardinality in resource class - const ontoClasses: ClassDefinition[] = this.ontology.getAllClassDefinitions(); - Object.keys(ontoClasses).forEach(key => { - if (ontoClasses[key].id === this.iri) { - - this._resourceClassFormService.setProperties(ontoClasses[key], ontoProperties); + if (this.showResourceClassForm) { + // edit mode: res class info (label and comment) + // get resource class info + const resourceClasses: ResourceClassDefinitionWithAllLanguages[] = this.ontology.getClassDefinitionsByType(ResourceClassDefinitionWithAllLanguages); + Object.keys(resourceClasses).forEach(key => { + if (resourceClasses[key].id === this.iri) { + this.resourceClassLabels = resourceClasses[key].labels; + this.resourceClassComments = resourceClasses[key].comments; + } + }); + this.resourceClassFormSub = this._resourceClassFormService.resourceClassForm$ + .subscribe(resourceClass => { + this.resourceClassForm = resourceClass; + }); + this.resourceClassForm.valueChanges.subscribe(data => this.onValueChanged(data)); - this.resourceClassFormSub = this._resourceClassFormService.resourceClassForm$ - .subscribe(resourceClass => { - this.resourceClassForm = resourceClass; - this.properties = this.resourceClassForm.get('properties') as FormArray; - }); - } - }); + } else { + // edit mode: res class cardinality + // get list of ontology properties + const ontoProperties: PropertyDefinition[] = this.ontology.getAllPropertyDefinitions(); + + // find prop cardinality in resource class + const ontoClasses: ClassDefinition[] = this.ontology.getAllClassDefinitions(); + Object.keys(ontoClasses).forEach(key => { + if (ontoClasses[key].id === this.iri) { + + this._resourceClassFormService.setProperties(ontoClasses[key], ontoProperties); + + this.resourceClassFormSub = this._resourceClassFormService.resourceClassForm$ + .subscribe(resourceClass => { + this.resourceClassForm = resourceClass; + this.properties = this.resourceClassForm.get('properties') as FormArray; + }); + } + }); + } } else { // create mode @@ -344,9 +367,58 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC submitData() { this.loading = true; if (this.edit) { - // edit mode - // submit properties and set cardinality - this.submitProps(this.resourceClassForm.value.properties, this.iri); + + if (this.showResourceClassForm) { + // edit mode: res class info (label and comment) + // label + const onto4Label = new UpdateOntology(); + onto4Label.id = this.ontology.id; + onto4Label.lastModificationDate = this.lastModificationDate; + + const updateLabel = new UpdateResourceClassLabel(); + updateLabel.id = this.iri; + updateLabel.labels = this.resourceClassLabels; + onto4Label.entity = updateLabel; + + // comment + const onto4Comment = new UpdateOntology(); + onto4Comment.id = this.ontology.id; + + const updateComment = new UpdateResourceClassComment(); + updateComment.id = this.iri; + 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); + } + ) + + }, + (error: ApiResponseError) => { + this._errorHandler.showMessage(error); + } + ); + + + } else { + // edit mode: res class cardinality + // submit properties and set cardinality + this.submitProps(this.resourceClassForm.value.properties, this.iri); + } } else { // create mode @@ -363,7 +435,7 @@ export class ResourceClassFormComponent implements OnInit, OnDestroy, AfterViewC const newResClass = new CreateResourceClass(); - newResClass.name = uniqueClassName + newResClass.name = uniqueClassName; newResClass.label = this.resourceClassLabels; newResClass.comment = this.resourceClassComments; newResClass.subClassOf = [this.iri];