1
|
import {Component, ViewChild} from '@angular/core';
|
2
|
import {ElementRef, Input} from '@angular/core';
|
3
|
import {ActivatedRoute, Router} from '@angular/router';
|
4
|
import {Title, Meta} from '@angular/platform-browser';
|
5
|
|
6
|
import {Observable} from 'rxjs/Observable';
|
7
|
|
8
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
9
|
import {PublicationInfo} from '../../utils/entities/publicationInfo';
|
10
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
11
|
|
12
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
13
|
import {PublicationService} from './publication.service';
|
14
|
|
15
|
|
16
|
@Component({
|
17
|
selector: 'publication',
|
18
|
templateUrl: 'publication.component.html',
|
19
|
|
20
|
})
|
21
|
|
22
|
export class PublicationComponent {
|
23
|
@Input() piwikSiteId = null;
|
24
|
public publicationInfo: PublicationInfo;
|
25
|
public articleId: string;
|
26
|
|
27
|
// APP BOX variables
|
28
|
public showAllCollectedFrom: boolean = false;
|
29
|
public showAllDownloadFrom: boolean = false;
|
30
|
|
31
|
// Metrics tab variables
|
32
|
public metricsClicked: boolean;
|
33
|
public viewsFrameUrl: string;
|
34
|
public downloadsFrameUrl: string;
|
35
|
public totalViews: number;
|
36
|
public totalDownloads: number;
|
37
|
public pageViews: number;
|
38
|
|
39
|
// Custom tab paging variables
|
40
|
public referencesPage: number = 1;
|
41
|
public organizationsPage: number = 1;
|
42
|
public softwarePage: number = 1;
|
43
|
public bioentitiesPage: number = 1;
|
44
|
public pageSize: number = 10;
|
45
|
/*
|
46
|
public startt: number = 0;
|
47
|
public stopp: number = 0;
|
48
|
*/
|
49
|
|
50
|
// Active tab variable for responsiveness
|
51
|
public activeTab: string = "References";
|
52
|
|
53
|
// Map counting variables
|
54
|
public bioentitiesNum: number = 0;
|
55
|
public relatedResearchResultsNum: number = 0;
|
56
|
|
57
|
// Message variables
|
58
|
public warningMessage = "";
|
59
|
public errorMessage = "";
|
60
|
public showLoading: boolean = true;
|
61
|
|
62
|
public routerHelper:RouterHelper = new RouterHelper();
|
63
|
|
64
|
private doi: string;
|
65
|
private result;
|
66
|
sub: any; piwiksub: any; infoSub: any;
|
67
|
properties:EnvProperties;
|
68
|
|
69
|
constructor ( private element: ElementRef,
|
70
|
private _publicationService: PublicationService,
|
71
|
private _piwikService:PiwikService,
|
72
|
private route: ActivatedRoute,
|
73
|
private _meta: Meta,
|
74
|
private _title: Title,
|
75
|
private _router: Router) {
|
76
|
}
|
77
|
|
78
|
ngOnInit() {
|
79
|
this.route.data
|
80
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
81
|
this.properties = data.envSpecific;
|
82
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
83
|
|
84
|
});
|
85
|
this.sub = this.route.queryParams.subscribe(data => {
|
86
|
this.publicationInfo = null;
|
87
|
this.updateTitle("Publication");
|
88
|
this.updateDescription("Publication, open access, collected from");
|
89
|
|
90
|
this.articleId = data['articleId'];
|
91
|
console.info("Article id is :"+this.articleId);
|
92
|
|
93
|
this.metricsClicked = false;
|
94
|
|
95
|
if(this.articleId){
|
96
|
|
97
|
this.getPublicationInfo(this.articleId);
|
98
|
// if (typeof document !== 'undefined') {
|
99
|
// switcher(UIkit);
|
100
|
// }
|
101
|
}else{
|
102
|
this.showLoading = false;
|
103
|
this.warningMessage="No valid publication id";
|
104
|
}
|
105
|
|
106
|
this.viewsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"'+this.articleId+'", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
|
107
|
|
108
|
this.downloadsFrameUrl =this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"'+this.articleId+'", "table":"","fields":[{"fld":"sum","agg":"sum","type":"column","yaxis":1,"c":false}],"xaxis":{"name":"month","agg":"sum"},"group":" ","color":"","type":"chart","size":30,"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"","xaxistitle":"Repository","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[],"filters":[{"name":"","values":[""],"to":"-1"}]}]&info_types=["column"]&stacking=normal&steps=false&fontFamily=Courier&spacing=[5,0,0,0]&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125, 1)&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233, 1)&colors[]=rgba(241, 92, 128, 1)&colors[]=rgba(228, 211, 84, 1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91, 1)&colors[]=rgba(145, 232, 225, 1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false';
|
109
|
|
110
|
if (typeof document !== 'undefined') {
|
111
|
this.element.nativeElement.scrollIntoView();
|
112
|
}
|
113
|
});
|
114
|
}
|
115
|
|
116
|
ngOnDestroy() {
|
117
|
if(this.sub){
|
118
|
this.sub.unsubscribe();
|
119
|
}
|
120
|
if(this.piwiksub){
|
121
|
this.piwiksub.unsubscribe();
|
122
|
}
|
123
|
if(this.infoSub) {
|
124
|
this.infoSub.unsubscribe();
|
125
|
}
|
126
|
}
|
127
|
|
128
|
private getPublicationInfo(id:string) {
|
129
|
this.warningMessage = '';
|
130
|
this.errorMessage=""
|
131
|
this.showLoading = true;
|
132
|
|
133
|
this.publicationInfo = null;
|
134
|
|
135
|
this.infoSub = this._publicationService.getPublicationInfo(this.articleId, this.properties).subscribe(
|
136
|
data => {
|
137
|
this.publicationInfo = data;
|
138
|
|
139
|
// this.result = []
|
140
|
// this.result = {id: id, type :"dataset", source : "openaire", title: this.publicationInfo.title,url: '', result: '', accessRights: this.publicationInfo.bestaccessright, embargoEndDate: ''};
|
141
|
/*if(this.publicationInfo.title.name != undefined && this.publicationInfo.title.name!= ''){
|
142
|
this.updateTitle(this.publicationInfo.title.name);
|
143
|
this.updateDescription("Dataset, search, repositories, open access,"+this.publicationInfo.title.name);
|
144
|
}*/
|
145
|
if(this.publicationInfo.title){
|
146
|
this.updateTitle(this.publicationInfo.title);
|
147
|
this.updateDescription("Dataset, search, repositories, open access,"+this.publicationInfo.title);
|
148
|
}
|
149
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
150
|
this.piwiksub = this._piwikService.trackView(this.properties, this.publicationInfo.title/*.name*/, this.piwikSiteId).subscribe();
|
151
|
}
|
152
|
|
153
|
let bioentitiesNum = 0;
|
154
|
if(this.publicationInfo.bioentities != undefined) {
|
155
|
this.publicationInfo.bioentities.forEach(function (value, key, map) {
|
156
|
bioentitiesNum += value.size;
|
157
|
});
|
158
|
}
|
159
|
this.bioentitiesNum = bioentitiesNum;
|
160
|
|
161
|
let relatedResearchResultsNum = 0;
|
162
|
if(this.publicationInfo.relatedResearchResults != undefined) {
|
163
|
this.publicationInfo.relatedResearchResults.forEach(function (value, key, map) {
|
164
|
relatedResearchResultsNum += value.length;
|
165
|
});
|
166
|
}
|
167
|
this.relatedResearchResultsNum = relatedResearchResultsNum;
|
168
|
|
169
|
this.result = {id: this.articleId, type :"publication", source : "openaire", title: this.publicationInfo.title,url: '', result: '', accessRights: /*this.publicationInfo.title.accessMode*/this.publicationInfo.accessMode, embargoEndDate: ''};
|
170
|
// this.result.push(result_);
|
171
|
|
172
|
if(this.publicationInfo.identifiers != undefined && this.publicationInfo.identifiers.has('doi')) {
|
173
|
this.doi = this.publicationInfo.identifiers.get('doi')[0];
|
174
|
}
|
175
|
|
176
|
this.showLoading = false;
|
177
|
|
178
|
if(this.publicationInfo.references) {
|
179
|
this.activeTab = "References";
|
180
|
} else if(this.publicationInfo.relatedResearchResults) {
|
181
|
this.activeTab = "Related Research Results";
|
182
|
} else if(this.publicationInfo.similarResearchResults) {
|
183
|
this.activeTab = "Similar Research Results";
|
184
|
} else if(this.publicationInfo.organizations) {
|
185
|
this.activeTab = "Related Organizations";
|
186
|
} else if(this.publicationInfo.bioentities) {
|
187
|
this.activeTab = "bioentities";
|
188
|
} else if(this.publicationInfo.software) {
|
189
|
this.activeTab = "Software";
|
190
|
} else {
|
191
|
this.activeTab = "Metrics";
|
192
|
this.metricsClicked = true;
|
193
|
}
|
194
|
console.info("activeTab is "+this.activeTab);
|
195
|
},
|
196
|
err => {
|
197
|
console.log(err);
|
198
|
console.info("error");
|
199
|
|
200
|
this.errorMessage = 'No publication found';
|
201
|
this.showLoading = false;
|
202
|
}
|
203
|
);
|
204
|
}
|
205
|
|
206
|
public metricsResults($event) {
|
207
|
this.totalViews = $event.totalViews;
|
208
|
this.totalDownloads = $event.totalDownloads;
|
209
|
this.pageViews = $event.pageViews;
|
210
|
}
|
211
|
|
212
|
public buildCurationTooltip() {
|
213
|
let tooltipContent: string = "<div class='uk-margin uk-padding-small'>";
|
214
|
|
215
|
tooltipContent += "<h4>Record in preview</h4>";
|
216
|
tooltipContent += "<p>Bibliographic record accepted by the system, but not yet processed by <br> OpenAIRE tools for information quality improvement and de-duplication</p>";
|
217
|
|
218
|
return tooltipContent+= "</div>";
|
219
|
}
|
220
|
|
221
|
private updateDescription(description:string){
|
222
|
this._meta.updateTag({content:description},"name='description'");
|
223
|
this._meta.updateTag({content:description},"property='og:description'");
|
224
|
}
|
225
|
private updateTitle(title:string){
|
226
|
var _prefix ="OpenAIRE | ";
|
227
|
var _title = _prefix + ((title.length> 50 ) ?title.substring(0,50):title);
|
228
|
this._title.setTitle(title);
|
229
|
this._meta.updateTag({content:title},"property='og:title'");
|
230
|
}
|
231
|
|
232
|
private updateUrl(url:string){
|
233
|
this._meta.updateTag({content:url},"property='og:url'");
|
234
|
}
|
235
|
|
236
|
public totalPages(totalResults: number): number {
|
237
|
let totalPages:any = totalResults/this.pageSize;
|
238
|
if(!(Number.isInteger(totalPages))) {
|
239
|
totalPages = (parseInt(totalPages, this.pageSize) + 1);
|
240
|
}
|
241
|
return totalPages;
|
242
|
}
|
243
|
|
244
|
public updateReferencesPage($event) {
|
245
|
this.referencesPage = $event.value;
|
246
|
}
|
247
|
|
248
|
public updateOrganizationsPage($event) {
|
249
|
this.organizationsPage = $event.value;
|
250
|
}
|
251
|
|
252
|
public updateSoftwarePage($event) {
|
253
|
this.softwarePage = $event.value;
|
254
|
}
|
255
|
|
256
|
public updateBioentitiesPage($event) {
|
257
|
this.bioentitiesPage = $event.value;
|
258
|
}
|
259
|
|
260
|
public keysToArray(bioentities: Map<string, string>) : string[] {
|
261
|
let keys: string[] = [];
|
262
|
bioentities.forEach(function (value, key, map) {
|
263
|
keys.push(key);
|
264
|
});
|
265
|
return keys;
|
266
|
}
|
267
|
public getKeys( map) {
|
268
|
return Array.from(map.keys());
|
269
|
}
|
270
|
/*
|
271
|
start(i: number, bioentitiesPage: number) {
|
272
|
let sum = 0;
|
273
|
let index=0;
|
274
|
let retValue = 0;
|
275
|
let valuesToPage = this.pageSize*bioentitiesPage;
|
276
|
let valuesToPreviousPage = valuesToPage - this.pageSize;
|
277
|
|
278
|
if(bioentitiesPage == 1) {
|
279
|
return 0;
|
280
|
}
|
281
|
|
282
|
this.publicationInfo.bioentities.forEach(function (value, key, map) {
|
283
|
sum += map.get(key).size;
|
284
|
|
285
|
if(index == i) {
|
286
|
if(sum <= valuesToPreviousPage) {
|
287
|
retValue = 0;
|
288
|
} else if((sum-map.get(key).size) >= valuesToPage){
|
289
|
retValue = 0;
|
290
|
} else {
|
291
|
if(map.get(key).size < (sum - valuesToPreviousPage)) {
|
292
|
retValue = 0;
|
293
|
} else {
|
294
|
retValue = map.get(key).size - (sum - valuesToPreviousPage);
|
295
|
}
|
296
|
}
|
297
|
}
|
298
|
index++;
|
299
|
});
|
300
|
this.startt = retValue;
|
301
|
return retValue;
|
302
|
}
|
303
|
|
304
|
stop(i: number, bioentitiesPage: number) {
|
305
|
let sum = 0;
|
306
|
let index=0;
|
307
|
let retValue = 0;
|
308
|
let valuesToPage = this.pageSize*bioentitiesPage;
|
309
|
let valuesToPreviousPage = valuesToPage - this.pageSize;
|
310
|
|
311
|
this.publicationInfo.bioentities.forEach(function (value, key, map) {
|
312
|
sum += map.get(key).size;
|
313
|
if(index == i) {
|
314
|
if(sum <= valuesToPreviousPage) {
|
315
|
retValue = 0;
|
316
|
} else if((sum - map.get(key).size) >= valuesToPage){
|
317
|
retValue = 0;
|
318
|
} else {
|
319
|
if(sum < valuesToPage) {
|
320
|
retValue = map.get(key).size;
|
321
|
} else {
|
322
|
retValue = map.get(key).size - (sum - valuesToPage);
|
323
|
}
|
324
|
}
|
325
|
}
|
326
|
index++;
|
327
|
});
|
328
|
this.stopp = retValue;
|
329
|
return retValue;
|
330
|
}
|
331
|
*/
|
332
|
|
333
|
}
|