Revision 56925
Added by Konstantina Galouni over 4 years ago
publication.component.ts | ||
---|---|---|
1 | 1 |
import {Component, Input} from '@angular/core'; |
2 |
import {ActivatedRoute, Router} from '@angular/router'; |
|
3 |
import {Meta, Title} from '@angular/platform-browser'; |
|
4 | 2 |
|
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 | 3 |
@Component({ |
17 | 4 |
selector: 'publication', |
18 |
templateUrl: 'publication.component.html', |
|
19 |
|
|
5 |
template: ` |
|
6 |
<result-landing type="publication" [piwikSiteId]="piwikSiteId" [communityId]="communityId" [activeTab]="'References'"></result-landing> |
|
7 |
` |
|
20 | 8 |
}) |
21 | 9 |
|
22 | 10 |
export class PublicationComponent { |
23 | 11 |
@Input() piwikSiteId = null; |
24 | 12 |
@Input() communityId = null; |
25 |
public publicationInfo: PublicationInfo; |
|
26 |
public articleId: string; |
|
27 | 13 |
|
28 |
// APP BOX variables |
|
29 |
public showAllCollectedFrom: boolean = false; |
|
30 |
public showAllDownloadFrom: boolean = false; |
|
14 |
constructor() {} |
|
31 | 15 |
|
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 = ""; |
|
276 |
if(!this.communityId) { |
|
277 |
_prefix = "OpenAIRE | "; |
|
278 |
} |
|
279 |
var _title = _prefix + ((title.length > 50) ? title.substring(0, 50) : title); |
|
280 |
this._title.setTitle(_title); |
|
281 |
this._meta.updateTag({content: _title}, "property='og:title'"); |
|
282 |
} |
|
283 |
|
|
284 |
private updateUrl(url: string) { |
|
285 |
this._meta.updateTag({content: url}, "property='og:url'"); |
|
286 |
} |
|
287 |
|
|
288 |
public totalPages(totalResults: number): number { |
|
289 |
let totalPages: any = totalResults / this.pageSize; |
|
290 |
if (!(Number.isInteger(totalPages))) { |
|
291 |
totalPages = (parseInt(totalPages, this.pageSize) + 1); |
|
292 |
} |
|
293 |
return totalPages; |
|
294 |
} |
|
295 |
|
|
296 |
public updateReferencesPage($event) { |
|
297 |
this.referencesPage = $event.value; |
|
298 |
} |
|
299 |
|
|
300 |
public updateOrganizationsPage($event) { |
|
301 |
this.organizationsPage = $event.value; |
|
302 |
} |
|
303 |
|
|
304 |
public updateSoftwarePage($event) { |
|
305 |
this.softwarePage = $event.value; |
|
306 |
} |
|
307 |
|
|
308 |
public updateBioentitiesPage($event) { |
|
309 |
this.bioentitiesPage = $event.value; |
|
310 |
} |
|
311 |
|
|
312 |
public updateOpenCitationsPage($event) { |
|
313 |
this.openCitationsPage = $event.value; |
|
314 |
} |
|
315 |
|
|
316 |
public keysToArray(bioentities: Map<string, string>): string[] { |
|
317 |
let keys: string[] = []; |
|
318 |
bioentities.forEach(function (value, key, map) { |
|
319 |
keys.push(key); |
|
320 |
}); |
|
321 |
return keys; |
|
322 |
} |
|
323 |
|
|
324 |
public getKeys(map) { |
|
325 |
return Array.from(map.keys()); |
|
326 |
} |
|
327 |
|
|
328 |
public scroll() { |
|
329 |
HelperFunctions.scroll(); |
|
330 |
} |
|
331 |
|
|
332 |
/* |
|
333 |
start(i: number, bioentitiesPage: number) { |
|
334 |
let sum = 0; |
|
335 |
let index=0; |
|
336 |
let retValue = 0; |
|
337 |
let valuesToPage = this.pageSize*bioentitiesPage; |
|
338 |
let valuesToPreviousPage = valuesToPage - this.pageSize; |
|
339 |
|
|
340 |
if(bioentitiesPage == 1) { |
|
341 |
return 0; |
|
342 |
} |
|
343 |
|
|
344 |
this.publicationInfo.bioentities.forEach(function (value, key, map) { |
|
345 |
sum += map.get(key).size; |
|
346 |
|
|
347 |
if(index == i) { |
|
348 |
if(sum <= valuesToPreviousPage) { |
|
349 |
retValue = 0; |
|
350 |
} else if((sum-map.get(key).size) >= valuesToPage){ |
|
351 |
retValue = 0; |
|
352 |
} else { |
|
353 |
if(map.get(key).size < (sum - valuesToPreviousPage)) { |
|
354 |
retValue = 0; |
|
355 |
} else { |
|
356 |
retValue = map.get(key).size - (sum - valuesToPreviousPage); |
|
357 |
} |
|
358 |
} |
|
359 |
} |
|
360 |
index++; |
|
361 |
}); |
|
362 |
this.startt = retValue; |
|
363 |
return retValue; |
|
364 |
} |
|
365 |
|
|
366 |
stop(i: number, bioentitiesPage: number) { |
|
367 |
let sum = 0; |
|
368 |
let index=0; |
|
369 |
let retValue = 0; |
|
370 |
let valuesToPage = this.pageSize*bioentitiesPage; |
|
371 |
let valuesToPreviousPage = valuesToPage - this.pageSize; |
|
372 |
|
|
373 |
this.publicationInfo.bioentities.forEach(function (value, key, map) { |
|
374 |
sum += map.get(key).size; |
|
375 |
if(index == i) { |
|
376 |
if(sum <= valuesToPreviousPage) { |
|
377 |
retValue = 0; |
|
378 |
} else if((sum - map.get(key).size) >= valuesToPage){ |
|
379 |
retValue = 0; |
|
380 |
} else { |
|
381 |
if(sum < valuesToPage) { |
|
382 |
retValue = map.get(key).size; |
|
383 |
} else { |
|
384 |
retValue = map.get(key).size - (sum - valuesToPage); |
|
385 |
} |
|
386 |
} |
|
387 |
} |
|
388 |
index++; |
|
389 |
}); |
|
390 |
this.stopp = retValue; |
|
391 |
return retValue; |
|
392 |
} |
|
393 |
*/ |
|
394 |
|
|
395 |
private handleError(message: string, error) { |
|
396 |
console.error("Publication Landing Page: " + message, error); |
|
397 |
} |
|
398 |
|
|
399 |
isRouteAvailable(routeToCheck: string) { |
|
400 |
for (let i = 0; i < this.router.config.length; i++) { |
|
401 |
let routePath: string = this.router.config[i].path; |
|
402 |
if (routePath == routeToCheck) { |
|
403 |
return true; |
|
404 |
} |
|
405 |
} |
|
406 |
return false; |
|
407 |
} |
|
16 |
ngOnInit() {} |
|
408 | 17 |
} |
Also available in: Unified diff
[mergeResultLandingPages | Library]:
1. Rename 'resultLanding.module' to 'resultLandingUtils.module'
2. Add property 'searchLinkToSoftwareLanding'
3. Add files: resultLandingInfo.ts, resultLanding.module.ts, resultLanding.component.ts, resultLanding.component.html for merging result landing pages (publication, dataset, software, orp)