From 6d2948d87ff14b44b06d8cbf6f62e79d4b1e95fc Mon Sep 17 00:00:00 2001 From: Konstantinos Triantafyllou Date: Wed, 9 Dec 2020 13:24:32 +0000 Subject: [PATCH] [Monitor Dashboard | Trunk]: Change reorder method git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-monitor-portal/trunk/monitor_dashboard@60104 d315682c-612b-4755-9ff5-7f18f6832af3 --- src/app/topic/indicators.component.ts | 51 +++++++++++++++------------ 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/app/topic/indicators.component.ts b/src/app/topic/indicators.component.ts index 1611ee4..75e0ece 100644 --- a/src/app/topic/indicators.component.ts +++ b/src/app/topic/indicators.component.ts @@ -23,7 +23,7 @@ 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 "../openaireLibrary/monitor/services/stakeholder.service"; +import {Reorder, 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"; @@ -200,7 +200,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } }); if (document !== undefined) { - let callback = (list, type: IndicatorType): void => { + let callback = (list, type: IndicatorType, action: 'moved' | 'added' | 'removed'): void => { let items: HTMLCollection = list.current.children; let reordered = []; for (let i = 0; i < items.length; i++) { @@ -208,28 +208,33 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV reordered.push(items.item(i).id); } } - this.reorderIndicators(list.current.id.toString().split('-')[1], type, reordered); + let reorder: Reorder = { + action: action, + target: list.detail[1].id, + ids: reordered + } + this.reorderIndicators(list.current.id.toString().split('-')[1], type, reorder); }; this.numbers.forEach((section) => { this.subscriptions.push(UIkit.util.on(document, 'moved', '#number-' + section._id, (list): void => { - callback(list, "number"); + callback(list, "number", 'moved'); })); this.subscriptions.push(UIkit.util.on(document, 'added', '#number-' + section._id, (list): void => { - callback(list, "number"); + callback(list, "number", 'added'); })); this.subscriptions.push(UIkit.util.on(document, 'removed', '#number-' + section._id, (list): void => { - callback(list, "number"); + callback(list, "number", 'removed'); })); }); this.charts.forEach((section) => { this.subscriptions.push(UIkit.util.on(document, 'moved', '#chart-' + section._id, (list): void => { - callback(list, "chart"); + callback(list, "chart", 'moved'); })); this.subscriptions.push(UIkit.util.on(document, 'added', '#chart-' + section._id, (list): void => { - callback(list, "chart"); + callback(list, "chart", 'added'); })); this.subscriptions.push(UIkit.util.on(document, 'removed', '#chart-' + section._id, (list): void => { - callback(list, "chart"); + callback(list, "chart", 'removed'); })); }); } @@ -405,9 +410,9 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } public getNumberClassBySize(size: IndicatorSize) { - if(size === 'small') { + if (size === 'small') { return 'uk-width-1-4@xl uk-width-1-3@l uk-width-1-2@m uk-width-1-1'; - } else if(size === 'medium') { + } else if (size === 'medium') { return 'uk-width-1-3@l uk-width-1-2@m uk-width-1-1'; } else { return 'uk-width-1-2@l uk-width-1-1@m uk-width-1-1'; @@ -415,9 +420,9 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } public getChartClassBySize(size: IndicatorSize) { - if(size === 'small') { + if (size === 'small') { return 'uk-width-1-3@xl uk-width-1-2@m uk-width-1-1'; - } else if(size === 'medium') { + } else if (size === 'medium') { return 'uk-width-1-2@l uk-width-1-1'; } else { return 'uk-width-1-1'; @@ -448,7 +453,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV public validateJsonPath(index: number) { let indicatorPath: FormGroup = this.numberIndicatorPaths.at(index); - if(this.indicator.defaultId === null) { + if (this.indicator.defaultId === null) { this.getJsonPath(index).disable(); } indicatorPath.get('result').setErrors({validating: true}); @@ -460,12 +465,12 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } }); setTimeout(() => { - if(this.indicator.defaultId === null) { + if (this.indicator.defaultId === null) { this.getJsonPath(index).enable(); } indicatorPath.get('result').setErrors(null); console.debug(result); - if(typeof result === 'string' || typeof result === 'number') { + if (typeof result === 'string' || typeof result === 'number') { result = Number(result); if (result !== Number.NaN) { indicatorPath.get('result').setValue(result); @@ -517,10 +522,10 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } )); for (let index = 0; index < this.numberIndicatorPaths.length; index++) { - if(this.numberIndicatorPaths.at(index).get('url').valid) { + if (this.numberIndicatorPaths.at(index).get('url').valid) { this.validateJsonPath(index); } - if(this.indicator.defaultId === null) { + if (this.indicator.defaultId === null) { this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => { this.numberIndicatorPaths.at(index).get('result').setValue(null); if (this.numberIndicatorPaths.at(index).get('url').valid) { @@ -544,7 +549,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV if (indicatorPath.source) { this.numberIndicatorPaths.at(index).get('source').setValue(indicatorPath.source); } - if(indicatorPath.jsonPath.length > 1 && this.getJsonPath(index).length ==1 ) { + if (indicatorPath.jsonPath.length > 1 && this.getJsonPath(index).length == 1) { let paths = indicatorPath.jsonPath; for (let i = 0; i < paths.length; i++) { if (i == this.getJsonPath(index).length) { @@ -558,7 +563,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV } }) ); - + this.subscriptions.push(this.numberIndicatorPaths.at(index).get('jsonPath').valueChanges.subscribe(value => { if (this.indicator.indicatorPaths[index]) { this.indicator.indicatorPaths[index].jsonPath = value; @@ -825,7 +830,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV })); } - reorderIndicators(sectionId: string, type: IndicatorType, indicatorIds: string[]) { + reorderIndicators(sectionId: string, type: IndicatorType, reorder: Reorder) { this.editing = true; let path = [ this.stakeholder._id, @@ -834,7 +839,7 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id, sectionId ]; - this.subscriptions.push(this.stakeholderService.reorderIndicators(this.properties.monitorServiceAPIURL, path, indicatorIds, type).subscribe(indicators => { + this.subscriptions.push(this.stakeholderService.reorderIndicators(this.properties.monitorServiceAPIURL, path, reorder, type).subscribe(indicators => { if (type === 'chart') { this.charts.find(section => section._id === sectionId).indicators = indicators; this.filterCharts(); @@ -861,9 +866,11 @@ export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterV public get isAdministrator(): boolean { return Session.isPortalAdministrator(this.user); } + public get isCurator(): boolean { return this.isAdministrator || Session.isMonitorCurator(this.user); } + refreshIndicator() { this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths, 'chart', true); this.indicator.indicatorPaths.forEach(indicatorPath => {