thingsboard/ui-ngx/src/app/modules/home/components/widget/data-keys.component.html

191 lines
10 KiB
HTML
Raw Normal View History

<!--
2023-01-31 10:43:56 +02:00
Copyright © 2016-2023 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.
-->
2023-05-19 17:54:27 +03:00
<mat-form-field [formGroup]="keysListFormGroup" class="mat-block">
<mat-label>{{placeholder}}</mat-label>
<mat-chip-grid #chipList formControlName="keys" [required]="required">
2023-02-24 19:25:19 +02:00
<div class="tb-datakeys-container"
[dndDropzone]="[dndId]"
[dndHorizontal]="true"
dndEffectAllowed="move"
dndAllowExternal="false"
2023-05-19 17:54:27 +03:00
[dndDisableIf]="disabled || dragDisabled"
2023-02-24 19:25:19 +02:00
(dndDrop)="onChipDrop($event)">
2023-05-19 17:54:27 +03:00
<div #placeholderChipRow
dndPlaceholderRef
class="mat-mdc-chip mat-mdc-chip-row mdc-evolution-chip mat-mdc-standard-chip tb-datakey-chip tb-datakey-chip-dnd-placeholder">
</div>
2023-02-24 19:25:19 +02:00
<mat-chip-row #chipRow *ngFor="let key of keys; let $index = index"
class="tb-datakey-chip"
(dndStart)="chipDragStart($index, chipRow, placeholderChipRow)"
(dndEnd)="chipDragEnd()"
[dndDraggable]="key"
2023-05-19 17:54:27 +03:00
[dndDisableIf]="disabled || dragDisabled"
2023-02-24 19:25:19 +02:00
dndType="{{ dndId }}"
dndEffectAllowed="move"
dndDraggingSourceClass="tb-chip-dragging"
[removable]="!disabled && !isCountDatasource"
2023-02-24 19:25:19 +02:00
(removed)="remove(key)">
2023-05-19 17:54:27 +03:00
<div dndDragImageRef fxLayout="row" fxLayoutAlign="start center" fxLayoutGap="4px" class="tb-attribute-chip"
2023-02-24 19:25:19 +02:00
[ngClass]="{'tb-dragging-chip-image': $index === dragIndex}">
<div class="tb-absolute-fill tb-dragging-chip-image-fill"></div>
2023-05-19 17:54:27 +03:00
<div dndHandle *ngIf="!disabled && !dragDisabled" class="tb-chip-drag-handle">
<mat-icon class="tb-mat-18">drag_indicator</mat-icon>
</div>
2023-02-24 19:25:19 +02:00
<div class="tb-chip-labels">
<div class="tb-chip-label">
<ng-container *ngIf="isEntityDatasource">
2023-05-19 17:54:27 +03:00
<mat-icon class="tb-mat-18 tb-datakey-icon" *ngIf="key.type === dataKeyTypes.alarm"
2023-02-24 19:25:19 +02:00
matTooltip="{{'datakey.alarm' | translate }}"
matTooltipPosition="above">notifications</mat-icon>
2023-05-19 17:54:27 +03:00
<mat-icon class="tb-mat-18 tb-datakey-icon" *ngIf="key.type === dataKeyTypes.attribute"
2023-02-24 19:25:19 +02:00
matTooltip="{{'datakey.attributes' | translate }}"
matTooltipPosition="above" svgIcon="mdi:alpha-a-circle-outline"></mat-icon>
2023-05-19 17:54:27 +03:00
<mat-icon class="tb-mat-18 tb-datakey-icon" *ngIf="key.type === dataKeyTypes.entityField"
2023-02-24 19:25:19 +02:00
matTooltip="{{'datakey.entity-field' | translate }}"
matTooltipPosition="above" svgIcon="mdi:alpha-e-circle-outline"></mat-icon>
2023-05-19 17:54:27 +03:00
<mat-icon class="tb-mat-18 tb-datakey-icon" *ngIf="key.type === dataKeyTypes.timeseries"
2023-02-24 19:25:19 +02:00
matTooltip="{{'datakey.timeseries' | translate }}"
matTooltipPosition="above">timeline</mat-icon>
</ng-container>
2023-05-19 17:54:27 +03:00
<span *ngIf="key.label !== key.name">{{key.label}}</span>
2023-02-24 19:25:19 +02:00
</div>
2023-05-19 17:54:27 +03:00
<div *ngIf="key.label !== key.name" class="tb-chip-separator">: </div>
2023-02-24 19:25:19 +02:00
<div class="tb-chip-label">
<strong>
<ng-container *ngTemplateOutlet="keyName; context:{key: key}"></ng-container>
</strong>
</div>
2023-02-23 19:01:53 +02:00
</div>
2023-05-19 17:54:27 +03:00
<div style="padding: 3px;">
<div class="tb-color-preview small box" (click)="showColorPicker(key)">
<div class="tb-color-result" [ngStyle]="{background: key.color}"></div>
</div>
</div>
2023-02-24 19:25:19 +02:00
<button *ngIf="!disabled"
type="button"
2023-05-19 17:54:27 +03:00
(click)="editDataKey(key, $index)" mat-icon-button class="tb-mat-24">
<mat-icon class="tb-mat-18">edit</mat-icon>
</button>
<button matChipRemove *ngIf="!disabled && !isCountDatasource"
type="button"
mat-icon-button class="tb-mat-24">
<mat-icon class="tb-mat-18">close</mat-icon>
2023-02-24 19:25:19 +02:00
</button>
</div>
2023-02-24 19:25:19 +02:00
</mat-chip-row>
2023-05-19 17:54:27 +03:00
<input matInput type="text" placeholder="{{ !disabled && (!maxDataKeysSet || keys.length < maxDataKeys) ? secondaryPlaceholder : '' }}"
2023-02-24 19:25:19 +02:00
[ngClass]="{'tb-dragging': dragIndex > -1}"
style="max-width: 200px;"
#keyInput
formControlName="key"
matAutocompleteOrigin
2023-05-19 17:54:27 +03:00
[readonly]="inputDisabled"
2023-02-24 19:25:19 +02:00
#origin="matAutocompleteOrigin"
[matAutocompleteConnectedTo]="origin"
(focusin)="onFocus()"
(drop)="$event.preventDefault();"
[matAutocomplete]="keyAutocomplete"
2023-05-19 17:54:27 +03:00
[matAutocompleteDisabled]="inputDisabled"
2023-02-24 19:25:19 +02:00
[matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes"
(matChipInputTokenEnd)="add($event)">
</div>
2023-02-17 19:24:01 +02:00
</mat-chip-grid>
<mat-autocomplete #keyAutocomplete="matAutocomplete"
class="tb-autocomplete"
2023-02-23 19:01:53 +02:00
panelWidth="fit-content"
[displayWith]="displayKeyFn">
<mat-option *ngFor="let key of filteredKeys | async" [value]="key">
<span style="white-space: nowrap;">
<ng-container *ngIf="isEntityDatasource">
2023-02-23 19:01:53 +02:00
<mat-icon class="tb-datakey-icon" *ngIf="key.type === dataKeyTypes.alarm"
matTooltip="{{'datakey.alarm' | translate }}"
matTooltipPosition="above">notifications</mat-icon>
<mat-icon class="tb-datakey-icon" *ngIf="key.type === dataKeyTypes.attribute"
matTooltip="{{'datakey.attributes' | translate }}"
matTooltipPosition="above" svgIcon="mdi:alpha-a-circle-outline"></mat-icon>
<mat-icon class="tb-datakey-icon" *ngIf="key.type === dataKeyTypes.entityField"
matTooltip="{{'datakey.entity-field' | translate }}"
matTooltipPosition="above" svgIcon="mdi:alpha-e-circle-outline"></mat-icon>
<mat-icon class="tb-datakey-icon" *ngIf="key.type === dataKeyTypes.timeseries"
matTooltip="{{'datakey.timeseries' | translate }}"
matTooltipPosition="above">timeline</mat-icon>
</ng-container>
<span [innerHTML]="key.name | highlight:searchText"></span>
</span>
</mat-option>
<mat-option *ngIf="!(filteredKeys | async)?.length" [value]="null" class="tb-not-found">
<div class="tb-not-found-content" (click)="$event.stopPropagation()">
<div *ngIf="!textIsNotEmpty(searchText); else searchNotEmpty">
<span translate>entity.no-keys-found</span>
</div>
<ng-template #searchNotEmpty>
<span>
{{ translate.get('entity.no-key-matching',
{key: truncate.transform(searchText, true, 6, &apos;...&apos;)}) | async }}
</span>
<span *ngIf="!isEntityDatasource; else createEntityKey">
<a translate (click)="createKey(searchText)">entity.create-new-key</a>
</span>
<ng-template #createEntityKey>
<span>{{'entity.create-new-key' | translate }} </span>
2023-02-23 19:01:53 +02:00
<mat-icon class="tb-datakey-icon new-key" *ngIf="widgetType === widgetTypes.alarm"
matTooltip="{{'datakey.alarm' | translate }}"
matTooltipPosition="above"
(click)="createKey(searchText, dataKeyTypes.alarm)">notifications</mat-icon>
<mat-icon class="tb-datakey-icon new-key" *ngIf="widgetType === widgetTypes.latest || widgetType === widgetTypes.alarm"
matTooltip="{{'datakey.attributes' | translate }}"
matTooltipPosition="above" svgIcon="mdi:alpha-a-circle-outline"
(click)="createKey(searchText, dataKeyTypes.attribute)"></mat-icon>
<mat-icon class="tb-datakey-icon new-key" *ngIf="widgetType === widgetTypes.latest || widgetType === widgetTypes.alarm"
matTooltip="{{'datakey.entity-field' | translate }}"
matTooltipPosition="above" svgIcon="mdi:alpha-e-circle-outline"
(click)="createKey(searchText, dataKeyTypes.entityField)"></mat-icon>
<mat-icon class="tb-datakey-icon new-key"
matTooltip="{{'datakey.timeseries' | translate }}"
matTooltipPosition="above"
(click)="createKey(searchText, dataKeyTypes.timeseries)">timeline</mat-icon>
</ng-template>
</ng-template>
</div>
</mat-option>
</mat-autocomplete>
<mat-error *ngIf="keysListFormGroup.get('keys').hasError('required')">
{{ requiredText }}
</mat-error>
</mat-form-field>
2023-05-19 17:54:27 +03:00
<div class="mat-caption" style="color: rgba(0,0,0,0.57);" *ngIf="maxDataKeysSet && maxDataKeys > 1">
{{ maxDataKeysText() }}
</div>
2023-02-23 19:01:53 +02:00
<ng-template #keyName let-key="key">
<ng-container *ngIf="dataKeyHasPostprocessing(key); else keyName">
<span>f(</span><ng-container *ngTemplateOutlet="keyNameTemplate; context:{key: key}"></ng-container><span>)</span>
</ng-container>
<ng-template #keyName>
<ng-container *ngTemplateOutlet="keyNameTemplate; context:{key: key}"></ng-container>
</ng-template>
</ng-template>
<ng-template #keyNameTemplate let-key="key">
<ng-container *ngIf="dataKeyHasAggregation(key); else keyName;">
<span class="tb-agg-func">{{ key.aggregationType }}</span><span>({{ key.name }})</span>
</ng-container>
<ng-template #keyName>
<span>{{key.name}}</span>
</ng-template>
</ng-template>