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 {Title, Meta}                  from '@angular/platform-browser';
5

    
6
import {EnvProperties}                from '../../utils/properties/env-properties';
7

    
8
import {ClaimProject, ClaimResult}    from '../claim-utils/claimEntities.class';
9

    
10
import {EntitiesSearchService}        from '../../utils/entitiesAutoComplete/entitySearch.service';
11
import {SearchPublicationsService}    from '../../services/searchPublications.service';
12
import {SearchDatasetsService}        from '../../services/searchDatasets.service';
13
import {SearchSoftwareService}        from '../../services/searchSoftware.service';
14
import {SearchOrpsService}        from '../../services/searchOrps.service';
15
import { SEOService } from '../../sharedComponents/SEO/SEO.service';
16

    
17

    
18
@Component({
19
    selector: 'directLinking',
20
    templateUrl: 'directLinking.component.html'
21
})
22
export class DirectLinkingComponent {
23
  contexts=[];
24
  projects=[];
25

    
26
  results = [];
27

    
28
  linkType:string ="project"; // link type (selected in home page) : project, context, software, etc
29
  /* url Parameters for inline linking */
30
  id:string = null; //entity id
31
  type:string = null; // entity type (publication or dataset)
32
  linkTo:string = null; // entity type (project or context or result)
33

    
34
  entityTypes=["dataset", "publication","software","orp", "project","context"];
35
  inlineResult:ClaimResult =null;
36
  displayedResult:ClaimResult =null;
37
  sub:any =null;
38
  show:string="claim"; //{claim,result}
39
  validInput:boolean = null;//'true;
40
  properties:EnvProperties;
41
  @Input() communityId:string= null;
42
  localStoragePrefix:string = "";
43
  url=null;
44

    
45
  constructor (private _router: Router, private route: ActivatedRoute, private entitySearch:EntitiesSearchService,
46
               private publicationsSearch:SearchPublicationsService, private datasetsSearch:SearchDatasetsService,
47
               private softwareSearch:SearchSoftwareService,private ORPSearch:SearchOrpsService,
48
                private _meta: Meta, private _title: Title, private seoService: SEOService ) {
49

    
50
                  var title = "OpenAIRE | Direct Linking";
51

    
52
                  this._meta.updateTag({content:title},"property='og:title'");
53
                  this._title.setTitle(title);
54
                  this.seoService.createLinkForCanonicalURL(false);
55

    
56
  }
57
  ngOnInit() {
58
    this.route.data
59
      .subscribe((data: { envSpecific: EnvProperties }) => {
60
         this.properties = data.envSpecific;
61
         this.url = data.envSpecific.baseLink+this._router.url;
62

    
63
      });
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 == "orp") ||  this.linkTo == "result" )){
76
           isInlineResult = true;
77
         }
78
         this.localStoragePrefix = this.type.substr(0,3)+"_"+this.linkTo.substr(0,3)+"_";
79
         console.log("\n\n"+this.localStoragePrefix+"\n\n");
80
         if(localStorage.getItem(this.localStoragePrefix + "projects")){
81
           this.projects  = JSON.parse(localStorage.getItem(this.localStoragePrefix + "projects"));
82
         }
83
         if(localStorage.getItem(this.localStoragePrefix + "contexts")){
84
           this.contexts  = JSON.parse(localStorage.getItem(this.localStoragePrefix + "contexts"));
85
         }
86
         if(localStorage.getItem(this.localStoragePrefix + "results")){
87
           this.results  = JSON.parse(localStorage.getItem(this.localStoragePrefix + "results"));
88
         }
89
         console.log("\n\nGetting inline entity "+this.type+"\n\n");
90
         if(this.type == "project"){
91
           this.linkType = "project";
92
           this.getProjectById(this.id);
93
         }else if(this.type == "publication"){
94
            this.getPublicationById(this.id,true);
95
         }else if(this.type == "dataset"){
96
            this.getDatasetById(this.id,true);
97
          }else if(this.type == "software"){
98
             this.getSoftwareById(this.id,true);
99
          }else if(this.type == "orp"){
100
             this.getOrpById(this.id,true);
101
           }else{
102
            this.validInput = this.isValidInput(null);
103
          }
104

    
105
       }else{
106
         this.validInput = this.isValidInput(null);
107

    
108
       }
109

    
110
   });
111
  }
112
  isValidInput(result){
113
    if(result == null){
114
      return false;
115
    }else if(this.type == "project" && this.linkTo != "result"){
116
      return false;
117
    }else if(["dataset","publication","software", "orp"].indexOf(this.type) != -1 && (["project","context","result"].indexOf(this.linkTo) == -1)){
118
      return false;
119
    }else if(["project","dataset","publication","software","orp"].indexOf(this.type) == -1){
120
      return false;
121
    }else{
122
      return true;
123
    }
124
  }
125
  getProjectById(id:string){
126
       this.sub = this.entitySearch.fetchByType(id,"project", this.properties).subscribe(
127
        data => {
128
          console.log(data);
129
          var item =data[0];
130
             var project: ClaimProject = new ClaimProject();
131
              project.funderId = item.funderId;
132
              project.funderName = item.funderName;
133
              project.projectId = id;
134
              project.projectName = item.projectName;
135
              project.projectAcronym = item.projectAcronym;
136
              project.startDate = item.startDate;
137
              project.endDate = item.endDate;
138
              project.code = item.code;
139
              project.jurisdiction = item.jurisdiction;
140
              project.fundingLevel0 = item.fundingLevel0;
141

    
142
            this.projects.push( project);
143
            this.validInput = this.isValidInput(project);
144

    
145
          },
146
        err => {
147
          this.validInput = this.isValidInput(null);
148
          console.log("An error occured")
149
        });
150
      }
151
    getPublicationById(id:string, isInlineResult:boolean){
152

    
153
        this.sub = this.publicationsSearch.searchPublicationById(id,this.properties).subscribe(
154
          data => {
155
             var item =data[0];
156
            var result: ClaimResult = new ClaimResult();
157
            result.id=id;
158
            result.type="publication";
159
            result.source="openaire";
160
            result.title = item['title'].name;
161
            result.url= item['title'].url;
162
            result.result = item;
163
            result.accessRights = item['title'].accessMode;
164
            result.date = item.year;
165
            this.displayedResult = result;
166
            if(isInlineResult){
167
              this.inlineResult = result;
168
            }else{
169
              this.results.push( result);
170
            }
171
            this.validInput = this.isValidInput(result);
172
        },
173
      err =>  {
174
        this.validInput = this.isValidInput(null);
175
        console.log("An error occured")
176
      });
177
      }
178
    getDatasetById(id:string, isInlineResult:boolean){
179
        this.sub = this.datasetsSearch.searchDatasetById(id,this.properties).subscribe(
180
          data => {
181
             var item =data[0];
182
             var result: ClaimResult = new ClaimResult();
183
             result.id=id;
184
             result.type="dataset";
185
             result.source="openaire";
186
             result.title = item['title'].name;
187
             result.url= item['title'].url;
188
             result.result = item;
189
             result.accessRights = item['title'].accessMode;
190
             result.embargoEndDate ="";
191
             result.date = item.year;
192
             this.displayedResult = result;
193
             if(isInlineResult){
194
               this.inlineResult = result;
195
             }else{
196
               this.results.push( result);
197
             }
198
             this.validInput = this.isValidInput(result);
199
        },
200
      err =>  {
201
        this.validInput = this.isValidInput(null);
202
        console.log("An error occured")
203
      });
204
  }
205
  getSoftwareById(id:string, isInlineResult:boolean){
206
      this.sub = this.softwareSearch.searchSoftwareById(id,this.properties).subscribe(
207
        data => {
208
           var item =data[0];
209
           var result: ClaimResult = new ClaimResult();
210
           result.id=id;
211
           result.type="software";
212
           result.source="openaire";
213
           result.title = item['title'].name;
214
           result.url= item['title'].url;
215
           result.result = item;
216
           result.accessRights = item['title'].accessMode;
217
           result.embargoEndDate ="";
218
           result.date = item.year;
219
           this.displayedResult = result;
220
           if(isInlineResult){
221
             this.inlineResult = result;
222
           }else{
223
             this.results.push( result);
224
           }
225
           this.validInput = this.isValidInput(result);
226
      },
227
    err =>  {
228
      this.validInput = this.isValidInput(null);
229
      console.log("An error occured")
230
    });
231
}
232
getOrpById(id:string, isInlineResult:boolean){
233
    this.sub = this.ORPSearch.searchOrpById(id,this.properties).subscribe(
234
      data => {
235
        console.log(data)
236
         var item =data[0];
237
         var result: ClaimResult = new ClaimResult();
238
         result.id=id;
239
         result.type="other";
240
         result.source="openaire";
241
         result.title = item['title'].name;
242
         result.url= item['title'].url;
243
         result.result = item;
244
         result.accessRights = item['title'].accessMode;
245
         result.embargoEndDate ="";
246
         result.date = item.year;
247
         this.displayedResult = result;
248
         console.log(item)
249
         if(isInlineResult){
250
           this.inlineResult = result;
251
         }else{
252
           this.results.push( result);
253
         }
254
         this.validInput = this.isValidInput(result);
255
    },
256
  err =>  {
257
    this.validInput = this.isValidInput(null);
258
    console.log("An error occured")
259
  });
260
}
261
}
(2-2/3)