16 changed files with 945 additions and 469 deletions
@ -0,0 +1,138 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
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. |
||||
|
|
||||
|
--> |
||||
|
<div class="tb-scada-symbol-behavior-settings-panel" [formGroup]="behaviorFormGroup"> |
||||
|
<div class="tb-scada-symbol-behavior-settings-title">{{ panelTitle | translate }}</div> |
||||
|
<div class="tb-scada-symbol-behavior-settings-panel-content"> |
||||
|
<div class="tb-form-row"> |
||||
|
<div class="fixed-title-width" translate>scada.behavior.id</div> |
||||
|
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<input required matInput formControlName="id" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-form-row"> |
||||
|
<div class="fixed-title-width" translate>scada.behavior.name</div> |
||||
|
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<input required matInput formControlName="name" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-form-row"> |
||||
|
<div class="fixed-title-width" translate>scada.behavior.hint</div> |
||||
|
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="hint" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-form-row"> |
||||
|
<div class="fixed-title-width" translate>scada.behavior.type</div> |
||||
|
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<mat-select formControlName="type"> |
||||
|
<mat-option *ngFor="let type of iotSvgBehaviorTypes" [value]="type"> |
||||
|
{{ iotSvgBehaviorTypeTranslations.get(type) | translate }} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div *ngIf="[IotSvgBehaviorType.value, IotSvgBehaviorType.action].includes(behaviorFormGroup.get('type').value)" class="tb-form-row"> |
||||
|
<div class="fixed-title-width" translate>scada.behavior.value-type</div> |
||||
|
<mat-form-field appearance="outline" subscriptSizing="dynamic" class="flex tb-value-type"> |
||||
|
<mat-select formControlName="valueType"> |
||||
|
<mat-select-trigger> |
||||
|
<div class="tb-value-type-row"> |
||||
|
<mat-icon class="tb-mat-18" svgIcon="{{ valueTypesMap.get(behaviorFormGroup.get('valueType').value).icon }}"></mat-icon> |
||||
|
<span>{{ valueTypesMap.get(behaviorFormGroup.get('valueType').value).name | translate }}</span> |
||||
|
</div> |
||||
|
</mat-select-trigger> |
||||
|
<mat-option *ngFor="let valueType of valueTypes" [value]="valueType"> |
||||
|
<mat-icon class="tb-mat-20" svgIcon="{{ valueTypesMap.get(valueType).icon }}"></mat-icon> |
||||
|
<span>{{ valueTypesMap.get(valueType).name | translate }}</span> |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<ng-container *ngIf="behaviorFormGroup.get('type').value === IotSvgBehaviorType.value"> |
||||
|
<div class="tb-form-row "> |
||||
|
<div class="fixed-title-width" translate>scada.behavior.default-value</div> |
||||
|
<tb-value-input fxFlex [valueType]="behaviorFormGroup.get('valueType').value" |
||||
|
formControlName="defaultValue"></tb-value-input> |
||||
|
</div> |
||||
|
<ng-container *ngIf="behaviorFormGroup.get('valueType').value === ValueType.BOOLEAN"> |
||||
|
<div class="tb-form-row"> |
||||
|
<div class="fixed-title-width" translate>scada.behavior.true-label</div> |
||||
|
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="trueLabel" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-form-row"> |
||||
|
<div class="fixed-title-width" translate>scada.behavior.false-label</div> |
||||
|
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="falseLabel" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
<div class="tb-form-row"> |
||||
|
<div class="fixed-title-width" translate>scada.behavior.state-label</div> |
||||
|
<mat-form-field class="flex" appearance="outline" subscriptSizing="dynamic"> |
||||
|
<input matInput formControlName="stateLabel" placeholder="{{ 'widget-config.set' | translate }}"> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
</ng-container> |
||||
|
</ng-container> |
||||
|
<ng-container *ngIf="behaviorFormGroup.get('type').value === IotSvgBehaviorType.action"> |
||||
|
<div class="tb-form-panel stroked"> |
||||
|
<div class="tb-form-row no-padding no-border column-xs"> |
||||
|
<div class="fixed-title-width">{{ 'scada.behavior.default-payload' | translate }}</div> |
||||
|
<tb-toggle-select fxFlex formControlName="valueToDataType"> |
||||
|
<tb-toggle-option *ngIf="behaviorFormGroup.get('valueType').value !== ValueType.BOOLEAN" [value]="ValueToDataType.VALUE">{{ 'widgets.value-action.converter-value' | translate }}</tb-toggle-option> |
||||
|
<tb-toggle-option *ngIf="behaviorFormGroup.get('valueType').value === ValueType.BOOLEAN" [value]="ValueToDataType.CONSTANT">{{ 'widgets.value-action.converter-constant' | translate }}</tb-toggle-option> |
||||
|
<tb-toggle-option [value]="ValueToDataType.FUNCTION">{{ 'widgets.value-action.converter-function' | translate }}</tb-toggle-option> |
||||
|
<tb-toggle-option [value]="ValueToDataType.NONE">{{ 'widgets.value-action.converter-none' | translate }}</tb-toggle-option> |
||||
|
</tb-toggle-select> |
||||
|
</div> |
||||
|
<tb-value-input *ngIf="behaviorFormGroup.get('valueToDataType').value === ValueToDataType.CONSTANT" |
||||
|
fxFlex |
||||
|
[layout]="{ |
||||
|
layout: 'row', |
||||
|
breakpoints: {xs: 'column'} |
||||
|
}" |
||||
|
formControlName="constantValue"> |
||||
|
</tb-value-input> |
||||
|
<tb-js-func *ngIf="behaviorFormGroup.get('valueToDataType').value === ValueToDataType.FUNCTION" |
||||
|
formControlName="valueToDataFunction" |
||||
|
required |
||||
|
[globalVariables]="functionScopeVariables" |
||||
|
[functionArgs]="['value']" |
||||
|
functionTitle="{{ 'widgets.value-action.convert-value-function' | translate }}" |
||||
|
helpId="widget/lib/rpc/convert_value_fn"> |
||||
|
</tb-js-func> |
||||
|
</div> |
||||
|
</ng-container> |
||||
|
</div> |
||||
|
<div class="tb-scada-symbol-behavior-settings-panel-buttons"> |
||||
|
<button mat-button |
||||
|
color="primary" |
||||
|
type="button" |
||||
|
(click)="cancel()"> |
||||
|
{{ 'action.cancel' | translate }} |
||||
|
</button> |
||||
|
<button mat-raised-button |
||||
|
color="primary" |
||||
|
type="button" |
||||
|
(click)="applyBehaviorSettings()" |
||||
|
[disabled]="behaviorFormGroup.invalid || !behaviorFormGroup.dirty"> |
||||
|
{{ (isAdd ? 'action.add' : 'action.apply') | translate }} |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
@ -0,0 +1,67 @@ |
|||||
|
/** |
||||
|
* 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 '../../../../../../scss/constants'; |
||||
|
|
||||
|
.tb-scada-symbol-behavior-settings-panel { |
||||
|
width: 540px; |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
gap: 16px; |
||||
|
@media #{$mat-lt-md} { |
||||
|
width: 90vw; |
||||
|
} |
||||
|
.tb-scada-symbol-behavior-settings-panel-content { |
||||
|
display: flex; |
||||
|
flex-direction: column; |
||||
|
gap: 16px; |
||||
|
overflow: auto; |
||||
|
margin: -10px; |
||||
|
padding: 10px; |
||||
|
.mat-mdc-form-field.tb-value-type { |
||||
|
.mat-mdc-form-field-infix { |
||||
|
max-height: 40px; |
||||
|
} |
||||
|
mat-select-trigger { |
||||
|
.tb-value-type-row { |
||||
|
display: flex; |
||||
|
flex-direction: row; |
||||
|
align-items: center; |
||||
|
justify-content: flex-start; |
||||
|
gap: 10px; |
||||
|
.mat-icon { |
||||
|
color: rgba(0, 0, 0, 0.38); |
||||
|
vertical-align: bottom; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
.tb-scada-symbol-behavior-settings-title { |
||||
|
font-size: 16px; |
||||
|
font-weight: 500; |
||||
|
line-height: 24px; |
||||
|
letter-spacing: 0.25px; |
||||
|
color: rgba(0, 0, 0, 0.87); |
||||
|
} |
||||
|
.tb-scada-symbol-behavior-settings-panel-buttons { |
||||
|
height: 40px; |
||||
|
display: flex; |
||||
|
flex-direction: row; |
||||
|
gap: 16px; |
||||
|
justify-content: flex-end; |
||||
|
align-items: flex-end; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,148 @@ |
|||||
|
///
|
||||
|
/// 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 { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core'; |
||||
|
import { TbPopoverComponent } from '@shared/components/popover.component'; |
||||
|
import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms'; |
||||
|
import { merge } from 'rxjs'; |
||||
|
import { |
||||
|
IotSvgBehavior, |
||||
|
IotSvgBehaviorType, |
||||
|
iotSvgBehaviorTypes, |
||||
|
iotSvgBehaviorTypeTranslations |
||||
|
} from '@app/modules/home/components/widget/lib/svg/iot-svg.models'; |
||||
|
import { ValueType, valueTypesMap } from '@shared/models/constants'; |
||||
|
import { ValueToDataType } from '@shared/models/action-widget-settings.models'; |
||||
|
import { WidgetService } from '@core/http/widget.service'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-scada-symbol-behavior-panel', |
||||
|
templateUrl: './scada-symbol-behavior-panel.component.html', |
||||
|
styleUrls: ['./scada-symbol-behavior-panel.component.scss'], |
||||
|
encapsulation: ViewEncapsulation.None |
||||
|
}) |
||||
|
export class ScadaSymbolBehaviorPanelComponent implements OnInit { |
||||
|
|
||||
|
IotSvgBehaviorType = IotSvgBehaviorType; |
||||
|
|
||||
|
ValueType = ValueType; |
||||
|
|
||||
|
ValueToDataType = ValueToDataType; |
||||
|
|
||||
|
iotSvgBehaviorTypes = iotSvgBehaviorTypes; |
||||
|
iotSvgBehaviorTypeTranslations = iotSvgBehaviorTypeTranslations; |
||||
|
|
||||
|
valueTypes = Object.keys(ValueType) as ValueType[]; |
||||
|
|
||||
|
valueTypesMap = valueTypesMap; |
||||
|
|
||||
|
@Input() |
||||
|
isAdd = false; |
||||
|
|
||||
|
@Input() |
||||
|
behavior: IotSvgBehavior; |
||||
|
|
||||
|
@Input() |
||||
|
popover: TbPopoverComponent<ScadaSymbolBehaviorPanelComponent>; |
||||
|
|
||||
|
@Output() |
||||
|
behaviorSettingsApplied = new EventEmitter<IotSvgBehavior>(); |
||||
|
|
||||
|
functionScopeVariables = this.widgetService.getWidgetScopeVariables(); |
||||
|
|
||||
|
panelTitle: string; |
||||
|
|
||||
|
behaviorFormGroup: UntypedFormGroup; |
||||
|
|
||||
|
constructor(private fb: UntypedFormBuilder, |
||||
|
private widgetService: WidgetService) { |
||||
|
} |
||||
|
|
||||
|
ngOnInit(): void { |
||||
|
this.panelTitle = this.isAdd ? 'scada.behavior.add-behavior' : 'scada.behavior.behavior-settings'; |
||||
|
this.behaviorFormGroup = this.fb.group( |
||||
|
{ |
||||
|
id: [this.behavior.id, [Validators.required]], |
||||
|
name: [this.behavior.name, [Validators.required]], |
||||
|
hint: [this.behavior.hint, []], |
||||
|
type: [this.behavior.type, [Validators.required]], |
||||
|
valueType: [this.behavior.valueType, [Validators.required]], |
||||
|
defaultValue: [this.behavior.defaultValue, [Validators.required]], |
||||
|
trueLabel: [this.behavior.trueLabel, []], |
||||
|
falseLabel: [this.behavior.falseLabel, []], |
||||
|
stateLabel: [this.behavior.stateLabel, []], |
||||
|
valueToDataType: [this.behavior.valueToDataType, [Validators.required]], |
||||
|
constantValue: [this.behavior.constantValue, [Validators.required]], |
||||
|
valueToDataFunction: [this.behavior.valueToDataFunction, [Validators.required]] |
||||
|
} |
||||
|
); |
||||
|
merge(this.behaviorFormGroup.get('type').valueChanges, |
||||
|
this.behaviorFormGroup.get('valueType').valueChanges, |
||||
|
this.behaviorFormGroup.get('valueToDataType').valueChanges).subscribe(() => { |
||||
|
this.updateValidators(); |
||||
|
}); |
||||
|
this.updateValidators(); |
||||
|
} |
||||
|
|
||||
|
cancel() { |
||||
|
this.popover?.hide(); |
||||
|
} |
||||
|
|
||||
|
applyBehaviorSettings() { |
||||
|
const behavior = this.behaviorFormGroup.getRawValue(); |
||||
|
this.behaviorSettingsApplied.emit(behavior); |
||||
|
} |
||||
|
|
||||
|
private updateValidators() { |
||||
|
const type: IotSvgBehaviorType = this.behaviorFormGroup.get('type').value; |
||||
|
const valueType: ValueType = this.behaviorFormGroup.get('valueType').value; |
||||
|
let valueToDataType: ValueToDataType = this.behaviorFormGroup.get('valueToDataType').value; |
||||
|
this.behaviorFormGroup.disable({emitEvent: false}); |
||||
|
this.behaviorFormGroup.get('id').enable({emitEvent: false}); |
||||
|
this.behaviorFormGroup.get('name').enable({emitEvent: false}); |
||||
|
this.behaviorFormGroup.get('type').enable({emitEvent: false}); |
||||
|
this.behaviorFormGroup.get('hint').enable({emitEvent: false}); |
||||
|
switch (type) { |
||||
|
case IotSvgBehaviorType.value: |
||||
|
this.behaviorFormGroup.get('valueType').enable({emitEvent: false}); |
||||
|
this.behaviorFormGroup.get('defaultValue').enable({emitEvent: false}); |
||||
|
if (valueType === ValueType.BOOLEAN) { |
||||
|
this.behaviorFormGroup.get('trueLabel').enable({emitEvent: false}); |
||||
|
this.behaviorFormGroup.get('falseLabel').enable({emitEvent: false}); |
||||
|
this.behaviorFormGroup.get('stateLabel').enable({emitEvent: false}); |
||||
|
} |
||||
|
break; |
||||
|
case IotSvgBehaviorType.action: |
||||
|
if (valueType === ValueType.BOOLEAN && valueToDataType === ValueToDataType.VALUE) { |
||||
|
this.behaviorFormGroup.patchValue({valueToDataType: ValueToDataType.CONSTANT}, {emitEvent: false}); |
||||
|
valueToDataType = ValueToDataType.CONSTANT; |
||||
|
} else if (valueType !== ValueType.BOOLEAN && valueToDataType === ValueToDataType.CONSTANT) { |
||||
|
this.behaviorFormGroup.patchValue({valueToDataType: ValueToDataType.VALUE}, {emitEvent: false}); |
||||
|
valueToDataType = ValueToDataType.VALUE; |
||||
|
} |
||||
|
this.behaviorFormGroup.get('valueType').enable({emitEvent: false}); |
||||
|
this.behaviorFormGroup.get('valueToDataType').enable({emitEvent: false}); |
||||
|
if (valueToDataType === ValueToDataType.CONSTANT) { |
||||
|
this.behaviorFormGroup.get('constantValue').enable({emitEvent: false}); |
||||
|
} else if (valueToDataType === ValueToDataType.FUNCTION) { |
||||
|
this.behaviorFormGroup.get('valueToDataFunction').enable({emitEvent: false}); |
||||
|
} |
||||
|
break; |
||||
|
case IotSvgBehaviorType.widgetAction: |
||||
|
break; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
Before Width: | Height: | Size: 18 KiB After Width: | Height: | Size: 17 KiB |
Loading…
Reference in new issue