Skip to content

Commit

Permalink
fix(link-value): loop through all ontologies of a project to create l…
Browse files Browse the repository at this point in the history
…ist of resource classes (#766)
  • Loading branch information
mdelez committed Jun 16, 2022
1 parent 9c83b7e commit 7c824bf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Expand Up @@ -127,8 +127,14 @@ export class CreateLinkResourceComponent implements OnInit {
case 'audio':
this.propertiesObj[Constants.HasAudioFileValue] = [this.fileValue];
break;
case 'movingImage':
this.propertiesObj[Constants.HasMovingImageFileValue] = [this.fileValue];
break;
case 'archive':
this.propertiesObj[Constants.HasArchiveFileValue] = [this.fileValue];
break;
case 'text':
this.propertiesObj[Constants.HasTextFileValue] = [this.fileValue];
}
}

Expand Down
Expand Up @@ -14,6 +14,7 @@ import { AbstractControl, FormBuilder, FormControl, FormGroup } from '@angular/f
import { MatAutocompleteTrigger } from '@angular/material/autocomplete';
import { MatDialog, MatDialogConfig } from '@angular/material/dialog';
import {
Constants,
CreateLinkValue,
KnoraApiConnection,
ReadLinkValue,
Expand Down Expand Up @@ -142,8 +143,19 @@ export class LinkValueComponent extends BaseValueDirective implements OnInit, On
);

this._dspApiConnection.v2.ontologyCache.getOntology(this.currentOntoIri).subscribe(
(onto: Map<string, ReadOntology>) => {
const resClasses = onto.get(this.currentOntoIri).getClassDefinitionsByType(ResourceClassDefinition);
(ontoMap: Map<string, ReadOntology>) => {

// filter out knorabase ontology
const filteredOntoMap = new Map(
Array.from(ontoMap).filter(([key, _]) => key !== Constants.KnoraApiV2)
);

let resClasses = [];

// loop through each ontology in the project and create an array of ResourceClassDefinitions
filteredOntoMap.forEach( onto => {
resClasses = resClasses.concat(filteredOntoMap.get(onto.id).getClassDefinitionsByType(ResourceClassDefinition));
});

// add the superclass to the list of resource classes
this.resourceClasses = resClasses.filter(
Expand All @@ -154,7 +166,7 @@ export class LinkValueComponent extends BaseValueDirective implements OnInit, On
// and add them to the list of resource classes
this.resourceClasses = this.resourceClasses.concat(this._getSubclasses(resClasses, this.restrictToResourceClass));

this.properties = onto.get(this.currentOntoIri).getPropertyDefinitionsByType(ResourcePropertyDefinition);
this.properties = filteredOntoMap.get(this.currentOntoIri).getPropertyDefinitionsByType(ResourcePropertyDefinition);
},
error => {
console.error(error);
Expand Down Expand Up @@ -263,7 +275,7 @@ export class LinkValueComponent extends BaseValueDirective implements OnInit, On
position: {
top: '112px'
},
data: { mode: mode, title: resClass.label, id: iri, parentResource: this.parentResource, resourceClassDefinition: resClass.id, ontoIri: this.currentOntoIri },
data: { mode: mode, title: resClass.label, id: iri, parentResource: this.parentResource, resourceClassDefinition: resClass.id },
disableClose: true
};

Expand Down

0 comments on commit 7c824bf

Please sign in to comment.