From b67c242fe70de58057b19620d3c80276c4473a8f Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Tue, 24 Oct 2023 11:51:55 +0300 Subject: [PATCH] [monitor-admin-library | DONE | CHANGED]: Make stakeholder types dynamic for Session methods. --- login/utils/helper.class.ts | 29 ++++--------------- monitor-admin/utils/indicator-utils.ts | 7 ++--- monitor/entities/stakeholder.ts | 8 +++++ .../indicators/indicator-themes.component.ts | 8 +++-- 4 files changed, 20 insertions(+), 32 deletions(-) diff --git a/login/utils/helper.class.ts b/login/utils/helper.class.ts index 63e15b2f..7ade96d7 100644 --- a/login/utils/helper.class.ts +++ b/login/utils/helper.class.ts @@ -1,3 +1,5 @@ +import {stakeholderTypes} from "../../monitor/entities/stakeholder"; + export class User { email: string; firstname: string; @@ -98,23 +100,11 @@ export class Session { } public static isMonitorCurator(user: User): boolean { - return this.isCommunityCurator(user) || this.isProjectCurator(user) || this.isFunderCurator(user) || this.isOrganizationCurator(user); + return stakeholderTypes.filter(stakeholderType => this.isTypeCurator(stakeholderType.value, user)).length > 0; } public static isCommunityCurator(user: User): boolean { - return this.isTypeCurator("Community", user); - } - - public static isFunderCurator(user: User): boolean { - return this.isTypeCurator("Funder", user); - } - - public static isProjectCurator(user: User): boolean { - return this.isTypeCurator("Project", user); - } - - public static isOrganizationCurator(user: User): boolean { - return this.isTypeCurator("Institution", user); + return this.isTypeCurator("community", user); } private static isTypeCurator(type: string, user: User): boolean { @@ -122,16 +112,7 @@ export class Session { } public static isCurator(type: string, user: User): boolean { - if (type == 'funder') { - return user && this.isFunderCurator(user); - } else if (type == 'ri' || type == 'community') { - return user && this.isCommunityCurator(user); - } else if (type == 'organization' || type == 'institution') { - return user && this.isOrganizationCurator(user); - } else if (type == 'project') { - return user && this.isProjectCurator(user); - } - return false; + return stakeholderTypes.find(stakeholderType => stakeholderType.value == type) && this.isTypeCurator(type, user); } public static isPortalAdministrator(user: User): boolean { diff --git a/monitor-admin/utils/indicator-utils.ts b/monitor-admin/utils/indicator-utils.ts index f7c71c0b..4dae319c 100644 --- a/monitor-admin/utils/indicator-utils.ts +++ b/monitor-admin/utils/indicator-utils.ts @@ -10,7 +10,7 @@ import { Stakeholder, StakeholderEntities, SubCategory, - Topic, + Topic, stakeholderTypes, Visibility } from "../../monitor/entities/stakeholder"; import {AbstractControl, ValidatorFn, Validators} from "@angular/forms"; @@ -28,10 +28,7 @@ export class StakeholderUtils { ]; types: Option[] = [ - {value: 'funder', label: StakeholderEntities.FUNDER}, - {value: 'ri', label: StakeholderEntities.RI}, - {value: 'project', label: StakeholderEntities.PROJECT}, - {value: 'organization', label: StakeholderEntities.ORGANIZATION} + ...stakeholderTypes ]; visibility: Option[] = [ diff --git a/monitor/entities/stakeholder.ts b/monitor/entities/stakeholder.ts index 09ab7022..13ed58cf 100644 --- a/monitor/entities/stakeholder.ts +++ b/monitor/entities/stakeholder.ts @@ -1,6 +1,7 @@ import {SafeResourceUrl} from "@angular/platform-browser"; import {properties} from "../../../../environments/environment"; import {Session, User} from "../../login/utils/helper.class"; +import {Option} from "../../sharedComponents/input/input.component"; export const ChartHelper = { prefix: "((__", @@ -309,3 +310,10 @@ export enum StakeholderEntities { ORGANIZATIONS = 'Research Institutions', PROJECTS = 'Projects' } + +export let stakeholderTypes: Option[] = [ + {value: 'funder', label: StakeholderEntities.FUNDER}, + {value: 'ri', label: StakeholderEntities.RI}, + {value: 'project', label: StakeholderEntities.PROJECT}, + {value: 'organization', label: StakeholderEntities.ORGANIZATION} +]; diff --git a/monitor/indicators/indicator-themes.component.ts b/monitor/indicators/indicator-themes.component.ts index fcb11a8e..4fb9e7e0 100644 --- a/monitor/indicators/indicator-themes.component.ts +++ b/monitor/indicators/indicator-themes.component.ts @@ -5,6 +5,7 @@ import {Meta, Title} from "@angular/platform-browser"; import {SEOService} from "../../sharedComponents/SEO/SEO.service"; import {Breadcrumb} from "../../utils/breadcrumbs/breadcrumbs.component"; import {Subscriber} from "rxjs"; +import {StakeholderEntities} from "../entities/stakeholder"; @Component({ selector: 'indicator-themes-page', @@ -53,9 +54,9 @@ import {Subscriber} from "rxjs"; This is the current set of indicator themes we cover. We’ll keep enriching it as new requests and data are coming into the OpenAIRE Graph. We are at your disposal, should you have any recommendations!

- Check out the indicator pages (for funders, - research institutions and - research initiatives) + Check out the indicator pages (for {{entities.FUNDERS}}, + {{entities.ORGANIZATIONS}} and + {{entities.RIS}}) for the specific indicators for each type of dashboard, and the methodology and terminology page on how we produce the metrics.

@@ -67,6 +68,7 @@ import {Subscriber} from "rxjs"; export class IndicatorThemesComponent implements OnInit, OnDestroy { private subscriptions: any[] = []; public properties = properties; + public entities = StakeholderEntities; public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'Resources - Themes'}]; constructor(private router: Router,