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' ;
2018-04-11 17:09:23 +02:00
2019-07-22 11:16:50 +02:00
import { DatasetInfo } from '../../utils/entities/datasetInfo' ;
import { EnvProperties } from '../../utils/properties/env-properties' ;
import { RouterHelper } from '../../utils/routerHelper.class' ;
2018-04-11 17:09:23 +02:00
2019-07-22 11:16:50 +02:00
import { DatasetService } from './dataset.service' ;
import { PiwikService } from '../../utils/piwik/piwik.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" ;
2018-04-11 17:09:23 +02:00
2017-12-19 13:53:46 +01:00
@Component ( {
2019-07-22 11:16:50 +02:00
selector : 'dataset' ,
templateUrl : 'dataset.component.html' ,
2017-12-19 13:53:46 +01:00
} )
export class DatasetComponent {
2019-07-22 11:16:50 +02:00
@Input ( ) piwikSiteId = null ;
@Input ( ) communityId = null ;
public datasetInfo : DatasetInfo ;
public datasetId : string ;
// APP BOX variables
public showAllCollectedFrom : boolean = false ;
public showAllDownloadFrom : boolean = false ;
public showAllPublishedIn : boolean = false ;
public thresholdDescription : number = 270 ;
public showNumDescription : number = 270 ;
// 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 pageSize : number = 10 ;
// Active tab variable for responsiveness
public activeTab : string = "References" ;
// Map counting variable
public relatedResearchResultsNum : number = 0 ;
// Message variables
public warningMessage = "" ;
public errorMessage = "" ;
public showLoading : boolean = true ;
public pageContents = null ;
public divContents = null ;
public routerHelper : RouterHelper = new RouterHelper ( ) ;
private result ;
sub : any ;
piwiksub : any ;
infoSub : any ;
properties : EnvProperties ;
constructor ( private _datasetService : DatasetService ,
private _piwikService : PiwikService ,
private route : ActivatedRoute ,
private router : Router ,
private _meta : Meta ,
private _title : Title ,
private _router : Router ,
private seoService : SEOService ,
private helper : HelperService ) {
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
ngOnInit() {
this . route . data
. subscribe ( ( data : { envSpecific : EnvProperties } ) = > {
this . properties = data . envSpecific ;
//this.getDivContents();
this . getPageContents ( ) ;
this . updateUrl ( data . envSpecific . baseLink + this . _router . url ) ;
} ) ;
this . sub = this . route . queryParams . subscribe ( params = > {
this . datasetInfo = null ;
this . updateTitle ( "Dataset" ) ;
this . updateDescription ( "" ) ;
this . datasetId = params [ 'datasetId' ] ;
if ( this . datasetId ) {
this . getDatasetInfo ( this . datasetId ) ;
} else {
this . showLoading = false ;
this . warningMessage = "No valid research data id" ;
}
2018-02-05 14:14:59 +01:00
2019-07-22 11:16:50 +02:00
this . metricsClicked = false ;
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 . datasetId + '", "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' ;
/ * t h i s . v i e w s F r a m e U r l = t h i s . p r o p e r t i e s . f r a m e s A P I U R L + ' m e r g e . p h p ? c o m = q u e r y & d a t a = [ { " q u e r y " : " r e s V i e w s T i m e l i n e " , " r e s T i t l e " : " ' + t h i s . d a t a s e t I d + ' " , " t a b l e " : " " , " f i e l d s " : [ { " f l d " : " s u m " , " a g g " : " s u m " , " t y p e " : " c o l u m n " , " y a x i s " : 1 , " c " : f a l s e } ] , " x a x i s " : { " n a m e " : " m o n t h " , " a g g " : " s u m " } , " g r o u p " : " " , " c o l o r " : " " , " t y p e " : " c h a r t " , " s i z e " : 3 0 , " s o r t " : " x a x i s " , " x S t y l e " : { " r " : - 3 0 , " s " : " 0 " , " l " : " - " , " f t " : " - " , " w t " : " - " } , " t i t l e " : " " , " s u b t i t l e " : " " , " x a x i s t i t l e " : " R e p o s i t o r y " , " y a x i s h e a d e r s " : [ " M o n t h l y v i e w s " ] , " g e n e r a l x a x i s " : " " , " t h e m e " : 0 , " i n " : [ ] , " f i l t e r s " : [ { " n a m e " : " " , " v a l u e s " : [ " " ] , " t o " : " - 1 " } ] } ] & i n f o _ t y p e s = [ " c o l u m n " ] & s t a c k i n g = n o r m a l & s t e p s = f a l s e & f o n t F a m i l y = C o u r i e r & s p a c i n g = [ 5 , 0 , 0 , 0 ] & s t y l e = [ { " c o l o r " : " r g b a ( 0 , 0 , 0 , 1 ) " , " s i z e " : " 1 8 " } , { " c o l o r " : " r g b a ( 0 , 0 , 0 , 1 ) " , " s i z e " : " 1 8 " } , { " c o l o r " : " 0 0 0 0 0 0 " , " s i z e " : " " } , { " c o l o r " : " 0 0 0 0 0 0 " , " s i z e " : " " } ] & b a c k g r o u n d C o l o r = r g b a ( 2 5 5 , 2 5 5 , 2 5 5 , 1 ) & c o l o r s [ ] = r g b a ( 1 2 4 , 1 8 1 , 2 3 6 , 1 ) & c o l o r s [ ] = r g b a ( 6 7 , 6 7 , 7 2 , 1 ) & c o l o r s [ ] = r g b a ( 1 4 4 , 2 3 7 , 1 2 5 , 1 ) & c o l o r s [ ] = r g b a ( 2 4 7 , 1 6 3 , 9 2 , 1 ) & c o l o r s [ ] = r g b a ( 1 2 8 , 1 3 3 , 2 3 3 , 1 ) & c o l o r s [ ] = r g b a ( 2 4 1 , 9 2 , 1 2 8 , 1 ) & c o l o r s [ ] = r g b a ( 2 2 8 , 2 1 1 , 8 4 , 1 ) & c o l o r s [ ] = r g b a ( 4 3 , 1 4 4 , 1 4 3 , 1 ) & c o l o r s [ ] = r g b a ( 2 4 4 , 9 1 , 9 1 , 1 ) & c o l o r s [ ] = r g b a ( 1 4 5 , 2 3 2 , 2 2 5 , 1 ) & x l i n e w = 0 & y l i n e w = 1 & l e g e n d s = t r u e & t o o l t i p s = t r u e & p e r s i s t e n t = f a l s e ' ;
* /
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 . datasetId + '", "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' ;
/ * t h i s . d o w n l o a d s F r a m e U r l = t h i s . p r o p e r t i e s . f r a m e s A P I U R L + ' m e r g e . p h p ? c o m = q u e r y & d a t a = [ { " q u e r y " : " r e s R e p o D o w n l o a d T i m e l i n e " , " r e s T i t l e " : " ' + t h i s . d a t a s e t I d + ' " , " t a b l e " : " " , " f i e l d s " : [ { " f l d " : " s u m " , " a g g " : " s u m " , " t y p e " : " c o l u m n " , " y a x i s " : 1 , " c " : f a l s e } ] , " x a x i s " : { " n a m e " : " m o n t h " , " a g g " : " s u m " } , " g r o u p " : " " , " c o l o r " : " " , " t y p e " : " c h a r t " , " s i z e " : 3 0 , " s o r t " : " x a x i s " , " x S t y l e " : { " r " : - 3 0 , " s " : " 0 " , " l " : " - " , " f t " : " - " , " w t " : " - " } , " t i t l e " : " " , " s u b t i t l e " : " " , " x a x i s t i t l e " : " R e p o s i t o r y " , " y a x i s h e a d e r s " : [ " M o n t h l y d o w n l o a d s " ] , " g e n e r a l x a x i s " : " " , " t h e m e " : 0 , " i n " : [ ] , " f i l t e r s " : [ { " n a m e " : " " , " v a l u e s " : [ " " ] , " t o " : " - 1 " } ] } ] & i n f o _ t y p e s = [ " c o l u m n " ] & s t a c k i n g = n o r m a l & s t e p s = f a l s e & f o n t F a m i l y = C o u r i e r & s p a c i n g = [ 5 , 0 , 0 , 0 ] & s t y l e = [ { " c o l o r " : " r g b a ( 0 , 0 , 0 , 1 ) " , " s i z e " : " 1 8 " } , { " c o l o r " : " r g b a ( 0 , 0 , 0 , 1 ) " , " s i z e " : " 1 8 " } , { " c o l o r " : " 0 0 0 0 0 0 " , " s i z e " : " " } , { " c o l o r " : " 0 0 0 0 0 0 " , " s i z e " : " " } ] & b a c k g r o u n d C o l o r = r g b a ( 2 5 5 , 2 5 5 , 2 5 5 , 1 ) & c o l o r s [ ] = r g b a ( 6 7 , 6 7 , 7 2 , 1 ) & c o l o r s [ ] = r g b a ( 1 4 4 , 2 3 7 , 1 2 5 , 1 ) & c o l o r s [ ] = r g b a ( 2 4 7 , 1 6 3 , 9 2 , 1 ) & c o l o r s [ ] = r g b a ( 1 2 8 , 1 3 3 , 2 3 3 , 1 ) & c o l o r s [ ] = r g b a ( 2 4 1 , 9 2 , 1 2 8 , 1 ) & c o l o r s [ ] = r g b a ( 2 2 8 , 2 1 1 , 8 4 , 1 ) & c o l o r s [ ] = r g b a ( 4 3 , 1 4 4 , 1 4 3 , 1 ) & c o l o r s [ ] = r g b a ( 2 4 4 , 9 1 , 9 1 , 1 ) & c o l o r s [ ] = r g b a ( 1 4 5 , 2 3 2 , 2 2 5 , 1 ) & x l i n e w = 0 & y l i n e w = 1 & l e g e n d s = t r u e & t o o l t i p s = t r u e ' ;
* /
this . scroll ( ) ;
} ) ;
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
}
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 ;
} )
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
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 ( ) ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
if ( this . infoSub ) {
this . infoSub . unsubscribe ( ) ;
}
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
private getDatasetInfo ( id : string ) {
this . warningMessage = '' ;
this . errorMessage = ""
this . showLoading = true ;
this . datasetInfo = null ;
this . infoSub = this . _datasetService . getDatasetInfo ( id , this . properties ) . subscribe (
data = > {
this . datasetInfo = data ;
this . seoService . createLinkForCanonicalURL ( this . properties . baseLink + this . properties . searchLinkToDataset + this . datasetInfo . record [ "result" ] [ "header" ] [ "dri:objIdentifier" ] ) ;
/ *
if ( this . datasetInfo . title . name != undefined && this . datasetInfo . title . name != '' ) {
this . updateTitle ( this . datasetInfo . title . name ) ;
this . updateDescription ( "Dataset, search, repositories, open access," + this . datasetInfo . title . name ) ;
}
* /
if ( this . datasetInfo . title ) {
this . updateTitle ( this . datasetInfo . title ) ;
this . updateDescription ( ( this . datasetInfo . description ? ( this . datasetInfo . description ) : ( "," + this . datasetInfo . title ) ) ) ;
}
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
this . piwiksub = this . _piwikService . trackView ( this . properties , this . datasetInfo . title /*.name*/ , this . piwikSiteId ) . subscribe ( ) ;
}
this . result = [ ]
this . result = {
id : id ,
type : "dataset" ,
source : "openaire" ,
title : this.datasetInfo.title ,
url : '' ,
result : '' ,
accessRights : /*this.datasetInfo.title.accessMode*/ this . datasetInfo . accessMode ,
embargoEndDate : ''
} ;
let relatedResearchResultsNum = 0 ;
if ( this . datasetInfo . relatedResearchResults != undefined ) {
this . datasetInfo . relatedResearchResults . forEach ( function ( value , key , map ) {
relatedResearchResultsNum += value . length ;
} ) ;
}
this . relatedResearchResultsNum = relatedResearchResultsNum ;
this . showLoading = false ;
} ,
err = > {
//console.log(err)
this . handleError ( "Error getting research data for id: " + this . datasetId , err ) ;
this . seoService . createLinkForCanonicalURL ( this . properties . baseLink + this . properties . searchLinkToDatasets ) ;
this . errorMessage = 'No research data found' ;
this . showLoading = false ;
2018-09-05 14:37:47 +02:00
}
2019-07-22 11:16:50 +02:00
) ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
// showChange($event) {
// this.showAllReferences=$event.value;
// }
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
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 ) {
2019-08-02 16:55:32 +02:00
var _prefix = "" ;
if ( ! this . communityId ) {
_prefix = "OpenAIRE | " ;
}
2019-07-22 11:16:50 +02:00
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 buildCurationTooltip() {
let tooltipContent : string = "<div class='uk-padding-small uk-light'>" ;
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></di>" ;
2019-02-15 13:50:24 +01:00
2019-07-22 11:16:50 +02:00
return tooltipContent ;
}
2019-03-21 10:36:39 +01:00
2019-07-22 11:16:50 +02:00
public getKeys ( map ) {
return Array . from ( map . keys ( ) ) ;
}
2019-03-21 10:36:39 +01:00
2019-07-22 11:16:50 +02:00
private handleError ( message : string , error ) {
console . error ( "Research Data Landing Page: " + message , error ) ;
}
public updateReferencesPage ( $event ) {
this . referencesPage = $event . value ;
}
2019-05-02 11:03:05 +02: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 ) ;
2019-05-02 11:03:05 +02:00
}
2019-07-22 11:16:50 +02:00
return totalPages ;
}
public scroll() {
HelperFunctions . scroll ( ) ;
}
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
}