Project

General

Profile

1
import {Component, Input, OnChanges, OnInit, SimpleChanges} 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  implements OnInit, OnChanges  {
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
  @Input() description;
20
  public json;
21
  
22
  constructor(private documentParser: OpenAireJsonldConverterService,
23
              private documentSerializer: JsonldDocumentSerializerService) {
24
    
25
  }
26
  ngOnChanges(changes: SimpleChanges): void {
27
    if (changes.description) {
28
      this.createJson();
29
    }
30
  }
31
  ngOnInit() {
32
    this.createJson();
33
  }
34

    
35
  createJson(){
36
    var docOvject;
37
    if (this.type == 'project') {
38
      docOvject = this.documentParser.convertProject(this.data, this.URL);
39
      this.json = this.documentSerializer.serializeOrganization(docOvject);
40
    } else if (this.type == 'organization') {
41
      docOvject = this.documentParser.convertOrganization(this.data, this.URL, this.description);
42
      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
      this.json = this.documentParser.createHome(this.name, this.URL, this.logoURL, this.description);
48
    } else if (this.type == 'search') {
49
      this.json = this.documentParser.createSearchPage(this.name, this.URL, this.logoURL, this.searchAction, this.description);
50
    } else if (this.type == 'result') {
51
      docOvject = this.documentParser.convertResult(this.data, this.URL);
52
      this.json = this.documentSerializer.serializeDataset(docOvject);
53
    } else {
54
      this.json = this.documentParser.createSimplePage(this.name, this.URL, this.description);
55
    }
56
  }
57
}
(1-1/2)