From 76f2dadc8e69ed9013ebf5747d37a607106e687b Mon Sep 17 00:00:00 2001 From: Konstantinos Triantafyllou Date: Wed, 3 Jun 2020 13:44:03 +0000 Subject: [PATCH] [Monitor_Dashboard | Trunk]: Move stakeholder class and service to library git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@58829 d315682c-612b-4755-9ff5-7f18f6832af3 --- src/app/app.component.ts | 4 +- .../manageStakeholders.component.ts | 4 +- src/app/monitor/monitor.component.ts | 4 +- src/app/services/stakeholder.service.ts | 113 ---------- src/app/stakeholder/stakeholder.component.ts | 4 +- src/app/topic/indicators.component.ts | 4 +- src/app/topic/topic.component.ts | 4 +- src/app/utils/entities/stakeholder.ts | 203 ------------------ src/app/utils/entities/stakeholderCreator.ts | 2 +- src/app/utils/indicator-utils.ts | 2 +- src/app/utils/services/statistics.service.ts | 2 +- 11 files changed, 15 insertions(+), 331 deletions(-) delete mode 100644 src/app/services/stakeholder.service.ts delete mode 100644 src/app/utils/entities/stakeholder.ts diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 0cb22db..28a2829 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -4,11 +4,11 @@ import {EnvProperties} from './openaireLibrary/utils/properties/env-properties'; import {EnvironmentSpecificService} from './openaireLibrary/utils/properties/environment-specific.service'; import {Session, User} from './openaireLibrary/login/utils/helper.class'; import {UserManagementService} from "./openaireLibrary/services/user-management.service"; -import {StakeholderService} from "./services/stakeholder.service"; +import {StakeholderService} from "./openaireLibrary/monitor/services/stakeholder.service"; import {BehaviorSubject, Subscriber} from "rxjs"; import {LayoutService} from "./openaireLibrary/dashboard/sharedComponents/sidebar/layout.service"; import {MenuItem} from "./openaireLibrary/sharedComponents/menu"; -import {Stakeholder} from "./utils/entities/stakeholder"; +import {Stakeholder} from "./openaireLibrary/monitor/entities/stakeholder"; @Component({ diff --git a/src/app/manageStakeholders/manageStakeholders.component.ts b/src/app/manageStakeholders/manageStakeholders.component.ts index 0fa8447..5d4775e 100644 --- a/src/app/manageStakeholders/manageStakeholders.component.ts +++ b/src/app/manageStakeholders/manageStakeholders.component.ts @@ -1,8 +1,8 @@ import {Component, OnDestroy, OnInit, ViewChild} from "@angular/core"; -import {StakeholderService} from "../services/stakeholder.service"; +import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service"; import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties"; import {EnvironmentSpecificService} from "../openaireLibrary/utils/properties/environment-specific.service"; -import {Stakeholder} from "../utils/entities/stakeholder"; +import {Stakeholder} from "../openaireLibrary/monitor/entities/stakeholder"; import {Subscriber, zip} from "rxjs"; import {StakeholderUtils} from "../utils/indicator-utils"; import {FormBuilder, FormGroup, Validators} from "@angular/forms"; diff --git a/src/app/monitor/monitor.component.ts b/src/app/monitor/monitor.component.ts index ba37faa..c7356a5 100644 --- a/src/app/monitor/monitor.component.ts +++ b/src/app/monitor/monitor.component.ts @@ -10,8 +10,8 @@ import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes'; import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component'; import {HelperService} from "../openaireLibrary/utils/helper/helper.service"; import {SEOService} from "../openaireLibrary/sharedComponents/SEO/SEO.service"; -import {StakeholderService} from "../services/stakeholder.service"; -import {Category, ChartHelper, IndicatorPath, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder"; +import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service"; +import {Category, ChartHelper, IndicatorPath, Stakeholder, SubCategory, Topic} from "../openaireLibrary/monitor/entities/stakeholder"; import {StatisticsService} from "../utils/services/statistics.service"; import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils"; import {LayoutService} from "../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service"; diff --git a/src/app/services/stakeholder.service.ts b/src/app/services/stakeholder.service.ts deleted file mode 100644 index 090c6cf..0000000 --- a/src/app/services/stakeholder.service.ts +++ /dev/null @@ -1,113 +0,0 @@ -import {Injectable} from "@angular/core"; -import {HttpClient} from "@angular/common/http"; -import {BehaviorSubject, Observable} from "rxjs"; -import {Indicator, IndicatorPath, Section, Stakeholder} from "../utils/entities/stakeholder"; -import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class"; -import {map} from "rxjs/operators"; -import {StakeholderCreator} from "../utils/entities/stakeholderCreator"; - -let maps: string[] = ['parameters', 'filters']; - -@Injectable({ - providedIn: "root" -}) -export class StakeholderService { - - private stakeholderSubject: BehaviorSubject = null; - - constructor(private http: HttpClient) { - this.stakeholderSubject = new BehaviorSubject(null); - } - - getStakeholder(url: string, alias:string): Observable { - /*return new BehaviorSubject( - StakeholderCreator.createFunderFromDefaultProfile("ec","funder","ec__________::EC", - "European Commission","EC", - false,"ec",true,true)).asObservable();*/ - return this.http.get(url + '/stakeholder/' + encodeURIComponent(alias)).pipe(map(stakeholder => { - return this.formalize(stakeholder); - })); - } - - getAllStakeholders(url: string, type: string = null): Observable { - return this.http.get(url + '/stakeholder/all' + ((type)?('?type=' + type):'')).pipe(map(stakeholders => { - return this.formalize(stakeholders); - })); - } - - getStakeholders(url: string, type: string = null): Observable { - return this.http.get(url + '/stakeholder' + ((type)?('?type=' + type):'')).pipe(map(stakeholders => { - return this.formalize(stakeholders); - })); - } - - getDefaultStakeholders(url: string, type: string = null): Observable { - return this.http.get(url + '/stakeholder/default' + ((type)?('?type=' + type):'')).pipe(map(stakeholders => { - return this.formalize(stakeholders); - })); - } - - buildStakeholder(url: string, stakeholder: Stakeholder): Observable { - return this.http.post(url + '/build-stakeholder', stakeholder).pipe(map(stakeholder => { - return this.formalize(stakeholder); - })); - } - - saveStakeholder(url: string, stakeholder: Stakeholder): Observable { - return this.http.post(url + '/stakeholder/save', stakeholder).pipe(map(stakeholder => { - return this.formalize(stakeholder); - })); - } - - toggleStatus(url: string, path: string[]): Observable { - return this.http.post(url + '/' + path.join('/') + '/toggle-status', null); - } - - toggleAccess(url: string, path: string[]): Observable { - return this.http.post(url + '/' + path.join('/') + '/toggle-access', null); - } - - saveElement(url: string, element: any, path: string[] = []): Observable { - path = HelperFunctions.encodeArray(path); - return this.http.post(url + ((path.length > 0)?'/':'') + path.join('/') + - '/save', element).pipe(map(element => { - return this.formalize(element); - })); - } - - saveSection(url: string, element: any, path: string[] = [], index: number = -1): Observable
{ - path = HelperFunctions.encodeArray(path); - return this.http.post
(url + ((path.length > 0)?'/':'') + path.join('/') + - '/save/' + index, element).pipe(map(element => { - return this.formalize(element); - })); - } - - deleteElement(url: string, path: string[]): Observable { - path = HelperFunctions.encodeArray(path); - return this.http.delete(url + '/' + path.join('/') + '/delete'); - } - - reorderIndicators(url: string, path: string[], indicatorIds: string[], type: string = 'chart'): Observable { - path = HelperFunctions.encodeArray(path); - return this.http.post(url + '/' + path.join('/') + '/' + type + '/reorder', indicatorIds).pipe(map(indicators => { - return this.formalize(indicators); - })); - } - - getStakeholderAsObservable(): Observable { - return this.stakeholderSubject.asObservable(); - } - - get stakeholder(): Stakeholder { - return this.stakeholderSubject.getValue(); - } - - setStakeholder(stakeholder: Stakeholder) { - this.stakeholderSubject.next(stakeholder); - } - - private formalize(element: any) { - return HelperFunctions.copy(element); - } -} diff --git a/src/app/stakeholder/stakeholder.component.ts b/src/app/stakeholder/stakeholder.component.ts index f84ca86..0ca19cd 100644 --- a/src/app/stakeholder/stakeholder.component.ts +++ b/src/app/stakeholder/stakeholder.component.ts @@ -5,8 +5,8 @@ import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties' import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes'; import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.component'; -import {Stakeholder, Topic} from "../utils/entities/stakeholder"; -import {StakeholderService} from "../services/stakeholder.service"; +import {Stakeholder, Topic} from "../openaireLibrary/monitor/entities/stakeholder"; +import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service"; import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class"; import {AlertModal} from "../openaireLibrary/utils/modal/alert"; import {Subscriber} from "rxjs"; diff --git a/src/app/topic/indicators.component.ts b/src/app/topic/indicators.component.ts index 9e3f3f2..383685b 100644 --- a/src/app/topic/indicators.component.ts +++ b/src/app/topic/indicators.component.ts @@ -9,14 +9,14 @@ import { SimpleChanges, ViewChild } from "@angular/core"; -import {Indicator, IndicatorPath, IndicatorType, Section, Stakeholder} from "../utils/entities/stakeholder"; +import {Indicator, IndicatorPath, IndicatorType, Section, Stakeholder} from "../openaireLibrary/monitor/entities/stakeholder"; import {IndicatorUtils} from "../utils/indicator-utils"; import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms"; import {AlertModal} from "../openaireLibrary/utils/modal/alert"; import {StatisticsService} from "../utils/services/statistics.service"; import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class"; import {DomSanitizer, SafeResourceUrl} from "@angular/platform-browser"; -import {StakeholderService} from "../services/stakeholder.service"; +import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service"; import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties"; import {Subscriber} from "rxjs"; import {LayoutService} from "../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service"; diff --git a/src/app/topic/topic.component.ts b/src/app/topic/topic.component.ts index fd4bf04..226d40b 100644 --- a/src/app/topic/topic.component.ts +++ b/src/app/topic/topic.component.ts @@ -2,8 +2,8 @@ import {Component, OnDestroy, OnInit, ViewChild} from '@angular/core'; import {ActivatedRoute, Router} from '@angular/router'; import {Title} from '@angular/platform-browser'; import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties'; -import {Category, Section, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder"; -import {StakeholderService} from "../services/stakeholder.service"; +import {Category, Section, Stakeholder, SubCategory, Topic} from "../openaireLibrary/monitor/entities/stakeholder"; +import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service"; import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class"; import {AlertModal} from "../openaireLibrary/utils/modal/alert"; import {Subscriber, Subscription} from "rxjs"; diff --git a/src/app/utils/entities/stakeholder.ts b/src/app/utils/entities/stakeholder.ts deleted file mode 100644 index f83f26f..0000000 --- a/src/app/utils/entities/stakeholder.ts +++ /dev/null @@ -1,203 +0,0 @@ -import {SafeResourceUrl} from "@angular/platform-browser"; - -export const ChartHelper = { - prefix: "((__", - suffix: "__))" -}; - -export type StakeholderType = 'funder' | 'ri' | 'project' | 'organization'; -export type IndicatorType = 'number' | 'chart'; -export type IndicatorWidth = 'small' | 'medium' | 'large'; -export type IndicatorPathType = 'table' | 'bar' | 'column' | 'pie' | 'line' | 'other'; -export type SourceType = 'statistics' | 'search' | 'metrics' | 'stats-tool' | 'old' | 'image'; - -export class Stakeholder { - _id: string; - type: StakeholderType; - name: string; - index_id; - index_name: string; - index_shortName: string; - alias: string; - defaultId: string; - isActive: boolean; - isPublic: boolean; - creationDate: Date = null; - updateDate: Date; - managers: string[]; - logoUrl:string; - topics: Topic[]; - - constructor(id: string, type: StakeholderType, index_id, index_name: string, index_shortName: string, alias: string, isActive: boolean, isPublic: boolean, logoUrl:string, defaultId: string = null) { - this.initializeFunder(id, type, index_id, index_name, index_shortName, defaultId, alias, isActive, isPublic, logoUrl); - this.topics = []; - this.managers = []; - } - - initializeFunder(id: string, type: StakeholderType, index_id, index_name: string, index_shortName: string, defaultId: string, alias: string, isActive: boolean, isPublic: boolean, logoUrl:string) { - 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.isActive = isActive; - this.isPublic = isPublic; - this.logoUrl = logoUrl; - } -} - -export class Topic { - _id: string; - name: string; - alias: string; - description: string; - isActive: boolean; - isPublic: boolean; - defaultId: string; - categories: Category[]; - - constructor(name: string, description: string, alias: string, isActive: boolean, isPublic: boolean, defaultId: string = null) { - this._id = null; - this.name = name; - this.description = description; - this.alias = alias; - this.isActive = isActive; - this.isPublic = isPublic; - this.defaultId = defaultId; - this.categories = []; - } -} - -export class Category { - _id: string; - name: string; - alias: string; - description: string; - isActive: boolean; - isPublic: boolean; - defaultId: string; - subCategories: SubCategory[]; - - constructor(name: string, description: string, alias: string, isActive: boolean, isPublic: boolean, defaultId: string = null) { - this._id = null; - this.name = name; - this.description = description; - this.alias = alias; - this.isActive = isActive; - this.isPublic = isPublic; - this.defaultId = defaultId; - this.subCategories = []; - } -} - -export class SubCategory { - _id: string; - name: string; - alias: string; - description: string; - isActive: boolean; - isPublic: boolean; - defaultId: string; - charts: Section[]; - numbers: Section[]; - recommendedFor:string[]; - - constructor(name: string, description: string, alias: string, isActive: boolean, isPublic: boolean, defaultId: string = null) { - this._id = null; - this.name = name; - this.description = description; - this.alias = alias; - this.isActive = isActive; - this.isPublic = isPublic; - this.defaultId = defaultId; - this.charts = []; - this.numbers = []; - this.recommendedFor= []; - } - -} - -export class Section { - _id: string; - title: string; - defaultId: string; - 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; - type: IndicatorType; - width: IndicatorWidth; - tags: string[]; - isActive: boolean; - isPublic: boolean; - defaultId: string; - indicatorPaths: IndicatorPath[]; - recommendedFor:string[]; - - constructor(name: string, description: string, type: IndicatorType, width: IndicatorWidth, isActive: boolean, isPublic: boolean, indicatorPaths: IndicatorPath[], defaultId: string = null) { - this._id = null; - this.name = name; - this.description = description; - this.type = type; - this.width = width; - this.isActive = isActive; - this.isPublic = isPublic; - this.defaultId = defaultId; - this.indicatorPaths = indicatorPaths; - this.recommendedFor = []; - } - -} - -export class IndicatorPath { - type: IndicatorPathType; - source: SourceType; - url: string; - safeResourceUrl: SafeResourceUrl; // initialize on front end - jsonPath: string[]; - chartObject: string; - parameters: any; - filters: any; - - 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 = {}; - } - - static createParameters(funderName: string = null, title: string = null, chartType: string = null): any { - return { - index_name: funderName, - title: title, - type: chartType - }; - } - - static createResultFilters(dbType: string = null): any { - return { - fundingL0: '{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}', - start_year: '{"groupFilters":[{"field":"' + dbType + '.year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}', - end_year: '{"groupFilters":[{"field":"' + dbType + '.year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}' - }; - } -} diff --git a/src/app/utils/entities/stakeholderCreator.ts b/src/app/utils/entities/stakeholderCreator.ts index 8bdd2d5..a4b0dc7 100644 --- a/src/app/utils/entities/stakeholderCreator.ts +++ b/src/app/utils/entities/stakeholderCreator.ts @@ -1,4 +1,4 @@ -import {Stakeholder, Topic, Category, SubCategory, Indicator, IndicatorPath, ChartHelper, Section} from "./stakeholder"; +import {Stakeholder, Topic, Category, SubCategory, Indicator, IndicatorPath, ChartHelper, Section} from "../../openaireLibrary/monitor/entities/stakeholder"; import {IndicatorUtils} from "../indicator-utils"; export class StakeholderCreator { diff --git a/src/app/utils/indicator-utils.ts b/src/app/utils/indicator-utils.ts index 09ec38d..a9015d7 100644 --- a/src/app/utils/indicator-utils.ts +++ b/src/app/utils/indicator-utils.ts @@ -6,7 +6,7 @@ import { Stakeholder, SubCategory, Topic -} from "./entities/stakeholder"; +} from "../openaireLibrary/monitor/entities/stakeholder"; import {AbstractControl, ValidatorFn, Validators} from "@angular/forms"; import {Option} from "../openaireLibrary/dashboard/sharedComponents/input/input.component"; diff --git a/src/app/utils/services/statistics.service.ts b/src/app/utils/services/statistics.service.ts index 8e95521..b8b0c11 100644 --- a/src/app/utils/services/statistics.service.ts +++ b/src/app/utils/services/statistics.service.ts @@ -2,7 +2,7 @@ import {Injectable} from '@angular/core'; import {HttpClient} from "@angular/common/http"; import {EnvironmentSpecificService} from "../../openaireLibrary/utils/properties/environment-specific.service"; import {Observable} from "rxjs"; -import {SourceType} from "../entities/stakeholder"; +import {SourceType} from "../../openaireLibrary/monitor/entities/stakeholder"; @Injectable({