From 8210fe3e374a6d05968149ed1da0422b7706cc1b Mon Sep 17 00:00:00 2001 From: Konstantinos Triantafyllou Date: Mon, 11 Nov 2019 13:28:36 +0000 Subject: [PATCH] [MonitorDashboard]: Add service of stakeholder. Move copy to Library. Change name of Tools to IndicatorUtils. git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@57574 d315682c-612b-4755-9ff5-7f18f6832af3 --- src/app/home/home.component.ts | 4 +-- src/app/services/stakeholder.service.ts | 30 +++++++++++++++++-- src/app/topic/indicators.component.ts | 2 +- src/app/topic/topic.component.ts | 16 +++++----- .../utils/{Tools.ts => indicator-utils.ts} | 7 ----- src/assets/monitor-custom.css | 2 +- 6 files changed, 40 insertions(+), 21 deletions(-) rename src/app/utils/{Tools.ts => indicator-utils.ts} (76%) diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index 23d3f6b..0bd452f 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -8,7 +8,7 @@ import {ErrorMessagesComponent} from '../openaireLibrary/utils/errorMessages.com import {Stakeholder, Topic} from "../utils/entities/stakeholder"; import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service"; import {StakeholderService} from "../services/stakeholder.service"; -import {Tools} from "../utils/Tools"; +import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class"; declare var UIkit; @@ -45,7 +45,7 @@ export class HomeComponent implements OnInit, OnDestroy { this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => { if (stakeholder) { this.sideBarService.setHasSidebar(true); - this.stakeholder = Tools.copy(stakeholder); + this.stakeholder = HelperFunctions.copy(stakeholder); this.topic = null; this.title.setTitle(stakeholder.index_name); } diff --git a/src/app/services/stakeholder.service.ts b/src/app/services/stakeholder.service.ts index 49c671a..883fbb8 100644 --- a/src/app/services/stakeholder.service.ts +++ b/src/app/services/stakeholder.service.ts @@ -1,7 +1,7 @@ import {Injectable} from "@angular/core"; import {HttpClient} from "@angular/common/http"; import {BehaviorSubject, Observable} from "rxjs"; -import {Stakeholder} from "../utils/entities/stakeholder"; +import {Indicator, Stakeholder} from "../utils/entities/stakeholder"; @Injectable({ providedIn: "root" @@ -16,7 +16,33 @@ export class StakeholderService { getStakeholder(url: string, alias:string): Observable { // return new BehaviorSubject(Stakeholder.createECStakeholder()).asObservable(); - return this.http.get(url + '/stakeholder/' + alias); + return this.http.get(url + '/stakeholder/' + encodeURIComponent(alias)); + } + + getAllStakeholders(url: string, type: string = null): Observable { + return this.http.get(url + '/stakeholder/all' + (type)?('?type=' + type):''); + } + + getStakeholders(url: string, type: string = null): Observable { + return this.http.get(url + '/stakeholder' + (type)?('?type=' + type):''); + } + + getDefaultStakeholders(url: string, type: string = null): Observable { + return this.http.get(url + '/stakeholder/default' + (type)?('?type=' + type):''); + } + + saveStakeholder(url: string, stakeholder: Stakeholder): Observable { + return this.http.post(url + '/stakeholder/save', stakeholder); + } + + saveIndicator(url: string, path: string[], indicator: Indicator): Observable { + return this.http.post(url + '/' + path.join('/') + + '/indicator/save', indicator); + } + + deleteIndicator(url: string, path: string[], indicatorId: string): Observable { + return this.http.delete(url + '/' + path.join('/') + + '/indicator/delete/' + encodeURIComponent(indicatorId)); } getStakeholderAsObservable(): Observable { diff --git a/src/app/topic/indicators.component.ts b/src/app/topic/indicators.component.ts index fb08358..1d2ed8f 100644 --- a/src/app/topic/indicators.component.ts +++ b/src/app/topic/indicators.component.ts @@ -1,7 +1,7 @@ import {Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core"; import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service"; import {Indicator, Stakeholder} from "../utils/entities/stakeholder"; -import {IndicatorUtils} from "../utils/Tools"; +import {IndicatorUtils} from "../utils/indicator-utils"; @Component({ selector: 'indicators', diff --git a/src/app/topic/topic.component.ts b/src/app/topic/topic.component.ts index 75fbf0c..89e0070 100644 --- a/src/app/topic/topic.component.ts +++ b/src/app/topic/topic.component.ts @@ -5,7 +5,7 @@ import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties' import {Category, Stakeholder, SubCategory, Topic} from "../utils/entities/stakeholder"; import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service"; import {StakeholderService} from "../services/stakeholder.service"; -import {Tools} from "../utils/Tools"; +import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class"; declare var UIkit; @@ -44,7 +44,7 @@ export class TopicComponent implements OnInit, OnDestroy { this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => { if (stakeholder) { this.sideBarService.setHasSidebar(true); - this.stakeholder = Tools.copy(stakeholder); + this.stakeholder = HelperFunctions.copy(stakeholder); this.topicIndex = this.stakeholder.topics.findIndex(topic => topic.alias === params['topic']); if(this.topicIndex === -1) { this.navigateToError(); @@ -90,7 +90,7 @@ export class TopicComponent implements OnInit, OnDestroy { if(element.className.indexOf('uk-open') !== -1) { this.hide(element); } else { - this.copyCategory = Tools.copy(this.stakeholder.topics[this.topicIndex].categories[index]); + this.copyCategory = HelperFunctions.copy(this.stakeholder.topics[this.topicIndex].categories[index]); this.show(element); this.valid = true; } @@ -103,7 +103,7 @@ export class TopicComponent implements OnInit, OnDestroy { if(index === -1) { this.stakeholder.topics[this.topicIndex].categories.push(this.copyCategory); } else { - this.stakeholder.topics[this.topicIndex].categories[index] = Tools.copy(this.copyCategory); + this.stakeholder.topics[this.topicIndex].categories[index] = HelperFunctions.copy(this.copyCategory); } this.hide(element); } else { @@ -118,7 +118,7 @@ export class TopicComponent implements OnInit, OnDestroy { if(element.className.indexOf('uk-open') !== -1) { this.hide(element); } else { - this.copySubCategory = Tools.copy(this.stakeholder.topics[this.topicIndex]. + this.copySubCategory = HelperFunctions.copy(this.stakeholder.topics[this.topicIndex]. categories[this.categoryIndex].subCategories[index]); this.show(element); this.valid = true; @@ -134,7 +134,7 @@ export class TopicComponent implements OnInit, OnDestroy { subCategories.push(this.copySubCategory); } else { this.stakeholder.topics[this.topicIndex].categories[this.selectedCategoryIndex]. - subCategories[index] = Tools.copy(this.copySubCategory); + subCategories[index] = HelperFunctions.copy(this.copySubCategory); } this.hide(element); } else { @@ -146,7 +146,7 @@ export class TopicComponent implements OnInit, OnDestroy { if(element.className.indexOf('uk-open') !== -1) { this.hide(element); } else { - this.topic = Tools.copy(this.stakeholder.topics[this.topicIndex]); + this.topic = HelperFunctions.copy(this.stakeholder.topics[this.topicIndex]); this.valid = true; this.show(element); } @@ -155,7 +155,7 @@ export class TopicComponent implements OnInit, OnDestroy { public saveTopic(element) { if(this.topic.name && this.topic.name !== '') { this.topic.alias = this.topic.name.toLowerCase(); - this.stakeholder.topics[this.topicIndex] = Tools.copy(this.topic); + this.stakeholder.topics[this.topicIndex] = HelperFunctions.copy(this.topic); this.hide(element); } else { this.valid = false; diff --git a/src/app/utils/Tools.ts b/src/app/utils/indicator-utils.ts similarity index 76% rename from src/app/utils/Tools.ts rename to src/app/utils/indicator-utils.ts index 7e82d48..4733f25 100644 --- a/src/app/utils/Tools.ts +++ b/src/app/utils/indicator-utils.ts @@ -16,10 +16,3 @@ export class IndicatorUtils { isActiveIcon: string = 'brightness_1'; } - -export class Tools { - - public static copy(element: any): any { - return JSON.parse(JSON.stringify(element)); - } -} diff --git a/src/assets/monitor-custom.css b/src/assets/monitor-custom.css index 9c85306..fcfcbbe 100644 --- a/src/assets/monitor-custom.css +++ b/src/assets/monitor-custom.css @@ -49,7 +49,7 @@ li>a:hover .onHover { margin-left: var(--sidebar-width) !important; } } -/* Custom width of sidebar, change var: sidebar-width*/ +/* Custom height of header, change var: header-height*/ body { padding-top: var(--header-height) !important; }