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
|
|
10
|
import { Meta} from '../../../angular2-meta';
|
11
|
|
12
|
@Component({
|
13
|
selector: 'directLinking',
|
14
|
templateUrl: 'directLinking.component.html'
|
15
|
})
|
16
|
export class DirectLinkingComponent {
|
17
|
contexts=[];
|
18
|
projects=[];
|
19
|
|
20
|
results = [];
|
21
|
|
22
|
linkType:string ="project"; // link type (selected in home page) : project, context, software, etc
|
23
|
/* url Parameters for inline linking */
|
24
|
id:string = null; //entity id
|
25
|
type:string = null; // entity type (publication or dataset)
|
26
|
linkTo:string = null; // entity type (project or context or result)
|
27
|
|
28
|
entityTypes=["dataset", "publication","software", "project","context"];
|
29
|
inlineResult:ClaimResult =null;
|
30
|
displayedResult:ClaimResult =null;
|
31
|
sub:any =null;
|
32
|
show:string="claim"; //{claim,result}
|
33
|
validInput:boolean = null;//'true;
|
34
|
constructor ( private _router: Router, private route: ActivatedRoute, private entitySearch:EntitiesSearchService,
|
35
|
private publicationsSearch:SearchPublicationsService, private datasetsSearch:SearchDatasetsService, private softwareSearch:SearchSoftwareService, private _meta: Meta) {
|
36
|
this._meta.setTitle("OpenAIRE | Direct Linking");
|
37
|
}
|
38
|
ngOnInit() {
|
39
|
if(localStorage.getItem("projects")){
|
40
|
this.projects = JSON.parse(localStorage.getItem("projects"));
|
41
|
}
|
42
|
if(localStorage.getItem("contexts")){
|
43
|
this.contexts = JSON.parse(localStorage.getItem("contexts"));
|
44
|
}
|
45
|
if(localStorage.getItem("results")){
|
46
|
this.results = JSON.parse(localStorage.getItem("results"));
|
47
|
}
|
48
|
if(localStorage.getItem("inlineEntity")){
|
49
|
this.inlineResult = JSON.parse(localStorage.getItem("inlineEntity"));
|
50
|
}
|
51
|
|
52
|
localStorage.removeItem("projects");
|
53
|
localStorage.removeItem("contexts");
|
54
|
localStorage.removeItem("results");
|
55
|
localStorage.removeItem("inlineEntity");
|
56
|
|
57
|
this.sub = this.route.queryParams.subscribe(params => {
|
58
|
this.id = params['id'];
|
59
|
this.type = params['type'];
|
60
|
this.linkTo = params['linkTo'];
|
61
|
if(this.type!=null && this.linkTo!=null){
|
62
|
this.type = (this.entityTypes.indexOf(this.type) != -1)? this.type:'publication';
|
63
|
this.linkTo = (this.entityTypes.indexOf(this.linkTo) != -1 || this.linkTo == "result")? this.linkTo:'project';
|
64
|
this.show = (this.linkTo != "result")?"claim":"result";
|
65
|
this.linkType = this.linkTo;
|
66
|
var isInlineResult:boolean = false; // is a link result - result
|
67
|
// if((this.type == "publication" || this.type == "dataset" || this.type == "software") && ((this.linkTo == "publication" || this.linkTo == "dataset" || this.linkTo == "software") || this.linkTo == "result" )){
|
68
|
// isInlineResult = true;
|
69
|
// }
|
70
|
if(this.type == "project"){
|
71
|
this.linkType = "project";
|
72
|
this.getProjectById(this.id);
|
73
|
}else if(this.type == "publication"){
|
74
|
this.getPublicationById(this.id,true);
|
75
|
}else if(this.type == "dataset"){
|
76
|
this.getDatasetById(this.id,true);
|
77
|
}else if(this.type == "software"){
|
78
|
this.getSoftwareById(this.id,true);
|
79
|
}else{
|
80
|
this.validInput = this.isValidInput(null);
|
81
|
}
|
82
|
|
83
|
}else{
|
84
|
this.validInput = this.isValidInput(null);
|
85
|
|
86
|
}
|
87
|
|
88
|
});
|
89
|
}
|
90
|
isValidInput(result){
|
91
|
if(result == null){
|
92
|
return false;
|
93
|
}else if(this.type == "project" && this.linkTo != "result"){
|
94
|
return false;
|
95
|
}else if(["dataset","publication","software"].indexOf(this.type) != -1 && (["project","context","result"].indexOf(this.linkTo) == -1)){
|
96
|
return false;
|
97
|
}else if(["project","dataset","publication","software"].indexOf(this.type) == -1){
|
98
|
return false;
|
99
|
}else{
|
100
|
return true;
|
101
|
}
|
102
|
}
|
103
|
getProjectById(id:string){
|
104
|
this.sub = this.entitySearch.fetchByType(id,"project").subscribe(
|
105
|
data => {
|
106
|
console.log(data);
|
107
|
var item =data[0];
|
108
|
var project: ClaimProject = new ClaimProject();
|
109
|
project.funderId = item.funderId;
|
110
|
project.funderName = item.funderName;
|
111
|
project.projectId = id;
|
112
|
project.projectName = item.projectName;
|
113
|
project.projectAcronym = item.projectAcronym;
|
114
|
project.startDate = item.startDate;
|
115
|
project.endDate = item.endDate;
|
116
|
project.code = item.code;
|
117
|
project.jurisdiction = item.jurisdiction;
|
118
|
project.fundingLevel0 = item.fundingLevel0;
|
119
|
|
120
|
this.projects.push( project);
|
121
|
this.validInput = this.isValidInput(project);
|
122
|
|
123
|
},
|
124
|
err => {
|
125
|
this.validInput = this.isValidInput(null);
|
126
|
console.log("An error occured")
|
127
|
});
|
128
|
}
|
129
|
getPublicationById(id:string, isInlineResult:boolean){
|
130
|
|
131
|
this.sub = this.publicationsSearch.searchPublicationById(id).subscribe(
|
132
|
data => {
|
133
|
var item =data[0];
|
134
|
var result: ClaimResult = new ClaimResult();
|
135
|
result.id=id;
|
136
|
result.type="publication";
|
137
|
result.source="openaire";
|
138
|
result.title = item['title'].name;
|
139
|
result.url= item['title'].url;
|
140
|
result.result = item;
|
141
|
result.accessRights = item['title'].accessMode;
|
142
|
result.date = item.year;
|
143
|
this.displayedResult = result;
|
144
|
if(isInlineResult){
|
145
|
this.inlineResult = result;
|
146
|
}else{
|
147
|
this.results.push( result);
|
148
|
}
|
149
|
this.validInput = this.isValidInput(result);
|
150
|
},
|
151
|
err => {
|
152
|
this.validInput = this.isValidInput(null);
|
153
|
console.log("An error occured")
|
154
|
});
|
155
|
}
|
156
|
getDatasetById(id:string, isInlineResult:boolean){
|
157
|
this.sub = this.datasetsSearch.searchDatasetById(id).subscribe(
|
158
|
data => {
|
159
|
var item =data[0];
|
160
|
var result: ClaimResult = new ClaimResult();
|
161
|
result.id=id;
|
162
|
result.type="dataset";
|
163
|
result.source="openaire";
|
164
|
result.title = item['title'].name;
|
165
|
result.url= item['title'].url;
|
166
|
result.result = item;
|
167
|
result.accessRights = item['title'].accessMode;
|
168
|
result.date = item.year;
|
169
|
this.displayedResult = result;
|
170
|
if(isInlineResult){
|
171
|
this.inlineResult = result;
|
172
|
}else{
|
173
|
this.results.push( result);
|
174
|
}
|
175
|
this.validInput = this.isValidInput(result);
|
176
|
},
|
177
|
err => {
|
178
|
this.validInput = this.isValidInput(null);
|
179
|
console.log("An error occured")
|
180
|
});
|
181
|
}
|
182
|
getSoftwareById(id:string, isInlineResult:boolean){
|
183
|
this.sub = this.softwareSearch.searchSoftwareById(id).subscribe(
|
184
|
data => {
|
185
|
var item =data[0];
|
186
|
var result: ClaimResult = new ClaimResult();
|
187
|
result.id=id;
|
188
|
result.type="software";
|
189
|
result.source="openaire";
|
190
|
result.title = item['title'].name;
|
191
|
result.url= item['title'].url;
|
192
|
result.result = item;
|
193
|
result.accessRights = item['title'].accessMode;
|
194
|
result.date = item.year;
|
195
|
this.displayedResult = result;
|
196
|
if(isInlineResult){
|
197
|
this.inlineResult = result;
|
198
|
}else{
|
199
|
this.results.push( result);
|
200
|
}
|
201
|
this.validInput = this.isValidInput(result);
|
202
|
},
|
203
|
err => {
|
204
|
this.validInput = this.isValidInput(null);
|
205
|
console.log("An error occured")
|
206
|
});
|
207
|
}
|
208
|
}
|