1
|
import {Component, ElementRef, Input} from '@angular/core';
|
2
|
import {OpenAireJsonldConverterService} from './service/open-aire-jsonld-converter.service';
|
3
|
import {JsonldDocumentSerializerService} from './service/jsonld-document-serializer.service';
|
4
|
|
5
|
@Component({
|
6
|
selector: 'schema2jsonld',
|
7
|
template: `
|
8
|
<ngx-json-ld [json]="json"></ngx-json-ld>
|
9
|
`
|
10
|
})
|
11
|
export class Schema2jsonldComponent {
|
12
|
@Input() data; // for project, organization, datasource
|
13
|
@Input() URL;
|
14
|
@Input() logoURL; // for home, search
|
15
|
@Input() otherURL; //for project, datasource
|
16
|
@Input() name;
|
17
|
@Input() searchAction = true;
|
18
|
@Input() type = "result";
|
19
|
public json;
|
20
|
|
21
|
constructor(private documentParser: OpenAireJsonldConverterService,
|
22
|
private documentSerializer: JsonldDocumentSerializerService) {
|
23
|
|
24
|
}
|
25
|
|
26
|
ngOnInit() {
|
27
|
var docOvject;
|
28
|
if (this.type == 'project') {
|
29
|
docOvject = this.documentParser.convertProject(this.data, this.URL, this.otherURL);
|
30
|
this.json = this.documentSerializer.serializeOrganization(docOvject);
|
31
|
} else if (this.type == 'organization') {
|
32
|
docOvject = this.documentParser.convertOrganization(this.data, this.URL);
|
33
|
this.json = this.documentSerializer.serializeOrganization(docOvject);
|
34
|
} else if (this.type == 'datasource') {
|
35
|
docOvject = this.documentParser.convertDatasource(this.data, this.URL, this.otherURL);
|
36
|
this.json = this.documentSerializer.serializeOrganization(docOvject);
|
37
|
} else if (this.type == 'home') {
|
38
|
this.json = this.documentParser.createHome(this.name, this.URL, this.logoURL);
|
39
|
} else if (this.type == 'search') {
|
40
|
this.json = this.documentParser.createSearchPage(this.name, this.URL, this.logoURL, this.searchAction);
|
41
|
} else if (this.type == 'result') {
|
42
|
docOvject = this.documentParser.convertResult(this.data, this.URL);
|
43
|
this.json = this.documentSerializer.serializeDataset(docOvject);
|
44
|
} else {
|
45
|
this.json = this.documentParser.createSimplePage(this.name, this.URL);
|
46
|
}
|
47
|
}
|
48
|
}
|