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