Merge pull request #10990 from ArtemDzhereleiko/AD/bug-fix/widget-settings/min-max-gradient
Fixed min/max editable for gradient settings
This commit is contained in:
commit
f9c554e96f
@ -102,6 +102,8 @@
|
|||||||
<tb-color-settings formControlName="valueColor"
|
<tb-color-settings formControlName="valueColor"
|
||||||
rangeAdvancedMode
|
rangeAdvancedMode
|
||||||
gradientAdvancedMode
|
gradientAdvancedMode
|
||||||
|
minValue="0"
|
||||||
|
maxValue="100"
|
||||||
[aliasController]="aliasController"
|
[aliasController]="aliasController"
|
||||||
[dataKeyCallbacks]="callbacks"
|
[dataKeyCallbacks]="callbacks"
|
||||||
[datasource]="datasource"
|
[datasource]="datasource"
|
||||||
@ -114,6 +116,8 @@
|
|||||||
<tb-color-settings formControlName="batteryLevelColor"
|
<tb-color-settings formControlName="batteryLevelColor"
|
||||||
rangeAdvancedMode
|
rangeAdvancedMode
|
||||||
gradientAdvancedMode
|
gradientAdvancedMode
|
||||||
|
minValue="0"
|
||||||
|
maxValue="100"
|
||||||
[aliasController]="aliasController"
|
[aliasController]="aliasController"
|
||||||
[dataKeyCallbacks]="callbacks"
|
[dataKeyCallbacks]="callbacks"
|
||||||
[datasource]="datasource"
|
[datasource]="datasource"
|
||||||
@ -125,6 +129,8 @@
|
|||||||
<tb-color-settings formControlName="batteryShapeColor"
|
<tb-color-settings formControlName="batteryShapeColor"
|
||||||
rangeAdvancedMode
|
rangeAdvancedMode
|
||||||
gradientAdvancedMode
|
gradientAdvancedMode
|
||||||
|
minValue="0"
|
||||||
|
maxValue="100"
|
||||||
[aliasController]="aliasController"
|
[aliasController]="aliasController"
|
||||||
[dataKeyCallbacks]="callbacks"
|
[dataKeyCallbacks]="callbacks"
|
||||||
[datasource]="datasource"
|
[datasource]="datasource"
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import { deepClone } from '@core/utils';
|
|||||||
import { WidgetService } from '@core/http/widget.service';
|
import { WidgetService } from '@core/http/widget.service';
|
||||||
import { ColorSettingsComponent } from '@home/components/widget/lib/settings/common/color-settings.component';
|
import { ColorSettingsComponent } from '@home/components/widget/lib/settings/common/color-settings.component';
|
||||||
import { IAliasController } from '@core/api/widget-api.models';
|
import { IAliasController } from '@core/api/widget-api.models';
|
||||||
import { coerceBoolean, coerceNumber } from '@shared/decorators/coercion';
|
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||||
import { DataKeysCallbacks } from '@home/components/widget/config/data-keys.component.models';
|
import { DataKeysCallbacks } from '@home/components/widget/config/data-keys.component.models';
|
||||||
import { Datasource } from '@shared/models/widget.models';
|
import { Datasource } from '@shared/models/widget.models';
|
||||||
|
|
||||||
@ -74,11 +74,9 @@ export class ColorSettingsPanelComponent extends PageComponent implements OnInit
|
|||||||
gradientAdvancedMode = false;
|
gradientAdvancedMode = false;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
@coerceNumber()
|
|
||||||
minValue: number;
|
minValue: number;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
@coerceNumber()
|
|
||||||
maxValue: number;
|
maxValue: number;
|
||||||
|
|
||||||
colorType = ColorType;
|
colorType = ColorType;
|
||||||
|
|||||||
@ -33,7 +33,7 @@ import {
|
|||||||
} from '@home/components/widget/lib/settings/common/color-settings-panel.component';
|
} from '@home/components/widget/lib/settings/common/color-settings-panel.component';
|
||||||
import { IAliasController } from '@core/api/widget-api.models';
|
import { IAliasController } from '@core/api/widget-api.models';
|
||||||
import { deepClone, isDefinedAndNotNull } from '@core/utils';
|
import { deepClone, isDefinedAndNotNull } from '@core/utils';
|
||||||
import { coerceBoolean, coerceNumber } from '@shared/decorators/coercion';
|
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||||
import { DataKeysCallbacks } from '@home/components/widget/config/data-keys.component.models';
|
import { DataKeysCallbacks } from '@home/components/widget/config/data-keys.component.models';
|
||||||
import { Datasource } from '@shared/models/widget.models';
|
import { Datasource } from '@shared/models/widget.models';
|
||||||
|
|
||||||
@ -102,12 +102,10 @@ export class ColorSettingsComponent implements OnInit, ControlValueAccessor, OnD
|
|||||||
gradientAdvancedMode = false;
|
gradientAdvancedMode = false;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
@coerceNumber()
|
minValue: number;
|
||||||
minValue = 0;
|
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
@coerceNumber()
|
maxValue: number;
|
||||||
maxValue = 100;
|
|
||||||
|
|
||||||
colorType = ColorType;
|
colorType = ColorType;
|
||||||
|
|
||||||
|
|||||||
@ -36,19 +36,21 @@
|
|||||||
|
|
||||||
<div class="gradient-settings" [ngSwitch]="gradientFormGroup.get('advancedMode').value">
|
<div class="gradient-settings" [ngSwitch]="gradientFormGroup.get('advancedMode').value">
|
||||||
<ng-template [ngSwitchCase]="false">
|
<ng-template [ngSwitchCase]="false">
|
||||||
<div class="gradient" formGroupName="gradient">
|
<div class="gradient">
|
||||||
<div class="gradient-container gradient-container-start">
|
<div class="gradient-container gradient-container-start">
|
||||||
<div translate>widgets.color.gradient-start</div>
|
<div translate>widgets.color.gradient-start</div>
|
||||||
<div class="start-gradient-container">
|
<div class="start-gradient-container">
|
||||||
<div class="tb-form-row no-border no-padding" fxHide.xs [fxHide]="!minValue?.toString()?.length">
|
<div class="tb-form-row no-border no-padding">
|
||||||
<div class="gradient-text" translate>widgets.color.start-value</div>
|
<div class="gradient-text" fxHide.xs translate>widgets.color.start-value</div>
|
||||||
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
|
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
|
||||||
<input matInput type="number" min="0" disabled [(ngModel)]="minValue" [ngModelOptions]="{standalone: true}" placeholder="{{ 'widget-config.set' | translate }}">
|
<input matInput type="number" formControlName="minValue" placeholder="{{ 'widget-config.set' | translate }}">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
|
<ng-container formGroupName="gradient">
|
||||||
<tb-color-input asBoxInput
|
<tb-color-input asBoxInput
|
||||||
formControlName="start">
|
formControlName="start">
|
||||||
</tb-color-input>
|
</tb-color-input>
|
||||||
|
</ng-container>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -94,19 +96,21 @@
|
|||||||
<mat-icon>add</mat-icon>
|
<mat-icon>add</mat-icon>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<div class="gradient" formGroupName="gradient">
|
<div class="gradient">
|
||||||
<div class="gradient-container gradient-container-end">
|
<div class="gradient-container gradient-container-end">
|
||||||
<div translate>widgets.color.gradient-end</div>
|
<div translate>widgets.color.gradient-end</div>
|
||||||
<div class="end-gradient-container">
|
<div class="end-gradient-container">
|
||||||
<div class="tb-form-row no-border no-padding" fxHide.xs [fxHide]="!maxValue?.toString()?.length">
|
<div class="tb-form-row no-border no-padding">
|
||||||
<div class="gradient-text" translate>widgets.color.end-value</div>
|
<div class="gradient-text" fxHide.xs translate>widgets.color.end-value</div>
|
||||||
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
|
<mat-form-field appearance="outline" class="number" subscriptSizing="dynamic">
|
||||||
<input matInput type="number" min="0" disabled [(ngModel)]="maxValue" [ngModelOptions]="{standalone: true}" placeholder="{{ 'widget-config.set' | translate }}">
|
<input matInput type="number" formControlName="maxValue" placeholder="{{ 'widget-config.set' | translate }}">
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</div>
|
</div>
|
||||||
|
<ng-container formGroupName="gradient">
|
||||||
<tb-color-input asBoxInput
|
<tb-color-input asBoxInput
|
||||||
formControlName="end">
|
formControlName="end">
|
||||||
</tb-color-input>
|
</tb-color-input>
|
||||||
|
</ng-container>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import { takeUntil } from 'rxjs/operators';
|
|||||||
import { CdkDragDrop } from '@angular/cdk/drag-drop';
|
import { CdkDragDrop } from '@angular/cdk/drag-drop';
|
||||||
import { IAliasController } from '@core/api/widget-api.models';
|
import { IAliasController } from '@core/api/widget-api.models';
|
||||||
import { DomSanitizer } from '@angular/platform-browser';
|
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 { isDefinedAndNotNull } from '@core/utils';
|
||||||
import { DataKeysCallbacks } from '@home/components/widget/config/data-keys.component.models';
|
import { DataKeysCallbacks } from '@home/components/widget/config/data-keys.component.models';
|
||||||
import { Datasource } from '@shared/models/widget.models';
|
import { Datasource } from '@shared/models/widget.models';
|
||||||
@ -71,11 +71,9 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro
|
|||||||
datasource: Datasource;
|
datasource: Datasource;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
@coerceNumber()
|
|
||||||
minValue: number;
|
minValue: number;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
@coerceNumber()
|
|
||||||
maxValue: number;
|
maxValue: number;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
@ -111,7 +109,9 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro
|
|||||||
source: [{type: ValueSourceType.constant}],
|
source: [{type: ValueSourceType.constant}],
|
||||||
color: ['rgba(255, 0, 0, 1)']
|
color: ['rgba(255, 0, 0, 1)']
|
||||||
})
|
})
|
||||||
})
|
}),
|
||||||
|
minValue: {value: 0, disabled: isFinite(this.minValue)},
|
||||||
|
maxValue: {value: 100, disabled: isFinite(this.maxValue)}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.gradientFormGroup.valueChanges.pipe(
|
this.gradientFormGroup.valueChanges.pipe(
|
||||||
@ -141,6 +141,8 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro
|
|||||||
writeValue(value: ColorGradientSettings): void {
|
writeValue(value: ColorGradientSettings): void {
|
||||||
if (isDefinedAndNotNull(value)) {
|
if (isDefinedAndNotNull(value)) {
|
||||||
this.gradientFormGroup.get('advancedMode').patchValue(value.advancedMode, {emitEvent: false});
|
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) {
|
if (value?.gradient?.length) {
|
||||||
this.gradientFormGroup.get('gradient').get('start').patchValue(value.gradient[0], {emitEvent: false});
|
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});
|
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('') +
|
this.advancedGradientListFormArray.value.map((v, i) => this.pointer(shift * (i + 1), i+1, null, true)).join('') +
|
||||||
`<div class="pointer end"></div>`;
|
`<div class="pointer end"></div>`;
|
||||||
} else {
|
} 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 shift = 100 / (this.gradientListFormArray.value.length + 1);
|
||||||
const min = isDefinedAndNotNull(this.minValue) ? this.minValue : 0;
|
|
||||||
const max = isDefinedAndNotNull(this.maxValue) ? this.maxValue : 100;
|
|
||||||
return `<div class="pointer start"><div class="pointer-value"><span class="pointer-value-text">${min}</span></div></div>` +
|
return `<div class="pointer start"><div class="pointer-value"><span class="pointer-value-text">${min}</span></div></div>` +
|
||||||
this.gradientListFormArray.value.map((v, i) => this.pointer(shift * (i + 1), i+1, point)).join('') +
|
this.gradientListFormArray.value.map((v, i) => this.pointer(shift * (i + 1), i+1, point)).join('') +
|
||||||
`<div class="pointer end"><div class="pointer-value"><span class="pointer-value-text">${max}</span></div></div>`;
|
`<div class="pointer end"><div class="pointer-value"><span class="pointer-value-text">${max}</span></div></div>`;
|
||||||
@ -180,7 +182,8 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro
|
|||||||
return `<div class="pointer" style="left: ${shift}%"></div>`;
|
return `<div class="pointer" style="left: ${shift}%"></div>`;
|
||||||
} else {
|
} else {
|
||||||
return `<div class="pointer" style="left: ${shift}%">` +
|
return `<div class="pointer" style="left: ${shift}%">` +
|
||||||
`<div class="pointer-value"><span class="pointer-value-text">${Math.floor(+this.minValue + (value * index))}</span></div></div>`;
|
`<div class="pointer-value"><span class="pointer-value-text">` +
|
||||||
|
`${Math.floor(+this.gradientFormGroup.get('minValue').value + (value * index))}</span></div></div>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -256,15 +259,14 @@ export class GradientComponent implements OnInit, ControlValueAccessor, OnDestro
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateModel() {
|
updateModel() {
|
||||||
|
const gradient = this.gradientFormGroup.getRawValue();
|
||||||
this.propagateChange(
|
this.propagateChange(
|
||||||
{
|
{
|
||||||
advancedMode: this.gradientFormGroup.value.advancedMode,
|
advancedMode: gradient.advancedMode,
|
||||||
gradient: [this.gradientFormGroup.value.gradient.start,
|
gradient: [gradient.gradient.start, ...gradient.gradient.gradientList.map(item => item.color), gradient.gradient.end],
|
||||||
...this.gradientFormGroup.value.gradient.gradientList.map(item => item.color),
|
gradientAdvanced: [gradient.gradientAdvanced.start, ...gradient.gradientAdvanced.gradientList, gradient.gradientAdvanced.end],
|
||||||
this.gradientFormGroup.value.gradient.end],
|
minValue: gradient.minValue,
|
||||||
gradientAdvanced: [this.gradientFormGroup.value.gradientAdvanced.start,
|
maxValue: gradient.maxValue
|
||||||
...this.gradientFormGroup.value.gradientAdvanced.gradientList,
|
|
||||||
this.gradientFormGroup.value.gradientAdvanced.end]
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -51,6 +51,8 @@
|
|||||||
<tb-color-settings formControlName="valueColor"
|
<tb-color-settings formControlName="valueColor"
|
||||||
rangeAdvancedMode
|
rangeAdvancedMode
|
||||||
gradientAdvancedMode
|
gradientAdvancedMode
|
||||||
|
minValue="0"
|
||||||
|
maxValue="100"
|
||||||
[aliasController]="aliasController"
|
[aliasController]="aliasController"
|
||||||
[dataKeyCallbacks]="dataKeyCallbacks"
|
[dataKeyCallbacks]="dataKeyCallbacks"
|
||||||
[datasource]="datasource"
|
[datasource]="datasource"
|
||||||
@ -63,6 +65,8 @@
|
|||||||
<tb-color-settings formControlName="batteryLevelColor"
|
<tb-color-settings formControlName="batteryLevelColor"
|
||||||
rangeAdvancedMode
|
rangeAdvancedMode
|
||||||
gradientAdvancedMode
|
gradientAdvancedMode
|
||||||
|
minValue="0"
|
||||||
|
maxValue="100"
|
||||||
[aliasController]="aliasController"
|
[aliasController]="aliasController"
|
||||||
[dataKeyCallbacks]="dataKeyCallbacks"
|
[dataKeyCallbacks]="dataKeyCallbacks"
|
||||||
[datasource]="datasource"
|
[datasource]="datasource"
|
||||||
@ -74,6 +78,8 @@
|
|||||||
<tb-color-settings formControlName="batteryShapeColor"
|
<tb-color-settings formControlName="batteryShapeColor"
|
||||||
rangeAdvancedMode
|
rangeAdvancedMode
|
||||||
gradientAdvancedMode
|
gradientAdvancedMode
|
||||||
|
minValue="0"
|
||||||
|
maxValue="100"
|
||||||
[aliasController]="aliasController"
|
[aliasController]="aliasController"
|
||||||
[dataKeyCallbacks]="dataKeyCallbacks"
|
[dataKeyCallbacks]="dataKeyCallbacks"
|
||||||
[datasource]="datasource"
|
[datasource]="datasource"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user