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 = false;
18
  @Input() type = "result";
19
  @Input() description = null;
20
  @Input() searchActionRoute =  "/search/find/";
21
  public json;
22
  
23
  constructor(private documentParser: OpenAireJsonldConverterService,
24
              private documentSerializer: JsonldDocumentSerializerService) {
25
    
26
  }
27
  ngOnChanges(changes: SimpleChanges): void {
28
    if (changes.description) {
29
      this.createJson();
30
    }
31
  }
32
  ngOnInit() {
33
    this.createJson();
34
  }
35

    
36
  createJson(){
37
    var docOvject;
38
    if (this.type == 'project') {
39
      docOvject = this.documentParser.convertProject(this.data, this.URL);
40
      this.json = this.documentSerializer.serializeOrganization(docOvject);
41
    } else if (this.type == 'organization') {
42
      docOvject = this.documentParser.convertOrganization(this.data, this.URL, this.description);
43
      this.json = this.documentSerializer.serializeOrganization(docOvject);
44
    } else if (this.type == 'datasource') {
45
      docOvject = this.documentParser.convertDatasource(this.data, this.URL, this.otherURL);
46
      this.json = this.documentSerializer.serializeOrganization(docOvject);
47
    } else if (this.type == 'home') {
48
      this.json = this.documentParser.createHome(this.name, this.URL, this.logoURL, this.description, this.searchActionRoute);
49
    } else if (this.type == 'search') {
50
      this.json = this.documentParser.createSearchPage(this.name, this.URL, this.logoURL, this.searchAction, this.description, this.searchActionRoute );
51
    } else if (this.type == 'result') {
52
      docOvject = this.documentParser.convertResult(this.data, this.URL);
53
      this.json = this.documentSerializer.serializeDataset(docOvject);
54
    } else {
55
      this.json = this.documentParser.createSimplePage(this.name, this.URL, this.description);
56
    }
57
  }
58
}
(1-1/2)