2019-07-22 11:16:50 +02:00
import { Component , Input } from '@angular/core' ;
import { ActivatedRoute , Router } from '@angular/router' ;
import { Meta , Title } from '@angular/platform-browser' ;
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
import { EnvProperties } from '../../utils/properties/env-properties' ;
import { PublicationInfo } from '../../utils/entities/publicationInfo' ;
import { RouterHelper } from '../../utils/routerHelper.class' ;
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
import { PiwikService } from '../../utils/piwik/piwik.service' ;
import { PublicationService } from './publication.service' ;
import { SEOService } from '../../sharedComponents/SEO/SEO.service' ;
2019-04-24 14:31:01 +02:00
import { HelperFunctions } from "../../utils/HelperFunctions.class" ;
2019-07-22 11:16:50 +02:00
import { HelperService } from "../../utils/helper/helper.service" ;
2017-12-19 13:53:46 +01:00
@Component ( {
2019-07-22 11:16:50 +02:00
selector : 'publication' ,
templateUrl : 'publication.component.html' ,
2017-12-19 13:53:46 +01:00
} )
export class PublicationComponent {
2018-04-11 10:59:01 +02:00
@Input ( ) piwikSiteId = null ;
2019-07-22 11:16:50 +02:00
@Input ( ) communityId = null ;
2017-12-19 13:53:46 +01:00
public publicationInfo : PublicationInfo ;
public articleId : string ;
// APP BOX variables
public showAllCollectedFrom : boolean = false ;
public showAllDownloadFrom : boolean = false ;
2019-03-21 11:49:50 +01:00
public thresholdDescription : number = 270 ;
public showNumDescription : number = 270 ;
2017-12-19 13:53:46 +01:00
// Metrics tab variables
public metricsClicked : boolean ;
public viewsFrameUrl : string ;
public downloadsFrameUrl : string ;
public totalViews : number ;
public totalDownloads : number ;
public pageViews : number ;
// Custom tab paging variables
public referencesPage : number = 1 ;
public organizationsPage : number = 1 ;
public softwarePage : number = 1 ;
public bioentitiesPage : number = 1 ;
2018-12-17 12:03:46 +01:00
public openCitationsPage : number = 1 ;
2017-12-19 13:53:46 +01:00
public pageSize : number = 10 ;
/ *
public startt : number = 0 ;
public stopp : number = 0 ;
* /
// Active tab variable for responsiveness
public activeTab : string = "References" ;
// Map counting variables
public bioentitiesNum : number = 0 ;
public relatedResearchResultsNum : number = 0 ;
// Message variables
public warningMessage = "" ;
public errorMessage = "" ;
public showLoading : boolean = true ;
2019-07-22 11:16:50 +02:00
public routerHelper : RouterHelper = new RouterHelper ( ) ;
2017-12-19 13:53:46 +01:00
private doi : string ;
2018-12-17 12:03:46 +01:00
public doiURL : string ;
2017-12-19 13:53:46 +01:00
private result ;
2019-07-22 11:16:50 +02:00
sub : any ;
piwiksub : any ;
infoSub : any ;
properties : EnvProperties ;
public pageContents = null ;
public divContents = null ;
constructor ( private _publicationService : PublicationService ,
private _piwikService : PiwikService ,
private route : ActivatedRoute ,
private router : Router ,
private _meta : Meta ,
private _title : Title ,
private _router : Router ,
private helper : HelperService ,
2018-11-14 11:38:53 +01:00
private seoService : SEOService ) {
2017-12-19 13:53:46 +01:00
}
ngOnInit() {
2018-02-05 14:14:59 +01:00
this . route . data
. subscribe ( ( data : { envSpecific : EnvProperties } ) = > {
2019-07-22 11:16:50 +02:00
this . properties = data . envSpecific ;
//this.getDivContents();
this . getPageContents ( ) ;
this . doiURL = this . properties . doiURL ;
this . updateUrl ( data . envSpecific . baseLink + this . _router . url ) ;
2018-02-05 14:14:59 +01:00
} ) ;
2019-07-22 11:16:50 +02:00
this . sub = this . route . queryParams . subscribe ( data = > {
this . publicationInfo = null ;
this . updateTitle ( "Publication" ) ;
this . updateDescription ( "" ) ;
this . articleId = data [ 'articleId' ] ;
this . metricsClicked = false ;
if ( this . articleId ) {
this . getPublicationInfo ( this . articleId ) ;
// if (typeof document !== 'undefined') {
// switcher(UIkit);
// }
} else {
this . showLoading = false ;
this . warningMessage = "No valid publication id" ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
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' ;
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
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' ;
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
this . scroll ( ) ;
2017-12-19 13:53:46 +01:00
} ) ;
}
2019-07-22 11:16:50 +02:00
private getPageContents() {
this . helper . getPageHelpContents ( this . _router . url , this . properties , this . communityId ) . subscribe ( contents = > {
this . pageContents = contents ;
} )
}
private getDivContents() {
this . helper . getDivHelpContents ( this . _router . url , this . properties , this . communityId ) . subscribe ( contents = > {
this . divContents = contents ;
} )
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
ngOnDestroy() {
if ( this . sub ) {
this . sub . unsubscribe ( ) ;
}
if ( this . piwiksub ) {
this . piwiksub . unsubscribe ( ) ;
}
if ( this . infoSub ) {
this . infoSub . unsubscribe ( ) ;
}
}
private getOpenCitations ( id : string ) {
this . _publicationService . getOpenCitations ( this . articleId , this . properties ) . subscribe (
data = > {
this . publicationInfo . openCitations = data [ 1 ] ;
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting open citation for publication with id: " + this . articleId , err ) ;
}
) ;
}
private getPublicationInfo ( id : string ) {
this . warningMessage = '' ;
this . errorMessage = ""
this . showLoading = true ;
this . publicationInfo = null ;
this . infoSub = this . _publicationService . getPublicationInfo ( this . articleId , this . properties ) . subscribe (
data = > {
this . publicationInfo = data ;
this . seoService . createLinkForCanonicalURL ( this . properties . baseLink + this . properties . searchLinkToPublication + this . publicationInfo . record [ "result" ] [ "header" ] [ "dri:objIdentifier" ] ) ;
if ( ( this . properties . environment == "beta" || this . properties . environment == "development" ) && ( typeof document !== 'undefined' ) ) {
this . getOpenCitations ( this . articleId ) ;
2018-09-05 14:37:47 +02:00
}
2019-07-22 11:16:50 +02:00
// this.result = []
// this.result = {id: id, type :"dataset", source : "openaire", title: this.publicationInfo.title,url: '', result: '', accessRights: this.publicationInfo.bestaccessright, embargoEndDate: ''};
/ * i f ( t h i s . p u b l i c a t i o n I n f o . t i t l e . n a m e ! = u n d e f i n e d & & t h i s . p u b l i c a t i o n I n f o . t i t l e . n a m e ! = ' ' ) {
this . updateTitle ( this . publicationInfo . title . name ) ;
this . updateDescription ( "Dataset, search, repositories, open access," + this . publicationInfo . title . name ) ;
} * /
if ( this . publicationInfo . title ) {
this . updateTitle ( this . publicationInfo . title ) ;
this . updateDescription ( ( this . publicationInfo . description ? ( this . publicationInfo . description ) : ( "," + this . publicationInfo . title ) ) ) ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
this . piwiksub = this . _piwikService . trackView ( this . properties , this . publicationInfo . title /*.name*/ , this . piwikSiteId ) . subscribe ( ) ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
let bioentitiesNum = 0 ;
if ( this . publicationInfo . bioentities != undefined ) {
this . publicationInfo . bioentities . forEach ( function ( value , key , map ) {
bioentitiesNum += value . size ;
} ) ;
2018-12-17 12:03:46 +01:00
}
2019-07-22 11:16:50 +02:00
this . bioentitiesNum = bioentitiesNum ;
2018-12-17 12:03:46 +01:00
2019-07-22 11:16:50 +02:00
let relatedResearchResultsNum = 0 ;
if ( this . publicationInfo . relatedResearchResults != undefined ) {
this . publicationInfo . relatedResearchResults . forEach ( function ( value , key , map ) {
relatedResearchResultsNum += value . length ;
} ) ;
}
this . relatedResearchResultsNum = relatedResearchResultsNum ;
this . result = {
id : this.articleId ,
type : "publication" ,
source : "openaire" ,
title : this.publicationInfo.title ,
url : '' ,
result : '' ,
accessRights : /*this.publicationInfo.title.accessMode*/ this . publicationInfo . accessMode ,
embargoEndDate : ''
} ;
// this.result.push(result_);
if ( this . publicationInfo . identifiers != undefined && this . publicationInfo . identifiers . has ( 'doi' ) ) {
this . doi = this . publicationInfo . identifiers . get ( 'doi' ) [ 0 ] ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
this . showLoading = false ;
if ( this . publicationInfo . references ) {
this . activeTab = "References" ;
} else if ( this . publicationInfo . relatedResearchResults ) {
this . activeTab = "Related Research Results" ;
} else if ( this . publicationInfo . similarResearchResults ) {
this . activeTab = "Similar Research Results" ;
} else if ( this . publicationInfo . organizations ) {
this . activeTab = "Related Organizations" ;
} else if ( this . publicationInfo . bioentities ) {
this . activeTab = "bioentities" ;
} else if ( this . publicationInfo . software ) {
this . activeTab = "Software" ;
} else {
this . activeTab = "Metrics" ;
this . metricsClicked = true ;
}
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting publication for id: " + this . articleId , err ) ;
this . errorMessage = 'No publication found' ;
this . showLoading = false ;
this . seoService . createLinkForCanonicalURL ( this . properties . baseLink + this . properties . searchLinkToPublications ) ;
}
) ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
public metricsResults ( $event ) {
this . totalViews = $event . totalViews ;
this . totalDownloads = $event . totalDownloads ;
this . pageViews = $event . pageViews ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
public buildCurationTooltip() {
let tooltipContent : string = "<div class='uk-margin uk-padding-small'>" ;
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
tooltipContent += "<h4>Record in preview</h4>" ;
tooltipContent += "<p>Bibliographic record accepted by the system, but not yet processed by <br> OpenAIRE tools for information quality improvement and de-duplication</p>" ;
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
return tooltipContent += "</div>" ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
private updateDescription ( description : string ) {
this . _meta . updateTag ( { content : description } , "name='description'" ) ;
this . _meta . updateTag ( { content : description } , "property='og:description'" ) ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
private updateTitle ( title : string ) {
var _prefix = "OpenAIRE | " ;
var _title = _prefix + ( ( title . length > 50 ) ? title . substring ( 0 , 50 ) : title ) ;
this . _title . setTitle ( title ) ;
this . _meta . updateTag ( { content : title } , "property='og:title'" ) ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
private updateUrl ( url : string ) {
this . _meta . updateTag ( { content : url } , "property='og:url'" ) ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
public totalPages ( totalResults : number ) : number {
let totalPages : any = totalResults / this . pageSize ;
if ( ! ( Number . isInteger ( totalPages ) ) ) {
totalPages = ( parseInt ( totalPages , this . pageSize ) + 1 ) ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
return totalPages ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
public updateReferencesPage ( $event ) {
this . referencesPage = $event . value ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
public updateOrganizationsPage ( $event ) {
this . organizationsPage = $event . value ;
}
2018-12-17 12:03:46 +01:00
2019-07-22 11:16:50 +02:00
public updateSoftwarePage ( $event ) {
this . softwarePage = $event . value ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
public updateBioentitiesPage ( $event ) {
this . bioentitiesPage = $event . value ;
}
2019-03-21 11:49:50 +01:00
2019-07-22 11:16:50 +02:00
public updateOpenCitationsPage ( $event ) {
this . openCitationsPage = $event . value ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
public keysToArray ( bioentities : Map < string , string > ) : string [ ] {
let keys : string [ ] = [ ] ;
bioentities . forEach ( function ( value , key , map ) {
keys . push ( key ) ;
} ) ;
return keys ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
public getKeys ( map ) {
return Array . from ( map . keys ( ) ) ;
}
public scroll() {
HelperFunctions . scroll ( ) ;
}
/ *
start ( i : number , bioentitiesPage : number ) {
let sum = 0 ;
let index = 0 ;
let retValue = 0 ;
let valuesToPage = this . pageSize * bioentitiesPage ;
let valuesToPreviousPage = valuesToPage - this . pageSize ;
if ( bioentitiesPage == 1 ) {
return 0 ;
}
this . publicationInfo . bioentities . forEach ( function ( value , key , map ) {
sum += map . get ( key ) . size ;
if ( index == i ) {
if ( sum <= valuesToPreviousPage ) {
retValue = 0 ;
} else if ( ( sum - map . get ( key ) . size ) >= valuesToPage ) {
2017-12-19 13:53:46 +01:00
retValue = 0 ;
} else {
2019-07-22 11:16:50 +02:00
if ( map . get ( key ) . size < ( sum - valuesToPreviousPage ) ) {
retValue = 0 ;
} else {
retValue = map . get ( key ) . size - ( sum - valuesToPreviousPage ) ;
}
2017-12-19 13:53:46 +01:00
}
}
2019-07-22 11:16:50 +02:00
index ++ ;
} ) ;
this . startt = retValue ;
return retValue ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
stop ( i : number , bioentitiesPage : number ) {
let sum = 0 ;
let index = 0 ;
let retValue = 0 ;
let valuesToPage = this . pageSize * bioentitiesPage ;
let valuesToPreviousPage = valuesToPage - this . pageSize ;
this . publicationInfo . bioentities . forEach ( function ( value , key , map ) {
sum += map . get ( key ) . size ;
if ( index == i ) {
if ( sum <= valuesToPreviousPage ) {
retValue = 0 ;
} else if ( ( sum - map . get ( key ) . size ) >= valuesToPage ) {
retValue = 0 ;
2017-12-19 13:53:46 +01:00
} else {
2019-07-22 11:16:50 +02:00
if ( sum < valuesToPage ) {
retValue = map . get ( key ) . size ;
} else {
retValue = map . get ( key ) . size - ( sum - valuesToPage ) ;
}
2017-12-19 13:53:46 +01:00
}
}
2019-07-22 11:16:50 +02:00
index ++ ;
} ) ;
this . stopp = retValue ;
return retValue ;
}
* /
2017-12-19 13:53:46 +01:00
2019-02-15 13:50:24 +01:00
private handleError ( message : string , error ) {
2019-07-22 11:16:50 +02:00
console . error ( "Publication Landing Page: " + message , error ) ;
2019-02-15 13:50:24 +01:00
}
2019-07-22 11:16:50 +02:00
isRouteAvailable ( routeToCheck : string ) {
2019-06-12 16:13:56 +02:00
for ( let i = 0 ; i < this . router . config . length ; i ++ ) {
2019-07-22 11:16:50 +02:00
let routePath : string = this . router . config [ i ] . path ;
if ( routePath == routeToCheck ) {
2019-06-12 16:13:56 +02:00
return true ;
}
}
return false ;
}
2017-12-19 13:53:46 +01:00
}