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' ;
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
2019-07-22 11:16:50 +02:00
import { EnvProperties } from '../../utils/properties/env-properties' ;
Replace meta service import and use with meta and title from angular/platform-browser for user, publication, claimAdmin,claimsByToken, directLinking, linkingGeneric, myClaims, depositBySubject, depositBySubjectResult, deposit, depositResult, dataProvider, htmlProjectReport, organization, project, software, search, advancedSearchPage, searchPage and searchPageTableView component
git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@51835 d315682c-612b-4755-9ff5-7f18f6832af3
2018-04-17 15:00:23 +02:00
2019-07-22 11:16:50 +02:00
import { HtmlProjectReportService } from './htmlProjectReport.service' ;
import { ProjectService } from '../project/project.service' ;
import { PiwikService } from '../../utils/piwik/piwik.service' ;
import { SEOService } from '../../sharedComponents/SEO/SEO.service' ;
import { HelperService } from "../../utils/helper/helper.service" ;
2020-11-11 15:43:13 +01:00
import { Subscriber } from "rxjs" ;
2020-11-18 17:06:27 +01:00
import { properties } from "../../../../environments/environment" ;
2017-12-19 13:53:46 +01:00
declare var UIkit : any ;
@Component ( {
2019-07-22 11:16:50 +02:00
selector : 'htmlProjectReport' ,
template : `
2019-07-22 16:15:23 +02:00
< div id = "tm-main" class = " uk-section uk-padding-remove-top tm-middle" >
2019-07-22 11:16:50 +02:00
< div uk - grid >
< div class = "tm-main uk-width-1-1@s uk-width-1-1@m uk-width-1-1@l uk-row-first " >
< helper * ngIf = "pageContents && pageContents['top'] && pageContents['top'].length > 0"
[ texts ] = "pageContents['top']" styleName = "uk-width-1-1" > < / helper >
< div class = "uk-container uk-margin-top uk-width-1-1" >
< div * ngIf = "warningMessage" class = "uk-alert uk-alert-warning" role = "alert" > { { warningMessage } } < / div >
< div [ style.display ] = " showLoading ? ' inline ' : ' none ' "
class = "uk-animation-fade uk-margin-large-top uk-width-1-1" role = "alert" > < span
class = "loading-gif uk-align-center" > < / span > < / div >
2019-07-23 16:04:49 +02:00
2019-07-22 11:16:50 +02:00
< div * ngIf = "!showLoading && !warningMessage" >
2019-07-22 16:15:23 +02:00
< div * ngIf = "header1" class = "uk-h4 uk-text-bold " > { { header1 } } < / div >
< div * ngIf = "header1 || htmlResult" class = " " > { { header2 } } < / div >
2019-07-22 11:16:50 +02:00
< div class = "uk-clearfix uk-margin-bottom" >
< button * ngIf = "htmlResult" class = "uk-icon-clipboard uk-button uk-button-primary clipBtn uk-float-right"
( click ) = "copied()" >
2017-12-19 13:53:46 +01:00
Copy to clipboard
2019-07-22 11:16:50 +02:00
< / button >
< / div >
<!-- div class = "uk-panel-scrollable custom-html-table-height" * ngIf = "htmlResult" id = "clipboard" [ innerHTML ] = "htmlResult" > < / d i v - - >
< div class = "uk-overflow-auto custom-html-table-height" * ngIf = "htmlResult" id = "clipboard"
[ innerHTML ] = "htmlResult" > < / div >
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
< div * ngIf = "errorMessage" class = "uk-alert uk-alert-danger" role = "alert" > { { errorMessage } } < / div >
< / div >
2017-12-19 13:53:46 +01:00
< / div >
2019-07-22 11:16:50 +02:00
< helper * ngIf = "pageContents && pageContents['bottom'] && pageContents['bottom'].length > 0"
[ texts ] = "pageContents['bottom']" styleName = "uk-width-1-1" > < / helper >
< / div >
2017-12-19 13:53:46 +01:00
< / div >
< / div >
2019-07-22 11:16:50 +02:00
`
} )
export class HtmlProjectReportComponent {
2018-04-11 10:59:01 +02:00
@Input ( ) piwikSiteId = null ;
2019-07-22 11:16:50 +02:00
@Input ( ) communityId = null ;
private projectId : string ;
private totalResults : number = 10 ;
private resultsType : string = "publication" ;
public header1 : string = "" ;
public header2 : string = "" ;
public htmlResult : string = "" ;
2020-11-11 15:43:13 +01:00
subscriptions = [ ] ;
2019-07-22 11:16:50 +02:00
public warningMessage : string = "" ;
public errorMessage : string = "" ;
public showLoading : boolean = true ;
properties : EnvProperties ;
public pageContents = null ;
public divContents = null ;
constructor ( private route : ActivatedRoute ,
private htmlService : HtmlProjectReportService ,
private _piwikService : PiwikService ,
private _projectService : ProjectService ,
private _meta : Meta ,
private _title : Title ,
private _router : Router ,
private helper : HelperService ,
private seoService : SEOService ) {
}
ngOnInit() {
2020-11-18 17:06:27 +01:00
this . properties = properties ;
2019-07-22 11:16:50 +02:00
//this.getDivContents();
this . getPageContents ( ) ;
2020-09-18 12:10:18 +02:00
this . updateUrl ( this . properties . domain + this . properties . baseLink + this . _router . url ) ;
2020-09-18 09:57:42 +02:00
this . seoService . createLinkForCanonicalURL ( this . properties . domain + this . properties . baseLink + this . _router . url ) ;
2017-12-19 13:53:46 +01:00
2020-11-18 17:06:27 +01:00
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . route . queryParams . subscribe ( params = > {
2019-07-22 11:16:50 +02:00
this . projectId = params [ 'projectId' ] ;
if ( params [ 'size' ] == parseInt ( params [ 'size' ] , 10 ) ) {
this . totalResults = params [ 'size' ] ;
} else {
this . showLoading = false ;
this . warningMessage = "Requested size is not an integer" ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
if ( params [ 'type' ] && ( params [ 'type' ] == "publication" || params [ 'type' ] == "dataset" || params [ 'type' ] == "software" || params [ 'type' ] == "other" ) ) {
if ( params [ 'type' ] == "publication" ) {
this . resultsType = 'publication' ;
} else if ( params [ 'type' ] == "dataset" ) {
this . resultsType = 'research data' ;
} else if ( params [ 'type' ] == "software" ) {
this . resultsType = 'software' ;
} else if ( params [ 'type' ] == "other" ) {
this . resultsType = "other research product" ;
}
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
var title = "Project's " + this . resultsType + " report" ;
var description = "project, project " + this . resultsType + " report, funding, open access, publications, research data, software, other research products" ;
this . updateTitle ( title ) ;
this . updateDescription ( description ) ;
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
} else {
this . showLoading = false ;
this . warningMessage = "Requested type should be publication or research data or software or other research product" ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
//showLoading is true if no warnings
if ( this . showLoading ) {
if ( this . projectId ) {
this . createHeaders ( ) ;
} else {
this . showLoading = false ;
this . warningMessage = "No valid project id" ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
}
2020-11-11 15:43:13 +01:00
} ) ) ;
2019-07-22 11:16:50 +02:00
}
private getPageContents() {
2020-06-29 15:15:52 +02:00
if ( this . communityId ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . helper . getPageHelpContents ( this . properties , this . communityId , this . _router . url ) . subscribe ( contents = > {
2020-06-29 15:15:52 +02:00
this . pageContents = contents ;
2020-11-11 15:43:13 +01:00
} ) ) ;
2020-06-29 15:15:52 +02:00
}
2019-07-22 11:16:50 +02:00
}
private getDivContents() {
2020-06-29 15:15:52 +02:00
if ( this . communityId ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . helper . getDivHelpContents ( this . properties , this . communityId , this . _router . url ) . subscribe ( contents = > {
2020-06-29 15:15:52 +02:00
this . divContents = contents ;
2020-11-11 15:43:13 +01:00
} ) ) ;
2020-06-29 15:15:52 +02:00
}
2019-07-22 11:16:50 +02:00
}
ngOnDestroy() {
2020-11-11 15:43:13 +01:00
this . subscriptions . forEach ( subscription = > {
if ( subscription instanceof Subscriber ) {
subscription . unsubscribe ( ) ;
}
} ) ;
2019-07-22 11:16:50 +02:00
}
private createHeaders() {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . _projectService . getHTMLInfo ( this . projectId , this . properties ) . subscribe (
2019-07-22 11:16:50 +02:00
data = > {
this . createHeader1 ( data ) ;
if ( data . acronym ) {
this . updateTitle ( data . acronym + " " + this . resultsType + " report" ) ;
} else if ( data . title ) {
this . updateTitle ( data . title + " " + this . resultsType + " report" ) ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
if ( this . properties . enablePiwikTrack && ( typeof document !== 'undefined' ) ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . _piwikService . trackView ( this . properties , ( ( data . acronym ) ? data.acronym : data.title ) + " " + this . resultsType + " report" , this . piwikSiteId ) . subscribe ( ) ) ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
} ,
err = > {
this . handleError ( "Error getting html information for project id: " + this . projectId , err ) ;
//console.log(err);
2017-12-19 13:53:46 +01:00
this . createClipboard ( ) ;
2019-07-22 11:16:50 +02:00
}
2020-11-11 15:43:13 +01:00
) ) ;
2019-07-22 11:16:50 +02:00
if ( this . resultsType == "publication" ) {
this . header2 += this . totalResults . toLocaleString ( 'en-US' ) + " publications" ;
} else if ( this . resultsType == "research data" ) {
this . header2 += this . totalResults . toLocaleString ( 'en-US' ) + " research data" ;
} else if ( this . resultsType == "software" ) {
this . header2 += this . totalResults . toLocaleString ( 'en-US' ) + " software" ;
} else if ( this . resultsType == "other research product" ) {
this . header2 += this . totalResults . toLocaleString ( 'en-US' ) + " other" ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
}
private createClipboard() {
let intro : string = '<!doctype html>' ;
intro += '<html lang="en-gb" dir="ltr" vocab="http://schema.org/">' ;
intro += '<head>' ;
intro += '<title>' + this . header1 + '</title>'
intro += '</head>' ;
if ( typeof window !== 'undefined' ) {
2020-11-11 15:43:13 +01:00
this . subscriptions . push ( this . htmlService . getHTML ( this . projectId , this . resultsType , this . properties . csvAPIURL ) . subscribe (
2019-07-22 11:16:50 +02:00
data = > {
//let body: string = intro+'<body><h1>'+this.header1+'</h1><h2>'+this.header2+'</h2>'+data+'</body></html>';
let body : string = intro + '<body><h1>' + this . header1 + '</h1><h2>' + this . header2 + '</h2>' ;
body += "<table><thead><tr> <th>Title</th><th>Authors</th><th>Publication Year</th><th>DOI</th><th>Permanent Identifier</th><th>Publication type</th><th>Journal</th><th>Project Name (GA Number)</th><th>Access Mode</th></tr></thead><tbody>" + data + "</tbody></table>" ;
body += '</body></html>' ;
//this.htmlResult = data;
this . htmlResult = " < table > < thead > < tr > < th > Title < / th > < th > Authors < / th > < th > Publication Year < / th > < th > DOI < / th > < th > Permanent Identifier < / th > < th > Publication type < / th > < th > Journal < / th > < th > Project Name ( GA Number ) < / th > < th > Access Mode < / th > < / tr > < / thead > < tbody > " + data + " < / tbody > < / table > " ;
let clipboard ;
let Clipboard ;
Clipboard = require ( 'clipboard' ) ;
clipboard = new Clipboard ( '.clipBtn' , {
/ * t a r g e t : f u n c t i o n ( t r i g g e r ) {
return document . getElementById ( "clipboard" ) ;
} * /
text : function ( trigger ) {
return body ; //document.getElementById("clipboard").getAttribute('innerHTML');//"aaaa"+tmp+"oo";
}
} ) ;
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
this . showLoading = false ;
} ,
err = > {
//console.log(err);
this . handleError ( "Error getting html for id: " + this . projectId , err ) ;
2017-12-19 13:53:46 +01:00
2019-07-22 11:16:50 +02:00
this . errorMessage = 'Service not available' ;
this . showLoading = false ;
}
2020-11-11 15:43:13 +01:00
) ) ;
2017-12-19 13:53:46 +01:00
}
2019-07-22 11:16:50 +02:00
}
createHeader1 ( data : { "title" : string , "acronym" : string , "callIdentifier" : string } ) {
if ( this . resultsType == "publication" ) {
this . header1 += "Publications" ;
} else if ( this . resultsType == "research data" ) {
this . header1 += "Research Data" ;
} else if ( this . resultsType == "software" ) {
this . header1 += "Software" ;
} else if ( this . resultsType == "other research product" ) {
this . header1 += "Other Research Products" ;
2017-12-19 13:53:46 +01:00
}
2019-02-15 13:50:24 +01:00
2019-07-22 11:16:50 +02:00
if ( data != undefined ) {
if ( data . title != undefined && data . title != "" ) {
this . header1 += data . title ;
}
if ( ( data . title != undefined && data . title != "" ) &&
( ( data . acronym != undefined && data . acronym != "" ) ||
( data . callIdentifier != undefined && data . callIdentifier != "" ) ) ) {
this . header1 += "(" ;
}
if ( data . acronym != undefined && data . acronym != "" ) {
this . header1 += data . acronym + " - " ;
}
if ( data . callIdentifier != undefined && data . callIdentifier != "" ) {
this . header1 += data . callIdentifier ;
}
if ( ( data . title != undefined && data . title != "" ) &&
( ( data . acronym != undefined && data . acronym != "" ) ||
( data . callIdentifier != undefined && data . callIdentifier != "" ) ) ) {
this . header1 += ")" ;
}
2019-02-15 13:50:24 +01:00
}
2019-07-22 11:16:50 +02:00
this . createClipboard ( ) ;
}
public copied() {
UIkit . notification ( {
message : '<strong>Raw html is copied. Please paste it on an html file.<strong>' ,
status : 'success' ,
timeout : 3000 ,
pos : 'top-center'
} ) ;
}
private updateDescription ( description : string ) {
this . _meta . updateTag ( { content : description } , "name='description'" ) ;
this . _meta . updateTag ( { content : description } , "property='og:description'" ) ;
}
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'" ) ;
}
private updateUrl ( url : string ) {
this . _meta . updateTag ( { content : url } , "property='og:url'" ) ;
}
private handleError ( message : string , error ) {
console . error ( "Html Project Report Page: " + message , error ) ;
}
2017-12-19 13:53:46 +01:00
}