1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {Meta, Title} from '@angular/platform-browser';
|
4
|
|
5
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
6
|
import {PublicationInfo} from '../../utils/entities/publicationInfo';
|
7
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
8
|
|
9
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
10
|
import {PublicationService} from './publication.service';
|
11
|
import {SEOService} from '../../sharedComponents/SEO/SEO.service';
|
12
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
13
|
import {HelperService} from "../../utils/helper/helper.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
|
@Input() communityId = null;
|
25
|
public publicationInfo: PublicationInfo;
|
26
|
public articleId: string;
|
27
|
|
28
|
// APP BOX variables
|
29
|
public showAllCollectedFrom: boolean = false;
|
30
|
public showAllDownloadFrom: boolean = false;
|
31
|
|
32
|
public thresholdDescription: number = 270;
|
33
|
public showNumDescription: number = 270;
|
34
|
|
35
|
// Metrics tab variables
|
36
|
public metricsClicked: boolean;
|
37
|
public viewsFrameUrl: string;
|
38
|
public downloadsFrameUrl: string;
|
39
|
public totalViews: number;
|
40
|
public totalDownloads: number;
|
41
|
public pageViews: number;
|
42
|
|
43
|
// Custom tab paging variables
|
44
|
public referencesPage: number = 1;
|
45
|
public organizationsPage: number = 1;
|
46
|
public softwarePage: number = 1;
|
47
|
public bioentitiesPage: number = 1;
|
48
|
public openCitationsPage: number = 1;
|
49
|
public pageSize: number = 10;
|
50
|
/*
|
51
|
public startt: number = 0;
|
52
|
public stopp: number = 0;
|
53
|
*/
|
54
|
|
55
|
// Active tab variable for responsiveness
|
56
|
public activeTab: string = "References";
|
57
|
|
58
|
// Map counting variables
|
59
|
public bioentitiesNum: number = 0;
|
60
|
public relatedResearchResultsNum: number = 0;
|
61
|
|
62
|
// Message variables
|
63
|
public warningMessage = "";
|
64
|
public errorMessage = "";
|
65
|
public showLoading: boolean = true;
|
66
|
|
67
|
public routerHelper: RouterHelper = new RouterHelper();
|
68
|
|
69
|
private doi: string;
|
70
|
public doiURL: string;
|
71
|
private result;
|
72
|
sub: any;
|
73
|
piwiksub: any;
|
74
|
infoSub: any;
|
75
|
properties: EnvProperties;
|
76
|
public pageContents = null;
|
77
|
public divContents = null;
|
78
|
|
79
|
constructor(private _publicationService: PublicationService,
|
80
|
private _piwikService: PiwikService,
|
81
|
private route: ActivatedRoute,
|
82
|
private router: Router,
|
83
|
private _meta: Meta,
|
84
|
private _title: Title,
|
85
|
private _router: Router,
|
86
|
private helper: HelperService,
|
87
|
private seoService: SEOService) {
|
88
|
}
|
89
|
|
90
|
ngOnInit() {
|
91
|
this.route.data
|
92
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
93
|
this.properties = data.envSpecific;
|
94
|
//this.getDivContents();
|
95
|
this.getPageContents();
|
96
|
this.doiURL = this.properties.doiURL;
|
97
|
this.updateUrl(data.envSpecific.baseLink + this._router.url);
|
98
|
|
99
|
});
|
100
|
this.sub = this.route.queryParams.subscribe(data => {
|
101
|
this.publicationInfo = null;
|
102
|
this.updateTitle("Publication");
|
103
|
this.updateDescription("");
|
104
|
this.articleId = data['articleId'];
|
105
|
|
106
|
this.metricsClicked = false;
|
107
|
|
108
|
if (this.articleId) {
|
109
|
|
110
|
this.getPublicationInfo(this.articleId);
|
111
|
// if (typeof document !== 'undefined') {
|
112
|
// switcher(UIkit);
|
113
|
// }
|
114
|
} else {
|
115
|
this.showLoading = false;
|
116
|
this.warningMessage = "No valid publication id";
|
117
|
}
|
118
|
|
119
|
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';
|
120
|
|
121
|
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';
|
122
|
|
123
|
this.scroll();
|
124
|
});
|
125
|
}
|
126
|
|
127
|
private getPageContents() {
|
128
|
this.helper.getPageHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
|
129
|
this.pageContents = contents;
|
130
|
})
|
131
|
}
|
132
|
|
133
|
private getDivContents() {
|
134
|
this.helper.getDivHelpContents(this._router.url, this.properties, this.communityId).subscribe(contents => {
|
135
|
this.divContents = contents;
|
136
|
})
|
137
|
}
|
138
|
|
139
|
ngOnDestroy() {
|
140
|
if (this.sub) {
|
141
|
this.sub.unsubscribe();
|
142
|
}
|
143
|
if (this.piwiksub) {
|
144
|
this.piwiksub.unsubscribe();
|
145
|
}
|
146
|
if (this.infoSub) {
|
147
|
this.infoSub.unsubscribe();
|
148
|
}
|
149
|
}
|
150
|
|
151
|
private getOpenCitations(id: string) {
|
152
|
this._publicationService.getOpenCitations(this.articleId, this.properties).subscribe(
|
153
|
data => {
|
154
|
this.publicationInfo.openCitations = data[1];
|
155
|
},
|
156
|
err => {
|
157
|
//console.log(err);
|
158
|
this.handleError("Error getting open citation for publication with id: " + this.articleId, err);
|
159
|
}
|
160
|
);
|
161
|
}
|
162
|
|
163
|
private getPublicationInfo(id: string) {
|
164
|
this.warningMessage = '';
|
165
|
this.errorMessage = ""
|
166
|
this.showLoading = true;
|
167
|
|
168
|
this.publicationInfo = null;
|
169
|
|
170
|
this.infoSub = this._publicationService.getPublicationInfo(this.articleId, this.properties).subscribe(
|
171
|
data => {
|
172
|
this.publicationInfo = data;
|
173
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToPublication + this.publicationInfo.record["result"]["header"]["dri:objIdentifier"]);
|
174
|
if ((this.properties.environment == "beta" || this.properties.environment == "development") && (typeof document !== 'undefined')) {
|
175
|
this.getOpenCitations(this.articleId);
|
176
|
}
|
177
|
|
178
|
// this.result = []
|
179
|
// this.result = {id: id, type :"dataset", source : "openaire", title: this.publicationInfo.title,url: '', result: '', accessRights: this.publicationInfo.bestaccessright, embargoEndDate: ''};
|
180
|
/*if(this.publicationInfo.title.name != undefined && this.publicationInfo.title.name!= ''){
|
181
|
this.updateTitle(this.publicationInfo.title.name);
|
182
|
this.updateDescription("Dataset, search, repositories, open access,"+this.publicationInfo.title.name);
|
183
|
}*/
|
184
|
if (this.publicationInfo.title) {
|
185
|
this.updateTitle(this.publicationInfo.title);
|
186
|
this.updateDescription((this.publicationInfo.description ? (this.publicationInfo.description) : ("," + this.publicationInfo.title)));
|
187
|
}
|
188
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
189
|
this.piwiksub = this._piwikService.trackView(this.properties, this.publicationInfo.title/*.name*/, this.piwikSiteId).subscribe();
|
190
|
}
|
191
|
|
192
|
let bioentitiesNum = 0;
|
193
|
if (this.publicationInfo.bioentities != undefined) {
|
194
|
this.publicationInfo.bioentities.forEach(function (value, key, map) {
|
195
|
bioentitiesNum += value.size;
|
196
|
});
|
197
|
}
|
198
|
this.bioentitiesNum = bioentitiesNum;
|
199
|
|
200
|
let relatedResearchResultsNum = 0;
|
201
|
if (this.publicationInfo.relatedResearchResults != undefined) {
|
202
|
this.publicationInfo.relatedResearchResults.forEach(function (value, key, map) {
|
203
|
relatedResearchResultsNum += value.length;
|
204
|
});
|
205
|
}
|
206
|
this.relatedResearchResultsNum = relatedResearchResultsNum;
|
207
|
|
208
|
this.result = {
|
209
|
id: this.articleId,
|
210
|
type: "publication",
|
211
|
source: "openaire",
|
212
|
title: this.publicationInfo.title,
|
213
|
url: '',
|
214
|
result: '',
|
215
|
accessRights: /*this.publicationInfo.title.accessMode*/this.publicationInfo.accessMode,
|
216
|
embargoEndDate: ''
|
217
|
};
|
218
|
// this.result.push(result_);
|
219
|
|
220
|
if (this.publicationInfo.identifiers != undefined && this.publicationInfo.identifiers.has('doi')) {
|
221
|
this.doi = this.publicationInfo.identifiers.get('doi')[0];
|
222
|
}
|
223
|
|
224
|
this.showLoading = false;
|
225
|
|
226
|
if (this.publicationInfo.references) {
|
227
|
this.activeTab = "References";
|
228
|
} else if (this.publicationInfo.relatedResearchResults) {
|
229
|
this.activeTab = "Related Research Results";
|
230
|
} else if (this.publicationInfo.similarResearchResults) {
|
231
|
this.activeTab = "Similar Research Results";
|
232
|
} else if (this.publicationInfo.organizations) {
|
233
|
this.activeTab = "Related Organizations";
|
234
|
} else if (this.publicationInfo.bioentities) {
|
235
|
this.activeTab = "bioentities";
|
236
|
} else if (this.publicationInfo.software) {
|
237
|
this.activeTab = "Software";
|
238
|
} else {
|
239
|
this.activeTab = "Metrics";
|
240
|
this.metricsClicked = true;
|
241
|
}
|
242
|
},
|
243
|
err => {
|
244
|
//console.log(err);
|
245
|
this.handleError("Error getting publication for id: " + this.articleId, err);
|
246
|
|
247
|
this.errorMessage = 'No publication found';
|
248
|
this.showLoading = false;
|
249
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink + this.properties.searchLinkToPublications);
|
250
|
}
|
251
|
);
|
252
|
}
|
253
|
|
254
|
public metricsResults($event) {
|
255
|
this.totalViews = $event.totalViews;
|
256
|
this.totalDownloads = $event.totalDownloads;
|
257
|
this.pageViews = $event.pageViews;
|
258
|
}
|
259
|
|
260
|
public buildCurationTooltip() {
|
261
|
let tooltipContent: string = "<div class='uk-margin uk-padding-small'>";
|
262
|
|
263
|
tooltipContent += "<h4>Record in preview</h4>";
|
264
|
tooltipContent += "<p>Bibliographic record accepted by the system, but not yet processed by <br> OpenAIRE tools for information quality improvement and de-duplication</p>";
|
265
|
|
266
|
return tooltipContent += "</div>";
|
267
|
}
|
268
|
|
269
|
private updateDescription(description: string) {
|
270
|
this._meta.updateTag({content: description}, "name='description'");
|
271
|
this._meta.updateTag({content: description}, "property='og:description'");
|
272
|
}
|
273
|
|
274
|
private updateTitle(title: string) {
|
275
|
var _prefix = "OpenAIRE | ";
|
276
|
var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title);
|
277
|
this._title.setTitle(title);
|
278
|
this._meta.updateTag({content: title}, "property='og:title'");
|
279
|
}
|
280
|
|
281
|
private updateUrl(url: string) {
|
282
|
this._meta.updateTag({content: url}, "property='og:url'");
|
283
|
}
|
284
|
|
285
|
public totalPages(totalResults: number): number {
|
286
|
let totalPages: any = totalResults / this.pageSize;
|
287
|
if (!(Number.isInteger(totalPages))) {
|
288
|
totalPages = (parseInt(totalPages, this.pageSize) + 1);
|
289
|
}
|
290
|
return totalPages;
|
291
|
}
|
292
|
|
293
|
public updateReferencesPage($event) {
|
294
|
this.referencesPage = $event.value;
|
295
|
}
|
296
|
|
297
|
public updateOrganizationsPage($event) {
|
298
|
this.organizationsPage = $event.value;
|
299
|
}
|
300
|
|
301
|
public updateSoftwarePage($event) {
|
302
|
this.softwarePage = $event.value;
|
303
|
}
|
304
|
|
305
|
public updateBioentitiesPage($event) {
|
306
|
this.bioentitiesPage = $event.value;
|
307
|
}
|
308
|
|
309
|
public updateOpenCitationsPage($event) {
|
310
|
this.openCitationsPage = $event.value;
|
311
|
}
|
312
|
|
313
|
public keysToArray(bioentities: Map<string, string>): string[] {
|
314
|
let keys: string[] = [];
|
315
|
bioentities.forEach(function (value, key, map) {
|
316
|
keys.push(key);
|
317
|
});
|
318
|
return keys;
|
319
|
}
|
320
|
|
321
|
public getKeys(map) {
|
322
|
return Array.from(map.keys());
|
323
|
}
|
324
|
|
325
|
public scroll() {
|
326
|
HelperFunctions.scroll();
|
327
|
}
|
328
|
|
329
|
/*
|
330
|
start(i: number, bioentitiesPage: number) {
|
331
|
let sum = 0;
|
332
|
let index=0;
|
333
|
let retValue = 0;
|
334
|
let valuesToPage = this.pageSize*bioentitiesPage;
|
335
|
let valuesToPreviousPage = valuesToPage - this.pageSize;
|
336
|
|
337
|
if(bioentitiesPage == 1) {
|
338
|
return 0;
|
339
|
}
|
340
|
|
341
|
this.publicationInfo.bioentities.forEach(function (value, key, map) {
|
342
|
sum += map.get(key).size;
|
343
|
|
344
|
if(index == i) {
|
345
|
if(sum <= valuesToPreviousPage) {
|
346
|
retValue = 0;
|
347
|
} else if((sum-map.get(key).size) >= valuesToPage){
|
348
|
retValue = 0;
|
349
|
} else {
|
350
|
if(map.get(key).size < (sum - valuesToPreviousPage)) {
|
351
|
retValue = 0;
|
352
|
} else {
|
353
|
retValue = map.get(key).size - (sum - valuesToPreviousPage);
|
354
|
}
|
355
|
}
|
356
|
}
|
357
|
index++;
|
358
|
});
|
359
|
this.startt = retValue;
|
360
|
return retValue;
|
361
|
}
|
362
|
|
363
|
stop(i: number, bioentitiesPage: number) {
|
364
|
let sum = 0;
|
365
|
let index=0;
|
366
|
let retValue = 0;
|
367
|
let valuesToPage = this.pageSize*bioentitiesPage;
|
368
|
let valuesToPreviousPage = valuesToPage - this.pageSize;
|
369
|
|
370
|
this.publicationInfo.bioentities.forEach(function (value, key, map) {
|
371
|
sum += map.get(key).size;
|
372
|
if(index == i) {
|
373
|
if(sum <= valuesToPreviousPage) {
|
374
|
retValue = 0;
|
375
|
} else if((sum - map.get(key).size) >= valuesToPage){
|
376
|
retValue = 0;
|
377
|
} else {
|
378
|
if(sum < valuesToPage) {
|
379
|
retValue = map.get(key).size;
|
380
|
} else {
|
381
|
retValue = map.get(key).size - (sum - valuesToPage);
|
382
|
}
|
383
|
}
|
384
|
}
|
385
|
index++;
|
386
|
});
|
387
|
this.stopp = retValue;
|
388
|
return retValue;
|
389
|
}
|
390
|
*/
|
391
|
|
392
|
private handleError(message: string, error) {
|
393
|
console.error("Publication Landing Page: " + message, error);
|
394
|
}
|
395
|
|
396
|
isRouteAvailable(routeToCheck: string) {
|
397
|
for (let i = 0; i < this.router.config.length; i++) {
|
398
|
let routePath: string = this.router.config[i].path;
|
399
|
if (routePath == routeToCheck) {
|
400
|
return true;
|
401
|
}
|
402
|
}
|
403
|
return false;
|
404
|
}
|
405
|
}
|