2020-06-25 10:10:42 +02:00
|
|
|
import {ChangeDetectorRef, Component, OnDestroy, OnInit, ViewRef} 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';
|
2020-07-07 16:08:47 +02:00
|
|
|
import {Dates, StringUtils} from '../openaireLibrary/utils/string-utils.class';
|
2019-10-24 09:44:29 +02:00
|
|
|
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";
|
2020-06-03 15:44:03 +02:00
|
|
|
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
|
2020-10-23 15:58:16 +02:00
|
|
|
import {
|
2020-11-05 17:50:06 +01:00
|
|
|
Category, Indicator,
|
2020-12-01 16:43:43 +01:00
|
|
|
IndicatorPath, IndicatorSize,
|
2020-10-23 15:58:16 +02:00
|
|
|
Stakeholder,
|
|
|
|
SubCategory,
|
|
|
|
Topic,
|
|
|
|
Visibility
|
|
|
|
} from "../openaireLibrary/monitor/entities/stakeholder";
|
2019-10-24 09:44:29 +02:00
|
|
|
import {StatisticsService} from "../utils/services/statistics.service";
|
2019-11-29 14:35:13 +01:00
|
|
|
import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils";
|
2019-12-23 14:54:37 +01:00
|
|
|
import {LayoutService} from "../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
|
2019-11-29 15:58:52 +01:00
|
|
|
import {FormBuilder, FormControl} from "@angular/forms";
|
2020-11-13 17:42:12 +01:00
|
|
|
import {Subscriber, Subscription} from "rxjs";
|
|
|
|
import {User} from "../openaireLibrary/login/utils/helper.class";
|
2019-12-13 16:48:24 +01:00
|
|
|
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
|
2020-07-10 10:37:51 +02:00
|
|
|
import {RangeFilter} from "../openaireLibrary/utils/rangeFilter/rangeFilterHelperClasses.class";
|
2020-11-13 17:42:12 +01:00
|
|
|
import {Filter} from "../openaireLibrary/searchPages/searchUtils/searchHelperClasses.class";
|
2020-07-14 17:22:39 +02:00
|
|
|
import {Location} from "@angular/common";
|
|
|
|
import {RouterHelper} from "../openaireLibrary/utils/routerHelper.class";
|
2020-09-18 11:19:47 +02:00
|
|
|
import {properties} from "../../environments/environment";
|
2020-11-27 11:46:58 +01:00
|
|
|
import {IndexInfoService} from "../openaireLibrary/utils/indexInfo.service";
|
2020-12-18 16:31:21 +01:00
|
|
|
import {ConfigurationService} from "../openaireLibrary/utils/configuration/configuration.service";
|
2019-10-24 09:44:29 +02:00
|
|
|
|
|
|
|
@Component({
|
2019-12-15 13:38:09 +01:00
|
|
|
selector: 'monitor',
|
|
|
|
templateUrl: 'monitor.component.html',
|
2020-11-26 17:23:21 +01:00
|
|
|
styleUrls: ['monitor.component.css']
|
2019-10-24 09:44:29 +02:00
|
|
|
})
|
2020-07-06 11:19:01 +02:00
|
|
|
export class MonitorComponent implements OnInit, OnDestroy {
|
2019-12-15 13:38:09 +01:00
|
|
|
public user: User;
|
|
|
|
public subscriptions: any[] = [];
|
2020-12-18 16:31:21 +01:00
|
|
|
piwikSiteId;
|
|
|
|
title;
|
|
|
|
description;
|
2019-12-15 13:38:09 +01:00
|
|
|
public pageContents = null;
|
|
|
|
public divContents = null;
|
|
|
|
public status: number;
|
2020-07-07 16:08:47 +02:00
|
|
|
public loading: boolean = true;
|
2020-05-13 10:23:19 +02:00
|
|
|
public isViewPublic: boolean = false;
|
2019-12-15 13:38:09 +01:00
|
|
|
public indicatorUtils: IndicatorUtils = new IndicatorUtils();
|
|
|
|
public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
|
|
|
|
public activeTopic: Topic = null;
|
|
|
|
public activeCategory: Category = null;
|
|
|
|
public activeSubCategory: SubCategory = null;
|
|
|
|
public errorCodes: ErrorCodes;
|
|
|
|
public stakeholder: Stakeholder;
|
2020-01-08 12:00:50 +01:00
|
|
|
public numberResults: Map<string, number> = new Map<string, number>();
|
|
|
|
public chartsActiveType: Map<string, IndicatorPath> = new Map<string, IndicatorPath>();
|
2019-12-15 13:38:09 +01:00
|
|
|
private errorMessages: ErrorMessagesComponent;
|
2020-11-04 10:10:54 +01:00
|
|
|
properties: EnvProperties = properties;
|
2020-07-10 10:37:51 +02:00
|
|
|
filterToggle = false;
|
2020-07-14 17:22:39 +02:00
|
|
|
public routerHelper: RouterHelper = new RouterHelper();
|
2020-11-26 17:23:21 +01:00
|
|
|
filters: Filter[] = [];
|
2020-07-14 17:22:39 +02:00
|
|
|
queryParams = {};
|
2021-01-11 10:28:34 +01:00
|
|
|
public currentYear = new Date().getFullYear();
|
2020-11-26 17:23:21 +01:00
|
|
|
periodFilter: RangeFilter = {
|
|
|
|
title: "Time range",
|
|
|
|
filterId: "year",
|
|
|
|
originalFilterIdFrom: null,
|
|
|
|
originalFilterIdTo: null,
|
|
|
|
selectedFromValue: null,
|
|
|
|
selectedToValue: null,
|
|
|
|
selectedFromAndToValues: ""
|
|
|
|
};
|
2020-06-24 15:36:00 +02:00
|
|
|
privateStakeholder = false;
|
2019-12-15 13:38:09 +01:00
|
|
|
public keyword: FormControl;
|
2020-11-27 11:46:58 +01:00
|
|
|
public statsUpdateDate: Date;
|
2019-12-15 13:38:09 +01:00
|
|
|
constructor(
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private _router: Router,
|
|
|
|
private _meta: Meta,
|
|
|
|
private _title: Title,
|
|
|
|
private _piwikService: PiwikService,
|
|
|
|
private helper: HelperService,
|
|
|
|
private stakeholderService: StakeholderService,
|
|
|
|
private userManagementService: UserManagementService,
|
|
|
|
private statisticsService: StatisticsService,
|
|
|
|
private layoutService: LayoutService,
|
|
|
|
private seoService: SEOService,
|
|
|
|
private cdr: ChangeDetectorRef,
|
2020-11-27 11:46:58 +01:00
|
|
|
private indexInfoService: IndexInfoService,
|
2020-12-18 16:31:21 +01:00
|
|
|
private sanitizer: DomSanitizer, private _fb: FormBuilder, private router: Router,
|
|
|
|
private configurationService: ConfigurationService) {
|
2019-12-15 13:38:09 +01:00
|
|
|
this.errorCodes = new ErrorCodes();
|
|
|
|
this.errorMessages = new ErrorMessagesComponent();
|
|
|
|
this.status = this.errorCodes.LOADING;
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
public ngOnInit() {
|
2020-11-27 11:46:58 +01:00
|
|
|
if (typeof document !== 'undefined') {
|
|
|
|
this.subscriptions.push(this.indexInfoService.getStatsLastDate(this.properties).subscribe(lastIndexUpdate => {
|
|
|
|
if (lastIndexUpdate) {
|
|
|
|
this.statsUpdateDate = new Date(lastIndexUpdate);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}
|
2019-12-15 13:38:09 +01:00
|
|
|
this.keyword = this._fb.control('');
|
2020-11-13 17:42:12 +01:00
|
|
|
this.subscriptions.push(this.keyword.valueChanges.subscribe(value => {
|
2019-12-15 13:38:09 +01:00
|
|
|
console.log("Keyword Changed!");
|
|
|
|
//TODO do a real action
|
2020-11-13 17:42:12 +01:00
|
|
|
}));
|
|
|
|
let subscription: Subscription;
|
|
|
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
|
|
|
this.user = user;
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2020-11-13 17:42:12 +01:00
|
|
|
this.subscriptions.push(this.route.params.subscribe(params => {
|
|
|
|
this.loading = true;
|
|
|
|
this.activeTopic = null;
|
|
|
|
this.activeCategory = null;
|
|
|
|
this.activeSubCategory = null;
|
|
|
|
this.filterToggle = false;
|
|
|
|
if (subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
var url = properties.domain + properties.baseLink + this._router.url;
|
|
|
|
this.subscriptions.push(this.route.queryParams.subscribe(params => {
|
|
|
|
this.queryParams = Object.assign({}, params);
|
|
|
|
this.isViewPublic = (params['view'] == 'public');
|
|
|
|
}));
|
|
|
|
if (!this.stakeholder || this.stakeholder.alias !== params['stakeholder']) {
|
|
|
|
this.status = this.errorCodes.LOADING;
|
|
|
|
this.numberResults = new Map<string, number>();
|
|
|
|
this.chartsActiveType = new Map<string, IndicatorPath>();
|
|
|
|
subscription = this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
|
|
|
if (stakeholder) {
|
|
|
|
this.stakeholder = stakeholder;
|
|
|
|
// add fl0 filter only for EC
|
2020-11-26 17:23:21 +01:00
|
|
|
if (this.stakeholder.index_id == "ec__________::EC") {
|
|
|
|
this.filters.push({
|
|
|
|
title: "Funding Stream",
|
|
|
|
filterId: "relfundinglevel0_id",
|
|
|
|
originalFilterId: "relfundinglevel0_id",
|
|
|
|
countSelectedValues: 0,
|
|
|
|
values: [{name: "EC|FP7", id: "ec__________::EC::FP7", selected: false, number: 0}, {
|
|
|
|
name: "EC|H2020",
|
|
|
|
id: "ec__________::EC::H2020",
|
|
|
|
selected: false,
|
|
|
|
number: 0
|
|
|
|
}]
|
|
|
|
,
|
|
|
|
filterOperator: "or",
|
|
|
|
valueIsExact: true,
|
|
|
|
filterType: "radio",
|
|
|
|
radioValue: ""
|
|
|
|
});
|
2020-11-13 17:42:12 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
if (this.stakeholder.type == "funder") {
|
2020-11-13 17:42:12 +01:00
|
|
|
// this.filters.push({title: "Co-funded research outcomes",filterId: "co-funded",originalFilterId: "co-funded", countSelectedValues: 0,
|
|
|
|
// values:[{name: "true", id: "co-funded", selected: false, number: 0}, {name: "false", id: "no-co-funded", selected: false, number: 0}]
|
|
|
|
// ,filterOperator: "or", valueIsExact: true, filterType: "radio", radioValue:""});
|
2020-11-26 17:23:21 +01:00
|
|
|
this.filters.push({
|
|
|
|
title: "Co-funded", filterId: "co-funded", originalFilterId: "co-funded", countSelectedValues: 0,
|
|
|
|
values: [{name: "Co-funded research output", id: "co-funded-results", selected: false, number: 0}]
|
|
|
|
, filterOperator: "or", valueIsExact: true, filterType: "checkbox", radioValue: ""
|
|
|
|
});
|
2020-11-13 17:42:12 +01:00
|
|
|
}
|
2020-07-14 17:22:39 +02:00
|
|
|
this.initializeFilters();
|
2020-11-13 17:42:12 +01:00
|
|
|
this.seoService.createLinkForCanonicalURL(url, false);
|
|
|
|
this._meta.updateTag({content: url}, "property='og:url'");
|
2020-12-18 16:31:21 +01:00
|
|
|
this.description = "Monitor Dashboard | " + this.stakeholder.name;
|
|
|
|
this.title = "Monitor Dashboard | " + this.stakeholder.name;
|
|
|
|
this._meta.updateTag({content: this.description}, "name='description'");
|
|
|
|
this._meta.updateTag({content: this.description}, "property='og:description'");
|
|
|
|
this._meta.updateTag({content: this.title}, "property='og:title'");
|
|
|
|
this._title.setTitle(this.title);
|
2020-11-13 17:42:12 +01:00
|
|
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
2020-12-18 16:31:21 +01:00
|
|
|
this.subscriptions.push(this.configurationService.communityInformationState.subscribe(portal => {
|
|
|
|
if (portal && portal.piwik) {
|
|
|
|
console.debug(portal)
|
|
|
|
this.piwikSiteId = portal.piwik;
|
|
|
|
console.debug(this.piwikSiteId)
|
|
|
|
this.subscriptions.push(this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe());
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
|
2020-11-13 17:42:12 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
if (this.isPublicOrIsMember(stakeholder.visibility)) {
|
2020-11-13 17:42:12 +01:00
|
|
|
//this.getDivContents();
|
|
|
|
// this.getPageContents();
|
|
|
|
this.status = this.errorCodes.DONE;
|
|
|
|
this.setView(params);
|
|
|
|
} else {
|
|
|
|
this.privateStakeholder = true;
|
|
|
|
// this.navigateToError();
|
2020-11-26 17:23:21 +01:00
|
|
|
if (subscription) {
|
2020-11-13 17:42:12 +01:00
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2020-12-18 16:31:21 +01:00
|
|
|
}else{
|
|
|
|
this.navigateToError();
|
|
|
|
if (subscription) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
2020-05-13 10:23:19 +02:00
|
|
|
}
|
|
|
|
});
|
2020-11-13 17:42:12 +01:00
|
|
|
this.subscriptions.push(subscription);
|
|
|
|
} else {
|
2020-12-18 16:31:21 +01:00
|
|
|
if (this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
|
|
|
if (this.piwikSiteId) {
|
|
|
|
console.debug(this.piwikSiteId)
|
|
|
|
this.subscriptions.push(this._piwikService.trackView(this.properties, this.title, this.piwikSiteId).subscribe());
|
|
|
|
}
|
|
|
|
}
|
2020-11-13 17:42:12 +01:00
|
|
|
this.initializeFilters();
|
|
|
|
this.setView(params);
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
}));
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
private initializeFilters() {
|
|
|
|
this.periodFilter.selectedFromValue = (this.queryParams['year'] && this.queryParams['year'].indexOf("range") == 0) ? this.queryParams['year'].split("range")[1].split(":")[0] : "";
|
|
|
|
this.periodFilter.selectedToValue = (this.queryParams['year'] && this.queryParams['year'].indexOf("range") == 0) ? this.queryParams['year'].split("range")[1].split(":")[1] : "";
|
2020-07-14 17:22:39 +02:00
|
|
|
this.validateYearRange(false);
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
for (let filter of this.filters) {
|
2020-07-14 17:22:39 +02:00
|
|
|
if (this.queryParams[filter.filterId]) {
|
|
|
|
for (let value of filter.values) {
|
2020-11-27 11:46:58 +01:00
|
|
|
if (value.id == StringUtils.URIDecode(StringUtils.unquote(this.queryParams[filter.filterId]))) {
|
2020-07-14 17:22:39 +02:00
|
|
|
value.selected = true;
|
|
|
|
filter.countSelectedValues = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
} else {
|
2020-07-15 12:06:15 +02:00
|
|
|
this.clearfFilter(filter);
|
2020-07-14 17:22:39 +02:00
|
|
|
}
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2020-07-14 17:22:39 +02:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
private validateYearRange(navigateTo: boolean = false) {
|
2020-07-10 10:37:51 +02:00
|
|
|
let validYears = true;
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
if (this.periodFilter.selectedToValue && (this.periodFilter.selectedToValue.length == 0 || !Dates.isValidYear(this.periodFilter.selectedToValue, Dates.currentYear - 20, Dates.currentYear))) {
|
|
|
|
this.periodFilter.selectedToValue = Dates.currentYear + "";
|
2020-07-10 10:37:51 +02:00
|
|
|
validYears = false;
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
if (this.periodFilter.selectedFromValue && (this.periodFilter.selectedFromValue.length == 0 || !Dates.isValidYear(this.periodFilter.selectedFromValue, Dates.currentYear - 20, Dates.currentYear))) {
|
|
|
|
this.periodFilter.selectedFromValue = Dates.currentYear - 20 + "";
|
2020-07-10 10:37:51 +02:00
|
|
|
validYears = false;
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
if (this.periodFilter.selectedFromValue && this.periodFilter.selectedFromValue.length && this.periodFilter.selectedToValue && this.periodFilter.selectedToValue.length > 0 && parseInt(this.periodFilter.selectedFromValue, 10) > parseInt(this.periodFilter.selectedToValue, 10)) {
|
2020-07-10 10:37:51 +02:00
|
|
|
this.periodFilter.selectedFromValue = this.periodFilter.selectedToValue;
|
|
|
|
validYears = false;
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
if (!validYears || navigateTo) {
|
|
|
|
if (this.periodFilter.selectedFromValue || this.periodFilter.selectedToValue) {
|
|
|
|
this.queryParams["year"] = 'range' + (this.periodFilter.selectedFromValue ? this.periodFilter.selectedFromValue : '') + ":" + (this.periodFilter.selectedToValue ? this.periodFilter.selectedToValue : "");
|
|
|
|
} else {
|
|
|
|
delete this.queryParams["year"];
|
2020-07-14 17:22:39 +02:00
|
|
|
}
|
2020-08-06 09:34:41 +02:00
|
|
|
// this.location.go(location.pathname, this.routerHelper.createQueryParamsString( Object.keys(this.queryParams), Object.values(this.queryParams)));
|
2020-11-26 17:23:21 +01:00
|
|
|
this.router.navigate([], {queryParams: this.queryParams});
|
2020-07-14 17:22:39 +02:00
|
|
|
this.setIndicators();
|
2020-07-10 10:37:51 +02:00
|
|
|
}
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
clearAll() {
|
|
|
|
for (let filter of this.filters) {
|
2020-07-15 12:06:15 +02:00
|
|
|
this.clearfFilter(filter);
|
2020-07-14 17:22:39 +02:00
|
|
|
}
|
|
|
|
this.periodFilter.selectedFromValue = "";
|
|
|
|
this.periodFilter.selectedToValue = "";
|
|
|
|
this.validateYearRange(true)
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
clearfFilter(filter: Filter) {
|
2020-07-15 12:06:15 +02:00
|
|
|
filter.countSelectedValues = 0;
|
|
|
|
filter.radioValue = "";
|
|
|
|
for (let value of filter.values) {
|
|
|
|
if (value.selected) {
|
|
|
|
value.selected = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (this.queryParams[filter.filterId]) {
|
|
|
|
delete this.queryParams[filter.filterId];
|
|
|
|
}
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
countSelectedFilters(): number {
|
2020-07-14 17:22:39 +02:00
|
|
|
let count = 0;
|
2020-11-26 17:23:21 +01:00
|
|
|
if (this.periodFilter.selectedFromAndToValues.length > 0) {
|
|
|
|
count += 2;
|
2020-07-14 17:22:39 +02:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
for (let filter of this.filters) {
|
|
|
|
count += filter.countSelectedValues;
|
2020-07-14 17:22:39 +02:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
public get isSmallScreen() {
|
|
|
|
return this.layoutService.isSmallScreen;
|
|
|
|
}
|
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
public get open() {
|
|
|
|
return this.layoutService.open;
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
private getPageContents() {
|
2020-12-18 16:31:21 +01:00
|
|
|
this.subscriptions.push(this.helper.getPageHelpContents(this.properties, this.properties.adminToolsCommunity, this._router.url).subscribe(contents => {
|
2019-12-15 13:38:09 +01:00
|
|
|
this.pageContents = contents;
|
2020-11-13 17:42:12 +01:00
|
|
|
}));
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
private getDivContents() {
|
2020-12-18 16:31:21 +01:00
|
|
|
this.subscriptions.push(this.helper.getDivHelpContents(this.properties, this.properties.adminToolsCommunity, this._router.url).subscribe(contents => {
|
2019-12-15 13:38:09 +01:00
|
|
|
this.divContents = contents;
|
2020-11-13 17:42:12 +01:00
|
|
|
}));
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
private setView(params: Params) {
|
2020-07-28 16:57:17 +02:00
|
|
|
this.loading = false;
|
2019-12-15 13:38:09 +01:00
|
|
|
if (params['topic']) {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.activeTopic = this.stakeholder.topics.find(topic => topic.alias === decodeURIComponent(params['topic']) && this.isPublicOrIsMember(topic.visibility));
|
2019-12-15 13:38:09 +01:00
|
|
|
if (this.activeTopic) {
|
|
|
|
if (params['category']) {
|
|
|
|
this.activeCategory = this.activeTopic.categories.find(category =>
|
2020-10-23 15:58:16 +02:00
|
|
|
(category.alias === params['category']) && this.isPublicOrIsMember(category.visibility));
|
2019-12-15 13:38:09 +01:00
|
|
|
if (!this.activeCategory) {
|
|
|
|
this.navigateToError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.activeCategory = this.activeTopic.categories.find(category => this.isPublicOrIsMember(category.visibility));
|
2019-12-15 13:38:09 +01:00
|
|
|
if (this.activeCategory) {
|
|
|
|
this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
|
2020-10-23 15:58:16 +02:00
|
|
|
this.isPublicOrIsMember(subCategory.visibility));
|
2019-12-15 13:38:09 +01:00
|
|
|
if (this.activeSubCategory) {
|
|
|
|
this.setIndicators();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2019-12-04 12:47:20 +01:00
|
|
|
}
|
2019-12-15 13:38:09 +01:00
|
|
|
if (this.activeCategory) {
|
|
|
|
if (params['subCategory']) {
|
|
|
|
this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
|
2020-10-23 15:58:16 +02:00
|
|
|
(subCategory.alias === params['subCategory'] && this.isPublicOrIsMember(subCategory.visibility)));
|
2019-12-15 13:38:09 +01:00
|
|
|
if (!this.activeSubCategory) {
|
|
|
|
this.navigateToError();
|
|
|
|
return;
|
2019-12-04 12:47:20 +01:00
|
|
|
}
|
2019-12-15 13:38:09 +01:00
|
|
|
} else {
|
|
|
|
this.activeSubCategory = this.activeCategory.subCategories.find(subCategory =>
|
2020-10-23 15:58:16 +02:00
|
|
|
this.isPublicOrIsMember(subCategory.visibility));
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
|
|
|
if (this.activeSubCategory) {
|
|
|
|
this.setIndicators();
|
|
|
|
} else {
|
|
|
|
this.navigateToError();
|
|
|
|
}
|
|
|
|
return;
|
2019-12-04 12:47:20 +01:00
|
|
|
} else {
|
2019-12-15 13:38:09 +01:00
|
|
|
this.activeSubCategory = null;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this.navigateToError();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.activeTopic = this.stakeholder.topics.find(topic => this.isPublicOrIsMember(topic.visibility));
|
2019-12-15 13:38:09 +01:00
|
|
|
if (this.activeTopic) {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.activeCategory = this.activeTopic.categories.find(category => this.isPublicOrIsMember(category.visibility));
|
2019-12-15 13:38:09 +01:00
|
|
|
if (this.activeCategory) {
|
2020-10-23 15:58:16 +02:00
|
|
|
this.activeSubCategory = this.activeCategory.subCategories.find(subCategory => this.isPublicOrIsMember(subCategory.visibility));
|
2019-12-15 13:38:09 +01:00
|
|
|
if (this.activeSubCategory) {
|
|
|
|
this.setIndicators();
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
filter() {
|
2020-07-10 10:37:51 +02:00
|
|
|
this.validateYearRange(true);
|
2020-07-07 16:08:47 +02:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
filterChanged($event, navigate: boolean = true) {
|
2020-07-14 17:22:39 +02:00
|
|
|
let selected = "";
|
2020-11-26 17:23:21 +01:00
|
|
|
for (let value of $event.value.values) {
|
|
|
|
if (value.selected) {
|
2020-07-14 17:22:39 +02:00
|
|
|
selected = value.id;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
if (selected) {
|
2020-11-27 11:46:58 +01:00
|
|
|
this.queryParams[$event.value.filterId] = StringUtils.quote(StringUtils.URIEncode(selected));
|
2020-11-26 17:23:21 +01:00
|
|
|
} else {
|
2020-07-14 17:22:39 +02:00
|
|
|
delete this.queryParams[$event.value.filterId];
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
if (navigate) {
|
|
|
|
this.router.navigate([], {queryParams: this.queryParams});
|
2020-07-14 17:22:39 +02:00
|
|
|
this.setIndicators();
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2020-07-14 17:22:39 +02:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
private getfl0() {
|
|
|
|
if (this.queryParams["relfundinglevel0_id"] && this.filters.length > 0) {
|
2020-11-27 11:46:58 +01:00
|
|
|
let value = StringUtils.URIDecode(StringUtils.unquote(this.queryParams["relfundinglevel0_id"] ));
|
|
|
|
return value.split("::")[value.split("::").length - 1];
|
2020-07-14 17:22:39 +02:00
|
|
|
}
|
|
|
|
return null;
|
2020-07-28 17:56:48 +02:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
private getCoFunded() {
|
|
|
|
if (this.queryParams["co-funded"] && this.filters.length > 0) {
|
2021-01-15 17:02:30 +01:00
|
|
|
return this.queryParams["co-funded"] && StringUtils.URIDecode(StringUtils.unquote(this.queryParams["co-funded"] )) == "co-funded-results";
|
2020-07-28 17:56:48 +02:00
|
|
|
}
|
|
|
|
return false;
|
2020-07-14 17:22:39 +02:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
clearPeriodFilter() {
|
|
|
|
if (this.periodFilter.selectedFromValue || this.periodFilter.selectedToValue) {
|
2020-07-10 10:37:51 +02:00
|
|
|
this.periodFilter.selectedFromValue = "";
|
|
|
|
this.periodFilter.selectedToValue = "";
|
|
|
|
this.filter();
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2020-07-10 10:37:51 +02:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
private setIndicators() {
|
2020-11-26 17:23:21 +01:00
|
|
|
this.periodFilter.selectedFromAndToValues = (this.periodFilter.selectedFromValue || this.periodFilter.selectedToValue ? ((this.periodFilter.selectedFromValue && !this.periodFilter.selectedToValue ? "From " : "") + (!this.periodFilter.selectedFromValue && this.periodFilter.selectedToValue ? "Until " : "") + (this.periodFilter.selectedFromValue ? this.periodFilter.selectedFromValue : "") +
|
|
|
|
(this.periodFilter.selectedFromValue && this.periodFilter.selectedToValue ? " - " : "") + (this.periodFilter.selectedToValue ? this.periodFilter.selectedToValue : "")) : "");
|
2020-07-10 10:37:51 +02:00
|
|
|
//clear numbers when filters change
|
|
|
|
this.numberResults.clear();
|
2020-01-08 12:00:50 +01:00
|
|
|
let urls: Map<string, [number, number][]> = new Map<string, [number, number][]>();
|
|
|
|
this.activeSubCategory.numbers.forEach((section, i) => {
|
|
|
|
section.indicators.forEach((number, j) => {
|
2020-10-23 15:58:16 +02:00
|
|
|
if (this.isPublicOrIsMember(number.visibility)) {
|
2020-11-26 17:23:21 +01:00
|
|
|
let url = this.indicatorUtils.getFullUrlWithFilters(this.stakeholder, number.indicatorPaths[0], this.getfl0(), this.periodFilter.selectedFromValue, this.periodFilter.selectedToValue, this.getCoFunded());
|
2020-01-08 12:00:50 +01:00
|
|
|
const pair = JSON.stringify([number.indicatorPaths[0].source, url]);
|
|
|
|
const indexes = urls.get(pair) ? urls.get(pair) : [];
|
|
|
|
indexes.push([i, j]);
|
|
|
|
urls.set(pair, indexes);
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2020-01-08 12:00:50 +01:00
|
|
|
});
|
2019-12-15 13:38:09 +01:00
|
|
|
});
|
|
|
|
urls.forEach((indexes, pair) => {
|
|
|
|
pair = JSON.parse(pair);
|
2020-11-26 17:23:21 +01:00
|
|
|
this.subscriptions.push(this.statisticsService.getNumbers(this.statisticsService.getSourceType(pair[0]), pair[1]).subscribe(response => {
|
2020-01-08 12:00:50 +01:00
|
|
|
indexes.forEach(([i, j]) => {
|
2019-12-15 13:38:09 +01:00
|
|
|
let result = JSON.parse(JSON.stringify(response));
|
2020-01-08 12:00:50 +01:00
|
|
|
this.activeSubCategory.numbers[i].indicators[j].indicatorPaths[0].jsonPath.forEach(jsonPath => {
|
2019-12-15 13:38:09 +01:00
|
|
|
if (result) {
|
|
|
|
result = result[jsonPath];
|
2019-10-29 12:33:42 +01:00
|
|
|
}
|
2019-12-15 13:38:09 +01:00
|
|
|
});
|
2020-12-17 16:39:31 +01:00
|
|
|
if (typeof result === 'string' || typeof result === 'number') {
|
|
|
|
result = Number(result);
|
|
|
|
if (result === Number.NaN) {
|
|
|
|
result = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result = 0;
|
|
|
|
}
|
2020-01-08 12:00:50 +01:00
|
|
|
this.numberResults.set(i + '-' + j, result);
|
2019-10-24 09:44:29 +02:00
|
|
|
});
|
2020-11-13 17:42:12 +01:00
|
|
|
}));
|
2019-12-15 13:38:09 +01:00
|
|
|
});
|
2020-01-08 12:00:50 +01:00
|
|
|
this.activeSubCategory.charts.forEach((section, i) => {
|
|
|
|
section.indicators.forEach((indicator, j) => {
|
|
|
|
if (indicator.indicatorPaths.length > 0) {
|
|
|
|
indicator.indicatorPaths[0].safeResourceUrl = this.getUrlByStakeHolder(indicator.indicatorPaths[0]);
|
|
|
|
this.chartsActiveType.set(i + '-' + j, indicator.indicatorPaths[0]);
|
|
|
|
}
|
|
|
|
});
|
2019-12-15 13:38:09 +01:00
|
|
|
});
|
2020-06-25 10:10:42 +02:00
|
|
|
if (this.cdr && !(this.cdr as ViewRef).destroyed) {
|
|
|
|
this.cdr.detectChanges();
|
|
|
|
}
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
public getUrlByStakeHolder(indicatorPath: IndicatorPath) {
|
|
|
|
return this.sanitizer.bypassSecurityTrustResourceUrl(
|
2020-11-26 17:23:21 +01:00
|
|
|
this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrlWithFilters(this.stakeholder, indicatorPath, this.getfl0(), this.periodFilter.selectedFromValue, this.periodFilter.selectedToValue, this.getCoFunded())));
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2020-01-08 12:00:50 +01:00
|
|
|
public setActiveChart(i: number, j: number, type: string) {
|
|
|
|
let activeChart = this.activeSubCategory.charts[i].indicators[j].indicatorPaths.filter(indicatorPath => indicatorPath.type === type)[0];
|
2019-12-15 13:38:09 +01:00
|
|
|
activeChart.safeResourceUrl = this.getUrlByStakeHolder(activeChart);
|
2020-01-08 12:00:50 +01:00
|
|
|
this.chartsActiveType.set(i + '-' + j, activeChart);
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
private navigateToError() {
|
|
|
|
this._router.navigate(['/error'], {queryParams: {'page': this._router.url}});
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
public navigateTo(stakeholder: string, topic: string, category: string = null, subcategory: string = null) {
|
|
|
|
let url = stakeholder + '/' + topic + ((category) ? ('/'
|
|
|
|
+ category) : '') + ((subcategory) ? ('/' + subcategory) : '');
|
2020-11-26 17:23:21 +01:00
|
|
|
return this._router.navigate([url], {queryParams: this.queryParams});
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
public quote(param: string): string {
|
|
|
|
return StringUtils.quote(param);
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2019-12-15 13:38:09 +01:00
|
|
|
public ngOnDestroy() {
|
2020-11-13 17:42:12 +01:00
|
|
|
this.subscriptions.forEach(subscription => {
|
|
|
|
if (subscription instanceof Subscriber) {
|
|
|
|
subscription.unsubscribe();
|
|
|
|
}
|
|
|
|
});
|
2019-12-15 13:38:09 +01:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2020-10-23 15:58:16 +02:00
|
|
|
public isPublicOrIsMember(visibility: Visibility): boolean {
|
2020-11-26 17:23:21 +01:00
|
|
|
if (visibility == "PRIVATE" || (this.isViewPublic && visibility != "PUBLIC")) {
|
2020-05-13 10:23:19 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-11-04 12:16:47 +01:00
|
|
|
return true;
|
2020-05-13 10:23:19 +02:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
public countSubCategoriesToShow(category: Category): number {
|
2020-08-04 09:57:51 +02:00
|
|
|
let counter = 0;
|
|
|
|
for (let sub of category.subCategories) {
|
2020-11-26 17:23:21 +01:00
|
|
|
if (this.isPublicOrIsMember(sub.visibility)) {
|
2020-11-04 12:16:47 +01:00
|
|
|
counter++;
|
2020-08-04 09:57:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return counter;
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
public countIndicatorsToShow(indicators: Indicator[]): number {
|
2020-11-05 17:50:06 +01:00
|
|
|
let counter = 0;
|
|
|
|
for (let i of indicators) {
|
2020-11-26 17:23:21 +01:00
|
|
|
if (this.isPublicOrIsMember(i.visibility)) {
|
2020-11-05 17:50:06 +01:00
|
|
|
counter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return counter;
|
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
2020-08-06 09:34:41 +02:00
|
|
|
/*
|
|
|
|
Feedback mail
|
|
|
|
*/
|
|
|
|
public get mailText() {
|
2020-11-26 17:23:21 +01:00
|
|
|
return "mailto:" + this.properties.feedbackmail + "?subject=%5BOpenAIRE%20Monitor%5D%20" + (this.stakeholder ? this.stakeholder.name : "") + "%20dashboard%20feedback"
|
2020-08-06 09:34:41 +02:00
|
|
|
}
|
2020-11-26 17:23:21 +01:00
|
|
|
|
|
|
|
mailMe() {
|
2020-08-06 09:34:41 +02:00
|
|
|
window.location.href = this.mailText;
|
|
|
|
}
|
2020-12-01 16:43:43 +01:00
|
|
|
|
|
|
|
public getNumberClassBySize(size: IndicatorSize) {
|
|
|
|
if(size === 'small') {
|
|
|
|
return 'uk-width-1-4@xl uk-width-1-3@l uk-width-1-2@m uk-width-1-1';
|
|
|
|
} else if(size === 'medium') {
|
|
|
|
return 'uk-width-1-3@l uk-width-1-2@m uk-width-1-1';
|
|
|
|
} else {
|
|
|
|
return 'uk-width-1-2@l uk-width-1-1@m uk-width-1-1';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public getChartClassBySize(size: IndicatorSize) {
|
|
|
|
if(size === 'small') {
|
|
|
|
return 'uk-width-1-3@xl uk-width-1-2@m uk-width-1-1';
|
|
|
|
} else if(size === 'medium') {
|
|
|
|
return 'uk-width-1-2@l uk-width-1-1';
|
|
|
|
} else {
|
|
|
|
return 'uk-width-1-1';
|
|
|
|
}
|
|
|
|
}
|
2019-10-24 09:44:29 +02:00
|
|
|
}
|