/
ontology-class-item.component.ts
85 lines (63 loc) · 2.42 KB
/
ontology-class-item.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
import { Component, Inject, Input, OnInit } from '@angular/core';
import { ActivatedRoute, Router } from '@angular/router';
import { ClassDefinition, KnoraApiConnection, CountQueryResponse, ApiResponseError } from '@dasch-swiss/dsp-js';
import { DspApiConnectionToken } from 'src/app/main/declarations/dsp-api-tokens';
import { ErrorHandlerService } from 'src/app/main/services/error-handler.service';
import { OntologyService } from 'src/app/project/ontology/ontology.service';
@Component({
selector: 'app-ontology-class-item',
templateUrl: './ontology-class-item.component.html',
styleUrls: ['./ontology-class-item.component.scss']
})
export class OntologyClassItemComponent implements OnInit {
@Input() resClass: ClassDefinition;
@Input() projectMember: boolean;
gravsearch: string;
results: number;
link: string;
// i18n setup
itemPluralMapping = {
resource: {
'=1': '1 resource',
other: '# resources'
}
};
constructor(
@Inject(DspApiConnectionToken) private _dspApiConnection: KnoraApiConnection,
private _errorHandler: ErrorHandlerService,
private _ontologyService: OntologyService,
private _route: ActivatedRoute,
private _router: Router
) {
}
ngOnInit(): void {
const projectCode = this._route.snapshot.params.shortcode;
const splitIri = this.resClass.id.split('#');
const ontologyName = this._ontologyService.getOntologyName(splitIri[0]);
this.link = `/beta/project/${projectCode}/ontology/${ontologyName}/${splitIri[1]}`;
this.gravsearch = this._setGravsearch(this.resClass.id);
// get number of resource instances
this._dspApiConnection.v2.search.doExtendedSearchCountQuery(this.gravsearch).subscribe(
(res: CountQueryResponse) => {
this.results = res.numberOfResults;
},
(error: ApiResponseError) => {
this._errorHandler.showMessage(error);
}
);
}
open(route: string) {
this._router.navigateByUrl(route);
}
private _setGravsearch(iri: string): string {
return `
PREFIX knora-api: <http://api.knora.org/ontology/knora-api/v2#>
CONSTRUCT {
?mainRes knora-api:isMainResource true .
} WHERE {
?mainRes a knora-api:Resource .
?mainRes a <${iri}> .
}
OFFSET 0`;
}
}