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