Project

General

Profile

1
import {Component, Input} from '@angular/core';
2
import {Observable}       from 'rxjs/Observable';
3
import {ActivatedRoute, Router} from '@angular/router';
4
import {EntitiesSearchService} from '../../utils/entitiesAutoComplete/entitySearch.service';
5
import {ClaimProject, ClaimResult} from '../claim-utils/claimEntities.class';
6
import {SearchPublicationsService} from '../../services/searchPublications.service';
7
import {SearchDatasetsService} from '../../services/searchDatasets.service';
8
import {SearchSoftwareService} from '../../services/searchSoftware.service';
9
import{EnvProperties} from '../../utils/properties/env-properties';
10

    
11
import { Meta} from '../../sharedComponents/metaService';
12

    
13
@Component({
14
    selector: 'directLinking',
15
    templateUrl: 'directLinking.component.html'
16
})
17
export class DirectLinkingComponent {
18
  contexts=[];
19
  projects=[];
20

    
21
  results = [];
22

    
23
  linkType:string ="project"; // link type (selected in home page) : project, context, software, etc
24
  /* url Parameters for inline linking */
25
  id:string = null; //entity id
26
  type:string = null; // entity type (publication or dataset)
27
  linkTo:string = null; // entity type (project or context or result)
28

    
29
  entityTypes=["dataset", "publication","software", "project","context"];
30
  inlineResult:ClaimResult =null;
31
  displayedResult:ClaimResult =null;
32
  sub:any =null;
33
  show:string="claim"; //{claim,result}
34
  validInput:boolean = null;//'true;
35
  properties:EnvProperties;
36

    
37
  constructor ( private _router: Router,  private route: ActivatedRoute, private entitySearch:EntitiesSearchService,
38
    private publicationsSearch:SearchPublicationsService, private datasetsSearch:SearchDatasetsService, private softwareSearch:SearchSoftwareService, private _meta: Meta) {
39
      this._meta.setTitle("OpenAIRE | Direct Linking");
40
  }
41
  ngOnInit() {
42
    this.route.data
43
      .subscribe((data: { envSpecific: EnvProperties }) => {
44
         this.properties = data.envSpecific;
45

    
46
      });
47
    if(localStorage.getItem("projects")){
48
      this.projects  = JSON.parse(localStorage.getItem("projects"));
49
    }
50
    if(localStorage.getItem("contexts")){
51
      this.contexts  = JSON.parse(localStorage.getItem("contexts"));
52
    }
53
    if(localStorage.getItem("results")){
54
      this.results  = JSON.parse(localStorage.getItem("results"));
55
    }
56
    if(localStorage.getItem("inlineEntity")){
57
      this.inlineResult  = JSON.parse(localStorage.getItem("inlineEntity"));
58
    }
59

    
60
    localStorage.removeItem("projects");
61
    localStorage.removeItem("contexts");
62
    localStorage.removeItem("results");
63
    localStorage.removeItem("inlineEntity");
64

    
65
    this.sub = this.route.queryParams.subscribe(params => {
66
       this.id = params['id'];
67
       this.type = params['type'];
68
       this.linkTo = params['linkTo'];
69
       if(this.type!=null && this.linkTo!=null){
70
         this.type = (this.entityTypes.indexOf(this.type) != -1)? this.type:'publication';
71
         this.linkTo = (this.entityTypes.indexOf(this.linkTo) != -1 || this.linkTo == "result")? this.linkTo:'project';
72
         this.show = (this.linkTo != "result")?"claim":"result";
73
         this.linkType = this.linkTo;
74
         var isInlineResult:boolean = false; // is a link result - result
75
         if((this.type == "publication" || this.type == "dataset" || this.type == "software") && ((this.linkTo == "publication" || this.linkTo == "dataset" || this.linkTo == "software") ||  this.linkTo == "result" )){
76
           isInlineResult = true;
77
         }
78
         if(this.type == "project"){
79
           this.linkType = "project";
80
           this.getProjectById(this.id);
81
         }else if(this.type == "publication"){
82
            this.getPublicationById(this.id,true);
83
         }else if(this.type == "dataset"){
84
            this.getDatasetById(this.id,true);
85
          }else if(this.type == "software"){
86
             this.getSoftwareById(this.id,true);
87
           }else{
88
            this.validInput = this.isValidInput(null);
89
          }
90

    
91
       }else{
92
         this.validInput = this.isValidInput(null);
93

    
94
       }
95

    
96
   });
97
  }
98
  isValidInput(result){
99
    if(result == null){
100
      return false;
101
    }else if(this.type == "project" && this.linkTo != "result"){
102
      return false;
103
    }else if(["dataset","publication","software"].indexOf(this.type) != -1 && (["project","context","result"].indexOf(this.linkTo) == -1)){
104
      return false;
105
    }else if(["project","dataset","publication","software"].indexOf(this.type) == -1){
106
      return false;
107
    }else{
108
      return true;
109
    }
110
  }
111
  getProjectById(id:string){
112
       this.sub = this.entitySearch.fetchByType(id,"project", this.properties).subscribe(
113
        data => {
114
          console.log(data);
115
          var item =data[0];
116
             var project: ClaimProject = new ClaimProject();
117
              project.funderId = item.funderId;
118
              project.funderName = item.funderName;
119
              project.projectId = id;
120
              project.projectName = item.projectName;
121
              project.projectAcronym = item.projectAcronym;
122
              project.startDate = item.startDate;
123
              project.endDate = item.endDate;
124
              project.code = item.code;
125
              project.jurisdiction = item.jurisdiction;
126
              project.fundingLevel0 = item.fundingLevel0;
127

    
128
            this.projects.push( project);
129
            this.validInput = this.isValidInput(project);
130

    
131
          },
132
        err => {
133
          this.validInput = this.isValidInput(null);
134
          console.log("An error occured")
135
        });
136
      }
137
    getPublicationById(id:string, isInlineResult:boolean){
138

    
139
        this.sub = this.publicationsSearch.searchPublicationById(id,this.properties).subscribe(
140
          data => {
141
             var item =data[0];
142
            var result: ClaimResult = new ClaimResult();
143
            result.id=id;
144
            result.type="publication";
145
            result.source="openaire";
146
            result.title = item['title'].name;
147
            result.url= item['title'].url;
148
            result.result = item;
149
            result.accessRights = item['title'].accessMode;
150
            result.date = item.year;
151
            this.displayedResult = result;
152
            if(isInlineResult){
153
              this.inlineResult = result;
154
            }else{
155
              this.results.push( result);
156
            }
157
            this.validInput = this.isValidInput(result);
158
        },
159
      err =>  {
160
        this.validInput = this.isValidInput(null);
161
        console.log("An error occured")
162
      });
163
      }
164
    getDatasetById(id:string, isInlineResult:boolean){
165
        this.sub = this.datasetsSearch.searchDatasetById(id,this.properties).subscribe(
166
          data => {
167
             var item =data[0];
168
             var result: ClaimResult = new ClaimResult();
169
             result.id=id;
170
             result.type="dataset";
171
             result.source="openaire";
172
             result.title = item['title'].name;
173
             result.url= item['title'].url;
174
             result.result = item;
175
             result.accessRights = item['title'].accessMode;
176
             result.date = item.year;
177
             this.displayedResult = result;
178
             if(isInlineResult){
179
               this.inlineResult = result;
180
             }else{
181
               this.results.push( result);
182
             }
183
             this.validInput = this.isValidInput(result);
184
        },
185
      err =>  {
186
        this.validInput = this.isValidInput(null);
187
        console.log("An error occured")
188
      });
189
  }
190
  getSoftwareById(id:string, isInlineResult:boolean){
191
      this.sub = this.softwareSearch.searchSoftwareById(id,this.properties).subscribe(
192
        data => {
193
           var item =data[0];
194
           var result: ClaimResult = new ClaimResult();
195
           result.id=id;
196
           result.type="software";
197
           result.source="openaire";
198
           result.title = item['title'].name;
199
           result.url= item['title'].url;
200
           result.result = item;
201
           result.accessRights = item['title'].accessMode;
202
           result.date = item.year;
203
           this.displayedResult = result;
204
           if(isInlineResult){
205
             this.inlineResult = result;
206
           }else{
207
             this.results.push( result);
208
           }
209
           this.validInput = this.isValidInput(result);
210
      },
211
    err =>  {
212
      this.validInput = this.isValidInput(null);
213
      console.log("An error occured")
214
    });
215
}
216
}
(2-2/3)