187 lines
7.2 KiB
TypeScript
187 lines
7.2 KiB
TypeScript
import {Component} from '@angular/core';
|
|
import {ActivatedRoute, Params, Router} from '@angular/router';
|
|
import {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";
|
|
import {Category, Indicator, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder";
|
|
import {MenuItem, RootMenuItem, SideMenuItem} from "../openaireLibrary/sharedComponents/menu";
|
|
|
|
@Component({
|
|
selector: 'monitor',
|
|
templateUrl: 'monitor.component.html',
|
|
})
|
|
export class MonitorComponent {
|
|
public piwiksub: any;
|
|
public pageContents = null;
|
|
public divContents = null;
|
|
public status: number;
|
|
public loading: boolean = true;
|
|
public activeTopic: Topic = null;
|
|
public activeCategory: Category = null;
|
|
public activeSubCategory: SubCategory = null;
|
|
public sideMenuItems: SideMenuItem[] = null;
|
|
public errorCodes: ErrorCodes;
|
|
public stakeholder: Stakeholder;
|
|
public numbers: Indicator[] = [];
|
|
public charts: Indicator[] = [];
|
|
private errorMessages: ErrorMessagesComponent;
|
|
properties: EnvProperties;
|
|
|
|
constructor(
|
|
private route: ActivatedRoute,
|
|
private _router: Router,
|
|
private _meta: Meta,
|
|
private _title: Title,
|
|
private _piwikService: PiwikService,
|
|
private helper: HelperService,
|
|
private stakeholderService: StakeholderService,
|
|
private seoService: SEOService) {
|
|
this.errorCodes = new ErrorCodes();
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
this.status = this.errorCodes.LOADING;
|
|
}
|
|
|
|
public ngOnInit() {
|
|
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;
|
|
this.stakeholderService.getStakeholder(params['stakeholder']).subscribe(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);
|
|
}, error => {
|
|
this.navigateToError();
|
|
})
|
|
} else {
|
|
this.setView(params);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
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 === decodeURIComponent(params['category']))[0];
|
|
} else {
|
|
let category: Category = this.activeTopic.categories[0];
|
|
this.navigateTo(this.stakeholder.alias, this.activeTopic.alias, category.alias);
|
|
return;
|
|
}
|
|
if(this.activeCategory) {
|
|
if(params['subCategory']) {
|
|
this.activeSubCategory = this.activeCategory.subCategories.filter(subCategory =>
|
|
subCategory.alias = decodeURIComponent(params['subCategory']))[0];
|
|
} else {
|
|
this.activeSubCategory = this.activeCategory.subCategories.filter(subCategory => !subCategory.alias)[0];
|
|
}
|
|
if(this.activeSubCategory) {
|
|
this.setSideBar();
|
|
this.setIndicators();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
this.navigateToError();
|
|
} else {
|
|
let topic: Topic = this.stakeholder.topics[0];
|
|
let category: Category = topic.categories[0];
|
|
this.navigateTo(this.stakeholder.alias, topic.alias, category.alias);
|
|
}
|
|
}
|
|
|
|
private setSideBar() {
|
|
this.sideMenuItems = [];
|
|
this.activeTopic.categories.forEach(category => {
|
|
let rootItem: MenuItem = new MenuItem(category.alias, category.name, null, (
|
|
'/monitor/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias),
|
|
false, null, null, null);
|
|
let items: RootMenuItem[] = [];
|
|
category.subCategories.forEach(subCategory => {
|
|
if(subCategory.alias != null) {
|
|
items.push({
|
|
items: [],
|
|
rootItem: new MenuItem(subCategory.alias, subCategory.name, null, (
|
|
'/monitor/' + this.stakeholder.alias + '/' + this.activeTopic.alias + '/' + category.alias + '/' + subCategory.alias),
|
|
false, null, null, null)
|
|
});
|
|
}
|
|
});
|
|
this.sideMenuItems.push({
|
|
rootItem: rootItem,
|
|
items: items,
|
|
ukIcon: null
|
|
});
|
|
});
|
|
}
|
|
|
|
private setIndicators() {
|
|
this.stakeholderService.getIndicators(this.activeSubCategory.numbers).subscribe( numbers => {
|
|
this.numbers = numbers;
|
|
});
|
|
this.stakeholderService.getIndicators(this.activeSubCategory.charts).subscribe( charts => {
|
|
this.charts = charts;
|
|
});
|
|
}
|
|
|
|
public navigateToError() {
|
|
this._router.navigate(['/error'],{queryParams: {'page': this._router.url}});
|
|
}
|
|
|
|
public navigateTo(stakeholder: string, topic: string, category: string = null, subcategory: string = null) {
|
|
let url = 'monitor/' + stakeholder+ '/' + topic + ((category)?('/'
|
|
+ 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();
|
|
}
|
|
}
|
|
}
|