From b3fdeb99c586d56a5d84fd27e7e63ad126283fc8 Mon Sep 17 00:00:00 2001 From: Konstantinos Triantafyllou Date: Fri, 29 Nov 2019 12:14:49 +0000 Subject: [PATCH] [MonitorDashboard]: Add edit stakeholder modal git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@57768 d315682c-612b-4755-9ff5-7f18f6832af3 --- src/app/home/home.component.html | 60 ++++++++++++---- src/app/home/home.component.ts | 71 ++++++++++++++++--- src/app/home/home.module.ts | 6 +- .../sharedComponents/input/input.component.ts | 4 +- src/app/topic/indicators.component.ts | 2 +- src/app/utils/indicator-utils.ts | 23 ++++++ 6 files changed, 140 insertions(+), 26 deletions(-) diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 668862d..7d2c0a8 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -3,12 +3,12 @@
@@ -41,12 +41,13 @@
- {{indicatorUtils.isPublicIcon.get(stakeholder.isPublic)}} + {{stakeholderUtils.isPublicIcon.get(stakeholder.isPublic)}} {{(stakeholder.isPublic) ? 'Public' : 'Private'}} {{indicatorUtils.isActiveIcon}} + [class.md-color-green-300]="stakeholder.isActive">{{stakeholderUtils.isActiveIcon}} {{(stakeholder.isActive) ? 'Active' : 'Inactive'}}
@@ -64,12 +65,12 @@
- {{indicatorUtils.isPublicIcon.get(stakeholder.isPublic)}} + {{stakeholderUtils.isPublicIcon.get(stakeholder.isPublic)}}
{{(stakeholder.isPublic) ? 'Public' : 'Private'}}
{{indicatorUtils.isActiveIcon}} + [class.md-color-green-300]="stakeholder.isActive">{{stakeholderUtils.isActiveIcon}}
{{(stakeholder.isActive) ? 'Active' : 'Inactive'}}
@@ -92,12 +93,13 @@
- {{indicatorUtils.isPublicIcon.get(stakeholder.isPublic)}} + {{stakeholderUtils.isPublicIcon.get(stakeholder.isPublic)}} {{(stakeholder.isPublic) ? 'Public' : 'Private'}} {{indicatorUtils.isActiveIcon}} + [class.md-color-green-300]="stakeholder.isActive">{{stakeholderUtils.isActiveIcon}} {{(stakeholder.isActive) ? 'Active' : 'Inactive'}}
@@ -105,8 +107,12 @@ (click)="$event.stopPropagation();$event.preventDefault()">more_vert
@@ -116,12 +122,12 @@
- {{indicatorUtils.isPublicIcon.get(stakeholder.isPublic)}} + {{stakeholderUtils.isPublicIcon.get(stakeholder.isPublic)}}
{{(stakeholder.isPublic) ? 'Public' : 'Private'}}
{{indicatorUtils.isActiveIcon}} + [class.md-color-green-300]="stakeholder.isActive">{{stakeholderUtils.isActiveIcon}}
{{(stakeholder.isActive) ? 'Active' : 'Inactive'}}
@@ -132,3 +138,33 @@
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ diff --git a/src/app/home/home.component.ts b/src/app/home/home.component.ts index c010f57..f01268e 100644 --- a/src/app/home/home.component.ts +++ b/src/app/home/home.component.ts @@ -1,11 +1,12 @@ -import {Component, OnDestroy, OnInit} from "@angular/core"; +import {Component, OnDestroy, OnInit, ViewChild} from "@angular/core"; import {StakeholderService} from "../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 {Subscriber, zip} from "rxjs"; -import {IndicatorUtils, Option} from "../utils/indicator-utils"; -import {FormBuilder, FormGroup} from "@angular/forms"; +import {IndicatorUtils, Option, StakeholderUtils} from "../utils/indicator-utils"; +import {FormBuilder, FormGroup, Validators} from "@angular/forms"; +import {AlertModal} from "../openaireLibrary/utils/modal/alert"; @Component({ selector: 'home', @@ -15,15 +16,19 @@ export class HomeComponent implements OnInit, OnDestroy { public properties: EnvProperties; public loading: boolean = true; - public indicatorUtils: IndicatorUtils = new IndicatorUtils(); + public stakeholderUtils: StakeholderUtils = new StakeholderUtils(); public defaultStakeholders: Stakeholder[]; public stakeholders: Stakeholder[]; - public stakeholder: FormGroup; + public stakeholder: Stakeholder; + public stakeholderFb: FormGroup; + public index: number; + /** * Filtered Stakeholders */ public displayDefaultStakeholders: Stakeholder[]; public displayStakeholders: Stakeholder[]; + /** * Top filters */ @@ -39,6 +44,9 @@ export class HomeComponent implements OnInit, OnDestroy { public grid: boolean = true; private subscriptions: any[] = []; + @ViewChild('editStakeholderModal') editStakeholderModal: AlertModal; + @ViewChild('deleteStakeholderModal') deleteStakeholderModal: AlertModal; + constructor(private stakeholderService: StakeholderService, private propertiesService: EnvironmentSpecificService, private fb: FormBuilder) { @@ -136,10 +144,53 @@ export class HomeComponent implements OnInit, OnDestroy { } } - public editStakeholder(index = -1) { - /*let stakeholder = this.d - this.fb.group({ - _id: this.fb.control() - })*/ + public editStakeholder(stakeholder: Stakeholder = null, isDefault: boolean = false) { + if(isDefault) { + this.index = (stakeholder)?this.defaultStakeholders.findIndex(value => value._id === stakeholder._id):-1; + } else { + this.index = (stakeholder)?this.stakeholders.findIndex(value => value._id === stakeholder._id):-1; + } + if(!stakeholder) { + this.stakeholder = new Stakeholder(null, null, null, + null, null, isDefault, null, false, false); + } else { + this.stakeholder = stakeholder; + } + this.stakeholderFb = this.fb.group( { + _id: this.fb.control(stakeholder._id), + index_name: this.fb.control(stakeholder.index_name, Validators.required), + index_id: this.fb.control(stakeholder.index_id, Validators.required), + index_shortName: this.fb.control(stakeholder.index_shortName, Validators.required), + isDefaultProfile: this.fb.control(stakeholder.isDefaultProfile), + alias: this.fb.control(stakeholder.alias, Validators.required), + isPublic: this.fb.control(stakeholder.isPublic), + isActive: this.fb.control(stakeholder.isActive), + type: this.fb.control(stakeholder.type, Validators.required), + topics: this.fb.control(stakeholder.topics) + }); + if(this.index !== -1) { + this.stakeholderFb.get('type').disable(); + } + this.editStakeholderModal.cancelButtonText = 'Cancel'; + this.editStakeholderModal.okButtonText = 'Save Changes'; + this.editStakeholderModal.okButtonLeft = false; + this.editStakeholderModal.alertMessage = false; + this.editStakeholderModal.open(); + } + + public saveStakeholder() { + + } + + public deleteStakeholderOpen(stakeholder: Stakeholder, isDefault = false) { + if(isDefault) { + this.index = (stakeholder)?this.defaultStakeholders.findIndex(value => value._id === stakeholder._id):-1; + } else { + this.index = (stakeholder)?this.stakeholders.findIndex(value => value._id === stakeholder._id):-1; + } + } + + public deleteStakeholder() { + } } diff --git a/src/app/home/home.module.ts b/src/app/home/home.module.ts index 27e34ab..0e47c6c 100644 --- a/src/app/home/home.module.ts +++ b/src/app/home/home.module.ts @@ -7,6 +7,8 @@ import {CommonModule} from "@angular/common"; import {RouterModule} from "@angular/router"; import {InputModule} from "../library/sharedComponents/input/input.module"; import {LoadingModule} from "../library/sharedComponents/loading/loading.module"; +import {AlertModalModule} from "../openaireLibrary/utils/modal/alertModal.module"; +import {ReactiveFormsModule} from "@angular/forms"; @NgModule({ declarations: [HomeComponent], @@ -15,7 +17,9 @@ import {LoadingModule} from "../library/sharedComponents/loading/loading.module" CommonModule, RouterModule, InputModule, - LoadingModule + LoadingModule, + AlertModalModule, + ReactiveFormsModule ], providers: [ FreeGuard, PreviousRouteRecorder, diff --git a/src/app/library/sharedComponents/input/input.component.ts b/src/app/library/sharedComponents/input/input.component.ts index 730d3db..2a729f3 100644 --- a/src/app/library/sharedComponents/input/input.component.ts +++ b/src/app/library/sharedComponents/input/input.component.ts @@ -1,6 +1,6 @@ import {Component, Input, OnDestroy, OnInit} from "@angular/core"; import {Option} from "../../../utils/indicator-utils"; -import {FormControl} from "@angular/forms"; +import {AbstractControl} from "@angular/forms"; import {HelperFunctions} from "../../../openaireLibrary/utils/HelperFunctions.class"; @Component({ @@ -20,7 +20,7 @@ import {HelperFunctions} from "../../../openaireLibrary/utils/HelperFunctions.cl ` }) export class InputComponent implements OnInit, OnDestroy { - @Input('formInput') formControl: FormControl; + @Input('formInput') formControl: AbstractControl; @Input('type') type: string = 'text'; @Input('label') label: string; @Input('rows') rows: number = 3; diff --git a/src/app/topic/indicators.component.ts b/src/app/topic/indicators.component.ts index 64c47a2..c23ac79 100644 --- a/src/app/topic/indicators.component.ts +++ b/src/app/topic/indicators.component.ts @@ -310,7 +310,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } public editIndicatorOpen(id = null) { - this.index = this.charts.findIndex(value => value._id === id); + this.index = (id)?this.charts.findIndex(value => value._id === id):-1; if (this.index !== -1) { this.indicator = HelperFunctions.copy(this.charts[this.index]); } diff --git a/src/app/utils/indicator-utils.ts b/src/app/utils/indicator-utils.ts index 704dfc8..c84cf03 100644 --- a/src/app/utils/indicator-utils.ts +++ b/src/app/utils/indicator-utils.ts @@ -8,6 +8,29 @@ export interface Option { label: string } +export class StakeholderUtils { + types: Option[] = [ + {value: 'funder', label: 'Funder'} + ]; + + isPublic: Option[] = [ + {icon: 'public', value: true, label: 'Public'}, + {icon: 'lock', value: false, label: 'Private'}, + ]; + + isActive: Option[] = [ + {icon: 'brightness_1', iconClass: '', value: true, label: 'Active'}, + {icon: 'brightness_1', value: false, label: 'Inactive'}, + ]; + + isPublicIcon: Map = new Map([ + [true, 'public'], + [false, 'lock'] + ]); + + isActiveIcon: string = 'brightness_1'; +} + export class IndicatorUtils { chartTypes: Option[] = [