2020-06-03 15:43:14 +02:00
import { SafeResourceUrl } from "@angular/platform-browser" ;
2022-02-16 17:18:12 +01:00
import { Session , User } from "../../login/utils/helper.class" ;
2024-02-20 09:58:47 +01:00
import { StringUtils } from "../../utils/string-utils.class" ;
2020-06-03 15:43:14 +02:00
export const ChartHelper = {
prefix : "((__" ,
suffix : "__))"
} ;
2024-06-02 20:39:47 +02:00
export type StakeholderType = 'funder' | 'ri' | 'project' | 'organization' | 'publisher' | 'journal' | 'country' | 'researcher' | 'datasource' ;
2020-06-03 15:43:14 +02:00
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' ;
2024-01-24 19:13:05 +01:00
export type Overlay = 'embed' | 'description' | false ;
2020-06-03 15:43:14 +02:00
2024-07-25 09:31:08 +02:00
export interface IndicatorImport {
indicatorPaths? : IndicatorPathImport [ ] ;
type : IndicatorType ,
name : string ,
description : string ,
additionalDescription : string ,
visibility : Visibility ,
width : IndicatorSize ,
height : IndicatorSize ,
sectionTitle : string ,
sectionType : IndicatorType ,
sectionIndex : number
}
export interface IndicatorPathImport {
jsonPath? : string [ ] ,
tab : string ,
url : string
}
export interface ImportIndicators {
stakeholder : Stakeholder ,
indicators : IndicatorImport [ ]
}
2024-06-11 16:32:16 +02:00
export class ManageStakeholders {
2024-06-12 11:47:47 +02:00
templates : ( Stakeholder & StakeholderInfo ) [ ] ;
standalone : ( Stakeholder & StakeholderInfo ) [ ] ;
dependent : ( Stakeholder & StakeholderInfo ) [ ] ;
umbrella : ( Stakeholder & StakeholderInfo ) [ ] ;
2024-05-21 10:05:16 +02:00
}
2020-06-03 15:43:14 +02:00
export class Stakeholder {
_id : string ;
type : StakeholderType ;
2023-11-13 14:00:05 +01:00
funderType : string ;
2020-06-03 15:43:14 +02:00
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 [ ] ;
2024-04-12 10:14:26 +02:00
copy : boolean = true ;
2024-05-21 10:05:16 +02:00
standalone : boolean = true ;
umbrella : Umbrella ;
2024-05-30 09:41:26 +02:00
parent : Stakeholder ;
otherParents : Stakeholder [ ] = [ ] ;
2024-01-07 12:20:17 +01:00
details? : any ;
2020-06-05 14:56:28 +02:00
2023-11-13 14:00:05 +01:00
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 ) {
2020-12-10 17:36:28 +01:00
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 ;
2024-04-12 10:14:26 +02:00
this . copy = ! ! this . defaultId && this . defaultId !== '-1' ;
2024-05-21 10:05:16 +02:00
this . standalone = true ;
2020-12-10 17:36:28 +01:00
this . topics = [ ] ;
2020-06-03 15:43:14 +02:00
}
2024-02-20 09:58:47 +01:00
static checkIsUpload ( response : Stakeholder | Stakeholder [ ] ) : any | any [ ] {
if ( Array . isArray ( response ) ) {
response . forEach ( value = > {
value . isUpload = value . logoUrl && ! StringUtils . isValidUrl ( value . logoUrl ) ;
} ) ;
} else {
response . isUpload = response . logoUrl && ! StringUtils . isValidUrl ( response . logoUrl ) ;
}
return response ;
}
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 = > {
2024-06-12 12:05:26 +02:00
stakeholder . isManager = Session . isPortalAdministrator ( user ) || Session . isCurator ( stakeholder . type , user ) || Session . isManager ( stakeholder . type , stakeholder . alias , user ) ;
stakeholder . isMember = stakeholder . isManager || Session . isMember ( stakeholder . type , stakeholder . alias , user ) ;
2022-02-16 17:18:12 +01:00
return stakeholder ;
} )
}
2020-06-05 14:56:28 +02:00
}
2024-05-21 10:05:16 +02:00
export class Umbrella {
2024-06-11 16:32:16 +02:00
types : StakeholderType [ ] ;
children : any ;
2024-05-21 10:05:16 +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 [ ] ;
2024-04-05 19:13:05 +02:00
activePath : number = 0 ;
2024-01-24 19:13:05 +01:00
overlay : Overlay = 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 ;
2024-04-30 14:38:31 +02:00
safeResourceUrl? : SafeResourceUrl ; // initialize on front end
2020-06-03 15:43:14 +02:00
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
2024-01-17 14:43:43 +01:00
export type FilterType = "fundingL0" | "start_year" | "end_year" | "co-funded" | "foslvl1" | "foslvl2" | "publicly-funded" ;
2023-04-11 00:28:53 +02:00
export class IndicatorFilterUtils {
2024-01-17 14:43:43 +01:00
public static filteredFields = {
"year" : {
"result" : "result.year" ,
"indi_pub_downloads_year" : "indi_pub_downloads_year.year" , //exclude indi_pub_downloads_year.year because it throws errors. when there is a solution remove the exclusion
"indi_pub_downloads" : "indi_pub_downloads.result.year" ,
"result_apc" : "result_apc.result.year" ,
"result_apc_affiliations" : "result_apc_affiliations.result.year" ,
2024-06-25 13:04:34 +02:00
"cross_country" : "cross_country.year" ,
2024-01-17 14:43:43 +01:00
"indi_impact_measures" : "indi_impact_measures.result.year" ,
"project" : "project.start year"
} ,
"fundingL0" : {
"result" : "result.project funding level 0" ,
"project" : "project.funding level 0" ,
"country" : "country.organization.project.funding level 0" ,
"organization" : "organization.project.funding level 0"
} ,
"co-funded" : {
"result" : "result.No of funders" ,
} ,
"foslvl1" :
{
"publication" : "publication.topics.result.result_fos.lvl1" ,
2024-01-30 10:42:21 +01:00
"result" : "result.topics.result.result_fos.lvl1" ,
2024-01-17 14:43:43 +01:00
"indi_pub_downloads" : "indi_pub_downloads.result.result_fos.lvl1" ,
"indi_pub_downloads_year" : "indi_pub_downloads_year.result.result_fos.lvl1" ,
"indi_impact_measures" : "indi_impact_measures.result.result_fos.lvl1" ,
"result_apc" : "result_apc.result.result_fos.lvl1" ,
"result_apc_affiliations" : "result_apc_affiliations.result.result_fos.lvl1" ,
2024-06-25 13:04:34 +02:00
"cross_country" : "cross_country.lvl1" ,
2024-01-17 14:43:43 +01:00
"historical_snapshots_irish_fos" : "historical_snapshots_irish_fos.lvl1"
} ,
"foslvl2" : {
"publication" : "publication.topics.result.result_fos.lvl2" ,
2024-01-30 10:42:21 +01:00
"result" : "result.topics.result.result_fos.lvl2" ,
2024-01-17 14:43:43 +01:00
"indi_pub_downloads" : "indi_pub_downloads.result.result_fos.lvl2" ,
"indi_pub_downloads_year" : "indi_pub_downloads_year.result.result_fos.lvl2" ,
"indi_impact_measures" : "indi_impact_measures.result.result_fos.lvl2" ,
"result_apc" : "result_apc.result.result_fos.lvl2" ,
"result_apc_affiliations" : "result_apc_affiliations.result.result_fos.lvl2" ,
2024-06-25 13:04:34 +02:00
"cross_country" : "cross_country.lvl2" ,
2024-01-17 14:43:43 +01:00
"historical_snapshots_irish_fos" : "historical_snapshots_irish_fos.lvl2"
} ,
"publicly-funded" : {
"result" : "result.indi_pub_publicly_funded.publicly_funded" ,
"indi_pub_downloads" : "indi_pub_downloads.result.indi_pub_publicly_funded.publicly_funded" ,
"indi_pub_downloads_year" : "indi_pub_downloads_year.result.indi_pub_publicly_funded.publicly_funded" ,
"indi_impact_measures" : "indi_impact_measures.result.indi_pub_publicly_funded.publicly_funded" ,
"result_apc" : "result_apc.result.indi_pub_publicly_funded.publicly_funded" ,
"result_apc_affiliations" : "result_apc_affiliations.result.indi_pub_publicly_funded.publicly_funded" ,
2024-06-25 13:04:34 +02:00
"cross_country" : "cross_country.publicly_funded"
2022-10-17 13:22:06 +02:00
}
2023-12-12 15:39:59 +01:00
2024-01-17 14:43:43 +01:00
}
static getFieldForTable ( field , table ) {
2024-01-30 10:29:31 +01:00
if ( [ "publication" , "software" , "dataset" , "other" , "result" ] . indexOf ( table ) != - 1 && IndicatorFilterUtils . filteredFields [ field ] [ "result" ] ) {
2024-04-18 10:08:41 +02:00
return IndicatorFilterUtils . filteredFields [ field ] [ "result" ] . replace ( "result." , table + "." ) ;
2024-01-17 14:43:43 +01:00
} else {
return IndicatorFilterUtils . filteredFields [ field ] [ table ] ;
2020-07-07 15:50:49 +02:00
}
2024-01-17 14:43:43 +01:00
}
static getFilter ( fieldPath : string , filterType :FilterType , value :string | string [ ] = null ) {
let tablename = fieldPath . split ( "." ) [ 0 ] ;
if ( ( filterType == "start_year" || filterType == "end_year" ) && ( IndicatorFilterUtils . getFieldForTable ( "year" , tablename ) ) ) {
if ( filterType == "start_year" ) {
return '{"groupFilters":[{"field":"' + IndicatorFilterUtils . getFieldForTable ( "year" , tablename ) + '","type":">=","values":["' + ChartHelper . prefix + 'start_year' + ChartHelper . suffix + '"]}],"op":"AND"}' ;
} else if ( filterType == "end_year" ) {
return '{"groupFilters":[{"field":"' + IndicatorFilterUtils . getFieldForTable ( "year" , tablename ) + '","type":"<=","values":["' + ChartHelper . prefix + 'end_year' + ChartHelper . suffix + '"]}],"op":"AND"}' ;
}
2021-01-15 13:27:52 +01:00
}
2024-01-17 14:43:43 +01:00
if ( filterType == "fundingL0" && IndicatorFilterUtils . getFieldForTable ( "fundingL0" , tablename ) ) {
return '{"groupFilters":[{"field":"' + IndicatorFilterUtils . getFieldForTable ( "fundingL0" , tablename ) + '","type":"=","values":["' + ChartHelper . prefix + 'fundingL0' + ChartHelper . suffix + '"]}],"op":"AND"}' ;
2023-07-25 12:24:24 +02:00
2024-01-17 14:43:43 +01:00
} else if ( filterType == "co-funded" && IndicatorFilterUtils . getFieldForTable ( "co-funded" , tablename ) ) {
return '{"groupFilters":[{"field":"' + IndicatorFilterUtils . getFieldForTable ( "co-funded" , tablename ) + '","type":">","values":["1"]}],"op":"AND"}' ;
} else if ( filterType == "publicly-funded" && IndicatorFilterUtils . getFieldForTable ( "publicly-funded" , tablename ) ) {
return '{"groupFilters":[{"field":"' + IndicatorFilterUtils . getFieldForTable ( "publicly-funded" , tablename ) + '","type":"=","values":["' + ( value == "true" ? "1" : "0" ) + '"]}],"op":"AND"}' ;
} else if ( filterType == "foslvl1" && IndicatorFilterUtils . getFieldForTable ( "foslvl1" , tablename ) && value && value . length > 0 ) {
let filterString = '{"groupFilters":[' ;
let filters = [ ] ;
for ( let v of value ) {
filters . push ( '{"field":"' + IndicatorFilterUtils . getFieldForTable ( "foslvl1" , tablename ) + '","type":"=","values":["' + v + '"]}' ) ;
2021-01-15 13:27:52 +01:00
}
2024-01-17 14:43:43 +01:00
filterString += filters . join ( ", " )
filterString += '],"op":"OR"}'
return filterString ;
} else if ( filterType == "foslvl2" && IndicatorFilterUtils . getFieldForTable ( "foslvl2" , tablename ) && value && value . length > 0 ) {
let filterString = '{"groupFilters":[' ;
let filters = [ ] ;
for ( let v of value ) {
filters . push ( '{"field":"' + IndicatorFilterUtils . getFieldForTable ( "foslvl2" , tablename ) + '","type":"=","values":["' + v + '"]}' ) ;
}
filterString += filters . join ( ", " )
filterString += '],"op":"OR"}'
return filterString ;
2021-01-11 10:21:42 +01:00
}
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
2023-11-13 14:00:05 +01:00
/ * *
* @deprecated
*
* TODO : Remove after merge with develop
* * /
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' ,
2023-10-27 14:52:55 +02:00
COUNTRY = 'National' ,
2022-06-08 13:01:45 +02:00
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'
}