2018-11-12 16:36:20 +01:00
|
|
|
import {Component, ElementRef, Input} from '@angular/core';
|
|
|
|
import { OpenAireJsonldConverterService } from './service/open-aire-jsonld-converter.service';
|
|
|
|
import { JsonldDocumentSerializerService } from './service/jsonld-document-serializer.service';
|
|
|
|
@Component({
|
|
|
|
selector: 'schema2jsonld',
|
|
|
|
template: `
|
|
|
|
<ngx-json-ld [json]="json"></ngx-json-ld>
|
|
|
|
`
|
|
|
|
})
|
|
|
|
export class Schema2jsonldComponent {
|
2018-11-13 14:01:38 +01:00
|
|
|
@Input() data; // for project, organization, datasource
|
2018-11-12 16:36:20 +01:00
|
|
|
@Input() URL;
|
2018-11-13 14:01:38 +01:00
|
|
|
@Input() logoURL; // for home, search
|
|
|
|
@Input() otherURL; //for project, datasource
|
2018-11-12 16:36:20 +01:00
|
|
|
@Input() name;
|
2018-11-14 11:38:53 +01:00
|
|
|
@Input() searchAction = true;
|
2018-11-12 16:36:20 +01:00
|
|
|
@Input() type="result";
|
|
|
|
|
|
|
|
json;
|
|
|
|
constructor( private documentParser: OpenAireJsonldConverterService,
|
|
|
|
private documentSerializer: JsonldDocumentSerializerService) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
var docOvject;
|
|
|
|
if(this.type == 'project'){
|
|
|
|
docOvject = this.documentParser.convertProject(this.data, this.URL, this.otherURL);
|
|
|
|
this.json = this.documentSerializer.serializeOrganization(docOvject);
|
|
|
|
}else if(this.type == 'organization'){
|
|
|
|
docOvject = this.documentParser.convertOrganization(this.data, this.URL);
|
|
|
|
this.json = this.documentSerializer.serializeOrganization(docOvject);
|
|
|
|
}else if(this.type == 'datasource'){
|
|
|
|
docOvject = this.documentParser.convertDatasource(this.data, this.URL, this.otherURL);
|
|
|
|
this.json = this.documentSerializer.serializeOrganization(docOvject);
|
|
|
|
}else if(this.type == 'home'){
|
|
|
|
this.json = this.documentParser.createHome(this.name, this.URL, this.logoURL);
|
2018-11-13 14:01:38 +01:00
|
|
|
}else if(this.type == 'search'){
|
2018-11-14 11:38:53 +01:00
|
|
|
this.json = this.documentParser.createSearchPage(this.name, this.URL, this.logoURL, this.searchAction);
|
|
|
|
}else if(this.type == 'result'){
|
2018-11-12 16:36:20 +01:00
|
|
|
docOvject = this.documentParser.convertResult(this.data, this.URL);
|
|
|
|
this.json = this.documentSerializer.serializeDataset(docOvject);
|
2018-11-14 11:38:53 +01:00
|
|
|
}else{
|
|
|
|
this.json = this.documentParser.createSimplePage(this.name, this.URL);
|
2018-11-12 16:36:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|