/
search-resource.component.ts
63 lines (43 loc) · 1.96 KB
/
search-resource.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { Component, Inject, Input, OnInit, ViewChild } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Constants } from '@dasch-swiss/dsp-js';
import { ResourceAndPropertySelectionComponent } from '../../../resource-and-property-selection.component';
import { LinkedResource, PropertyValue, PropertyWithValue, Value } from '../operator';
// https://stackoverflow.com/questions/45661010/dynamic-nested-reactive-form-expressionchangedafterithasbeencheckederror
const resolvedPromise = Promise.resolve(null);
@Component({
selector: 'app-search-resource',
templateUrl: './search-resource.component.html',
styleUrls: ['./search-resource.component.scss']
})
export class SearchResourceComponent implements OnInit, PropertyValue {
// parent FormGroup
@Input() formGroup: FormGroup;
@Input() restrictResourceClass: string;
// reference to the component that controls the resource class selection
@ViewChild('resAndPropSel') resourceAndPropertySelection: ResourceAndPropertySelectionComponent;
type = Constants.Resource;
form: FormGroup;
ontology: string;
constructor(@Inject(FormBuilder) private _fb: FormBuilder) {
}
ngOnInit(): void {
this.form = this._fb.group({});
resolvedPromise.then(() => {
this.formGroup.addControl('propValue', this.form);
});
// get ontology from restriction
this.ontology = this.restrictResourceClass.split('#')[0];
}
getValue(): Value {
const resClassOption = this.resourceAndPropertySelection.resourceClassComponent.selectedResourceClassIri;
let resClass;
if (resClassOption !== false) {
resClass = resClassOption;
}
const properties: PropertyWithValue[] = this.resourceAndPropertySelection.propertyComponents.map(
(propComp) => propComp.getPropertySelectedWithValue()
);
return new LinkedResource(properties, resClass);
}
}