2020-06-03 15:43:14 +02:00
|
|
|
import {SafeResourceUrl} from "@angular/platform-browser";
|
2021-01-15 13:27:52 +01:00
|
|
|
import {properties} from "../../../../environments/environment";
|
2022-02-16 17:18:12 +01:00
|
|
|
import {Session, User} from "../../login/utils/helper.class";
|
2020-06-03 15:43:14 +02:00
|
|
|
|
|
|
|
export const ChartHelper = {
|
|
|
|
prefix: "((__",
|
|
|
|
suffix: "__))"
|
|
|
|
};
|
|
|
|
|
|
|
|
export type StakeholderType = 'funder' | 'ri' | 'project' | 'organization';
|
|
|
|
export type IndicatorType = 'number' | 'chart';
|
2020-11-27 11:42:30 +01:00
|
|
|
export type IndicatorSize = 'small' | 'medium' | 'large';
|
2020-06-03 15:43:14 +02:00
|
|
|
export type IndicatorPathType = 'table' | 'bar' | 'column' | 'pie' | 'line' | 'other';
|
|
|
|
export type SourceType = 'statistics' | 'search' | 'metrics' | 'stats-tool' | 'old' | 'image';
|
2020-10-19 11:06:23 +02:00
|
|
|
export type Visibility = 'PUBLIC' | 'PRIVATE' | 'RESTRICTED';
|
2020-06-03 15:43:14 +02:00
|
|
|
|
|
|
|
export class Stakeholder {
|
|
|
|
_id: string;
|
|
|
|
type: StakeholderType;
|
|
|
|
name: string;
|
|
|
|
index_id;
|
|
|
|
index_name: string;
|
|
|
|
index_shortName: string;
|
|
|
|
alias: string;
|
|
|
|
defaultId: string;
|
2020-10-19 11:06:23 +02:00
|
|
|
visibility: Visibility;
|
2020-06-03 15:43:14 +02:00
|
|
|
creationDate: Date = null;
|
|
|
|
updateDate: Date;
|
2021-11-12 13:07:55 +01:00
|
|
|
/** @warning Use pipe in HTML or StringUtils.getLogoUrl in components */
|
2020-06-05 14:56:28 +02:00
|
|
|
logoUrl: string;
|
2020-09-29 16:24:38 +02:00
|
|
|
isUpload: boolean = false;
|
2020-06-05 14:56:28 +02:00
|
|
|
description: string;
|
2020-12-10 17:36:28 +01:00
|
|
|
topics: any[];
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2020-12-10 17:36:28 +01:00
|
|
|
constructor(_id: string, type: StakeholderType, index_id, index_name: string, index_shortName: string, alias: string, visibility: Visibility, logoUrl: string, defaultId: string = null, description: string = null) {
|
|
|
|
this._id = _id;
|
2020-06-03 15:43:14 +02:00
|
|
|
this.type = type;
|
|
|
|
this.index_id = index_id;
|
|
|
|
this.index_name = index_name;
|
|
|
|
this.index_shortName = index_shortName;
|
|
|
|
this.defaultId = defaultId;
|
|
|
|
this.alias = alias;
|
2020-10-19 11:06:23 +02:00
|
|
|
this.visibility = visibility;
|
2020-06-03 15:43:14 +02:00
|
|
|
this.logoUrl = logoUrl;
|
2020-10-19 11:06:23 +02:00
|
|
|
this.description = description;
|
2020-12-10 17:36:28 +01:00
|
|
|
this.topics = [];
|
2020-06-03 15:43:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-05 14:56:28 +02:00
|
|
|
export class StakeholderInfo extends Stakeholder {
|
|
|
|
isManager: boolean = false;
|
2020-11-02 17:55:05 +01:00
|
|
|
isMember: boolean = false;
|
2022-02-16 17:18:12 +01:00
|
|
|
|
|
|
|
public static toStakeholderInfo(stakeholders: (Stakeholder & StakeholderInfo)[], user: User): StakeholderInfo[] {
|
|
|
|
return stakeholders.map(stakeholder => {
|
|
|
|
stakeholder.isManager = Session.isPortalAdministrator(user) || Session.isMonitorCurator(user) || Session.isManager(stakeholder.type, stakeholder.alias, user);
|
|
|
|
stakeholder.isMember = Session.isMember(stakeholder.type, stakeholder.alias, user);
|
|
|
|
return stakeholder;
|
|
|
|
})
|
|
|
|
}
|
2020-06-05 14:56:28 +02:00
|
|
|
}
|
|
|
|
|
2020-06-03 15:43:14 +02:00
|
|
|
export class Topic {
|
|
|
|
_id: string;
|
|
|
|
name: string;
|
|
|
|
alias: string;
|
|
|
|
description: string;
|
2020-10-23 15:55:35 +02:00
|
|
|
visibility: Visibility;
|
2020-11-16 17:47:19 +01:00
|
|
|
creationDate: Date = null;
|
|
|
|
updateDate: Date;
|
2020-06-03 15:43:14 +02:00
|
|
|
defaultId: string;
|
|
|
|
categories: Category[];
|
2020-06-12 11:56:38 +02:00
|
|
|
icon: string;
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2020-10-23 15:55:35 +02:00
|
|
|
constructor(name: string, description: string, alias: string, visibility:Visibility, defaultId: string = null, icon: string = null) {
|
2020-06-03 15:43:14 +02:00
|
|
|
this._id = null;
|
|
|
|
this.name = name;
|
|
|
|
this.description = description;
|
|
|
|
this.alias = alias;
|
2020-10-23 15:55:35 +02:00
|
|
|
this.visibility = visibility;
|
2020-06-03 15:43:14 +02:00
|
|
|
this.defaultId = defaultId;
|
|
|
|
this.categories = [];
|
2020-06-12 11:56:38 +02:00
|
|
|
this.icon = icon;
|
2020-06-03 15:43:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Category {
|
|
|
|
_id: string;
|
|
|
|
name: string;
|
|
|
|
alias: string;
|
|
|
|
description: string;
|
2020-11-16 17:47:19 +01:00
|
|
|
creationDate: Date = null;
|
|
|
|
updateDate: Date;
|
2020-10-23 15:55:35 +02:00
|
|
|
visibility: Visibility;
|
2020-06-03 15:43:14 +02:00
|
|
|
defaultId: string;
|
|
|
|
subCategories: SubCategory[];
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2020-10-23 15:55:35 +02:00
|
|
|
constructor(name: string, description: string, alias: string, visibility: Visibility, defaultId: string = null) {
|
2020-06-03 15:43:14 +02:00
|
|
|
this._id = null;
|
|
|
|
this.name = name;
|
|
|
|
this.description = description;
|
|
|
|
this.alias = alias;
|
2020-10-23 15:55:35 +02:00
|
|
|
this.visibility = visibility;
|
2020-06-03 15:43:14 +02:00
|
|
|
this.defaultId = defaultId;
|
|
|
|
this.subCategories = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class SubCategory {
|
|
|
|
_id: string;
|
|
|
|
name: string;
|
|
|
|
alias: string;
|
|
|
|
description: string;
|
2020-11-16 17:47:19 +01:00
|
|
|
creationDate: Date = null;
|
|
|
|
updateDate: Date;
|
2020-10-23 15:55:35 +02:00
|
|
|
visibility: Visibility;
|
2020-06-03 15:43:14 +02:00
|
|
|
defaultId: string;
|
|
|
|
charts: Section[];
|
|
|
|
numbers: Section[];
|
2020-12-11 11:11:22 +01:00
|
|
|
|
2020-10-23 15:55:35 +02:00
|
|
|
constructor(name: string, description: string, alias: string, visibility: Visibility, defaultId: string = null) {
|
2020-06-03 15:43:14 +02:00
|
|
|
this._id = null;
|
|
|
|
this.name = name;
|
|
|
|
this.description = description;
|
|
|
|
this.alias = alias;
|
2020-10-23 15:55:35 +02:00
|
|
|
this.visibility = visibility;
|
2020-06-03 15:43:14 +02:00
|
|
|
this.defaultId = defaultId;
|
|
|
|
this.charts = [];
|
|
|
|
this.numbers = [];
|
|
|
|
}
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2020-06-03 15:43:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Section {
|
|
|
|
_id: string;
|
|
|
|
title: string;
|
|
|
|
defaultId: string;
|
2020-11-16 17:47:19 +01:00
|
|
|
creationDate: Date = null;
|
|
|
|
updateDate: Date;
|
2020-06-03 15:43:14 +02:00
|
|
|
stakeholderAlias: string;
|
|
|
|
type: IndicatorType;
|
|
|
|
indicators: Indicator[];
|
|
|
|
|
|
|
|
constructor(type: IndicatorType, title: string = null, defaultId: string = null, stakeholderAlias: string = null) {
|
|
|
|
this._id = null;
|
|
|
|
this.title = title;
|
|
|
|
this.type = type;
|
|
|
|
this.defaultId = defaultId;
|
|
|
|
this.stakeholderAlias = stakeholderAlias;
|
|
|
|
this.indicators = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Indicator {
|
|
|
|
_id: string;
|
|
|
|
name: string;
|
|
|
|
description: string;
|
2020-10-29 09:52:05 +01:00
|
|
|
additionalDescription: string;
|
2020-11-16 17:47:19 +01:00
|
|
|
creationDate: Date = null;
|
|
|
|
updateDate: Date;
|
2020-06-03 15:43:14 +02:00
|
|
|
type: IndicatorType;
|
2020-11-27 11:42:30 +01:00
|
|
|
width: IndicatorSize;
|
|
|
|
height: IndicatorSize;
|
2020-06-03 15:43:14 +02:00
|
|
|
tags: string[];
|
2020-10-23 15:55:35 +02:00
|
|
|
visibility: Visibility;
|
2020-06-03 15:43:14 +02:00
|
|
|
defaultId: string;
|
|
|
|
indicatorPaths: IndicatorPath[];
|
2020-12-11 11:11:22 +01:00
|
|
|
|
2020-11-27 11:42:30 +01:00
|
|
|
constructor(name: string, description: string, additionalDescription:string, type: IndicatorType, width: IndicatorSize,height: IndicatorSize, visibility: Visibility, indicatorPaths: IndicatorPath[], defaultId: string = null) {
|
2020-06-03 15:43:14 +02:00
|
|
|
this._id = null;
|
|
|
|
this.name = name;
|
|
|
|
this.description = description;
|
2020-10-29 09:52:05 +01:00
|
|
|
this.additionalDescription = additionalDescription;
|
2020-06-03 15:43:14 +02:00
|
|
|
this.type = type;
|
|
|
|
this.width = width;
|
2020-11-27 11:42:30 +01:00
|
|
|
this.height = height;
|
2020-10-23 15:55:35 +02:00
|
|
|
this.visibility = visibility;
|
2020-06-03 15:43:14 +02:00
|
|
|
this.defaultId = defaultId;
|
|
|
|
this.indicatorPaths = indicatorPaths;
|
|
|
|
}
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2020-06-03 15:43:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export class IndicatorPath {
|
|
|
|
type: IndicatorPathType;
|
|
|
|
source: SourceType;
|
|
|
|
url: string;
|
|
|
|
safeResourceUrl: SafeResourceUrl; // initialize on front end
|
|
|
|
jsonPath: string[];
|
|
|
|
chartObject: string;
|
|
|
|
parameters: any;
|
|
|
|
filters: any;
|
2020-07-28 16:47:51 +02:00
|
|
|
filtersApplied: number = 0;
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2020-06-03 15:43:14 +02:00
|
|
|
constructor(type: IndicatorPathType, source: SourceType, url: string, chartObject: string, jsonPath: string[]) {
|
|
|
|
this.type = type;
|
|
|
|
this.url = url;
|
|
|
|
this.source = source;
|
|
|
|
this.jsonPath = jsonPath;
|
|
|
|
this.chartObject = chartObject;
|
|
|
|
this.parameters = {};
|
|
|
|
this.filters = {};
|
2020-07-28 16:47:51 +02:00
|
|
|
this.filtersApplied = 0;
|
2020-06-03 15:43:14 +02:00
|
|
|
}
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2020-06-03 15:43:14 +02:00
|
|
|
static createParameters(funderName: string = null, title: string = null, chartType: string = null): any {
|
|
|
|
return {
|
|
|
|
index_name: funderName,
|
|
|
|
title: title,
|
|
|
|
type: chartType
|
|
|
|
};
|
|
|
|
}
|
2020-07-07 15:50:49 +02:00
|
|
|
|
|
|
|
}
|
2020-07-28 17:55:59 +02:00
|
|
|
export type FilterType = "fundingL0"|"start_year" | "end_year" | "co-funded";
|
2020-07-07 15:50:49 +02:00
|
|
|
export class IndicatorFilterUtils{
|
|
|
|
static getFilter(field: string, filterType:FilterType) {
|
|
|
|
if(["publication", "software", "dataset", "other", "result"].indexOf(field)!=-1){
|
|
|
|
return this.getResultFilter(field,filterType);
|
|
|
|
}else if (field == "project"){
|
|
|
|
return this.getProjectFilter(filterType);
|
|
|
|
}
|
2021-01-15 13:27:52 +01:00
|
|
|
else if (field == "country"){
|
2021-01-11 10:21:42 +01:00
|
|
|
return this.getCountryFilter(filterType);
|
|
|
|
}else if (field == "organization"){
|
|
|
|
return this.getOrganizationFilter(filterType);
|
2021-01-15 13:27:52 +01:00
|
|
|
}
|
2020-07-07 15:50:49 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
static getResultFilter(dbType: string = null, filterType:FilterType) {
|
|
|
|
if (filterType == "fundingL0") {
|
2021-01-15 13:27:52 +01:00
|
|
|
if(properties.useOldStatisticsSchema) {
|
|
|
|
return '{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
}else{//new statistcs schema
|
|
|
|
return '{"groupFilters":[{"field":"' + dbType + '.project funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
}
|
2020-07-07 15:50:49 +02:00
|
|
|
} else if (filterType == "start_year") {
|
|
|
|
return '{"groupFilters":[{"field":"' + dbType + '.year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
} else if (filterType == "end_year") {
|
|
|
|
return '{"groupFilters":[{"field":"' + dbType + '.year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
2020-07-28 17:55:59 +02:00
|
|
|
}else if (filterType == "co-funded") {
|
|
|
|
return '{"groupFilters":[{"field":"' + dbType + '.No of funders","type":">","values":["1"]}],"op":"AND"}';
|
2020-07-07 15:50:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
static getProjectFilter( filterType:FilterType) {
|
|
|
|
if (filterType == "fundingL0") {
|
|
|
|
return '{"groupFilters":[{"field":"project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
} else if (filterType == "start_year") {
|
|
|
|
return '{"groupFilters":[{"field":"project.start year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
} else if (filterType == "end_year") {
|
|
|
|
return '{"groupFilters":[{"field":"project.start year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static getOrganizationFilter( filterType:FilterType) {
|
2021-01-11 10:21:42 +01:00
|
|
|
if (filterType == "fundingL0") {
|
|
|
|
return '{"groupFilters":[{"field":"organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
} else if (filterType == "start_year") {
|
|
|
|
return '{"groupFilters":[{"field":"organization.project.start year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
} else if (filterType == "end_year") {
|
|
|
|
return '{"groupFilters":[{"field":"organization.project.start year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static getCountryFilter( filterType:FilterType) {
|
|
|
|
if (filterType == "fundingL0") {
|
|
|
|
return '{"groupFilters":[{"field":"country.organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
} else if (filterType == "start_year") {
|
|
|
|
return '{"groupFilters":[{"field":"country.organization.project.start year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
} else if (filterType == "end_year") {
|
|
|
|
return '{"groupFilters":[{"field":"country.organization.project.start year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
}
|
2020-07-07 15:50:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static filterIndexOf(filterToAdd, currentFilters):any{
|
|
|
|
for(let fi =0; fi< currentFilters.length; fi++){
|
|
|
|
for(let gfi =0; gfi< currentFilters[fi]["groupFilters"].length; gfi++ ){
|
|
|
|
if(currentFilters[fi]["groupFilters"][gfi].field == filterToAdd['groupFilters'][0]['field'] && currentFilters[fi]["groupFilters"][gfi].type == filterToAdd['groupFilters'][0]['type']){
|
|
|
|
return {"filter":fi, "groupFilter":gfi};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
2020-06-03 15:43:14 +02:00
|
|
|
}
|
|
|
|
}
|