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