From c1823ff1e2b7ecc72faeefb49d300f0a3fcaf430 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 28 Oct 2021 13:41:37 +0300 Subject: [PATCH] UI: Refactoring widget settings --- .../widget/legend-config.component.html | 6 +- .../widget/legend-config.component.ts | 78 ++- .../widget/widget-config.component.html | 458 +++++++++--------- .../widget/widget-config.component.scss | 7 +- 4 files changed, 269 insertions(+), 280 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/widget/legend-config.component.html b/ui-ngx/src/app/modules/home/components/widget/legend-config.component.html index 46faecb9f5..7d824a0186 100644 --- a/ui-ngx/src/app/modules/home/components/widget/legend-config.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/legend-config.component.html @@ -38,9 +38,6 @@
- - {{ 'legend.sort-legend' | translate }} - {{ 'legend.show-min' | translate }} @@ -53,5 +50,8 @@ {{ 'legend.show-total' | translate }} + + {{ 'legend.sort-legend' | translate }} +
diff --git a/ui-ngx/src/app/modules/home/components/widget/legend-config.component.ts b/ui-ngx/src/app/modules/home/components/widget/legend-config.component.ts index eb38e0adb1..1fa5e166f4 100644 --- a/ui-ngx/src/app/modules/home/components/widget/legend-config.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/legend-config.component.ts @@ -14,14 +14,7 @@ /// limitations under the License. /// -import { - Component, - forwardRef, - Input, - OnDestroy, - OnInit, - ViewContainerRef -} from '@angular/core'; +import { Component, forwardRef, Input, OnDestroy, OnInit } from '@angular/core'; import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms'; import { isDefined } from '@core/utils'; import { @@ -32,6 +25,7 @@ import { legendPositionTranslationMap } from '@shared/models/widget.models'; import { Subscription } from 'rxjs'; + // @dynamic @Component({ selector: 'tb-legend-config', @@ -49,7 +43,6 @@ export class LegendConfigComponent implements OnInit, OnDestroy, ControlValueAcc @Input() disabled: boolean; - legendSettings: LegendConfig; legendConfigForm: FormGroup; legendDirection = LegendDirection; legendDirections = Object.keys(LegendDirection); @@ -58,12 +51,11 @@ export class LegendConfigComponent implements OnInit, OnDestroy, ControlValueAcc legendPositions = Object.keys(LegendPosition); legendPositionTranslations = legendPositionTranslationMap; - legendSettingsChangesSubscription: Subscription; - + private legendSettingsFormChanges$: Subscription; + private legendSettingsFormDirectionChanges$: Subscription; private propagateChange = (_: any) => {}; - constructor(public fb: FormBuilder, - public viewContainerRef: ViewContainerRef) { + constructor(private fb: FormBuilder) { } ngOnInit(): void { @@ -76,9 +68,13 @@ export class LegendConfigComponent implements OnInit, OnDestroy, ControlValueAcc showAvg: [null, []], showTotal: [null, []] }); - this.legendConfigForm.get('direction').valueChanges.subscribe((direction: LegendDirection) => { - this.onDirectionChanged(direction); - }); + this.legendSettingsFormDirectionChanges$ = this.legendConfigForm.get('direction').valueChanges + .subscribe((direction: LegendDirection) => { + this.onDirectionChanged(direction); + }); + this.legendSettingsFormChanges$ = this.legendConfigForm.valueChanges.subscribe( + () => this.legendConfigUpdated() + ); } private onDirectionChanged(direction: LegendDirection) { @@ -93,7 +89,14 @@ export class LegendConfigComponent implements OnInit, OnDestroy, ControlValueAcc } ngOnDestroy(): void { - this.removeChangeSubscriptions(); + if (this.legendSettingsFormDirectionChanges$) { + this.legendSettingsFormDirectionChanges$.unsubscribe(); + this.legendSettingsFormDirectionChanges$ = null; + } + if (this.legendSettingsFormChanges$) { + this.legendSettingsFormChanges$.unsubscribe(); + this.legendSettingsFormChanges$ = null; + } } registerOnChange(fn: any): void { @@ -112,39 +115,22 @@ export class LegendConfigComponent implements OnInit, OnDestroy, ControlValueAcc } } - private removeChangeSubscriptions() { - if (this.legendSettingsChangesSubscription) { - this.legendSettingsChangesSubscription.unsubscribe(); - this.legendSettingsChangesSubscription = null; - } - } - - private createChangeSubscriptions() { - this.legendSettingsChangesSubscription = this.legendConfigForm.valueChanges.subscribe( - () => this.legendConfigUpdated() - ); - } - - writeValue(obj: LegendConfig): void { - this.legendSettings = obj; - this.removeChangeSubscriptions(); - if (this.legendSettings) { + writeValue(legendConfig: LegendConfig): void { + if (legendConfig) { this.legendConfigForm.patchValue({ - direction: this.legendSettings.direction, - position: this.legendSettings.position, - sortDataKeys: isDefined(this.legendSettings.sortDataKeys) ? this.legendSettings.sortDataKeys : false, - showMin: isDefined(this.legendSettings.showMin) ? this.legendSettings.showMin : false, - showMax: isDefined(this.legendSettings.showMax) ? this.legendSettings.showMax : false, - showAvg: isDefined(this.legendSettings.showAvg) ? this.legendSettings.showAvg : false, - showTotal: isDefined(this.legendSettings.showTotal) ? this.legendSettings.showTotal : false - }); + direction: legendConfig.direction, + position: legendConfig.position, + sortDataKeys: isDefined(legendConfig.sortDataKeys) ? legendConfig.sortDataKeys : false, + showMin: isDefined(legendConfig.showMin) ? legendConfig.showMin : false, + showMax: isDefined(legendConfig.showMax) ? legendConfig.showMax : false, + showAvg: isDefined(legendConfig.showAvg) ? legendConfig.showAvg : false, + showTotal: isDefined(legendConfig.showTotal) ? legendConfig.showTotal : false + }, {emitEvent: false}); } - this.onDirectionChanged(this.legendSettings.direction); - this.createChangeSubscriptions(); + this.onDirectionChanged(legendConfig.direction); } private legendConfigUpdated() { - this.legendSettings = this.legendConfigForm.value; - this.propagateChange(this.legendSettings); + this.propagateChange(this.legendConfigForm.value); } } diff --git a/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html b/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html index 0121b07cf6..555e489afa 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/widget-config.component.html @@ -82,241 +82,241 @@ - - - -
widget-config.datasources
-
{{ 'widget-config.maximum-datasources' | translate:{count: modelValue?.typeParameters.maxDatasources} }}
-
-
-
- datasource.add-datasource-prompt -
- -
- -
- widget-config.datasource-type - widget-config.datasource-parameters - -
+ + + + +
widget-config.datasources
+
{{ 'widget-config.maximum-datasources' | translate:{count: modelValue?.typeParameters.maxDatasources} }}
+
+
+
+ datasource.add-datasource-prompt
-
- - - - -
-
- - {{$index + 1}}. -
-
-
- - - - {{ datasourceTypesTranslations.get(datasourceType) | translate }} - - - -
- - - - - - - - - - - - - - - - + +
+ +
+ widget-config.datasource-type + widget-config.datasource-parameters + +
+
+
+ + + + +
+
+ + {{$index + 1}}. +
+
+
+ + + + {{ datasourceTypesTranslations.get(datasourceType) | translate }} + + + +
+ + + + + + + + + + + + + + + + +
+ +
- - -
- + +
-
- - + + +
+
+
+
- -
- -
-
- - - - {{ 'widget-config.target-device' | translate }} - - -
- - -
-
- - - - {{ 'widget-config.alarm-source' | translate }} - - -
-
- - - - {{ datasourceTypesTranslations.get(datasourceType) | translate }} - - - -
- - - - - - + + + + + {{ 'widget-config.target-device' | translate }} + + +
+ + +
+
+ + + + {{ 'widget-config.alarm-source' | translate }} + + +
+
+ + + + {{ datasourceTypesTranslations.get(datasourceType) | translate }} + + + +
+ + + + + + +
+ +
- - -
-
-
- -
- - - widget-config.data-settings - - -
- - widget-config.units - - - - widget-config.decimals - -
-
-
+ + + + widget-config.data-settings + + +
+ + widget-config.units + + + + widget-config.decimals + + +
+
+
+
-
+
widget-config.title - + {{ 'widget-config.display-title' | translate }}
-
+
widget-config.title-icon {{ 'widget-config.display-icon' | translate }} @@ -368,10 +368,10 @@
-
+
widget-config.widget-style
+ fxFlex="100%" fxLayoutGap="8px" class="tb-widget-style">
- + {{ 'widget-config.drop-shadow' | translate }} @@ -421,7 +421,7 @@
-
+
widget-config.legend @@ -439,7 +439,7 @@
-
+
widget-config.mobile-mode-settings diff --git a/ui-ngx/src/app/modules/home/components/widget/widget-config.component.scss b/ui-ngx/src/app/modules/home/components/widget/widget-config.component.scss index 4c4fa317ce..8d8cd742c6 100644 --- a/ui-ngx/src/app/modules/home/components/widget/widget-config.component.scss +++ b/ui-ngx/src/app/modules/home/components/widget/widget-config.component.scss @@ -85,6 +85,9 @@ padding: 0 16px 8px; } } + .tb-widget-style { + margin-top: 16px; + } } } @@ -128,10 +131,10 @@ align-items: center; } .mat-expansion-panel-body{ - padding: 0 0 16px; + padding: 0; } .tb-json-object-panel { - margin: 0; + margin: 0 0 8px; } .mat-checkbox-layout { margin: 5px 0;