From a5cc8f6fdb0f6bc838601eda1163b837cc940c79 Mon Sep 17 00:00:00 2001 From: Konstantinos Triantafyllou Date: Wed, 20 Nov 2019 10:32:28 +0000 Subject: [PATCH] [Monitor Dashboard]: Add form builder for edit indicator git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@57644 d315682c-612b-4755-9ff5-7f18f6832af3 --- src/app/services/stakeholder.service.ts | 8 ++--- src/app/topic/indicators.component.html | 31 ++++++++++-------- src/app/topic/indicators.component.ts | 42 +++++++++++++++++++------ src/app/utils/indicator-utils.ts | 2 ++ src/index.html | 5 +++ 5 files changed, 62 insertions(+), 26 deletions(-) diff --git a/src/app/services/stakeholder.service.ts b/src/app/services/stakeholder.service.ts index a4046bd..197bc8b 100644 --- a/src/app/services/stakeholder.service.ts +++ b/src/app/services/stakeholder.service.ts @@ -17,10 +17,10 @@ export class StakeholderService { } getStakeholder(url: string, alias:string): Observable { - // return new BehaviorSubject(Stakeholder.createECStakeholder()).asObservable(); - return this.http.get(url + '/stakeholder/' + encodeURIComponent(alias)).pipe(map(stakeholder => { - return this.formalizeStakeholder([stakeholder])[0]; - })); + return new BehaviorSubject(Stakeholder.createECStakeholder()).asObservable(); + // return this.http.get(url + '/stakeholder/' + encodeURIComponent(alias)).pipe(map(stakeholder => { + // return this.formalizeStakeholder([stakeholder])[0]; + // })); } getAllStakeholders(url: string, type: string = null): Observable { diff --git a/src/app/topic/indicators.component.html b/src/app/topic/indicators.component.html index 4bef60b..89306a1 100644 --- a/src/app/topic/indicators.component.html +++ b/src/app/topic/indicators.component.html @@ -149,7 +149,7 @@ {{(indicator.isActive) ? 'Active' : 'Inactive'}} - more_vert + more_vert
{{indicator.name}}
@@ -215,13 +215,13 @@ [okDisabled]="indicatorFb && indicatorFb.invalid">
-
+
-
+
@@ -234,18 +234,23 @@
-
---> + diff --git a/src/app/topic/indicators.component.ts b/src/app/topic/indicators.component.ts index eb5d2b8..50d970c 100644 --- a/src/app/topic/indicators.component.ts +++ b/src/app/topic/indicators.component.ts @@ -1,11 +1,12 @@ -import {Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from "@angular/core"; +import {ChangeDetectorRef, Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from "@angular/core"; import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service"; -import {Indicator, Stakeholder} from "../utils/entities/stakeholder"; +import {Indicator, IndicatorPath, Stakeholder} from "../utils/entities/stakeholder"; import {IndicatorUtils} from "../utils/indicator-utils"; import {FormArray, FormBuilder, 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} from "@angular/platform-browser"; @Component({ selector: 'indicators', @@ -55,7 +56,8 @@ export class IndicatorsComponent implements OnInit, OnChanges { constructor(private sideBarService: SideBarService, private statisticsService: StatisticsService, - private fb: FormBuilder) { + private fb: FormBuilder, + private sanitizer: DomSanitizer) { } ngOnInit(): void { @@ -64,7 +66,6 @@ export class IndicatorsComponent implements OnInit, OnChanges { ngOnChanges(changes: SimpleChanges): void { if (this.canEdit) { this.charts = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].charts; - console.log(this.charts); this.displayCharts = this.filterChartType(this.filterPrivacy( this.filterStatus(this.filterByKeyword(this.charts, this.keyword), this.status), this.privacy), @@ -157,6 +158,11 @@ export class IndicatorsComponent implements OnInit, OnChanges { return this.indicatorFb.get('urls') as FormArray; } + private getUrlByStakeHolder(indicatorPath: IndicatorPath) { + return this.sanitizer.bypassSecurityTrustResourceUrl( + this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(indicatorPath))); + } + public addUrl() { this.urls.push(this.fb.control('', [Validators.required, Validators.pattern('https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.' + @@ -196,15 +202,29 @@ export class IndicatorsComponent implements OnInit, OnChanges { this.indicatorUtils.generateIndicatorByChartUrl(this.statisticsService.getChartSource(url), url)); }); let index = this.charts.push(this.indicator); - this.editIndicatorOpen(index -1); + this.editIndicatorOpen(index - 1); } public editIndicatorOpen(index: number) { this.indicator = HelperFunctions.copy(this.charts[index]); - let indicatorPaths = this.fb.array([]); this.indicator.indicatorPaths.forEach(indicatorPath => { + indicatorPath.safeResourceUrl = this.getUrlByStakeHolder(indicatorPath) + console.log(indicatorPath.safeResourceUrl); + }); + let indicatorPaths = this.fb.array([]); + this.indicator.indicatorPaths.forEach(indicatorPath => { + let parameters = this.fb.array([]); + indicatorPath.parameters.forEach((value, key) => { + if (this.indicatorUtils.ignoredParameters.indexOf(key) === -1) { + // TODO add Validators Map + parameters.push(this.fb.group({ + key: this.fb.control(key), + value: this.fb.control(value, Validators.required) + })); + } + }); indicatorPaths.push(this.fb.group({ - parameters: this.fb.array([]) + parameters: parameters })); }); this.editIndicatorFb = this.fb.group({ @@ -216,15 +236,19 @@ export class IndicatorsComponent implements OnInit, OnChanges { width: this.fb.control(this.indicator.width, Validators.required), }); console.log(this.editIndicatorFb.value); - /*this.editIndicatorModal.alertTitle = this.indicator.name; + this.editIndicatorModal.alertHeader = false; this.editIndicatorModal.cancelButtonText = 'Cancel'; this.editIndicatorModal.okButtonText = 'Save Changes'; this.editIndicatorModal.okButtonLeft = false; this.editIndicatorModal.alertMessage = false; - this.editIndicatorModal.open();*/ + this.editIndicatorModal.open(); } saveIndicator() { } + + focus(event: FocusEvent) { + event.srcElement.parentElement.className = event.srcElement.parentElement.className + ' md-input-focus'; + } } diff --git a/src/app/utils/indicator-utils.ts b/src/app/utils/indicator-utils.ts index 31a7e05..5ae9614 100644 --- a/src/app/utils/indicator-utils.ts +++ b/src/app/utils/indicator-utils.ts @@ -18,6 +18,8 @@ export class IndicatorUtils { isActiveIcon: string = 'brightness_1'; + ignoredParameters = ['funder_name']; + public getFullUrl(indicatorPath: IndicatorPath): string { let replacedUrl = indicatorPath.chartObject; if (indicatorPath.parameters) { diff --git a/src/index.html b/src/index.html index 8b349d6..8070d3d 100644 --- a/src/index.html +++ b/src/index.html @@ -69,6 +69,7 @@ +