diff --git a/ui-ngx/src/app/modules/home/components/widget/config/basic/indicator/battery-level-basic-config.component.html b/ui-ngx/src/app/modules/home/components/widget/config/basic/indicator/battery-level-basic-config.component.html index 576b608c2f..f5a5693a63 100644 --- a/ui-ngx/src/app/modules/home/components/widget/config/basic/indicator/battery-level-basic-config.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/config/basic/indicator/battery-level-basic-config.component.html @@ -102,6 +102,8 @@ -
+
widgets.color.gradient-start
-
-
widgets.color.start-value
+
+
widgets.color.start-value
- +
- - + + + +
@@ -94,19 +96,21 @@ add -
+
widgets.color.gradient-end
-
-
widgets.color.end-value
+
+
widgets.color.end-value
- +
- - + + + +
diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/gradient.component.ts b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/gradient.component.ts index 8b78190f5a..a35c5a089a 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/gradient.component.ts +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/common/gradient.component.ts @@ -31,7 +31,7 @@ import { takeUntil } from 'rxjs/operators'; import { CdkDragDrop } from '@angular/cdk/drag-drop'; import { IAliasController } from '@core/api/widget-api.models'; import { DomSanitizer } from '@angular/platform-browser'; -import { coerceBoolean, coerceNumber } from '@shared/decorators/coercion'; +import { coerceBoolean } from '@shared/decorators/coercion'; import { isDefinedAndNotNull } from '@core/utils'; import { DataKeysCallbacks } from '@home/components/widget/config/data-keys.component.models'; import { Datasource } from '@shared/models/widget.models'; @@ -71,11 +71,9 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro datasource: Datasource; @Input() - @coerceNumber() minValue: number; @Input() - @coerceNumber() maxValue: number; @Input() @@ -111,7 +109,9 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro source: [{type: ValueSourceType.constant}], color: ['rgba(255, 0, 0, 1)'] }) - }) + }), + minValue: {value: 0, disabled: isFinite(this.minValue)}, + maxValue: {value: 100, disabled: isFinite(this.maxValue)} }); this.gradientFormGroup.valueChanges.pipe( @@ -141,6 +141,8 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro writeValue(value: ColorGradientSettings): void { if (isDefinedAndNotNull(value)) { this.gradientFormGroup.get('advancedMode').patchValue(value.advancedMode, {emitEvent: false}); + this.gradientFormGroup.get('minValue').patchValue(isFinite(value.minValue) ? value.minValue : this.minValue, {emitEvent: false}); + this.gradientFormGroup.get('maxValue').patchValue(isFinite(value.maxValue) ? value.maxValue : this.maxValue, {emitEvent: false}); if (value?.gradient?.length) { this.gradientFormGroup.get('gradient').get('start').patchValue(value.gradient[0], {emitEvent: false}); this.gradientFormGroup.get('gradient').get('end').patchValue(value.gradient[value.gradient.length - 1], {emitEvent: false}); @@ -165,10 +167,10 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro this.advancedGradientListFormArray.value.map((v, i) => this.pointer(shift * (i + 1), i+1, null, true)).join('') + `
`; } else { - const point = (+this.maxValue - +this.minValue) / (this.gradientListFormArray.value.length + 1); + const min = this.gradientFormGroup.get('minValue').value; + const max = this.gradientFormGroup.get('maxValue').value; + const point = (+max - +min) / (this.gradientListFormArray.value.length + 1); const shift = 100 / (this.gradientListFormArray.value.length + 1); - const min = isDefinedAndNotNull(this.minValue) ? this.minValue : 0; - const max = isDefinedAndNotNull(this.maxValue) ? this.maxValue : 100; return `
${min}
` + this.gradientListFormArray.value.map((v, i) => this.pointer(shift * (i + 1), i+1, point)).join('') + `
${max}
`; @@ -180,7 +182,8 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro return `
`; } else { return `
` + - `
${Math.floor(+this.minValue + (value * index))}
`; + `
` + + `${Math.floor(+this.gradientFormGroup.get('minValue').value + (value * index))}
`; } } @@ -256,15 +259,14 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro } updateModel() { + const gradient = this.gradientFormGroup.getRawValue(); this.propagateChange( { - advancedMode: this.gradientFormGroup.value.advancedMode, - gradient: [this.gradientFormGroup.value.gradient.start, - ...this.gradientFormGroup.value.gradient.gradientList.map(item => item.color), - this.gradientFormGroup.value.gradient.end], - gradientAdvanced: [this.gradientFormGroup.value.gradientAdvanced.start, - ...this.gradientFormGroup.value.gradientAdvanced.gradientList, - this.gradientFormGroup.value.gradientAdvanced.end] + advancedMode: gradient.advancedMode, + gradient: [gradient.gradient.start, ...gradient.gradient.gradientList.map(item => item.color), gradient.gradient.end], + gradientAdvanced: [gradient.gradientAdvanced.start, ...gradient.gradientAdvanced.gradientList, gradient.gradientAdvanced.end], + minValue: gradient.minValue, + maxValue: gradient.maxValue } ); } diff --git a/ui-ngx/src/app/modules/home/components/widget/lib/settings/indicator/battery-level-widget-settings.component.html b/ui-ngx/src/app/modules/home/components/widget/lib/settings/indicator/battery-level-widget-settings.component.html index c34b51a36b..572c50c392 100644 --- a/ui-ngx/src/app/modules/home/components/widget/lib/settings/indicator/battery-level-widget-settings.component.html +++ b/ui-ngx/src/app/modules/home/components/widget/lib/settings/indicator/battery-level-widget-settings.component.html @@ -51,6 +51,8 @@