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";
|
2023-10-24 10:51:55 +02:00
|
|
|
import {Option} from "../../sharedComponents/input/input.component";
|
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';
|
2022-06-08 13:56:47 +02:00
|
|
|
export type SourceType = 'statistics' | 'search' |'stats-tool' | 'old' | 'image';
|
2023-04-18 14:26:41 +02:00
|
|
|
export type Format = 'NUMBER' | 'PERCENTAGE';
|
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;
|
2023-04-12 16:59:04 +02:00
|
|
|
statsProfile: string = "monitor";
|
2023-06-09 19:52:10 +02:00
|
|
|
locale: string = 'eu';
|
2020-06-03 15:43:14 +02:00
|
|
|
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;
|
2023-07-19 18:51:54 +02:00
|
|
|
projectUpdateDate: 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[];
|
2023-04-06 10:31:22 +02:00
|
|
|
descriptionOverlay: boolean = false;
|
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;
|
2023-04-18 14:26:41 +02:00
|
|
|
format: Format;
|
2020-06-05 14:56:28 +02:00
|
|
|
|
2023-04-18 14:26:41 +02:00
|
|
|
constructor(type: IndicatorPathType, source: SourceType, url: string, chartObject: string, jsonPath: string[], format: Format = 'NUMBER') {
|
2020-06-03 15:43:14 +02:00
|
|
|
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;
|
2023-04-18 14:26:41 +02:00
|
|
|
this.format = format;
|
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
|
|
|
|
|
|
|
}
|
2023-04-11 00:28:53 +02:00
|
|
|
|
2020-07-28 17:55:59 +02:00
|
|
|
export type FilterType = "fundingL0"|"start_year" | "end_year" | "co-funded";
|
2023-04-11 00:28:53 +02:00
|
|
|
|
|
|
|
export class IndicatorFilterUtils {
|
2022-10-17 13:22:06 +02:00
|
|
|
|
|
|
|
static getFilter(fieldPath: string, filterType:FilterType) {
|
|
|
|
if((filterType == "start_year" || filterType == "end_year") && (fieldPath.indexOf(".year") != -1 || fieldPath.indexOf(".start year") != -1)
|
|
|
|
&& fieldPath.indexOf("indi_pub_downloads_year.year") == -1){
|
|
|
|
// make it work for any table with field year or start year no matter the type or the table name
|
|
|
|
//exclude indi_pub_downloads_year.year because it throws errors. when there is a solution remove the exclusion
|
|
|
|
if (filterType == "start_year") {
|
|
|
|
return '{"groupFilters":[{"field":"' + fieldPath + '","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
} else if (filterType == "end_year") {
|
|
|
|
return '{"groupFilters":[{"field":"' + fieldPath + '","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let table = fieldPath&&fieldPath.length > 0? fieldPath.split(".")[0]:"";
|
|
|
|
if(["publication", "software", "dataset", "other", "result"].indexOf(table)!=-1){
|
|
|
|
return this.getResultFilter(table,filterType);
|
|
|
|
}else if (table == "project"){
|
2020-07-07 15:50:49 +02:00
|
|
|
return this.getProjectFilter(filterType);
|
|
|
|
}
|
2022-10-17 13:22:06 +02:00
|
|
|
else if (table == "country"){
|
2021-01-11 10:21:42 +01:00
|
|
|
return this.getCountryFilter(filterType);
|
2022-10-17 13:22:06 +02:00
|
|
|
}else if (table == "organization"){
|
2021-01-11 10:21:42 +01:00
|
|
|
return this.getOrganizationFilter(filterType);
|
2021-01-15 13:27:52 +01:00
|
|
|
}
|
2023-07-25 12:24:24 +02:00
|
|
|
|
|
|
|
return "";
|
2020-07-07 15:50:49 +02:00
|
|
|
}
|
2022-10-17 13:22:06 +02:00
|
|
|
static getResultFilter(table: string = null, filterType:FilterType) {
|
|
|
|
//works for tables ["publication", "software", "dataset", "other", "result"]
|
2020-07-07 15:50:49 +02:00
|
|
|
if (filterType == "fundingL0") {
|
2021-01-15 13:27:52 +01:00
|
|
|
if(properties.useOldStatisticsSchema) {
|
2022-10-17 13:22:06 +02:00
|
|
|
return '{"groupFilters":[{"field":"' + table + '.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
2021-01-15 13:27:52 +01:00
|
|
|
}else{//new statistcs schema
|
2022-10-17 13:22:06 +02:00
|
|
|
return '{"groupFilters":[{"field":"' + table + '.project funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
2021-01-15 13:27:52 +01:00
|
|
|
}
|
2020-07-28 17:55:59 +02:00
|
|
|
}else if (filterType == "co-funded") {
|
2022-10-17 13:22:06 +02:00
|
|
|
return '{"groupFilters":[{"field":"' + table + '.No of funders","type":">","values":["1"]}],"op":"AND"}';
|
2020-07-07 15:50:49 +02:00
|
|
|
}
|
2023-07-25 12:24:24 +02:00
|
|
|
return "";
|
2020-07-07 15:50:49 +02:00
|
|
|
}
|
|
|
|
static getProjectFilter( filterType:FilterType) {
|
2022-10-17 13:22:06 +02:00
|
|
|
//works for table "project"
|
2020-07-07 15:50:49 +02:00
|
|
|
if (filterType == "fundingL0") {
|
|
|
|
return '{"groupFilters":[{"field":"project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
}
|
2023-07-25 12:24:24 +02:00
|
|
|
return "";
|
2020-07-07 15:50:49 +02:00
|
|
|
}
|
|
|
|
static getOrganizationFilter( filterType:FilterType) {
|
2022-10-17 13:22:06 +02:00
|
|
|
//works for table "organization"
|
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"}';
|
|
|
|
}
|
2023-07-25 12:24:24 +02:00
|
|
|
return "";
|
2021-01-11 10:21:42 +01:00
|
|
|
}
|
|
|
|
static getCountryFilter( filterType:FilterType) {
|
2022-10-17 13:22:06 +02:00
|
|
|
//works for table "country"
|
2021-01-11 10:21:42 +01:00
|
|
|
if (filterType == "fundingL0") {
|
|
|
|
return '{"groupFilters":[{"field":"country.organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
|
|
|
}
|
2023-07-25 12:24:24 +02:00
|
|
|
return "";
|
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
|
|
|
}
|
|
|
|
}
|
2022-06-08 13:01:45 +02:00
|
|
|
|
|
|
|
export enum StakeholderEntities {
|
|
|
|
STAKEHOLDER = 'Dashboard',
|
|
|
|
FUNDER = 'Funder',
|
2022-06-09 09:38:06 +02:00
|
|
|
RI = 'Research Initiative',
|
|
|
|
ORGANIZATION = 'Research Institution',
|
2022-06-08 13:01:45 +02:00
|
|
|
PROJECT = 'Project',
|
|
|
|
|
|
|
|
STAKEHOLDERS = 'Dashboards',
|
|
|
|
FUNDERS = 'Funders',
|
2022-06-09 09:38:06 +02:00
|
|
|
RIS = 'Research Initiatives',
|
|
|
|
ORGANIZATIONS = 'Research Institutions',
|
2022-06-08 13:01:45 +02:00
|
|
|
PROJECTS = 'Projects'
|
|
|
|
}
|
2023-10-24 10:51:55 +02:00
|
|
|
|
|
|
|
export let stakeholderTypes: Option[] = [
|
|
|
|
{value: 'funder', label: StakeholderEntities.FUNDER},
|
|
|
|
{value: 'ri', label: StakeholderEntities.RI},
|
2023-11-02 10:30:59 +01:00
|
|
|
{value: 'organization', label: StakeholderEntities.ORGANIZATION},
|
|
|
|
{value: 'project', label: StakeholderEntities.PROJECT}
|
2023-10-24 10:51:55 +02:00
|
|
|
];
|