Skip to content

Commit 8dcdd8f

Browse files
authored
feat(ontology): select link class from all ontologies (DEV-688) (#737)
* refactor(ontology): remove unused interface * feat(ontology): select link class from all ontologies (DEV-688) * test(ontolgy): fix broken test
1 parent b9f56a8 commit 8dcdd8f

4 files changed

Lines changed: 48 additions & 22 deletions

File tree

‎src/app/project/ontology/ontology.component.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ import { DefaultProperties, PropertyCategory, PropertyInfoObject } from './defau
3131
import { DefaultClass, DefaultResourceClasses } from './default-data/default-resource-classes';
3232
import { OntologyService } from './ontology.service';
3333

34-
export interface OntologyInfo {
35-
id: string;
36-
label: string;
37-
}
38-
3934
export interface CardinalityInfo {
4035
resClass: ClassDefinition;
4136
property: PropertyInfoObject;

‎src/app/project/ontology/property-form/property-form.component.html‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575

7676
<!-- depending on type: display gui attribute -->
7777
<div *ngIf="showGuiAttr" [ngSwitch]="propertyInfo.propType.objectType">
78+
<!-- list property -->
7879
<mat-form-field class="large-field property-type ontology-form-field" *ngSwitchCase="dspConstants.ListValue">
7980
<span matPrefix class="ontology-prefix-icon">
8081
<mat-icon>{{guiAttrIcon}}</mat-icon>&nbsp;
@@ -90,15 +91,18 @@
9091
</mat-hint>
9192
</mat-form-field>
9293

94+
<!-- link property -->
9395
<mat-form-field class="large-field property-type ontology-form-field" *ngSwitchCase="dspConstants.LinkValue">
9496
<span matPrefix class="ontology-prefix-icon">
9597
<mat-icon>{{guiAttrIcon}}</mat-icon>&nbsp;
9698
</span>
9799
<mat-label>Select resource class</mat-label>
98100
<mat-select formControlName="guiAttr">
99-
<mat-option *ngFor="let item of resourceClasses" [value]="item.id">
100-
{{item.label}}
101-
</mat-option>
101+
<mat-optgroup *ngFor="let onto of ontologyClasses" [label]="onto.ontologyLabel">
102+
<mat-option *ngFor="let class of onto.classes" [value]="class.id">
103+
{{class.label}}
104+
</mat-option>
105+
</mat-optgroup>
102106
</mat-select>
103107
<mat-hint *ngIf="formErrors.guiAttr">
104108
{{formErrors.guiAttr}}

‎src/app/project/ontology/property-form/property-form.component.spec.ts‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ describe('PropertyFormComponent', () => {
200200

201201
beforeEach(waitForAsync(() => {
202202

203-
const cacheServiceSpyOnto = jasmine.createSpyObj('CacheServiceOnto', ['get']);
204-
const cacheServiceSpyLists = jasmine.createSpyObj('CacheServiceLists', ['get']);
203+
const cacheServiceSpy = jasmine.createSpyObj('CacheService', ['get']);
205204

206205
const ontologyEndpointSpyObj = {
207206
v2: {
@@ -239,11 +238,7 @@ describe('PropertyFormComponent', () => {
239238
},
240239
{
241240
provide: CacheService,
242-
useValue: cacheServiceSpyOnto
243-
},
244-
{
245-
provide: CacheService,
246-
useValue: cacheServiceSpyLists
241+
useValue: cacheServiceSpy
247242
}
248243
]
249244
})
@@ -261,6 +256,18 @@ describe('PropertyFormComponent', () => {
261256
}
262257
);
263258

259+
// mock cache service for currentProjectOntologies
260+
const cacheSpyProjOnto = TestBed.inject(CacheService);
261+
(cacheSpyProjOnto as jasmine.SpyObj<CacheService>).get.withArgs('currentProjectOntologies').and.callFake (
262+
() => {
263+
const ontologies: ReadOntology[] = [];
264+
ontologies.push(MockOntology.mockReadOntology('http://0.0.0.0:3333/ontology/0001/anything/v2'));
265+
ontologies.push(MockOntology.mockReadOntology('http://0.0.0.0:3333/ontology/0001/minimal/v2'));
266+
const response: ReadOntology[] = ontologies;
267+
return of(response);
268+
}
269+
);
270+
264271
// mock cache service for currentOntologyLists
265272
const cacheSpyLists = TestBed.inject(CacheService);
266273
(cacheSpyLists as jasmine.SpyObj<CacheService>).get.withArgs('currentOntologyLists').and.callFake(

‎src/app/project/ontology/property-form/property-form.component.ts‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ import { AutocompleteItem } from 'src/app/workspace/search/advanced-search/resou
2929
import { DefaultProperties, DefaultProperty, PropertyCategory, PropertyInfoObject } from '../default-data/default-properties';
3030
import { OntologyService } from '../ontology.service';
3131

32+
export interface ClassToSelect {
33+
ontologyId: string;
34+
ontologyLabel: string;
35+
classes: ClassDefinition[];
36+
}
37+
3238
@Component({
3339
selector: 'app-property-form',
3440
templateUrl: './property-form.component.html',
@@ -106,7 +112,7 @@ export class PropertyFormComponent implements OnInit {
106112
lists: ListNodeInfo[];
107113

108114
// resource classes in this ontology
109-
resourceClasses: ClassDefinition[] = [];
115+
ontologyClasses: ClassToSelect[] = [];
110116

111117
loading = false;
112118

@@ -136,15 +142,12 @@ export class PropertyFormComponent implements OnInit {
136142

137143
this.loading = true;
138144

145+
// set various lists to select from
139146
this._cache.get('currentOntology').subscribe(
140147
(response: ReadOntology) => {
141148
this.ontology = response;
142149
this.lastModificationDate = response.lastModificationDate;
143150

144-
// set various lists to select from
145-
// a) in case of link value:
146-
// set list of resource classes from response; needed for linkValue
147-
this.resourceClasses = response.getAllClassDefinitions();
148151
const resourceProperties = response.getAllPropertyDefinitions();
149152

150153
// set list of all existing resource property names to avoid same name twice
@@ -156,7 +159,7 @@ export class PropertyFormComponent implements OnInit {
156159
});
157160

158161
// add all resource classes to the same list
159-
this.resourceClasses.forEach((resClass: ClassDefinition) => {
162+
response.getAllClassDefinitions().forEach((resClass: ClassDefinition) => {
160163
const name = this._os.getNameFromIri(resClass.id);
161164
this.existingNames.push(
162165
new RegExp('(?:^|W)' + name.toLowerCase() + '(?:$|W)')
@@ -169,8 +172,25 @@ export class PropertyFormComponent implements OnInit {
169172
}
170173
);
171174

172-
// b) in case of list value:s
175+
// a) in case of link value:
176+
// set list of resource classes from response; needed for linkValue
177+
this._cache.get('currentProjectOntologies').subscribe(
178+
(response: ReadOntology[]) => {
179+
// reset list of ontology classes
180+
this.ontologyClasses = [];
181+
response.forEach(onto => {
182+
const ontoClasses: ClassToSelect = {
183+
ontologyId: onto.id,
184+
ontologyLabel: onto.label,
185+
classes: onto.getAllClassDefinitions()
186+
};
187+
this.ontologyClasses.push(ontoClasses);
188+
});
189+
190+
}
191+
);
173192

193+
// b) in case of list value:
174194
// set list of lists; needed for listValue
175195
this._cache.get('currentOntologyLists').subscribe(
176196
(response: ListNodeInfo[]) => {

0 commit comments

Comments
 (0)