211 lines
9.1 KiB
TypeScript
211 lines
9.1 KiB
TypeScript
import {Component, ViewChild} from '@angular/core';
|
|
import {Input} from '@angular/core';
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
import {Title, Meta} from '@angular/platform-browser';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
import {OrpInfo} from '../../utils/entities/orpInfo';
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
|
import {RouterHelper} from '../../utils/routerHelper.class';
|
|
|
|
import {OrpService} from './orp.service';
|
|
import {PiwikService} from '../../utils/piwik/piwik.service';
|
|
import { SEOService } from '../../sharedComponents/SEO/SEO.service';
|
|
import {HelperFunctions} from "../../utils/HelperFunctions.class";
|
|
|
|
|
|
@Component({
|
|
selector: 'orp',
|
|
templateUrl: 'orp.component.html',
|
|
})
|
|
|
|
export class OrpComponent {
|
|
@Input() piwikSiteId = null;
|
|
public orpInfo: OrpInfo;
|
|
public orpId : 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 routerHelper:RouterHelper = new RouterHelper();
|
|
|
|
private result ;
|
|
sub: any; piwiksub: any; infoSub: any;
|
|
properties:EnvProperties;
|
|
|
|
constructor (private _orpService: OrpService,
|
|
private _piwikService:PiwikService,
|
|
private route: ActivatedRoute,
|
|
private _meta: Meta,
|
|
private _title: Title,
|
|
private _router: Router,
|
|
private seoService: SEOService) {
|
|
}
|
|
|
|
ngOnInit() {
|
|
this.route.data
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
this.properties = data.envSpecific;
|
|
this.updateUrl(data.envSpecific.baseLink+this._router.url);
|
|
this.seoService.createLinkForCanonicalURL(this.properties.baseLink+this._router.url);
|
|
|
|
});
|
|
this.sub = this.route.queryParams.subscribe(params => {
|
|
this.orpInfo = null;
|
|
this.updateTitle("Other Research Product");
|
|
this.updateDescription("");
|
|
this.orpId = params['orpId'];
|
|
|
|
if(this.orpId){
|
|
this.getOrpInfo(this.orpId);
|
|
}else{
|
|
this.showLoading = false;
|
|
this.warningMessage="No valid research product id";
|
|
}
|
|
|
|
this.metricsClicked = false;
|
|
|
|
this.viewsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoViews", "resTitle":"'+this.orpId+'", "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';
|
|
|
|
this.downloadsFrameUrl = this.properties.framesAPIURL+'merge.php?com=query&data=[{"query":"resRepoDownloads", "resTitle":"'+this.orpId+'", "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';
|
|
|
|
this.scroll();
|
|
});
|
|
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
if(this.sub){
|
|
this.sub.unsubscribe();
|
|
}
|
|
if(this.piwiksub){
|
|
this.piwiksub.unsubscribe();
|
|
}
|
|
if(this.infoSub) {
|
|
this.infoSub.unsubscribe();
|
|
}
|
|
}
|
|
|
|
private getOrpInfo(id:string) {
|
|
this.warningMessage = '';
|
|
this.errorMessage=""
|
|
this.showLoading = true;
|
|
|
|
this.orpInfo = null;
|
|
|
|
this.infoSub = this._orpService.getOrpInfo(id, this. properties).subscribe(
|
|
data => {
|
|
this.orpInfo = data;
|
|
if(this.orpInfo.title){
|
|
this.updateTitle(this.orpInfo.title);
|
|
this.updateDescription((this.orpInfo.description?(this.orpInfo.description):(","+this.orpInfo.title)));
|
|
}
|
|
if(this.properties.enablePiwikTrack && (typeof document !== 'undefined')){
|
|
this.piwiksub = this._piwikService.trackView(this.properties, this.orpInfo.title, this.piwikSiteId).subscribe();
|
|
}
|
|
|
|
this.result = []
|
|
this.result = {id: id, type :"orp", source : "openaire", title: this.orpInfo.title,url: '', result: '', accessRights: this.orpInfo.accessMode, embargoEndDate: ''};
|
|
|
|
let relatedResearchResultsNum = 0;
|
|
if(this.orpInfo.relatedResearchResults != undefined) {
|
|
this.orpInfo.relatedResearchResults.forEach(function (value, key, map) {
|
|
relatedResearchResultsNum += value.length;
|
|
});
|
|
}
|
|
this.relatedResearchResultsNum = relatedResearchResultsNum;
|
|
|
|
this.showLoading = false;
|
|
},
|
|
err => {
|
|
//console.log(err)
|
|
this.handleError("Error getting other research product for id: "+this.orpId, err);
|
|
|
|
this.errorMessage = 'No research product found';
|
|
this.showLoading = false;
|
|
}
|
|
);
|
|
}
|
|
|
|
public metricsResults($event) {
|
|
this.totalViews = $event.totalViews;
|
|
this.totalDownloads = $event.totalDownloads;
|
|
this.pageViews = $event.pageViews;
|
|
}
|
|
|
|
private updateDescription(description:string){
|
|
this._meta.updateTag({content:description},"name='description'");
|
|
this._meta.updateTag({content:description},"property='og:description'");
|
|
}
|
|
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'");
|
|
}
|
|
private updateUrl(url:string){
|
|
this._meta.updateTag({content:url},"property='og:url'");
|
|
}
|
|
|
|
public buildCurationTooltip() {
|
|
let tooltipContent: string = "<div class='uk-padding-small uk-light'>";
|
|
|
|
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>";
|
|
|
|
return tooltipContent;
|
|
}
|
|
public getKeys( map) {
|
|
return Array.from(map.keys());
|
|
}
|
|
|
|
public scroll() {
|
|
HelperFunctions.scroll();
|
|
}
|
|
|
|
private handleError(message: string, error) {
|
|
console.error("Other Research Product Landing Page: "+message, error);
|
|
}
|
|
|
|
public updateReferencesPage($event) {
|
|
this.referencesPage = $event.value;
|
|
}
|
|
|
|
public totalPages(totalResults: number): number {
|
|
let totalPages:any = totalResults/this.pageSize;
|
|
if(!(Number.isInteger(totalPages))) {
|
|
totalPages = (parseInt(totalPages, this.pageSize) + 1);
|
|
}
|
|
return totalPages;
|
|
}
|
|
}
|