2019-11-27 11:51:21 +01:00
|
|
|
import {ChangeDetectorRef, Component, OnDestroy, OnInit} from '@angular/core';
|
2019-10-24 09:44:29 +02:00
|
|
|
import {ActivatedRoute, Params, Router} from '@angular/router';
|
|
|
|
import {DomSanitizer, Meta, Title} from '@angular/platform-browser';
|
|
|
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
|
|
|
|
|
|
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
|
|
|
import {StringUtils} from '../openaireLibrary/utils/string-utils.class';
|
|
|
|
|
|
|
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
|
|
|
import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component';
|
|
|
|
import {HelperService} from "../openaireLibrary/utils/helper/helper.service";
|
|
|
|
import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service";
|
|
|
|
import {StakeholderService} from "../services/stakeholder.service";
|
2019-11-20 13:55:23 +01:00
|
|
|
import {Category, ChartHelper, IndicatorPath, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder";
|
2019-10-24 09:44:29 +02:00
|
|
|
import {StatisticsService} from "../utils/services/statistics.service";
|
2019-10-25 15:19:54 +02:00
|
|
|
import {Item, Sidebar} from "../utils/entities/sidebar";
|
2019-11-14 16:20:51 +01:00
|
|
|
import {IndicatorUtils} from "../utils/indicator-utils";
|
2019-11-28 17:27:49 +01:00
|
|
|
import {StakeholderCreator} from "../utils/entities/stakeholderCreator";
|
2019-11-27 11:09:14 +01:00
|
|
|
import {LayoutService} from "../library/sharedComponents/sidebar/layout.service";
|
2019-10-24 09:44:29 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'monitor',
|
|
|
|
templateUrl: 'monitor.component.html',
|
|
|
|
})
|
2019-10-29 12:33:42 +01:00
|
|
|
export class MonitorComponent implements OnInit, OnDestroy {
|
2019-10-24 09:44:29 +02:00
|
|
|
public piwiksub: any;
|
|
|
|
public pageContents = null;
|
|
|
|
public divContents = null;
|
|
|
|
public status: number;
|
|
|
|
public loading: boolean = true;
|
2019-11-14 16:20:51 +01:00
|
|
|
public indicatorUtils: IndicatorUtils = new IndicatorUtils();
|
2019-10-24 09:44:29 +02:00
|
|
|
public activeTopic: Topic = null;
|
|
|
|
public activeCategory: Category = null;
|
|
|
|
public activeSubCategory: SubCategory = null;
|
2019-10-25 15:19:54 +02:00
|
|
|
public sideBar: Sidebar = null;
|
2019-10-24 09:44:29 +02:00
|
|
|
public errorCodes: ErrorCodes;
|
|
|
|
public stakeholder: Stakeholder;
|
|
|
|
public numberResults: Map<number, number> = new Map<number, number>();
|
|
|
|
public chartsActiveType: Map<number, IndicatorPath> = new Map<number, IndicatorPath>();
|
|
|
|
private errorMessages: ErrorMessagesComponent;
|
|
|
|
properties: EnvProperties;
|
2019-11-20 13:55:23 +01:00
|
|
|
fundingL0;
|
|
|
|
startYear;
|
|
|
|
endYear;
|
2019-10-24 09:44:29 +02:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private _router: Router,
|
|
|
|
private _meta: Meta,
|
|
|
|
private _title: Title,
|
|
|
|
private _piwikService: PiwikService,
|
|
|
|
private helper: HelperService,
|
|
|
|
private stakeholderService: StakeholderService,
|
|
|
|
private statisticsService: StatisticsService,
|
2019-11-27 11:09:14 +01:00
|
|
|
private layoutService: LayoutService,
|
2019-10-24 09:44:29 +02:00
|
|
|
private seoService: SEOService,
|
2019-10-30 16:26:19 +01:00
|
|
|
private cdr: ChangeDetectorRef,
|
2019-10-24 09:44:29 +02:00
|
|
|
private sanitizer: DomSanitizer) {
|
2019-10-29 12:33:42 +01:00
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
|
|
this.status = this.errorCodes.LOADING;
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnInit() {
|
2019-11-28 17:27:49 +01:00
|
|
|
this.layoutService.setHasSidebar(false);
|
|
|
|
this.layoutService.setHasHeader(false);
|
2019-10-24 09:44:29 +02:00
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.route.params.subscribe(params => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
var url = data.envSpecific.baseLink + this._router.url;
|
|
|
|
if (!this.stakeholder || this.stakeholder.index_id !== params['stakeholder']) {
|
|
|
|
this.status = this.errorCodes.LOADING;
|
2019-10-29 12:33:42 +01:00
|
|
|
this.numberResults = new Map<number, number>();
|
2019-10-24 09:44:29 +02:00
|
|
|
this.chartsActiveType = new Map<number, IndicatorPath>();
|
2019-11-28 17:27:49 +01:00
|
|
|
// this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
|
|
let stakeholder:Stakeholder = null;
|
|
|
|
if(params['stakeholder']=="fwf"){
|
|
|
|
stakeholder = StakeholderCreator.createFunderFromDefaultProfile("fwf","funder","fwf_________::FWF",
|
|
|
|
"Austrian Science Fund (FWF)","FWF",
|
|
|
|
false,"fwf",true,true, null);
|
|
|
|
stakeholder.logoUrl = "./assets/fwf.png";
|
|
|
|
}else if(params['stakeholder']=="arc"){
|
|
|
|
stakeholder = StakeholderCreator.createFunderFromDefaultProfile("arc","funder","arc_________::ARC",
|
|
|
|
"Australian Research Council (ARC)","ARC",
|
|
|
|
false,"arc",true,true, null);
|
|
|
|
stakeholder.logoUrl = "./assets/arc1.gif";
|
|
|
|
}else{
|
|
|
|
stakeholder = StakeholderCreator.createFunderFromDefaultProfile("ec","funder","ec__________::EC",
|
|
|
|
"European Commission","EC",
|
|
|
|
false,"ec",true,true, null);
|
|
|
|
stakeholder.logoUrl = "./assets/ec.png";
|
|
|
|
}
|
|
|
|
|
2019-11-13 15:27:07 +01:00
|
|
|
if(stakeholder) {
|
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
this.seoService.createLinkForCanonicalURL(url, false);
|
|
|
|
this._meta.updateTag({content: url}, "property='og:url'");
|
|
|
|
var description = "Monitor Dashboard | " + this.stakeholder.index_name;
|
|
|
|
var title = "Monitor Dashboard | " + this.stakeholder.index_shortName;
|
|
|
|
this._meta.updateTag({content: description}, "name='description'");
|
|
|
|
this._meta.updateTag({content: description}, "property='og:description'");
|
|
|
|
this._meta.updateTag({content: title}, "property='og:title'");
|
|
|
|
this._title.setTitle(title);
|
|
|
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
|
|
|
this.piwiksub = this._piwikService.trackView(this.properties, title, this.properties.piwikSiteId).subscribe();
|
|
|
|
}
|
|
|
|
//this.getDivContents();
|
|
|
|
this.getPageContents();
|
|
|
|
this.status = this.errorCodes.DONE;
|
|
|
|
this.setView(params);
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
2019-11-28 17:27:49 +01:00
|
|
|
// }, error => {
|
|
|
|
// this.navigateToError();
|
|
|
|
// })
|
2019-10-24 09:44:29 +02:00
|
|
|
} else {
|
|
|
|
this.setView(params);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-10-29 12:33:42 +01:00
|
|
|
public get open() {
|
2019-11-27 11:09:14 +01:00
|
|
|
return this.layoutService.open;
|
2019-10-29 12:33:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public toggleOpen(event = null) {
|
|
|
|
if(!event) {
|
2019-11-27 11:09:14 +01:00
|
|
|
this.layoutService.setOpen(!this.open);
|
2019-10-29 12:33:42 +01:00
|
|
|
} else if(event && event['value'] === true) {
|
2019-11-27 11:09:14 +01:00
|
|
|
this.layoutService.setOpen(false);
|
2019-10-29 12:33:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 09:44:29 +02:00
|
|
|
private getPageContents() {
|
|
|
|
this.helper.getPageHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
|
|
|
|
this.pageContents = contents;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
private getDivContents() {
|
|
|
|
this.helper.getDivHelpContents(this._router.url, this.properties, 'monitor').subscribe(contents => {
|
|
|
|
this.divContents = contents;
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
private setView(params: Params) {
|
|
|
|
if (params && params['topic']) {
|
|
|
|
this.activeTopic = this.stakeholder.topics.filter(topic => topic.alias === decodeURIComponent(params['topic']))[0];
|
|
|
|
if (this.activeTopic) {
|
|
|
|
if (params['category']) {
|
|
|
|
this.activeCategory = this.activeTopic.categories.filter(category =>
|
|
|
|
(category.alias === params['category']) && category.isPublic && category.isActive)[0];
|
|
|
|
} else {
|
|
|
|
let category: Category = this.activeTopic.categories[0];
|
2019-11-05 15:59:06 +01:00
|
|
|
if(category) {
|
|
|
|
this.navigateTo(this.stakeholder.alias, this.activeTopic.alias, category.alias);
|
|
|
|
} else {
|
|
|
|
this.navigateToError();
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.activeCategory) {
|
|
|
|
if (params['subCategory']) {
|
|
|
|
this.activeSubCategory = this.activeCategory.subCategories.filter(subCategory =>
|
|
|
|
(subCategory.alias === params['subCategory'] && subCategory.isPublic && subCategory.isActive))[0];
|
|
|
|
} else {
|
|
|
|
this.activeSubCategory = this.activeCategory.subCategories.filter(subCategory =>
|
|
|
|
!subCategory.alias && subCategory.isPublic && subCategory.isActive)[0];
|
|
|
|
}
|
|
|
|
if (this.activeSubCategory) {
|
|
|
|
this.setSideBar();
|
|
|
|
this.setIndicators();
|
|
|
|
return;
|
|
|
|
} else {
|
2019-10-29 12:33:42 +01:00
|
|
|
let subCategory: SubCategory = this.activeCategory.subCategories.filter(subCategory =>
|
|
|
|
subCategory.isPublic && subCategory.isActive)[0];
|
2019-10-24 09:44:29 +02:00
|
|
|
this.navigateTo(this.stakeholder.alias, this.activeTopic.alias, this.activeCategory.alias, subCategory.alias);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.navigateToError();
|
|
|
|
} else {
|
|
|
|
let topic: Topic = this.stakeholder.topics[0];
|
|
|
|
let category: Category = topic.categories.filter(category => category.isPublic && category.isActive)[0];
|
2019-11-05 15:59:06 +01:00
|
|
|
if(topic && category) {
|
|
|
|
this.navigateTo(this.stakeholder.alias, topic.alias, category.alias);
|
|
|
|
} else {
|
|
|
|
this.navigateToError();
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private setSideBar() {
|
2019-10-25 15:19:54 +02:00
|
|
|
let items: Item[] = [];
|
2019-10-24 09:44:29 +02:00
|
|
|
this.activeTopic.categories.forEach(category => {
|
|
|
|
if (category.isPublic && category.isActive) {
|
2019-10-25 15:19:54 +02:00
|
|
|
let subItems: Item[] = [];
|
2019-10-24 09:44:29 +02:00
|
|
|
category.subCategories.forEach(subCategory => {
|
|
|
|
if (subCategory.alias != null && subCategory.isPublic && subCategory.isActive) {
|
2019-10-25 15:19:54 +02:00
|
|
|
subItems.push(new Item(subCategory.name, (
|
2019-11-28 17:27:49 +01:00
|
|
|
'/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias + '/' + subCategory.alias),
|
2019-10-25 15:19:54 +02:00
|
|
|
null, null, false));
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
});
|
2019-10-25 15:19:54 +02:00
|
|
|
const open = this.activeCategory.alias === category.alias;
|
|
|
|
items.push(new Item(category.name, (
|
2019-11-28 17:27:49 +01:00
|
|
|
'/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias),
|
2019-10-25 15:19:54 +02:00
|
|
|
subItems, null, open));
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
});
|
2019-11-01 19:30:11 +01:00
|
|
|
this.sideBar = new Sidebar(items, null);
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private setIndicators() {
|
|
|
|
let urls: Map<string, number[]> = new Map<string, number[]>();
|
|
|
|
this.activeSubCategory.numbers.forEach((number, index) => {
|
2019-10-29 12:33:42 +01:00
|
|
|
if (number.isActive && number.isPublic) {
|
2019-11-20 13:55:23 +01:00
|
|
|
let url = number.indicatorPaths[0].url;
|
|
|
|
//add fundingLevel0 filter in the query
|
|
|
|
if(this.fundingL0 && number.indicatorPaths[0].filters.get("fundingL0")){
|
|
|
|
url = url + number.indicatorPaths[0].filters.get("fundingL0").replace(ChartHelper.prefix+'fundingL0'+ChartHelper.suffix,encodeURIComponent(this.fundingL0));
|
|
|
|
}
|
|
|
|
const pair = JSON.stringify([number.indicatorPaths[0].source, url]);
|
2019-10-24 09:44:29 +02:00
|
|
|
const indexes = urls.get(pair) ? urls.get(pair) : [];
|
|
|
|
indexes.push(index);
|
|
|
|
urls.set(pair, indexes);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
urls.forEach((indexes, pair) => {
|
|
|
|
pair = JSON.parse(pair);
|
2019-10-29 12:33:42 +01:00
|
|
|
this.statisticsService.getNumbers(pair[0], pair[1]).subscribe(response => {
|
|
|
|
indexes.forEach(index => {
|
2019-10-24 09:44:29 +02:00
|
|
|
let result = JSON.parse(JSON.stringify(response));
|
|
|
|
this.activeSubCategory.numbers[index].indicatorPaths[0].jsonPath.forEach(jsonPath => {
|
2019-10-29 12:33:42 +01:00
|
|
|
if (result) {
|
|
|
|
result = result[jsonPath];
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
});
|
|
|
|
this.numberResults.set(index, result);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
this.activeSubCategory.charts.forEach((chart, index) => {
|
|
|
|
if (chart.indicatorPaths.length > 0) {
|
2019-10-30 16:26:19 +01:00
|
|
|
chart.indicatorPaths[0].safeResourceUrl = this.getUrlByStakeHolder(chart.indicatorPaths[0]);
|
2019-10-24 09:44:29 +02:00
|
|
|
this.chartsActiveType.set(index, chart.indicatorPaths[0]);
|
|
|
|
}
|
|
|
|
});
|
2019-10-30 16:26:19 +01:00
|
|
|
this.cdr.detectChanges();
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public getUrlByStakeHolder(indicatorPath: IndicatorPath) {
|
2019-11-14 16:20:51 +01:00
|
|
|
return this.sanitizer.bypassSecurityTrustResourceUrl(
|
2019-11-20 13:55:23 +01:00
|
|
|
this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(indicatorPath, this.fundingL0, this.startYear, this.endYear)));
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public setActiveChart(index, type: string) {
|
2019-10-30 16:26:19 +01:00
|
|
|
let activeChart = this.activeSubCategory.charts[index].indicatorPaths.filter(indicatorPath => indicatorPath.type === type)[0];
|
|
|
|
activeChart.safeResourceUrl = this.getUrlByStakeHolder(activeChart);
|
|
|
|
this.chartsActiveType.set(index, activeChart);
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private navigateToError() {
|
|
|
|
this._router.navigate(['/error'], {queryParams: {'page': this._router.url}});
|
|
|
|
}
|
|
|
|
|
|
|
|
public navigateTo(stakeholder: string, topic: string, category: string = null, subcategory: string = null) {
|
2019-11-27 11:51:21 +01:00
|
|
|
let url = stakeholder + '/' + topic + ((category) ? ('/'
|
2019-10-24 09:44:29 +02:00
|
|
|
+ category) : '') + ((subcategory) ? ('/' + subcategory) : '');
|
|
|
|
return this._router.navigate([url]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public quote(param: string): string {
|
|
|
|
return StringUtils.quote(param);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ngOnDestroy() {
|
|
|
|
if (this.piwiksub) {
|
|
|
|
this.piwiksub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|