/
property-info.component.ts
135 lines (115 loc) · 4.94 KB
/
property-info.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import { AfterContentInit, Component, Input, OnInit } from '@angular/core';
import { MatIconRegistry } from '@angular/material/icon';
import { DomSanitizer } from '@angular/platform-browser';
import {
ApiResponseData,
Constants,
IHasProperty,
ListNodeInfo,
ListsResponse,
ReadOntology,
ResourcePropertyDefinitionWithAllLanguages
} from '@dasch-swiss/dsp-js';
import { CacheService } from 'src/app/main/cache/cache.service';
import { Category, DefaultProperties, PropertyType } from '../default-data/default-properties';
import { Property } from '../resource-class-form/resource-class-form.service';
@Component({
selector: 'app-property-info',
templateUrl: './property-info.component.html',
styleUrls: ['./property-info.component.scss']
})
export class PropertyInfoComponent implements OnInit, AfterContentInit {
@Input() propDef: ResourcePropertyDefinitionWithAllLanguages;
@Input() propCard: IHasProperty;
@Input() projectcode: string;
propInfo: Property = new Property();
propType: PropertyType;
// list of default property types
propertyTypes: Category[] = DefaultProperties.data;
propAttribute: string;
constructor(
private _cache: CacheService,
private _domSanitizer: DomSanitizer,
private _matIconRegistry: MatIconRegistry
) {
// special icons for property type
this._matIconRegistry.addSvgIcon(
'integer_icon',
this._domSanitizer.bypassSecurityTrustResourceUrl('/assets/images/integer-icon.svg')
);
this._matIconRegistry.addSvgIcon(
'decimal_icon',
this._domSanitizer.bypassSecurityTrustResourceUrl('/assets/images/decimal-icon.svg')
);
}
ngOnInit(): void {
// convert cardinality from js-lib convention to app convention
switch (this.propCard.cardinality) {
case 0:
this.propInfo.multiple = false;
this.propInfo.required = true;
break;
case 1:
this.propInfo.multiple = false;
this.propInfo.required = false;
break;
case 2:
this.propInfo.multiple = true;
this.propInfo.required = false;
break;
case 3:
this.propInfo.multiple = true;
this.propInfo.required = true;
break;
}
// find gui ele from list of default property-types to set type value
if (this.propDef.guiElement) {
for (let group of this.propertyTypes) {
this.propType = group.elements.find(i => i.gui_ele === this.propDef.guiElement && (i.objectType === this.propDef.objectType || i.subPropOf === this.propDef.subPropertyOf[0]));
if (this.propType) {
break;
}
}
}
}
ngAfterContentInit() {
if (this.propDef.isLinkProperty) {
// this property is a link property to another resource class
// get current ontology to get linked res class information
this._cache.get('currentOntology').subscribe(
(response: ReadOntology) => {
// get the base ontology of object type
const baseOnto = this.propDef.objectType.split('#')[0];
if (baseOnto !== response.id) {
// get class info from another ontology
this._cache.get('currentProjectOntologies').subscribe(
(response: ReadOntology[]) => {
const onto = response.find(i => i.id === baseOnto);
if (!onto && this.propDef.objectType === Constants.Region) {
this.propAttribute = 'Region';
} else {
this.propAttribute = onto.classes[this.propDef.objectType].label;
}
}
)
} else {
this.propAttribute = response.classes[this.propDef.objectType].label;
}
}
);
}
if (this.propDef.objectType === Constants.ListValue) {
// this property is a list property
// get current ontology lists to get linked list information
this._cache.get('currentOntologyLists').subscribe(
(response: ListNodeInfo[]) => {
const re: RegExp = /\<([^)]+)\>/;
const listIri = this.propDef.guiAttributes[0].match(re)[1];
const listUrl = `/project/${this.projectcode}/lists/${encodeURIComponent(listIri)}`;
const list = response.find(i => i.id === listIri);
this.propAttribute = `<a href="${listUrl}">${list.labels[0].value}</a>`;
}
);
}
}
}