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