Project

General

Profile

1 59152 argiro.kok
import {Component, Input, OnChanges, OnInit, SimpleChanges} from '@angular/core';
2 58275 k.triantaf
import {OpenAireJsonldConverterService} from './service/open-aire-jsonld-converter.service';
3
import {JsonldDocumentSerializerService} from './service/jsonld-document-serializer.service';
4
5 52061 argiro.kok
@Component({
6
  selector: 'schema2jsonld',
7
  template: `
8 58275 k.triantaf
    <ngx-json-ld [json]="json"></ngx-json-ld>
9 52061 argiro.kok
  `
10
})
11 59152 argiro.kok
export class Schema2jsonldComponent  implements OnInit, OnChanges  {
12 58275 k.triantaf
  @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 59134 argiro.kok
  @Input() description;
20 58275 k.triantaf
  public json;
21
22
  constructor(private documentParser: OpenAireJsonldConverterService,
23
              private documentSerializer: JsonldDocumentSerializerService) {
24
25 52061 argiro.kok
  }
26 59152 argiro.kok
  ngOnChanges(changes: SimpleChanges): void {
27
    if (changes.description) {
28
      this.createJson();
29
    }
30
  }
31 52061 argiro.kok
  ngOnInit() {
32 59152 argiro.kok
    this.createJson();
33
  }
34
35
  createJson(){
36 58275 k.triantaf
    var docOvject;
37
    if (this.type == 'project') {
38 59152 argiro.kok
      docOvject = this.documentParser.convertProject(this.data, this.URL);
39 58275 k.triantaf
      this.json = this.documentSerializer.serializeOrganization(docOvject);
40
    } else if (this.type == 'organization') {
41 59152 argiro.kok
      docOvject = this.documentParser.convertOrganization(this.data, this.URL, this.description);
42 58275 k.triantaf
      this.json = this.documentSerializer.serializeOrganization(docOvject);
43
    } else if (this.type == 'datasource') {
44
      docOvject = this.documentParser.convertDatasource(this.data, this.URL, this.otherURL);
45
      this.json = this.documentSerializer.serializeOrganization(docOvject);
46
    } else if (this.type == 'home') {
47 59134 argiro.kok
      this.json = this.documentParser.createHome(this.name, this.URL, this.logoURL, this.description);
48 58275 k.triantaf
    } else if (this.type == 'search') {
49 59134 argiro.kok
      this.json = this.documentParser.createSearchPage(this.name, this.URL, this.logoURL, this.searchAction, this.description);
50 58275 k.triantaf
    } else if (this.type == 'result') {
51
      docOvject = this.documentParser.convertResult(this.data, this.URL);
52
      this.json = this.documentSerializer.serializeDataset(docOvject);
53
    } else {
54 59134 argiro.kok
      this.json = this.documentParser.createSimplePage(this.name, this.URL, this.description);
55 58275 k.triantaf
    }
56 52061 argiro.kok
  }
57
}