35 changed files with 1536 additions and 1358 deletions
@ -0,0 +1,172 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2022 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. |
||||
|
|
||||
|
--> |
||||
|
<section class="tb-widget-settings" [formGroup]="analogueCompassWidgetSettingsForm" fxLayout="column"> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.ticks-settings</legend> |
||||
|
<mat-form-field fxFlex class="mat-block" floatLabel="always"> |
||||
|
<mat-label translate>widgets.gauge.major-ticks-names</mat-label> |
||||
|
<mat-chip-list class="tb-drop-list" |
||||
|
#majorTicksNamesChipList |
||||
|
cdkDropList |
||||
|
cdkDropListOrientation="horizontal" |
||||
|
(cdkDropListDropped)="majorTickNameDrop($event)" |
||||
|
formControlName="majorTicks"> |
||||
|
<mat-chip class="tb-draggable" cdkDrag *ngFor="let tickName of majorTicksNamesList()" |
||||
|
[removable]="true" (removed)="removeMajorTickName(tickName)"> |
||||
|
{{tickName}} |
||||
|
<mat-icon matChipRemove>cancel</mat-icon> |
||||
|
</mat-chip> |
||||
|
<input [matChipInputFor]="majorTicksNamesChipList" |
||||
|
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" |
||||
|
matChipInputAddOnBlur |
||||
|
(matChipInputTokenEnd)="addMajorTickName($event)"> |
||||
|
</mat-chip-list> |
||||
|
</mat-form-field> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorMajorTicks" |
||||
|
label="{{ 'widgets.gauge.major-ticks-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.minor-ticks-count</mat-label> |
||||
|
<input matInput type="number" min="0" formControlName="minorTicks"> |
||||
|
</mat-form-field> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorMinorTicks" |
||||
|
label="{{ 'widgets.gauge.minor-ticks-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
<mat-slide-toggle formControlName="showStrokeTicks" class="slide-block"> |
||||
|
{{ 'widgets.gauge.show-stroke-ticks' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.major-ticks-font</legend> |
||||
|
<tb-widget-font formControlName="majorTickFont"></tb-widget-font> |
||||
|
</fieldset> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.plate-settings</legend> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorPlate" |
||||
|
label="{{ 'widgets.gauge.plate-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<mat-slide-toggle formControlName="showBorder" class="slide-block"> |
||||
|
{{ 'widgets.gauge.show-plate-border' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorBorder" |
||||
|
label="{{ 'widgets.gauge.border-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.border-width</mat-label> |
||||
|
<input matInput type="number" min="0" formControlName="borderOuterWidth"> |
||||
|
</mat-form-field> |
||||
|
</section> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.needle-settings</legend> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.needle-circle-size</mat-label> |
||||
|
<input matInput type="number" min="0" formControlName="needleCircleSize"> |
||||
|
</mat-form-field> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorNeedle" |
||||
|
label="{{ 'widgets.gauge.needle-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorNeedleCircle" |
||||
|
label="{{ 'widgets.gauge.needle-circle-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group fields-group-slider"> |
||||
|
<legend class="group-title" translate>widgets.gauge.animation-settings</legend> |
||||
|
<mat-expansion-panel class="tb-settings" [expanded]="analogueCompassWidgetSettingsForm.get('animation').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap"> |
||||
|
<mat-panel-title> |
||||
|
<mat-slide-toggle formControlName="animation" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'widgets.gauge.enable-animation' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</mat-panel-title> |
||||
|
<mat-panel-description fxLayoutAlign="end center" fxHide.xs translate> |
||||
|
widget-config.advanced-settings |
||||
|
</mat-panel-description> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<section fxLayout="column"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.animation-duration</mat-label> |
||||
|
<input matInput type="number" min="0" formControlName="animationDuration"> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.animation-rule</mat-label> |
||||
|
<mat-select formControlName="animationRule"> |
||||
|
<mat-option [value]="'linear'"> |
||||
|
{{ 'widgets.gauge.animation-linear' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'quad'"> |
||||
|
{{ 'widgets.gauge.animation-quad' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'quint'"> |
||||
|
{{ 'widgets.gauge.animation-quint' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'cycle'"> |
||||
|
{{ 'widgets.gauge.animation-cycle' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'bounce'"> |
||||
|
{{ 'widgets.gauge.animation-bounce' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'elastic'"> |
||||
|
{{ 'widgets.gauge.animation-elastic' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'dequad'"> |
||||
|
{{ 'widgets.gauge.animation-dequad' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'dequint'"> |
||||
|
{{ 'widgets.gauge.animation-dequint' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'decycle'"> |
||||
|
{{ 'widgets.gauge.animation-decycle' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'debounce'"> |
||||
|
{{ 'widgets.gauge.animation-debounce' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'delastic'"> |
||||
|
{{ 'widgets.gauge.animation-delastic' | translate }} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.animation-target</mat-label> |
||||
|
<mat-select formControlName="animationTarget"> |
||||
|
<mat-option [value]="'needle'"> |
||||
|
{{ 'widgets.gauge.animation-target-needle' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'plate'"> |
||||
|
{{ 'widgets.gauge.animation-target-plate' | translate }} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
</mat-form-field> |
||||
|
</section> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</fieldset> |
||||
|
</section> |
||||
@ -0,0 +1,171 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 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 { WidgetSettings, WidgetSettingsComponent } from '@shared/models/widget.models'; |
||||
|
import { FormBuilder, FormGroup, Validators } from '@angular/forms'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { Component } from '@angular/core'; |
||||
|
import { MatChipInputEvent } from '@angular/material/chips'; |
||||
|
import { COMMA, ENTER, SEMICOLON } from '@angular/cdk/keycodes'; |
||||
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-analogue-compass-widget-settings', |
||||
|
templateUrl: './analogue-compass-widget-settings.component.html', |
||||
|
styleUrls: ['./../widget-settings.scss'] |
||||
|
}) |
||||
|
export class AnalogueCompassWidgetSettingsComponent extends WidgetSettingsComponent { |
||||
|
|
||||
|
readonly separatorKeysCodes: number[] = [ENTER, COMMA, SEMICOLON]; |
||||
|
|
||||
|
analogueCompassWidgetSettingsForm: FormGroup; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected fb: FormBuilder) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
protected settingsForm(): FormGroup { |
||||
|
return this.analogueCompassWidgetSettingsForm; |
||||
|
} |
||||
|
|
||||
|
protected defaultSettings(): WidgetSettings { |
||||
|
return { |
||||
|
majorTicks: [], |
||||
|
minorTicks: 22, |
||||
|
showStrokeTicks: false, |
||||
|
needleCircleSize: 10, |
||||
|
showBorder: true, |
||||
|
borderOuterWidth: 10, |
||||
|
colorPlate: '#222', |
||||
|
colorMajorTicks: '#f5f5f5', |
||||
|
colorMinorTicks: '#ddd', |
||||
|
colorNeedle: '#f08080', |
||||
|
colorNeedleCircle: '#e8e8e8', |
||||
|
colorBorder: '#ccc', |
||||
|
majorTickFont: { |
||||
|
family: 'Roboto', |
||||
|
size: 20, |
||||
|
style: 'normal', |
||||
|
weight: '500', |
||||
|
color: '#ccc' |
||||
|
}, |
||||
|
animation: true, |
||||
|
animationDuration: 500, |
||||
|
animationRule: 'cycle', |
||||
|
animationTarget: 'needle' |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
protected onSettingsSet(settings: WidgetSettings) { |
||||
|
this.analogueCompassWidgetSettingsForm = this.fb.group({ |
||||
|
|
||||
|
// Ticks settings
|
||||
|
majorTicks: [settings.majorTicks, []], |
||||
|
colorMajorTicks: [settings.colorMajorTicks, []], |
||||
|
minorTicks: [settings.minorTicks, [Validators.min(0)]], |
||||
|
colorMinorTicks: [settings.colorMinorTicks, []], |
||||
|
showStrokeTicks: [settings.showStrokeTicks, []], |
||||
|
majorTickFont: [settings.majorTickFont, []], |
||||
|
|
||||
|
// Plate settings
|
||||
|
colorPlate: [settings.colorPlate, []], |
||||
|
showBorder: [settings.showBorder, []], |
||||
|
colorBorder: [settings.colorBorder, []], |
||||
|
borderOuterWidth: [settings.borderOuterWidth, [Validators.min(0)]], |
||||
|
|
||||
|
// Needle settings
|
||||
|
needleCircleSize: [settings.needleCircleSize, [Validators.min(0)]], |
||||
|
colorNeedle: [settings.colorNeedle, []], |
||||
|
colorNeedleCircle: [settings.colorNeedleCircle, []], |
||||
|
|
||||
|
// Animation settings
|
||||
|
animation: [settings.animation, []], |
||||
|
animationDuration: [settings.animationDuration, [Validators.min(0)]], |
||||
|
animationRule: [settings.animationRule, []], |
||||
|
animationTarget: [settings.animationTarget, []] |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
protected validatorTriggers(): string[] { |
||||
|
return ['showBorder', 'animation']; |
||||
|
} |
||||
|
|
||||
|
protected updateValidators(emitEvent: boolean) { |
||||
|
const showBorder: boolean = this.analogueCompassWidgetSettingsForm.get('showBorder').value; |
||||
|
const animation: boolean = this.analogueCompassWidgetSettingsForm.get('animation').value; |
||||
|
if (showBorder) { |
||||
|
this.analogueCompassWidgetSettingsForm.get('colorBorder').enable(); |
||||
|
this.analogueCompassWidgetSettingsForm.get('borderOuterWidth').enable(); |
||||
|
} else { |
||||
|
this.analogueCompassWidgetSettingsForm.get('colorBorder').disable(); |
||||
|
this.analogueCompassWidgetSettingsForm.get('borderOuterWidth').disable(); |
||||
|
} |
||||
|
if (animation) { |
||||
|
this.analogueCompassWidgetSettingsForm.get('animationDuration').enable(); |
||||
|
this.analogueCompassWidgetSettingsForm.get('animationRule').enable(); |
||||
|
this.analogueCompassWidgetSettingsForm.get('animationTarget').enable(); |
||||
|
} else { |
||||
|
this.analogueCompassWidgetSettingsForm.get('animationDuration').disable(); |
||||
|
this.analogueCompassWidgetSettingsForm.get('animationRule').disable(); |
||||
|
this.analogueCompassWidgetSettingsForm.get('animationTarget').disable(); |
||||
|
} |
||||
|
this.analogueCompassWidgetSettingsForm.get('colorBorder').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueCompassWidgetSettingsForm.get('borderOuterWidth').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueCompassWidgetSettingsForm.get('animationDuration').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueCompassWidgetSettingsForm.get('animationRule').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueCompassWidgetSettingsForm.get('animationTarget').updateValueAndValidity({emitEvent}); |
||||
|
} |
||||
|
|
||||
|
majorTicksNamesList(): string[] { |
||||
|
return this.analogueCompassWidgetSettingsForm.get('majorTicks').value; |
||||
|
} |
||||
|
|
||||
|
removeMajorTickName(tickName: string): void { |
||||
|
const tickNames: string[] = this.analogueCompassWidgetSettingsForm.get('majorTicks').value; |
||||
|
const index = tickNames.indexOf(tickName); |
||||
|
if (index >= 0) { |
||||
|
tickNames.splice(index, 1); |
||||
|
this.analogueCompassWidgetSettingsForm.get('majorTicks').setValue(tickNames); |
||||
|
this.analogueCompassWidgetSettingsForm.get('majorTicks').markAsDirty(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
addMajorTickName(event: MatChipInputEvent): void { |
||||
|
const input = event.input; |
||||
|
const value = event.value; |
||||
|
|
||||
|
const tickNames: string[] = this.analogueCompassWidgetSettingsForm.get('majorTicks').value; |
||||
|
|
||||
|
if ((value || '').trim()) { |
||||
|
tickNames.push(value.trim()); |
||||
|
this.analogueCompassWidgetSettingsForm.get('majorTicks').setValue(tickNames); |
||||
|
this.analogueCompassWidgetSettingsForm.get('majorTicks').markAsDirty(); |
||||
|
} |
||||
|
|
||||
|
if (input) { |
||||
|
input.value = ''; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
majorTickNameDrop(event: CdkDragDrop<string[]>): void { |
||||
|
const tickNames: string[] = this.analogueCompassWidgetSettingsForm.get('majorTicks').value; |
||||
|
moveItemInArray(tickNames, event.previousIndex, event.currentIndex); |
||||
|
this.analogueCompassWidgetSettingsForm.get('majorTicks').setValue(tickNames); |
||||
|
this.analogueCompassWidgetSettingsForm.get('majorTicks').markAsDirty(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,336 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2022 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. |
||||
|
|
||||
|
--> |
||||
|
<section class="tb-widget-settings" [formGroup]="analogueGaugeWidgetSettingsForm" fxLayout="column"> |
||||
|
<ng-container [ngSwitch]="gaugeType"> |
||||
|
<ng-container *ngSwitchCase="'radial'"> |
||||
|
<ng-container *ngTemplateOutlet="radialGauge; context: ctx "></ng-container> |
||||
|
</ng-container> |
||||
|
<ng-container *ngSwitchCase="'linear'"> |
||||
|
<ng-container *ngTemplateOutlet="linearGauge; context: ctx "></ng-container> |
||||
|
</ng-container> |
||||
|
</ng-container> |
||||
|
<tb-color-input |
||||
|
formControlName="defaultColor" |
||||
|
label="{{ 'widgets.gauge.default-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.ticks-settings</legend> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.min-value</mat-label> |
||||
|
<input matInput type="number" formControlName="minValue"> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.max-value</mat-label> |
||||
|
<input matInput type="number" formControlName="maxValue"> |
||||
|
</mat-form-field> |
||||
|
</section> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.major-ticks-count</mat-label> |
||||
|
<input matInput type="number" min="0" formControlName="majorTicksCount"> |
||||
|
</mat-form-field> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorMajorTicks" |
||||
|
label="{{ 'widgets.gauge.major-ticks-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.minor-ticks-count</mat-label> |
||||
|
<input matInput type="number" min="0" formControlName="minorTicks"> |
||||
|
</mat-form-field> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorMinorTicks" |
||||
|
label="{{ 'widgets.gauge.minor-ticks-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.tick-numbers-font</legend> |
||||
|
<tb-widget-font formControlName="numbersFont"></tb-widget-font> |
||||
|
</fieldset> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group fields-group-slider"> |
||||
|
<legend class="group-title" translate>widgets.gauge.unit-title-settings</legend> |
||||
|
<mat-expansion-panel class="tb-settings" [expanded]="analogueGaugeWidgetSettingsForm.get('showUnitTitle').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap"> |
||||
|
<mat-panel-title> |
||||
|
<mat-slide-toggle formControlName="showUnitTitle" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'widgets.gauge.show-unit-title' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</mat-panel-title> |
||||
|
<mat-panel-description fxLayoutAlign="end center" fxHide.xs translate> |
||||
|
widget-config.advanced-settings |
||||
|
</mat-panel-description> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<section fxLayout="column"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.unit-title</mat-label> |
||||
|
<input matInput formControlName="unitTitle"> |
||||
|
</mat-form-field> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.title-font</legend> |
||||
|
<tb-widget-font formControlName="titleFont"></tb-widget-font> |
||||
|
</fieldset> |
||||
|
</section> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.units-settings</legend> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.units-font</legend> |
||||
|
<tb-widget-font formControlName="unitsFont"></tb-widget-font> |
||||
|
</fieldset> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group fields-group-slider"> |
||||
|
<legend class="group-title" translate>widgets.gauge.value-box-settings</legend> |
||||
|
<mat-expansion-panel class="tb-settings" [expanded]="analogueGaugeWidgetSettingsForm.get('valueBox').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap"> |
||||
|
<mat-panel-title> |
||||
|
<mat-slide-toggle formControlName="valueBox" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'widgets.gauge.show-value-box' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</mat-panel-title> |
||||
|
<mat-panel-description fxLayoutAlign="end center" fxHide.xs translate> |
||||
|
widget-config.advanced-settings |
||||
|
</mat-panel-description> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<section fxLayout="column"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.value-int</mat-label> |
||||
|
<input matInput type="number" min="0" step="1" formControlName="valueInt"> |
||||
|
</mat-form-field> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.value-font</legend> |
||||
|
<tb-widget-font formControlName="valueFont" [hasShadowColor]="true"></tb-widget-font> |
||||
|
</fieldset> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorValueBoxRect" |
||||
|
label="{{ 'widgets.gauge.value-box-rect-stroke-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorValueBoxRectEnd" |
||||
|
label="{{ 'widgets.gauge.value-box-rect-stroke-color-end' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorValueBoxBackground" |
||||
|
label="{{ 'widgets.gauge.value-box-background-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorValueBoxShadow" |
||||
|
label="{{ 'widgets.gauge.value-box-shadow-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
</section> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.plate-settings</legend> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorPlate" |
||||
|
label="{{ 'widgets.gauge.plate-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<mat-slide-toggle formControlName="showBorder"> |
||||
|
{{ 'widgets.gauge.show-plate-border' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.needle-settings</legend> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorNeedle" |
||||
|
label="{{ 'widgets.gauge.needle-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorNeedleEnd" |
||||
|
label="{{ 'widgets.gauge.needle-color-end' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorNeedleShadowUp" |
||||
|
label="{{ 'widgets.gauge.needle-color-shadow-up' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorNeedleShadowDown" |
||||
|
label="{{ 'widgets.gauge.needle-color-shadow-down' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.highlights-settings</legend> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.highlights-width</mat-label> |
||||
|
<input matInput type="number" min="0" formControlName="highlightsWidth"> |
||||
|
</mat-form-field> |
||||
|
<fieldset class="fields-group"> |
||||
|
<legend class="group-title" translate>widgets.gauge.highlights</legend> |
||||
|
<div fxLayout="column"> |
||||
|
<div class="tb-control-list tb-drop-list" cdkDropList cdkDropListOrientation="vertical" |
||||
|
(cdkDropListDropped)="highlightDrop($event)"> |
||||
|
<div cdkDrag class="tb-draggable" *ngFor="let highlightControl of highlightsFormArray().controls; trackBy: trackByHighlight; |
||||
|
let $index = index; last as isLast;" |
||||
|
fxLayout="column" [ngStyle]="!isLast ? {paddingBottom: '8px'} : {}"> |
||||
|
<tb-gauge-highlight [formControl]="highlightControl" |
||||
|
[expanded]="highlightControl.new" |
||||
|
(removeHighlight)="removeHighlight($index)"> |
||||
|
</tb-gauge-highlight> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div *ngIf="!highlightsFormArray().controls.length"> |
||||
|
<span translate fxLayoutAlign="center center" |
||||
|
class="tb-prompt">widgets.gauge.no-highlights</span> |
||||
|
</div> |
||||
|
<div style="padding-top: 16px;"> |
||||
|
<button mat-raised-button color="primary" |
||||
|
type="button" |
||||
|
(click)="addHighlight()"> |
||||
|
<span translate>widgets.gauge.add-highlight</span> |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
|
</fieldset> |
||||
|
</fieldset> |
||||
|
<fieldset class="fields-group fields-group-slider"> |
||||
|
<legend class="group-title" translate>widgets.gauge.animation-settings</legend> |
||||
|
<mat-expansion-panel class="tb-settings" [expanded]="analogueGaugeWidgetSettingsForm.get('animation').value"> |
||||
|
<mat-expansion-panel-header fxLayout="row wrap"> |
||||
|
<mat-panel-title> |
||||
|
<mat-slide-toggle formControlName="animation" (click)="$event.stopPropagation()" |
||||
|
fxLayoutAlign="center"> |
||||
|
{{ 'widgets.gauge.enable-animation' | translate }} |
||||
|
</mat-slide-toggle> |
||||
|
</mat-panel-title> |
||||
|
<mat-panel-description fxLayoutAlign="end center" fxHide.xs translate> |
||||
|
widget-config.advanced-settings |
||||
|
</mat-panel-description> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<section fxLayout="column"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.animation-duration</mat-label> |
||||
|
<input matInput type="number" min="0" formControlName="animationDuration"> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.animation-rule</mat-label> |
||||
|
<mat-select formControlName="animationRule"> |
||||
|
<mat-option [value]="'linear'"> |
||||
|
{{ 'widgets.gauge.animation-linear' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'quad'"> |
||||
|
{{ 'widgets.gauge.animation-quad' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'quint'"> |
||||
|
{{ 'widgets.gauge.animation-quint' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'cycle'"> |
||||
|
{{ 'widgets.gauge.animation-cycle' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'bounce'"> |
||||
|
{{ 'widgets.gauge.animation-bounce' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'elastic'"> |
||||
|
{{ 'widgets.gauge.animation-elastic' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'dequad'"> |
||||
|
{{ 'widgets.gauge.animation-dequad' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'dequint'"> |
||||
|
{{ 'widgets.gauge.animation-dequint' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'decycle'"> |
||||
|
{{ 'widgets.gauge.animation-decycle' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'debounce'"> |
||||
|
{{ 'widgets.gauge.animation-debounce' | translate }} |
||||
|
</mat-option> |
||||
|
<mat-option [value]="'delastic'"> |
||||
|
{{ 'widgets.gauge.animation-delastic' | translate }} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
</mat-form-field> |
||||
|
</section> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</fieldset> |
||||
|
</section> |
||||
|
|
||||
|
<ng-template #radialGauge let-settingsForm="settingsForm"> |
||||
|
<fieldset class="fields-group" [formGroup]="settingsForm"> |
||||
|
<legend class="group-title" translate>widgets.gauge.radial-gauge-settings</legend> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.start-ticks-angle</mat-label> |
||||
|
<input matInput type="number" min="0" max="360" formControlName="startAngle"> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.ticks-angle</mat-label> |
||||
|
<input matInput type="number" min="0" max="360" formControlName="ticksAngle"> |
||||
|
</mat-form-field> |
||||
|
</section> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.needle-circle-size</mat-label> |
||||
|
<input matInput type="number" min="0" formControlName="needleCircleSize"> |
||||
|
</mat-form-field> |
||||
|
</fieldset> |
||||
|
</ng-template> |
||||
|
|
||||
|
<ng-template #linearGauge let-settingsForm="settingsForm"> |
||||
|
<fieldset class="fields-group" [formGroup]="settingsForm"> |
||||
|
<legend class="group-title" translate>widgets.gauge.linear-gauge-settings</legend> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<mat-form-field fxFlex class="mat-block"> |
||||
|
<mat-label translate>widgets.gauge.bar-stroke-width</mat-label> |
||||
|
<input matInput type="number" min="0" formControlName="barStrokeWidth"> |
||||
|
</mat-form-field> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorBarStroke" |
||||
|
label="{{ 'widgets.gauge.bar-stroke-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorBar" |
||||
|
label="{{ 'widgets.gauge.bar-background-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorBarEnd" |
||||
|
label="{{ 'widgets.gauge.bar-background-color-end' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorBarProgress" |
||||
|
label="{{ 'widgets.gauge.progress-bar-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
<tb-color-input fxFlex |
||||
|
formControlName="colorBarProgressEnd" |
||||
|
label="{{ 'widgets.gauge.progress-bar-color-end' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
</fieldset> |
||||
|
</ng-template> |
||||
@ -0,0 +1,250 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 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 { WidgetSettings, WidgetSettingsComponent } from '@shared/models/widget.models'; |
||||
|
import { AbstractControl, FormArray, FormBuilder, FormGroup, Validators } from '@angular/forms'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { GaugeHighlight } from '@home/components/widget/lib/settings/gauge/gauge-highlight.component'; |
||||
|
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; |
||||
|
|
||||
|
export class AnalogueGaugeWidgetSettingsComponent extends WidgetSettingsComponent { |
||||
|
|
||||
|
analogueGaugeWidgetSettingsForm: FormGroup; |
||||
|
|
||||
|
ctx = { |
||||
|
settingsForm: null |
||||
|
}; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected fb: FormBuilder) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
protected settingsForm(): FormGroup { |
||||
|
return this.analogueGaugeWidgetSettingsForm; |
||||
|
} |
||||
|
|
||||
|
protected defaultSettings(): WidgetSettings { |
||||
|
return { |
||||
|
startAngle: 45, |
||||
|
ticksAngle: 270, |
||||
|
needleCircleSize: 10, |
||||
|
minValue: 0, |
||||
|
maxValue: 100, |
||||
|
showUnitTitle: true, |
||||
|
unitTitle: null, |
||||
|
majorTicksCount: null, |
||||
|
minorTicks: 2, |
||||
|
valueBox: true, |
||||
|
valueInt: 3, |
||||
|
defaultColor: null, |
||||
|
colorPlate: '#fff', |
||||
|
colorMajorTicks: '#444', |
||||
|
colorMinorTicks: '#666', |
||||
|
colorNeedle: null, |
||||
|
colorNeedleEnd: null, |
||||
|
colorNeedleShadowUp: 'rgba(2,255,255,0.2)', |
||||
|
colorNeedleShadowDown: 'rgba(188,143,143,0.45)', |
||||
|
colorValueBoxRect: '#888', |
||||
|
colorValueBoxRectEnd: '#666', |
||||
|
colorValueBoxBackground: '#babab2', |
||||
|
colorValueBoxShadow: 'rgba(0,0,0,1)', |
||||
|
highlights: [], |
||||
|
highlightsWidth: 15, |
||||
|
showBorder: true, |
||||
|
numbersFont: { |
||||
|
family: 'Roboto', |
||||
|
size: 18, |
||||
|
style: 'normal', |
||||
|
weight: '500', |
||||
|
color: null |
||||
|
}, |
||||
|
titleFont: { |
||||
|
family: 'Roboto', |
||||
|
size: 24, |
||||
|
style: 'normal', |
||||
|
weight: '500', |
||||
|
color: '#888' |
||||
|
}, |
||||
|
unitsFont: { |
||||
|
family: 'Roboto', |
||||
|
size: 22, |
||||
|
style: 'normal', |
||||
|
weight: '500', |
||||
|
color: '#888' |
||||
|
}, |
||||
|
valueFont: { |
||||
|
family: 'Roboto', |
||||
|
size: 40, |
||||
|
style: 'normal', |
||||
|
weight: '500', |
||||
|
color: '#444', |
||||
|
shadowColor: 'rgba(0,0,0,0.3)' |
||||
|
}, |
||||
|
animation: true, |
||||
|
animationDuration: 500, |
||||
|
animationRule: 'cycle' |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
protected onSettingsSet(settings: WidgetSettings) { |
||||
|
const highlightsControls: Array<AbstractControl> = []; |
||||
|
if (settings.highlights) { |
||||
|
settings.highlights.forEach((highlight) => { |
||||
|
highlightsControls.push(this.fb.control(highlight, [Validators.required])); |
||||
|
}); |
||||
|
} |
||||
|
this.analogueGaugeWidgetSettingsForm = this.fb.group({ |
||||
|
|
||||
|
// Radial gauge settings
|
||||
|
startAngle: [settings.startAngle, [Validators.min(0), Validators.max(360)]], |
||||
|
ticksAngle: [settings.ticksAngle, [Validators.min(0), Validators.max(360)]], |
||||
|
needleCircleSize: [settings.needleCircleSize, [Validators.min(0)]], |
||||
|
|
||||
|
defaultColor: [settings.defaultColor, []], |
||||
|
|
||||
|
// Ticks settings
|
||||
|
minValue: [settings.minValue, []], |
||||
|
maxValue: [settings.maxValue, []], |
||||
|
majorTicksCount: [settings.majorTicksCount, [Validators.min(0)]], |
||||
|
colorMajorTicks: [settings.colorMajorTicks, []], |
||||
|
minorTicks: [settings.majorTicksCount, [Validators.min(0)]], |
||||
|
colorMinorTicks: [settings.colorMinorTicks, []], |
||||
|
numbersFont: [settings.numbersFont, []], |
||||
|
|
||||
|
// Unit title settings
|
||||
|
showUnitTitle: [settings.showUnitTitle, []], |
||||
|
unitTitle: [settings.unitTitle, []], |
||||
|
titleFont: [settings.titleFont, []], |
||||
|
|
||||
|
// Units settings
|
||||
|
unitsFont: [settings.unitsFont, []], |
||||
|
|
||||
|
// Value box settings
|
||||
|
valueBox: [settings.valueBox, []], |
||||
|
valueInt: [settings.valueInt, [Validators.min(0)]], |
||||
|
valueFont: [settings.valueFont, []], |
||||
|
colorValueBoxRect: [settings.colorValueBoxRect, []], |
||||
|
colorValueBoxRectEnd: [settings.colorValueBoxRectEnd, []], |
||||
|
colorValueBoxBackground: [settings.colorValueBoxBackground, []], |
||||
|
colorValueBoxShadow: [settings.colorValueBoxShadow, []], |
||||
|
|
||||
|
// Plate settings
|
||||
|
showBorder: [settings.showBorder, []], |
||||
|
colorPlate: [settings.colorPlate, []], |
||||
|
|
||||
|
// Needle settings
|
||||
|
colorNeedle: [settings.colorNeedle, []], |
||||
|
colorNeedleEnd: [settings.colorNeedleEnd, []], |
||||
|
colorNeedleShadowUp: [settings.colorNeedleShadowUp, []], |
||||
|
colorNeedleShadowDown: [settings.colorNeedleShadowDown, []], |
||||
|
|
||||
|
// Highlights settings
|
||||
|
highlightsWidth: [settings.highlightsWidth, [Validators.min(0)]], |
||||
|
highlights: this.fb.array(highlightsControls), |
||||
|
|
||||
|
// Animation settings
|
||||
|
animation: [settings.animation, []], |
||||
|
animationDuration: [settings.animationDuration, [Validators.min(0)]], |
||||
|
animationRule: [settings.animationRule, []], |
||||
|
}); |
||||
|
this.ctx.settingsForm = this.analogueGaugeWidgetSettingsForm; |
||||
|
} |
||||
|
|
||||
|
protected validatorTriggers(): string[] { |
||||
|
return ['showUnitTitle', 'valueBox', 'animation']; |
||||
|
} |
||||
|
|
||||
|
protected updateValidators(emitEvent: boolean) { |
||||
|
const showUnitTitle: boolean = this.analogueGaugeWidgetSettingsForm.get('showUnitTitle').value; |
||||
|
const valueBox: boolean = this.analogueGaugeWidgetSettingsForm.get('valueBox').value; |
||||
|
const animation: boolean = this.analogueGaugeWidgetSettingsForm.get('animation').value; |
||||
|
if (showUnitTitle) { |
||||
|
this.analogueGaugeWidgetSettingsForm.get('unitTitle').enable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('titleFont').enable(); |
||||
|
} else { |
||||
|
this.analogueGaugeWidgetSettingsForm.get('unitTitle').disable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('titleFont').disable(); |
||||
|
} |
||||
|
if (valueBox) { |
||||
|
this.analogueGaugeWidgetSettingsForm.get('valueInt').enable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('valueFont').enable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxRect').enable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxRectEnd').enable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxBackground').enable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxShadow').enable(); |
||||
|
} else { |
||||
|
this.analogueGaugeWidgetSettingsForm.get('valueInt').disable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('valueFont').disable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxRect').disable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxRectEnd').disable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxBackground').disable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxShadow').disable(); |
||||
|
} |
||||
|
if (animation) { |
||||
|
this.analogueGaugeWidgetSettingsForm.get('animationDuration').enable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('animationRule').enable(); |
||||
|
} else { |
||||
|
this.analogueGaugeWidgetSettingsForm.get('animationDuration').disable(); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('animationRule').disable(); |
||||
|
} |
||||
|
this.analogueGaugeWidgetSettingsForm.get('unitTitle').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('titleFont').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('valueInt').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('valueFont').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxRect').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxRectEnd').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxBackground').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('colorValueBoxShadow').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('animationDuration').updateValueAndValidity({emitEvent}); |
||||
|
this.analogueGaugeWidgetSettingsForm.get('animationRule').updateValueAndValidity({emitEvent}); |
||||
|
} |
||||
|
|
||||
|
highlightsFormArray(): FormArray { |
||||
|
return this.analogueGaugeWidgetSettingsForm.get('highlights') as FormArray; |
||||
|
} |
||||
|
|
||||
|
public trackByHighlight(index: number, highlightControl: AbstractControl): any { |
||||
|
const highlight: GaugeHighlight = highlightControl.value; |
||||
|
return highlight; |
||||
|
} |
||||
|
|
||||
|
public removeHighlight(index: number) { |
||||
|
(this.analogueGaugeWidgetSettingsForm.get('highlights') as FormArray).removeAt(index); |
||||
|
} |
||||
|
|
||||
|
public addHighlight() { |
||||
|
const highlight: GaugeHighlight = { |
||||
|
from: null, |
||||
|
to: null, |
||||
|
color: null |
||||
|
}; |
||||
|
const highlightsArray = this.analogueGaugeWidgetSettingsForm.get('highlights') as FormArray; |
||||
|
const highlightControl = this.fb.control(highlight, [Validators.required]); |
||||
|
(highlightControl as any).new = true; |
||||
|
highlightsArray.push(highlightControl); |
||||
|
this.analogueGaugeWidgetSettingsForm.updateValueAndValidity(); |
||||
|
} |
||||
|
|
||||
|
highlightDrop(event: CdkDragDrop<string[]>) { |
||||
|
const highlightsArray = this.analogueGaugeWidgetSettingsForm.get('highlights') as FormArray; |
||||
|
const highlight = highlightsArray.at(event.previousIndex); |
||||
|
highlightsArray.removeAt(event.previousIndex); |
||||
|
highlightsArray.insert(event.currentIndex, highlight); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,66 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 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 { Component } from '@angular/core'; |
||||
|
import { WidgetSettings } from '@shared/models/widget.models'; |
||||
|
import { FormBuilder, Validators } from '@angular/forms'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { |
||||
|
AnalogueGaugeWidgetSettingsComponent |
||||
|
} from '@home/components/widget/lib/settings/gauge/analogue-gauge-widget-settings.component'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-analogue-linear-gauge-widget-settings', |
||||
|
templateUrl: './analogue-gauge-widget-settings.component.html', |
||||
|
styleUrls: ['./../widget-settings.scss'] |
||||
|
}) |
||||
|
export class AnalogueLinearGaugeWidgetSettingsComponent extends AnalogueGaugeWidgetSettingsComponent { |
||||
|
|
||||
|
gaugeType = 'linear'; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected fb: FormBuilder) { |
||||
|
super(store, fb); |
||||
|
} |
||||
|
|
||||
|
protected defaultSettings(): WidgetSettings { |
||||
|
const settings = super.defaultSettings(); |
||||
|
settings.barStrokeWidth = 2.5; |
||||
|
settings.colorBarStroke = null; |
||||
|
settings.colorBar = '#fff'; |
||||
|
settings.colorBarEnd = '#ddd'; |
||||
|
settings.colorBarProgress = null; |
||||
|
settings.colorBarProgressEnd = null; |
||||
|
return settings; |
||||
|
} |
||||
|
|
||||
|
protected onSettingsSet(settings: WidgetSettings) { |
||||
|
super.onSettingsSet(settings); |
||||
|
this.analogueGaugeWidgetSettingsForm.addControl('barStrokeWidth', |
||||
|
this.fb.control(settings.barStrokeWidth, [Validators.min(0)])); |
||||
|
this.analogueGaugeWidgetSettingsForm.addControl('colorBarStroke', |
||||
|
this.fb.control(settings.colorBarStroke, [])); |
||||
|
this.analogueGaugeWidgetSettingsForm.addControl('colorBar', |
||||
|
this.fb.control(settings.colorBar, [])); |
||||
|
this.analogueGaugeWidgetSettingsForm.addControl('colorBarEnd', |
||||
|
this.fb.control(settings.colorBarEnd, [])); |
||||
|
this.analogueGaugeWidgetSettingsForm.addControl('colorBarProgress', |
||||
|
this.fb.control(settings.colorBarProgress, [])); |
||||
|
this.analogueGaugeWidgetSettingsForm.addControl('colorBarProgressEnd', |
||||
|
this.fb.control(settings.colorBarProgressEnd, [])); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,57 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 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 { Component } from '@angular/core'; |
||||
|
import { WidgetSettings } from '@shared/models/widget.models'; |
||||
|
import { FormBuilder, Validators } from '@angular/forms'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { |
||||
|
AnalogueGaugeWidgetSettingsComponent |
||||
|
} from '@home/components/widget/lib/settings/gauge/analogue-gauge-widget-settings.component'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-analogue-radial-gauge-widget-settings', |
||||
|
templateUrl: './analogue-gauge-widget-settings.component.html', |
||||
|
styleUrls: ['./../widget-settings.scss'] |
||||
|
}) |
||||
|
export class AnalogueRadialGaugeWidgetSettingsComponent extends AnalogueGaugeWidgetSettingsComponent { |
||||
|
|
||||
|
gaugeType = 'radial'; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
protected fb: FormBuilder) { |
||||
|
super(store, fb); |
||||
|
} |
||||
|
|
||||
|
protected defaultSettings(): WidgetSettings { |
||||
|
const settings = super.defaultSettings(); |
||||
|
settings.startAngle = 45; |
||||
|
settings.ticksAngle = 270; |
||||
|
settings.needleCircleSize = 10; |
||||
|
return settings; |
||||
|
} |
||||
|
|
||||
|
protected onSettingsSet(settings: WidgetSettings) { |
||||
|
super.onSettingsSet(settings); |
||||
|
this.analogueGaugeWidgetSettingsForm.addControl('startAngle', |
||||
|
this.fb.control(settings.startAngle, [Validators.min(0), Validators.max(360)])); |
||||
|
this.analogueGaugeWidgetSettingsForm.addControl('ticksAngle', |
||||
|
this.fb.control(settings.ticksAngle, [Validators.min(0), Validators.max(360)])); |
||||
|
this.analogueGaugeWidgetSettingsForm.addControl('needleCircleSize', |
||||
|
this.fb.control(settings.needleCircleSize, [Validators.min(0)])); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,60 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
Copyright © 2016-2022 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. |
||||
|
|
||||
|
--> |
||||
|
<mat-expansion-panel class="gauge-highlight" fxFlex [formGroup]="gaugeHighlightFormGroup" [(expanded)]="expanded"> |
||||
|
<mat-expansion-panel-header> |
||||
|
<div fxFlex fxLayout="row" fxLayoutAlign="start center"> |
||||
|
<mat-panel-title> |
||||
|
<div fxLayout="row" fxFlex fxLayoutAlign="start center"> |
||||
|
<div>{{ highlightRangeText() }}</div> |
||||
|
<div class="tb-color-preview" style="margin-left: 6px;"> |
||||
|
<div class="tb-color-result" [ngStyle]="{background: gaugeHighlightFormGroup.get('color').value}"></div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</mat-panel-title> |
||||
|
<span fxFlex></span> |
||||
|
<button *ngIf="!disabled" mat-icon-button style="min-width: 40px;" |
||||
|
type="button" |
||||
|
(click)="removeHighlight.emit()" |
||||
|
matTooltip="{{ 'action.remove' | translate }}" |
||||
|
matTooltipPosition="above"> |
||||
|
<mat-icon>delete</mat-icon> |
||||
|
</button> |
||||
|
</div> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<div fxLayout="column" fxLayoutGap="0.5em"> |
||||
|
<mat-divider></mat-divider> |
||||
|
<section class="tb-widget-settings" fxLayout="column"> |
||||
|
<section fxLayout="row" fxLayoutGap="8px" fxLayoutAlign="start center"> |
||||
|
<mat-form-field fxFlex> |
||||
|
<mat-label translate>widgets.gauge.highlight-from</mat-label> |
||||
|
<input matInput type="number" formControlName="from"> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field fxFlex> |
||||
|
<mat-label translate>widgets.gauge.highlight-to</mat-label> |
||||
|
<input matInput type="number" formControlName="to"> |
||||
|
</mat-form-field> |
||||
|
</section> |
||||
|
<tb-color-input |
||||
|
formControlName="color" |
||||
|
label="{{ 'widgets.gauge.highlight-color' | translate }}"> |
||||
|
</tb-color-input> |
||||
|
</section> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
@ -0,0 +1,116 @@ |
|||||
|
///
|
||||
|
/// Copyright © 2016-2022 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 { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core'; |
||||
|
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; |
||||
|
import { PageComponent } from '@shared/components/page.component'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@core/core.state'; |
||||
|
import { TranslateService } from '@ngx-translate/core'; |
||||
|
import { isNumber } from '@core/utils'; |
||||
|
|
||||
|
export interface GaugeHighlight { |
||||
|
from: number; |
||||
|
to: number; |
||||
|
color: string; |
||||
|
} |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-gauge-highlight', |
||||
|
templateUrl: './gauge-highlight.component.html', |
||||
|
styleUrls: ['./gauge-highlight.component.scss', './../widget-settings.scss'], |
||||
|
providers: [ |
||||
|
{ |
||||
|
provide: NG_VALUE_ACCESSOR, |
||||
|
useExisting: forwardRef(() => GaugeHighlightComponent), |
||||
|
multi: true |
||||
|
} |
||||
|
] |
||||
|
}) |
||||
|
export class GaugeHighlightComponent extends PageComponent implements OnInit, ControlValueAccessor { |
||||
|
|
||||
|
@Input() |
||||
|
disabled: boolean; |
||||
|
|
||||
|
@Input() |
||||
|
expanded = false; |
||||
|
|
||||
|
@Output() |
||||
|
removeHighlight = new EventEmitter(); |
||||
|
|
||||
|
private modelValue: GaugeHighlight; |
||||
|
|
||||
|
private propagateChange = null; |
||||
|
|
||||
|
public gaugeHighlightFormGroup: FormGroup; |
||||
|
|
||||
|
constructor(protected store: Store<AppState>, |
||||
|
private translate: TranslateService, |
||||
|
private fb: FormBuilder) { |
||||
|
super(store); |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.gaugeHighlightFormGroup = this.fb.group({ |
||||
|
from: [null, []], |
||||
|
to: [null, []], |
||||
|
color: [null, []] |
||||
|
}); |
||||
|
this.gaugeHighlightFormGroup.valueChanges.subscribe(() => { |
||||
|
this.updateModel(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
registerOnChange(fn: any): void { |
||||
|
this.propagateChange = fn; |
||||
|
} |
||||
|
|
||||
|
registerOnTouched(fn: any): void { |
||||
|
} |
||||
|
|
||||
|
setDisabledState(isDisabled: boolean): void { |
||||
|
this.disabled = isDisabled; |
||||
|
if (isDisabled) { |
||||
|
this.gaugeHighlightFormGroup.disable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.gaugeHighlightFormGroup.enable({emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
writeValue(value: GaugeHighlight): void { |
||||
|
this.modelValue = value; |
||||
|
this.gaugeHighlightFormGroup.patchValue( |
||||
|
value, {emitEvent: false} |
||||
|
); |
||||
|
} |
||||
|
|
||||
|
highlightRangeText(): string { |
||||
|
const value: GaugeHighlight = this.gaugeHighlightFormGroup.value; |
||||
|
const from = isNumber(value.from) ? value.from : 0; |
||||
|
const to = isNumber(value.to) ? value.to : 0; |
||||
|
return `${from} - ${to}`; |
||||
|
} |
||||
|
|
||||
|
private updateModel() { |
||||
|
const value: GaugeHighlight = this.gaugeHighlightFormGroup.value; |
||||
|
this.modelValue = value; |
||||
|
if (this.gaugeHighlightFormGroup.valid) { |
||||
|
this.propagateChange(this.modelValue); |
||||
|
} else { |
||||
|
this.propagateChange(null); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue