UI: Refactoring
This commit is contained in:
parent
1cdbd2c338
commit
2530c77268
@ -18,7 +18,8 @@ import {
|
|||||||
AfterViewInit,
|
AfterViewInit,
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
Component,
|
Component,
|
||||||
ElementRef, NgZone,
|
ElementRef,
|
||||||
|
NgZone,
|
||||||
OnDestroy,
|
OnDestroy,
|
||||||
OnInit,
|
OnInit,
|
||||||
Renderer2,
|
Renderer2,
|
||||||
@ -33,7 +34,8 @@ import { DomSanitizer } from '@angular/platform-browser';
|
|||||||
import { ValueType } from '@shared/models/constants';
|
import { ValueType } from '@shared/models/constants';
|
||||||
import {
|
import {
|
||||||
powerButtonDefaultSettings,
|
powerButtonDefaultSettings,
|
||||||
PowerButtonShape, powerButtonShapeSize,
|
PowerButtonShape,
|
||||||
|
powerButtonShapeSize,
|
||||||
PowerButtonWidgetSettings
|
PowerButtonWidgetSettings
|
||||||
} from '@home/components/widget/lib/rpc/power-button-widget.models';
|
} from '@home/components/widget/lib/rpc/power-button-widget.models';
|
||||||
import { SVG, Svg } from '@svgdotjs/svg.js';
|
import { SVG, Svg } from '@svgdotjs/svg.js';
|
||||||
|
|||||||
@ -30,7 +30,7 @@
|
|||||||
[class.tb-value-stepper-value-box-disabled]="(disabledState$ | async) === true">
|
[class.tb-value-stepper-value-box-disabled]="(disabledState$ | async) === true">
|
||||||
<div #value
|
<div #value
|
||||||
class="tb-value-stepper-value"
|
class="tb-value-stepper-value"
|
||||||
[class.tb-value-stepper-value-disabled]="(disabledState$ | async) === true"
|
[style.color]="(disabledState$ | async) === true ? disabledColor : valueStyleColor"
|
||||||
[style]="valueStyle">{{ valueText }}</div>
|
[style]="valueStyle">{{ valueText }}</div>
|
||||||
</div>
|
</div>
|
||||||
<div [class.!hidden]="!showRightButton"
|
<div [class.!hidden]="!showRightButton"
|
||||||
|
|||||||
@ -51,9 +51,6 @@
|
|||||||
height: 32px;
|
height: 32px;
|
||||||
padding: 0 12px;
|
padding: 0 12px;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
.tb-value-stepper-value-disabled {
|
|
||||||
color: rgba(0, 0, 0, 0.38) !important;
|
|
||||||
}
|
|
||||||
&-disabled {
|
&-disabled {
|
||||||
border-color: rgba(0, 0, 0, 0.38);
|
border-color: rgba(0, 0, 0, 0.38);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,7 +18,9 @@ import {
|
|||||||
AfterViewInit,
|
AfterViewInit,
|
||||||
ChangeDetectorRef,
|
ChangeDetectorRef,
|
||||||
Component,
|
Component,
|
||||||
|
DestroyRef,
|
||||||
ElementRef,
|
ElementRef,
|
||||||
|
inject,
|
||||||
NgZone,
|
NgZone,
|
||||||
OnDestroy,
|
OnDestroy,
|
||||||
OnInit,
|
OnInit,
|
||||||
@ -28,7 +30,7 @@ import {
|
|||||||
} from '@angular/core';
|
} from '@angular/core';
|
||||||
import { BasicActionWidgetComponent, ValueSetter } from '@home/components/widget/lib/action/action-widget.models';
|
import { BasicActionWidgetComponent, ValueSetter } from '@home/components/widget/lib/action/action-widget.models';
|
||||||
import { backgroundStyle, ComponentStyle, overlayStyle, textStyle } from '@shared/models/widget-settings.models';
|
import { backgroundStyle, ComponentStyle, overlayStyle, textStyle } from '@shared/models/widget-settings.models';
|
||||||
import { BehaviorSubject, combineLatest, Observable, Subject } from 'rxjs';
|
import { BehaviorSubject, combineLatest, Observable } from 'rxjs';
|
||||||
import { ImagePipe } from '@shared/pipe/image.pipe';
|
import { ImagePipe } from '@shared/pipe/image.pipe';
|
||||||
import { DomSanitizer } from '@angular/platform-browser';
|
import { DomSanitizer } from '@angular/platform-browser';
|
||||||
import { ValueType } from '@shared/models/constants';
|
import { ValueType } from '@shared/models/constants';
|
||||||
@ -46,7 +48,7 @@ import {
|
|||||||
ValueStepperWidgetSettings
|
ValueStepperWidgetSettings
|
||||||
} from '@home/components/widget/lib/rpc/value-stepper-widget.models';
|
} from '@home/components/widget/lib/rpc/value-stepper-widget.models';
|
||||||
import { UtilsService } from '@core/services/utils.service';
|
import { UtilsService } from '@core/services/utils.service';
|
||||||
import { takeUntil } from 'rxjs/operators';
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-value-stepper-widget',
|
selector: 'tb-value-stepper-widget',
|
||||||
@ -57,19 +59,19 @@ import { takeUntil } from 'rxjs/operators';
|
|||||||
export class ValueStepperWidgetComponent extends
|
export class ValueStepperWidgetComponent extends
|
||||||
BasicActionWidgetComponent implements OnInit, AfterViewInit, OnDestroy {
|
BasicActionWidgetComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||||
|
|
||||||
@ViewChild('leftButton', {static: false})
|
@ViewChild('leftButton', {static: true})
|
||||||
leftButton: ElementRef<HTMLElement>;
|
leftButton: ElementRef<HTMLElement>;
|
||||||
|
|
||||||
@ViewChild('rightButton', {static: false})
|
@ViewChild('rightButton', {static: true})
|
||||||
rightButton: ElementRef<HTMLElement>;
|
rightButton: ElementRef<HTMLElement>;
|
||||||
|
|
||||||
@ViewChild('stepperContent', {static: false})
|
@ViewChild('stepperContent', {static: true})
|
||||||
stepperContent: ElementRef<HTMLElement>;
|
stepperContent: ElementRef<HTMLElement>;
|
||||||
|
|
||||||
@ViewChild('valueBoxContainer', {static: false})
|
@ViewChild('valueBoxContainer', {static: true})
|
||||||
valueBox: ElementRef<HTMLElement>;
|
valueBox: ElementRef<HTMLElement>;
|
||||||
|
|
||||||
@ViewChild('value', {static: false})
|
@ViewChild('value', {static: true})
|
||||||
valueElement: ElementRef<HTMLElement>;
|
valueElement: ElementRef<HTMLElement>;
|
||||||
|
|
||||||
settings: ValueStepperWidgetSettings;
|
settings: ValueStepperWidgetSettings;
|
||||||
@ -79,6 +81,8 @@ export class ValueStepperWidgetComponent extends
|
|||||||
padding: string;
|
padding: string;
|
||||||
|
|
||||||
valueStyle: ComponentStyle = {};
|
valueStyle: ComponentStyle = {};
|
||||||
|
valueStyleColor = '';
|
||||||
|
disabledColor = 'rgba(0, 0, 0, 0.38)';
|
||||||
value: number = null;
|
value: number = null;
|
||||||
|
|
||||||
autoScale = false;
|
autoScale = false;
|
||||||
@ -108,7 +112,8 @@ export class ValueStepperWidgetComponent extends
|
|||||||
|
|
||||||
private leftDisabledState$ = new BehaviorSubject(false);
|
private leftDisabledState$ = new BehaviorSubject(false);
|
||||||
private rightDisabledState$ = new BehaviorSubject(false);
|
private rightDisabledState$ = new BehaviorSubject(false);
|
||||||
private readonly destroy$ = new Subject<void>();
|
|
||||||
|
protected destroyRef = inject(DestroyRef);
|
||||||
|
|
||||||
constructor(protected imagePipe: ImagePipe,
|
constructor(protected imagePipe: ImagePipe,
|
||||||
protected sanitizer: DomSanitizer,
|
protected sanitizer: DomSanitizer,
|
||||||
@ -135,7 +140,7 @@ export class ValueStepperWidgetComponent extends
|
|||||||
this.showLeftButton = this.settings.buttonAppearance.leftButton.showButton;
|
this.showLeftButton = this.settings.buttonAppearance.leftButton.showButton;
|
||||||
this.showRightButton = this.settings.buttonAppearance.rightButton.showButton;
|
this.showRightButton = this.settings.buttonAppearance.rightButton.showButton;
|
||||||
this.valueStyle = textStyle(this.settings.appearance.valueFont);
|
this.valueStyle = textStyle(this.settings.appearance.valueFont);
|
||||||
this.valueStyle.color = this.settings.appearance.valueColor;
|
this.valueStyleColor = this.settings.appearance.valueColor;
|
||||||
|
|
||||||
if (this.showValueBox) {
|
if (this.showValueBox) {
|
||||||
const valueBoxCss = `.tb-value-stepper-value-box {\n`+
|
const valueBoxCss = `.tb-value-stepper-value-box {\n`+
|
||||||
@ -171,7 +176,7 @@ export class ValueStepperWidgetComponent extends
|
|||||||
this.disabledState$.asObservable(),
|
this.disabledState$.asObservable(),
|
||||||
this.leftDisabledState$.asObservable()
|
this.leftDisabledState$.asObservable()
|
||||||
]).pipe(
|
]).pipe(
|
||||||
takeUntil(this.destroy$)
|
takeUntilDestroyed(this.destroyRef)
|
||||||
).subscribe(value => {
|
).subscribe(value => {
|
||||||
const state = value.includes(true);
|
const state = value.includes(true);
|
||||||
this.updateLeftDisabledState(state)
|
this.updateLeftDisabledState(state)
|
||||||
@ -182,7 +187,7 @@ export class ValueStepperWidgetComponent extends
|
|||||||
this.disabledState$.asObservable(),
|
this.disabledState$.asObservable(),
|
||||||
this.rightDisabledState$.asObservable()
|
this.rightDisabledState$.asObservable()
|
||||||
]).pipe(
|
]).pipe(
|
||||||
takeUntil(this.destroy$)
|
takeUntilDestroyed(this.destroyRef)
|
||||||
).subscribe(value => {
|
).subscribe(value => {
|
||||||
const state = value.includes(true);
|
const state = value.includes(true);
|
||||||
this.updateRightDisabledState(state)
|
this.updateRightDisabledState(state)
|
||||||
@ -200,8 +205,6 @@ export class ValueStepperWidgetComponent extends
|
|||||||
if (this.shapeResize$) {
|
if (this.shapeResize$) {
|
||||||
this.shapeResize$.disconnect();
|
this.shapeResize$.disconnect();
|
||||||
}
|
}
|
||||||
this.destroy$.next();
|
|
||||||
this.destroy$.complete();
|
|
||||||
super.ngOnDestroy();
|
super.ngOnDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -220,12 +223,12 @@ export class ValueStepperWidgetComponent extends
|
|||||||
private onValue(value: number): void {
|
private onValue(value: number): void {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.prevValue = value;
|
this.prevValue = value;
|
||||||
if ((this.value + this.settings.appearance.valueStep) >= this.settings.appearance.maxValueRange) {
|
if ((this.value + this.settings.appearance.valueStep) > this.settings.appearance.maxValueRange) {
|
||||||
this.rightDisabledState$.next(true);
|
this.rightDisabledState$.next(true);
|
||||||
} else {
|
} else {
|
||||||
this.rightDisabledState$.next(false);
|
this.rightDisabledState$.next(false);
|
||||||
}
|
}
|
||||||
if ((this.value - this.settings.appearance.valueStep) <= this.settings.appearance.minValueRange) {
|
if ((this.value - this.settings.appearance.valueStep) < this.settings.appearance.minValueRange) {
|
||||||
this.leftDisabledState$.next(true);
|
this.leftDisabledState$.next(true);
|
||||||
} else {
|
} else {
|
||||||
this.leftDisabledState$.next(false);
|
this.leftDisabledState$.next(false);
|
||||||
|
|||||||
@ -1,19 +1,32 @@
|
|||||||
|
///
|
||||||
|
/// Copyright © 2016-2024 The Thingsboard Authors
|
||||||
|
///
|
||||||
|
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
/// you may not use this file except in compliance with the License.
|
||||||
|
/// You may obtain a copy of the License at
|
||||||
|
///
|
||||||
|
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
///
|
||||||
|
/// Unless required by applicable law or agreed to in writing, software
|
||||||
|
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
/// See the License for the specific language governing permissions and
|
||||||
|
/// limitations under the License.
|
||||||
|
///
|
||||||
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DataToValueType,
|
DataToValueType,
|
||||||
GetValueAction,
|
GetValueAction,
|
||||||
GetValueSettings, SetValueAction,
|
GetValueSettings,
|
||||||
SetValueSettings, ValueToDataType
|
SetValueAction,
|
||||||
|
SetValueSettings,
|
||||||
|
ValueToDataType
|
||||||
} from '@shared/models/action-widget-settings.models';
|
} from '@shared/models/action-widget-settings.models';
|
||||||
import { defaultWidgetAction, WidgetAction } from '@shared/models/widget.models';
|
import { WidgetButtonCustomStyles } from '@shared/components/button/widget-button.models';
|
||||||
import {
|
|
||||||
ButtonToggleAppearance, segmentedButtonDefaultAppearance,
|
|
||||||
SegmentedButtonWidgetSettings
|
|
||||||
} from '@home/components/widget/lib/button/segmented-button-widget.models';
|
|
||||||
import { WidgetButtonCustomStyles, WidgetButtonType } from '@shared/components/button/widget-button.models';
|
|
||||||
import { BackgroundSettings, BackgroundType, cssUnit, Font } from '@shared/models/widget-settings.models';
|
import { BackgroundSettings, BackgroundType, cssUnit, Font } from '@shared/models/widget-settings.models';
|
||||||
import { AttributeScope } from '@shared/models/telemetry/telemetry.models';
|
import { AttributeScope } from '@shared/models/telemetry/telemetry.models';
|
||||||
|
|
||||||
|
|
||||||
const defaultMainColor = '#305680';
|
const defaultMainColor = '#305680';
|
||||||
|
|
||||||
export enum ValueStepperType {
|
export enum ValueStepperType {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user