Skip to content
Permalink
Browse files
fix(resource-instance-form): reloads cached resource to show changes …
…made to the data model (#547)
  • Loading branch information
mdelez committed Oct 5, 2021
1 parent 0a2bcfb commit 37bb2a75cceeafffd8ee74f19af18648020e9704

Some generated files are not rendered by default. Learn more.

@@ -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",
@@ -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);
});
@@ -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.';
}
@@ -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,15 +103,15 @@ describe('SelectOntologyComponent', () => {

const options = await select.getOptions();

expect(options.length).toEqual(14);
expect(options.length).toEqual(15);

const option1 = await options[0].getText();

expect(option1).toEqual('The anything ontology');

const option2 = await options[1].getText();

expect(option2).toEqual('A minimal ontology');
expect(option2).toEqual('The free test ontology');

});

@@ -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,15 +102,15 @@ describe('SearchSelectOntologyComponent', () => {

const options = await select.getOptions();

expect(options.length).toEqual(14);
expect(options.length).toEqual(15);

const option1 = await options[0].getText();

expect(option1).toEqual('The anything ontology');

const option2 = await options[1].getText();

expect(option2).toEqual('A minimal ontology');
expect(option2).toEqual('The free test ontology');

});

0 comments on commit 37bb2a7

Please sign in to comment.