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 { Meta} from '../../../angular2-meta';
9

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

    
18
  results = [];
19

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

    
26
  entityTypes=["dataset", "publication", "project","context"];
27
  inlineResult:ClaimResult =null;
28
  displayedResult:ClaimResult =null;
29
  sub:any =null;
30
  show:string="claim"; //{claim,result}
31
  validInput:boolean = null;//'true;
32
  constructor ( private _router: Router,  private route: ActivatedRoute, private entitySearch:EntitiesSearchService,
33
    private publicationsSearch:SearchPublicationsService, private datasetsSearch:SearchDatasetsService, private _meta: Meta) {
34
      this._meta.setTitle("OpenAIRE | Direct Linking");
35
  }
36
  ngOnInit() {
37
    if(localStorage.getItem("projects")){
38
      this.projects  = JSON.parse(localStorage.getItem("projects"));
39
    }
40
    if(localStorage.getItem("contexts")){
41
      this.contexts  = JSON.parse(localStorage.getItem("contexts"));
42
    }
43
    if(localStorage.getItem("results")){
44
      this.results  = JSON.parse(localStorage.getItem("results"));
45
    }
46
    if(localStorage.getItem("results")){
47
      this.results  = JSON.parse(localStorage.getItem("results"));
48
    }
49
    if(localStorage.getItem("inlineEntity")){
50
      this.inlineResult  = JSON.parse(localStorage.getItem("inlineEntity"));
51
    }
52

    
53
    localStorage.removeItem("projects");
54
    localStorage.removeItem("contexts");
55
    localStorage.removeItem("results");
56
    localStorage.removeItem("inlineEntity");
57

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

    
82
       }else{
83
         this.validInput = this.isValidInput(null);
84

    
85
       }
86

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

    
119
            this.projects.push( project);
120
            this.validInput = this.isValidInput(project);
121

    
122
          },
123
        err => {
124
          this.validInput = this.isValidInput(null);
125
          console.log("An error occured")
126
        });
127
      }
128
    getPublicationById(id:string, isInlineResult:boolean){
129

    
130
        this.sub = this.publicationsSearch.searchPublicationById(id).subscribe(
131
          data => {
132
             var item =data[0];
133
            var result: ClaimResult = new ClaimResult();
134
            result.id=id;
135
            result.type="publication";
136
            result.source="openaire";
137
            result.title = item['title'].name;
138
            result.url= item['title'].url;
139
            result.result = item;
140
            result.accessRights = item['title'].accessMode;
141
            result.date = item.year;
142
            this.displayedResult = result;
143
            if(isInlineResult){
144
              this.inlineResult = result;
145
            }else{
146
              this.results.push( result);
147
            }
148
            this.validInput = this.isValidInput(result);
149
        },
150
      err =>  {
151
        this.validInput = this.isValidInput(null);
152
        console.log("An error occured")
153
      });
154
      }
155
    getDatasetById(id:string, isInlineResult:boolean){
156
        this.sub = this.datasetsSearch.searchDatasetById(id).subscribe(
157
          data => {
158
             var item =data[0];
159
             var result: ClaimResult = new ClaimResult();
160
             result.id=id;
161
             result.type="dataset";
162
             result.source="openaire";
163
             result.title = item['title'].name;
164
             result.url= item['title'].url;
165
             result.result = item;
166
             result.accessRights = item['title'].accessMode;
167
             result.date = item.year;             this.displayedResult = result;
168
             if(isInlineResult){
169
               this.inlineResult = result;
170
             }else{
171
               this.results.push( result);
172
             }
173
             this.validInput = this.isValidInput(result);
174
        },
175
      err =>  {
176
        this.validInput = this.isValidInput(null);
177
        console.log("An error occured")
178
      });
179

    
180
  }
181

    
182

    
183

    
184

    
185

    
186

    
187

    
188
}
(3-3/4)