From 37bb2a75cceeafffd8ee74f19af18648020e9704 Mon Sep 17 00:00:00 2001 From: mdelez <60604010+mdelez@users.noreply.github.com> Date: Tue, 5 Oct 2021 10:11:21 +0200 Subject: [PATCH] fix(resource-instance-form): reloads cached resource to show changes made to the data model (#547) --- package-lock.json | 28 +++-- package.json | 4 +- .../resource-instance-form.component.spec.ts | 6 +- .../resource-instance-form.component.ts | 100 +++++++++--------- .../select-ontology.component.spec.ts | 6 +- .../search-select-ontology.component.spec.ts | 6 +- 6 files changed, 83 insertions(+), 67 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4a19d3b96d..75cb94dc36 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,7 @@ "@angular/platform-browser-dynamic": "^11.2.9", "@angular/router": "^11.2.9", "@ckeditor/ckeditor5-angular": "^1.2.3", - "@dasch-swiss/dsp-js": "^4.0.0", + "@dasch-swiss/dsp-js": "^4.1.0", "@ngx-translate/core": "^12.1.2", "@ngx-translate/http-loader": "5.0.0", "3d-force-graph": "^1.60.12", @@ -77,6 +77,20 @@ "typescript": "4.0.7" } }, + ".yalc/@dasch-swiss/dsp-js": { + "version": "4.0.0+714fcf1f", + "extraneous": true, + "license": "AGPL-3.0", + "dependencies": { + "@babel/helper-compilation-targets": "^7.14.5", + "@types/jsonld": "^1.5.0", + "json2typescript": "1.4.1", + "jsonld": "^5.2.0" + }, + "peerDependencies": { + "rxjs": "6.x" + } + }, "node_modules/@angular-devkit/architect": { "version": "0.1102.14", "resolved": "https://registry.npmjs.org/@angular-devkit/architect/-/architect-0.1102.14.tgz", @@ -2215,9 +2229,9 @@ } }, "node_modules/@dasch-swiss/dsp-js": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-4.0.0.tgz", - "integrity": "sha512-Aa1oKXMCxfOx+YYb3ZtfI2W2syLQtGdlqkmi6cs/EbGx+/ByIUcTxUexUZyJ3MTI9IzGBzV8JPKvWq7IUGO15Q==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-4.1.0.tgz", + "integrity": "sha512-UnCAxYWGpeAyceqwSflftv4xMrNfS18n/h2b2+Ld20MtQdmo6DMJgstBcj1xSQbwHN4v/f/MHazsZ9oZQlIyDA==", "dependencies": { "@babel/helper-compilation-targets": "^7.14.5", "@types/jsonld": "^1.5.0", @@ -21918,9 +21932,9 @@ } }, "@dasch-swiss/dsp-js": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-4.0.0.tgz", - "integrity": "sha512-Aa1oKXMCxfOx+YYb3ZtfI2W2syLQtGdlqkmi6cs/EbGx+/ByIUcTxUexUZyJ3MTI9IzGBzV8JPKvWq7IUGO15Q==", + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/@dasch-swiss/dsp-js/-/dsp-js-4.1.0.tgz", + "integrity": "sha512-UnCAxYWGpeAyceqwSflftv4xMrNfS18n/h2b2+Ld20MtQdmo6DMJgstBcj1xSQbwHN4v/f/MHazsZ9oZQlIyDA==", "requires": { "@babel/helper-compilation-targets": "^7.14.5", "@types/jsonld": "^1.5.0", diff --git a/package.json b/package.json index 02fdd65fa7..19df979da9 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "test-local": "ng test", "test-e2e-protractor": "ng e2e --prod=true --protractor-config=./e2e/protractor-ci.conf.js --webdriver-update=false", "webdriver-update": "webdriver-manager update --standalone false --gecko false --versions.chrome 2.37", - "yalc-add-lib": "rm -rf .yalc/@dasch-swiss && yalc add @dasch-swiss/dsp-js && yalc add @dasch-swiss/dsp-ui && npm install" + "yalc-add-lib": "rm -rf .yalc/@dasch-swiss && yalc add @dasch-swiss/dsp-js && npm install" }, "private": true, "dependencies": { @@ -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": "^4.0.0", + "@dasch-swiss/dsp-js": "^4.1.0", "@ngx-translate/core": "^12.1.2", "@ngx-translate/http-loader": "5.0.0", "3d-force-graph": "^1.60.12", diff --git a/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.spec.ts b/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.spec.ts index 9a426142d0..72b6bee154 100644 --- a/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.spec.ts +++ b/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.spec.ts @@ -300,7 +300,7 @@ describe('ResourceInstanceFormComponent', () => { }, v2: { onto: jasmine.createSpyObj('onto', ['getOntologiesByProjectIri', 'getOntology', 'getResourceClassDefinition']), - ontologyCache: jasmine.createSpyObj('ontologyCache', ['getOntology', 'getResourceClassDefinition']), + ontologyCache: jasmine.createSpyObj('ontologyCache', ['getOntology', 'getResourceClassDefinition', 'reloadCachedItem']), res: jasmine.createSpyObj('res', ['createResource']) } }; @@ -444,7 +444,9 @@ describe('ResourceInstanceFormComponent', () => { const selectOntoComp = resourceInstanceFormComponentDe.query(By.directive(MockSelectOntologyComponent)); - expect((selectOntoComp.componentInstance as MockSelectOntologyComponent).ontologiesMetadata.ontologies.length).toEqual(10); + console.log('ontos: ', (selectOntoComp.componentInstance as MockSelectOntologyComponent).ontologiesMetadata.ontologies); + + expect((selectOntoComp.componentInstance as MockSelectOntologyComponent).ontologiesMetadata.ontologies.length).toEqual(11); expect(dspConnSpy.v2.onto.getOntologiesByProjectIri).toHaveBeenCalledTimes(1); }); diff --git a/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.ts b/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.ts index 102a73bac1..d61a28362a 100644 --- a/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.ts +++ b/src/app/workspace/resource/resource-instance-form/resource-instance-form.component.ts @@ -296,9 +296,6 @@ export class ResourceInstanceFormComponent implements OnInit, OnDestroy { // if there is already a select-resource-class component (i.e. the user clicked the back button), reset the resource & label if (this.selectResourceClassComponent) { - this.selectResourceClassComponent.form.controls.resources.setValue(null); - this.selectResourceClassComponent.form.controls.label.setValue(null); - // since the component already exists, we need to add the control back here as it is normally done in the OnInit of the component this.selectResourceForm.addControl('resources', this.selectResourceClassComponent.form); } @@ -343,54 +340,57 @@ export class ResourceInstanceFormComponent implements OnInit, OnDestroy { if (resourceClassIri === null) { this.selectResourceClasses(this.selectedOntology); } else if (resourceClassIri) { - this._dspApiConnection.v2.ontologyCache.getResourceClassDefinition(resourceClassIri).subscribe( - (onto: ResourceClassAndPropertyDefinitions) => { - this.ontologyInfo = onto; - - this.selectedResourceClass = onto.classes[resourceClassIri]; - - // set label from resource class - const defaultClassLabel = this.defaultClasses.find(i => i.iri === this.selectedResourceClass.subClassOf[0]); - this.resourceLabel = this.selectedResourceClass.label + (defaultClassLabel ? ' (' + defaultClassLabel.label + ')' : ''); - - // filter out all props that cannot be edited or are link props but also the hasFileValue props - this.properties = onto.getPropertyDefinitionsByType(ResourcePropertyDefinition).filter( - prop => - !prop.isLinkProperty && - prop.isEditable && - prop.id !== Constants.HasStillImageFileValue && - prop.id !== Constants.HasDocumentFileValue && - prop.id !== Constants.HasAudioFileValue // --> TODO for UPLOAD: expand with other representation file values + this._dspApiConnection.v2.ontologyCache.reloadCachedItem(this.selectedOntology).subscribe( + (res: ReadOntology) => { + this._dspApiConnection.v2.ontologyCache.getResourceClassDefinition(resourceClassIri).subscribe( + (onto: ResourceClassAndPropertyDefinitions) => { + this.ontologyInfo = onto; + + this.selectedResourceClass = onto.classes[resourceClassIri]; + + // set label from resource class + const defaultClassLabel = this.defaultClasses.find(i => i.iri === this.selectedResourceClass.subClassOf[0]); + this.resourceLabel = this.selectedResourceClass.label + (defaultClassLabel ? ' (' + defaultClassLabel.label + ')' : ''); + + // filter out all props that cannot be edited or are link props but also the hasFileValue props + this.properties = onto.getPropertyDefinitionsByType(ResourcePropertyDefinition).filter( + prop => + !prop.isLinkProperty && + prop.isEditable && + prop.id !== Constants.HasStillImageFileValue && + prop.id !== Constants.HasDocumentFileValue && + prop.id !== Constants.HasAudioFileValue // --> TODO for UPLOAD: expand with other representation file values + ); + + if (onto.properties[Constants.HasStillImageFileValue]) { + this.hasFileValue = 'stillImage'; + } else if (onto.properties[Constants.HasDocumentFileValue]) { + this.hasFileValue = 'document'; + } else if (onto.properties[Constants.HasAudioFileValue]) { + this.hasFileValue = 'audio'; + } else { + this.hasFileValue = undefined; + } + + // notifies the user that the selected resource does not have any properties defined yet. + if (!this.selectPropertiesComponent && this.properties.length === 0) { + this.errorMessage = 'No properties defined for the selected resource.'; + } + + if (this.resourceClasses.length > 1 && !this.userWentBack) { + // automatically go to the next step when a resource class is selected + // but not in case the user went back to previous form + this.nextStep(); + } else { + // or update the title because the user select another res class + this.updateParent.emit({ title: this.resourceLabel, subtitle: 'Create new resource' }); + } + }, + (error: ApiResponseError) => { + this._errorHandler.showMessage(error); + } ); - - if (onto.properties[Constants.HasStillImageFileValue]) { - this.hasFileValue = 'stillImage'; - } else if (onto.properties[Constants.HasDocumentFileValue]) { - this.hasFileValue = 'document'; - } else if (onto.properties[Constants.HasAudioFileValue]) { - this.hasFileValue = 'audio'; - } else { - this.hasFileValue = undefined; - } - - // notifies the user that the selected resource does not have any properties defined yet. - if (!this.selectPropertiesComponent && this.properties.length === 0) { - this.errorMessage = 'No properties defined for the selected resource.'; - } - - if (this.resourceClasses.length > 1 && !this.userWentBack) { - // automatically go to the next step when a resource class is selected - // but not in case the user went back to previous form - this.nextStep(); - } else { - // or update the title because the user select another res class - this.updateParent.emit({ title: this.resourceLabel, subtitle: 'Create new resource' }); - } - }, - (error: ApiResponseError) => { - this._errorHandler.showMessage(error); - } - ); + }); } else { this.errorMessage = 'No resource class defined for the selected ontology.'; } diff --git a/src/app/workspace/resource/resource-instance-form/select-ontology/select-ontology.component.spec.ts b/src/app/workspace/resource/resource-instance-form/select-ontology/select-ontology.component.spec.ts index 82045286f5..7d47431feb 100644 --- a/src/app/workspace/resource/resource-instance-form/select-ontology/select-ontology.component.spec.ts +++ b/src/app/workspace/resource/resource-instance-form/select-ontology/select-ontology.component.spec.ts @@ -88,7 +88,7 @@ describe('SelectOntologyComponent', () => { it('should initialise the ontologies metadata', () => { expect(testHostComponent.selectOntology.ontologiesMetadata.ontologies).toBeDefined(); - expect(testHostComponent.selectOntology.ontologiesMetadata.ontologies.length).toEqual(14); + expect(testHostComponent.selectOntology.ontologiesMetadata.ontologies.length).toEqual(15); }); it('should init the MatSelect and MatOptions correctly', async () => { @@ -103,7 +103,7 @@ describe('SelectOntologyComponent', () => { const options = await select.getOptions(); - expect(options.length).toEqual(14); + expect(options.length).toEqual(15); const option1 = await options[0].getText(); @@ -111,7 +111,7 @@ describe('SelectOntologyComponent', () => { const option2 = await options[1].getText(); - expect(option2).toEqual('A minimal ontology'); + expect(option2).toEqual('The free test ontology'); }); diff --git a/src/app/workspace/search/advanced-search/search-select-ontology/search-select-ontology.component.spec.ts b/src/app/workspace/search/advanced-search/search-select-ontology/search-select-ontology.component.spec.ts index 714047e348..289b1d858e 100644 --- a/src/app/workspace/search/advanced-search/search-select-ontology/search-select-ontology.component.spec.ts +++ b/src/app/workspace/search/advanced-search/search-select-ontology/search-select-ontology.component.spec.ts @@ -86,7 +86,7 @@ describe('SearchSelectOntologyComponent', () => { it('should initialise the ontologies\' metadata', () => { expect(testHostComponent.selectOntology.ontologiesMetadata.ontologies).toBeDefined(); - expect(testHostComponent.selectOntology.ontologiesMetadata.ontologies.length).toEqual(14); + expect(testHostComponent.selectOntology.ontologiesMetadata.ontologies.length).toEqual(15); }); @@ -102,7 +102,7 @@ describe('SearchSelectOntologyComponent', () => { const options = await select.getOptions(); - expect(options.length).toEqual(14); + expect(options.length).toEqual(15); const option1 = await options[0].getText(); @@ -110,7 +110,7 @@ describe('SearchSelectOntologyComponent', () => { const option2 = await options[1].getText(); - expect(option2).toEqual('A minimal ontology'); + expect(option2).toEqual('The free test ontology'); });