thingsboard/ui-ngx/src/app/modules/home/components/widget/lib/multiple-input-widget.component.html

219 lines
12 KiB
HTML
Raw Normal View History

2020-02-28 19:49:14 +02:00
<!--
2023-01-31 10:43:56 +02:00
Copyright © 2016-2023 The Thingsboard Authors
2020-02-28 19:49:14 +02:00
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.
-->
<form #formContainer class="tb-multiple-input"
[formGroup]="multipleInputFormGroup"
tb-toast toastTarget="{{ toastTargetId }}"
(ngSubmit)="saveForm()" novalidate autocomplete="off">
<div class="tb-multiple-input-container" *ngIf="entityDetected && isAllParametersValid">
2020-02-28 19:49:14 +02:00
<fieldset *ngFor="let source of sources" [ngClass]="{'fields-group': settings.showGroupTitle}">
<legend class="group-title" *ngIf="settings.showGroupTitle">{{ getGroupTitle(source.datasource) }}
</legend>
2023-07-31 13:28:53 +03:00
<div class="tb-multiple-input-layout layout-wrap"
2020-02-28 19:49:14 +02:00
[ngClass]="{'vertical-alignment': isVerticalAlignment || changeAlignment}">
<div *ngFor="let key of visibleKeys(source)"
[ngStyle]="{width: (isVerticalAlignment || changeAlignment) ? '100%' : inputWidthSettings}">
<div class="input-field" *ngIf="key.settings.dataKeyValueType === 'string'">
2023-07-28 18:32:36 +03:00
<mat-form-field class="mat-block" appearance="outline">
2020-02-28 19:49:14 +02:00
<mat-label>{{key.label}}</mat-label>
<input matInput
formControlName="{{key.formId}}"
[required]="key.settings.required"
[readonly]="key.settings.isEditable === 'readonly'"
type="text"
(focus)="key.isFocused = true; focusInputElement($event)"
(blur)="key.isFocused = false; inputChanged(source, key)">
<ng-container *ngIf="key.settings.icon || key.settings.safeCustomIcon" matPrefix>
<tb-icon *ngIf="!key.settings.safeCustomIcon; else customToggleIcon">{{key.settings.icon}}</tb-icon>
<ng-template #customToggleIcon>
<img class="mat-icon" [src]="key.settings.safeCustomIcon" alt="icon">
</ng-template>
</ng-container>
2020-02-28 19:49:14 +02:00
<mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')">
2020-10-09 11:07:10 +03:00
{{ getErrorMessageText(key.settings, 'required') }}
2020-02-28 19:49:14 +02:00
</mat-error>
</mat-form-field>
</div>
<div class="input-field" *ngIf="key.settings.dataKeyValueType === 'double' ||
key.settings.dataKeyValueType === 'integer'">
2023-07-28 18:32:36 +03:00
<mat-form-field class="mat-block" appearance="outline">
2020-02-28 19:49:14 +02:00
<mat-label>{{key.label}}</mat-label>
<input matInput
formControlName="{{key.formId}}"
[required]="key.settings.required"
[readonly]="key.settings.isEditable === 'readonly'"
type="number"
step="{{key.settings.step}}"
2020-09-15 18:14:31 +03:00
min="{{key.settings.minValue}}"
max="{{key.settings.maxValue}}"
2020-02-28 19:49:14 +02:00
(focus)="key.isFocused = true; focusInputElement($event)"
(blur)="key.isFocused = false; inputChanged(source, key)">
<ng-container *ngIf="key.settings.icon || key.settings.safeCustomIcon" matPrefix>
<tb-icon *ngIf="!key.settings.safeCustomIcon; else customToggleIcon">{{key.settings.icon}}</tb-icon>
<ng-template #customToggleIcon>
<img class="mat-icon" [src]="key.settings.safeCustomIcon" alt="icon">
</ng-template>
</ng-container>
2020-02-28 19:49:14 +02:00
<mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')">
2020-10-09 11:07:10 +03:00
{{ getErrorMessageText(key.settings,'required') }}
2020-02-28 19:49:14 +02:00
</mat-error>
2020-09-15 18:14:31 +03:00
<mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('min')">
2020-10-09 11:07:10 +03:00
{{ getErrorMessageText(key.settings,'min') }}
2020-09-15 18:14:31 +03:00
</mat-error>
<mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('max')">
2020-10-09 11:07:10 +03:00
{{ getErrorMessageText(key.settings,'max') }}
2020-09-15 18:14:31 +03:00
</mat-error>
2020-02-28 19:49:14 +02:00
</mat-form-field>
</div>
<div class="input-field mat-block" *ngIf="key.settings.dataKeyValueType === 'booleanCheckbox'">
<mat-checkbox formControlName="{{key.formId}}"
(change)="inputChanged(source, key)">
<span class="label-wrapper">{{key.label}}</span>
2020-02-28 19:49:14 +02:00
</mat-checkbox>
</div>
2022-10-24 11:38:08 +03:00
<div class="input-field" *ngIf="key.settings.dataKeyValueType === 'JSON'">
2023-07-28 18:32:36 +03:00
<mat-form-field class="mat-block" appearance="outline">
2022-10-24 11:38:08 +03:00
<mat-label>{{key.label}}</mat-label>
<input
matInput
type="text"
formControlName="{{key.formId}}"
tb-json-to-string
[readonly]="key.settings.isEditable === 'readonly'"
[required]="key.settings.required"
(focus)="key.isFocused = true; focusInputElement($event)"
(blur)="key.isFocused = false; inputChanged(source, key)"
/>
<ng-container *ngIf="key.settings.icon || key.settings.safeCustomIcon" matPrefix>
<tb-icon *ngIf="!key.settings.safeCustomIcon; else customToggleIcon">{{key.settings.icon}}</tb-icon>
2022-10-24 11:38:08 +03:00
<ng-template #customToggleIcon>
<img class="mat-icon" [src]="key.settings.safeCustomIcon" alt="icon">
</ng-template>
</ng-container>
<button [disabled]="key.settings.isEditable === 'disabled' || key.settings.isEditable === 'readonly'"
type="button"
matSuffix mat-icon-button
2022-10-24 11:38:08 +03:00
(click)="openEditJSONDialog($event, key, source)">
<mat-icon>open_in_new</mat-icon>
</button>
<mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')">
{{ getErrorMessageText(key.settings,'required') }}
</mat-error>
<mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('invalidJSON')">
{{ getErrorMessageText(key.settings,'invalidJSON') | translate }}
2022-10-24 11:38:08 +03:00
</mat-error>
</mat-form-field>
</div>
2020-02-28 19:49:14 +02:00
<div class="input-field mat-block" *ngIf="key.settings.dataKeyValueType === 'booleanSwitch'">
<mat-slide-toggle formControlName="{{key.formId}}"
[labelPosition]="key.settings.slideToggleLabelPosition"
2020-02-28 19:49:14 +02:00
(change)="inputChanged(source, key)">
<ng-container *ngIf="key.settings.icon || key.settings.safeCustomIcon">
<tb-icon *ngIf="!key.settings.safeCustomIcon; else customToggleIcon">{{key.settings.icon}}</tb-icon>
<ng-template #customToggleIcon>
<img class="mat-icon" [src]="key.settings.safeCustomIcon" alt="icon">
</ng-template>
</ng-container>
<span class="label-wrapper">{{key.label}}</span>
2020-02-28 19:49:14 +02:00
</mat-slide-toggle>
</div>
<div class="input-field mat-block date-time-input" *ngIf="(key.settings.dataKeyValueType === 'dateTime') ||
(key.settings.dataKeyValueType === 'date') ||
(key.settings.dataKeyValueType === 'time')" fxLayout="column">
2023-07-28 18:32:36 +03:00
<mat-form-field appearance="outline">
2023-02-17 19:24:01 +02:00
<mat-label>{{key.label}}</mat-label>
<mat-datetimepicker-toggle [for]="datePicker" matPrefix></mat-datetimepicker-toggle>
<mat-datetimepicker #datePicker type="{{datePickerType(key.settings.dataKeyValueType)}}"
openOnFocus="true"></mat-datetimepicker>
<input matInput formControlName="{{key.formId}}"
[required]="key.settings.required"
[readonly]="key.settings.isEditable === 'readonly'"
[matDatetimepicker]="datePicker"
(focus)="key.isFocused = true;"
(blur)="key.isFocused = false;"
(dateChange)="inputChanged(source, key)">
<mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')">
2020-10-09 11:07:10 +03:00
{{ getErrorMessageText(key.settings, 'required') }}
</mat-error>
<mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('matDatepickerParse')">
2020-10-09 11:07:10 +03:00
{{ getErrorMessageText(key.settings, 'invalidDate') }}
</mat-error>
</mat-form-field>
2020-02-28 19:49:14 +02:00
</div>
<div class="input-field" *ngIf="key.settings.dataKeyValueType === 'select'">
2023-07-28 18:32:36 +03:00
<mat-form-field class="mat-block" appearance="outline">
<mat-label>{{key.label}}</mat-label>
<mat-select formControlName="{{key.formId}}"
[required]="key.settings.required"
(focus)="key.isFocused = true;"
(selectionChange)="key.isFocused = false; inputChanged(source, key)">
<mat-option *ngFor="let option of key.settings.selectOptions"
2021-09-01 15:44:49 +03:00
[value]="option.value"
[disabled]="key.settings.isEditable === 'readonly'">
{{ getCustomTranslationText(option.label ? option.label : option.value) }}
</mat-option>
</mat-select>
<mat-error *ngIf="multipleInputFormGroup.get(key.formId).hasError('required')">
{{ getErrorMessageText(key.settings, 'required') }}
</mat-error>
</mat-form-field>
</div>
2023-07-28 18:32:36 +03:00
2023-07-31 13:28:53 +03:00
<div class="tb-form-row space-between color-picker-input" *ngIf="key.settings.dataKeyValueType === 'color'">
<div class="label-container">
2023-07-28 18:32:36 +03:00
<ng-container *ngIf="key.settings.icon || key.settings.safeCustomIcon">
<mat-icon *ngIf="!key.settings.safeCustomIcon; else customToggleIcon">{{key.settings.icon}}</mat-icon>
<ng-template #customToggleIcon>
<img class="mat-icon" [src]="key.settings.safeCustomIcon" alt="icon">
</ng-template>
</ng-container>
{{key.label}}
</div>
2023-07-31 13:28:53 +03:00
<tb-color-input asBoxInput
[required]="key.settings.required"
[requiredText]="getErrorMessageText(key.settings, 'required')"
openOnInput
formControlName="{{key.formId}}">
</tb-color-input>
2023-07-28 18:32:36 +03:00
</div>
2020-02-28 19:49:14 +02:00
</div>
</div>
</fieldset>
</div>
2023-07-31 13:28:53 +03:00
<div class="mat-padding tb-multiple-input--buttons-container"
*ngIf="entityDetected && isAllParametersValid && settings.showActionButtons">
<button mat-button color="primary" type="button"
2023-07-31 13:28:53 +03:00
(click)="discardAll()" class="tb-multiple-input--buttons-container__button"
[disabled]="!multipleInputFormGroup.dirty">
{{ resetButtonLabel }}
</button>
<button mat-button mat-raised-button color="primary" type="submit"
2023-07-31 13:28:53 +03:00
class="tb-multiple-input--buttons-container__button"
[disabled]="!multipleInputFormGroup.dirty || multipleInputFormGroup.invalid">
{{ saveButtonLabel }}
</button>
2020-02-28 19:49:14 +02:00
</div>
2023-07-31 13:28:53 +03:00
<div class="tb-multiple-input__errors" *ngIf="(!entityDetected || !isAllParametersValid) && datasourceDetected">
<div class="tb-multiple-input__error" [fxHide]="entityDetected">
2020-02-28 19:49:14 +02:00
{{ 'widgets.input-widgets.no-entity-selected' | translate }}
</div>
2023-07-31 13:28:53 +03:00
<div class="tb-multiple-input__error" [fxShow]="entityDetected && !isAllParametersValid">
2020-02-28 19:49:14 +02:00
{{ 'widgets.input-widgets.not-allowed-entity' | translate }}
</div>
</div>
</form>