openaire-library/monitor/entities/stakeholder.ts

356 lines
12 KiB
TypeScript
Raw Normal View History

import {SafeResourceUrl} from "@angular/platform-browser";
import {properties} from "../../../../environments/environment";
import {Session, User} from "../../login/utils/helper.class";
export const ChartHelper = {
prefix: "((__",
suffix: "__))"
};
2023-10-27 14:52:55 +02:00
export type StakeholderType = 'funder' | 'ri' | 'project' | 'organization' | 'country' | 'researcher' | 'datasource';
export type IndicatorType = 'number' | 'chart';
export type IndicatorSize = 'small' | 'medium' | 'large';
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';
export type Format = 'NUMBER' | 'PERCENTAGE';
export type Visibility = 'PUBLIC' | 'PRIVATE' | 'RESTRICTED';
export class Stakeholder {
_id: string;
type: StakeholderType;
funderType: string;
name: string;
index_id;
index_name: string;
index_shortName: string;
2023-04-12 16:59:04 +02:00
statsProfile: string = "monitor";
locale: string = 'eu';
alias: string;
defaultId: string;
visibility: Visibility;
creationDate: Date = null;
updateDate: Date;
projectUpdateDate: Date;
/** @warning Use pipe in HTML or StringUtils.getLogoUrl in components */
logoUrl: string;
isUpload: boolean = false;
description: string;
topics: any[];
constructor(_id: string, type: StakeholderType, index_id: string, index_name: string, index_shortName: string, alias: string, visibility: Visibility, logoUrl: string, defaultId: string = null, description: string = null) {
this._id = _id;
this.type = type;
this.index_id = index_id;
this.index_name = index_name;
this.index_shortName = index_shortName;
this.defaultId = defaultId;
this.alias = alias;
this.visibility = visibility;
this.logoUrl = logoUrl;
this.description = description;
this.topics = [];
}
}
export class StakeholderInfo extends Stakeholder {
isManager: boolean = false;
isMember: boolean = false;
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;
})
}
}
export class Topic {
_id: string;
name: string;
alias: string;
description: string;
visibility: Visibility;
creationDate: Date = null;
updateDate: Date;
defaultId: string;
categories: Category[];
icon: string;
constructor(name: string, description: string, alias: string, visibility:Visibility, defaultId: string = null, icon: string = null) {
this._id = null;
this.name = name;
this.description = description;
this.alias = alias;
this.visibility = visibility;
this.defaultId = defaultId;
this.categories = [];
this.icon = icon;
}
}
export class Category {
_id: string;
name: string;
alias: string;
description: string;
creationDate: Date = null;
updateDate: Date;
visibility: Visibility;
defaultId: string;
subCategories: SubCategory[];
constructor(name: string, description: string, alias: string, visibility: Visibility, defaultId: string = null) {
this._id = null;
this.name = name;
this.description = description;
this.alias = alias;
this.visibility = visibility;
this.defaultId = defaultId;
this.subCategories = [];
}
}
export class SubCategory {
_id: string;
name: string;
alias: string;
description: string;
creationDate: Date = null;
updateDate: Date;
visibility: Visibility;
defaultId: string;
charts: Section[];
numbers: Section[];
constructor(name: string, description: string, alias: string, visibility: Visibility, defaultId: string = null) {
this._id = null;
this.name = name;
this.description = description;
this.alias = alias;
this.visibility = visibility;
this.defaultId = defaultId;
this.charts = [];
this.numbers = [];
}
}
export class Section {
_id: string;
title: string;
defaultId: string;
creationDate: Date = null;
updateDate: Date;
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;
additionalDescription: string;
creationDate: Date = null;
updateDate: Date;
type: IndicatorType;
width: IndicatorSize;
height: IndicatorSize;
tags: string[];
visibility: Visibility;
defaultId: string;
indicatorPaths: IndicatorPath[];
descriptionOverlay: boolean = false;
constructor(name: string, description: string, additionalDescription:string, type: IndicatorType, width: IndicatorSize,height: IndicatorSize, visibility: Visibility, indicatorPaths: IndicatorPath[], defaultId: string = null) {
this._id = null;
this.name = name;
this.description = description;
this.additionalDescription = additionalDescription;
this.type = type;
this.width = width;
this.height = height;
this.visibility = visibility;
this.defaultId = defaultId;
this.indicatorPaths = indicatorPaths;
}
}
export class IndicatorPath {
type: IndicatorPathType;
source: SourceType;
url: string;
safeResourceUrl: SafeResourceUrl; // initialize on front end
jsonPath: string[];
chartObject: string;
parameters: any;
filters: any;
filtersApplied: number = 0;
format: Format;
constructor(type: IndicatorPathType, source: SourceType, url: string, chartObject: string, jsonPath: string[], format: Format = 'NUMBER') {
this.type = type;
this.url = url;
this.source = source;
this.jsonPath = jsonPath;
this.chartObject = chartObject;
this.parameters = {};
this.filters = {};
this.filtersApplied = 0;
this.format = format;
}
static createParameters(funderName: string = null, title: string = null, chartType: string = null): any {
return {
index_name: funderName,
title: title,
type: chartType
};
}
}
export type FilterType = "fundingL0"|"start_year" | "end_year" | "co-funded" | "foslvl1" | "foslvl2";
export class IndicatorFilterUtils {
static getFilter(fieldPath: string, filterType:FilterType, value:string|string[] =null) {
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"}';
}
}
if ((filterType == "foslvl1" || filterType == "foslvl2") ){
if (filterType == "foslvl1" && fieldPath.indexOf("result.result_fos.lvl1")!=-1 && value && value.length > 0) {
let filterString = '{"groupFilters":[' ;
let filters = [];
for(let v of value) {
filters.push('{"field":"' + fieldPath + '","type":"=","values":["' + v + '"]}');
}
filterString+=filters.join(", ")
filterString+='],"op":"OR"}'
return filterString;
}
if (filterType == "foslvl1" && fieldPath.indexOf("result.result_fos.lvl2")!=-1 && value && value.length > 0) {
let filterString = '{"groupFilters":[' ;
let filters = [];
for(let v of value) {
filters.push('{"field":"' + (fieldPath.replace(".lvl2",".lvl1")) + '","type":"=","values":["' + v + '"]}');
}
filterString+=filters.join(", ")
filterString+='],"op":"OR"}'
return filterString;
}
if (filterType == "foslvl2" && fieldPath.indexOf("result.result_fos.lvl2")!=-1 && value && value.length > 0) {
let filterString = '{"groupFilters":[' ;
let filters = [];
for(let v of value) {
filters.push('{"field":"' + fieldPath + '","type":"=","values":["' + v + '"]}');
}
filterString+=filters.join(", ")
filterString+='],"op":"OR"}'
return filterString;
}
return "";
}
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"){
return this.getProjectFilter(filterType);
}
else if (table == "country"){
return this.getCountryFilter(filterType);
}else if (table == "organization"){
return this.getOrganizationFilter(filterType);
}
return "";
}
static getResultFilter(table: string = null, filterType:FilterType) {
//works for tables ["publication", "software", "dataset", "other", "result"]
if (filterType == "fundingL0") {
if(properties.useOldStatisticsSchema) {
return '{"groupFilters":[{"field":"' + table + '.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
}else{//new statistcs schema
return '{"groupFilters":[{"field":"' + table + '.project funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
}
}else if (filterType == "co-funded") {
return '{"groupFilters":[{"field":"' + table + '.No of funders","type":">","values":["1"]}],"op":"AND"}';
}else if (table == "publication" &&(filterType == "foslvl1" || filterType == "foslvl2") ){
return '{"groupFilters":[{"field":"' + (filterType == "foslvl1"?"publication.topics.result.result_fos.lvl1":"publication.topics.result.result_fos.lvl2") + '","type":"=","values":["' + ChartHelper.prefix + filterType + ChartHelper.suffix + '"]}],"op":"OR"}';
}
return "";
}
static getProjectFilter( filterType:FilterType) {
//works for table "project"
if (filterType == "fundingL0") {
return '{"groupFilters":[{"field":"project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
}
return "";
}
static getOrganizationFilter( filterType:FilterType) {
//works for table "organization"
if (filterType == "fundingL0") {
return '{"groupFilters":[{"field":"organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
}
return "";
}
static getCountryFilter( filterType:FilterType) {
//works for table "country"
if (filterType == "fundingL0") {
return '{"groupFilters":[{"field":"country.organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
}
return "";
}
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;
}
}
2022-06-08 13:01:45 +02:00
/**
* @deprecated
*
* TODO: Remove after merge with develop
* */
2022-06-08 13:01:45 +02:00
export enum StakeholderEntities {
STAKEHOLDER = 'Dashboard',
FUNDER = 'Funder',
RI = 'Research Initiative',
ORGANIZATION = 'Research Institution',
2022-06-08 13:01:45 +02:00
PROJECT = 'Project',
2023-10-27 14:52:55 +02:00
COUNTRY = 'National',
2022-06-08 13:01:45 +02:00
STAKEHOLDERS = 'Dashboards',
FUNDERS = 'Funders',
RIS = 'Research Initiatives',
ORGANIZATIONS = 'Research Institutions',
2022-06-08 13:01:45 +02:00
PROJECTS = 'Projects'
}