Browse Source

Merge pull request #4218 from vvlladd28/improvement/data-key/autocomplete

UI: Fixed init dataKeys widget autocomplete after change datasourceType
pull/4247/head
Igor Kulikov 6 years ago
committed by GitHub
parent
commit
e99d1b06f1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      ui-ngx/src/app/modules/home/components/widget/data-keys.component.html
  2. 42
      ui-ngx/src/app/modules/home/components/widget/data-keys.component.ts

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

@ -20,7 +20,7 @@
<mat-chip <mat-chip
*ngFor="let key of keys; let $index = index" *ngFor="let key of keys; let $index = index"
[selectable]="!disabled" [selectable]="!disabled"
[removable]="!disabled && datasourceType !== datasourceTypes.entityCount" [removable]="!disabled && !isEntityCountDatasource"
(removed)="remove(key)"> (removed)="remove(key)">
<div fxLayout="row" fxLayoutAlign="start center" class="tb-attribute-chip"> <div fxLayout="row" fxLayoutAlign="start center" class="tb-attribute-chip">
<div *ngIf="!disabled" class="tb-chip-drag-handle" style="margin-right: 5px;"> <div *ngIf="!disabled" class="tb-chip-drag-handle" style="margin-right: 5px;">
@ -31,7 +31,7 @@
</div> </div>
<div class="tb-chip-labels"> <div class="tb-chip-labels">
<div class="tb-chip-label"> <div class="tb-chip-label">
<span *ngIf="datasourceType !== datasourceTypes.function && datasourceType !== datasourceTypes.entityCount"> <span *ngIf="datasourceType === datasourceTypes.entity">
<span *ngIf="key.type === dataKeyTypes.alarm" <span *ngIf="key.type === dataKeyTypes.alarm"
matTooltip="{{'datakey.alarm' | translate }}" matTooltip="{{'datakey.alarm' | translate }}"
matTooltipPosition="above"> matTooltipPosition="above">
@ -70,7 +70,7 @@
(click)="editDataKey(key, $index)" mat-button mat-icon-button class="tb-mat-32"> (click)="editDataKey(key, $index)" mat-button mat-icon-button class="tb-mat-32">
<mat-icon class="tb-mat-20">edit</mat-icon> <mat-icon class="tb-mat-20">edit</mat-icon>
</button> </button>
<mat-icon matChipRemove *ngIf="!disabled && datasourceType !== datasourceTypes.entityCount">close</mat-icon> <mat-icon matChipRemove *ngIf="!disabled && !isEntityCountDatasource">close</mat-icon>
</div> </div>
</mat-chip> </mat-chip>
<input matInput type="text" placeholder="{{ !disabled ? placeholder : '' }}" <input matInput type="text" placeholder="{{ !disabled ? placeholder : '' }}"
@ -78,10 +78,12 @@
#keyInput #keyInput
formControlName="key" formControlName="key"
matAutocompleteOrigin matAutocompleteOrigin
[readonly]="isEntityCountDatasource"
#origin="matAutocompleteOrigin" #origin="matAutocompleteOrigin"
[matAutocompleteConnectedTo]="origin" [matAutocompleteConnectedTo]="origin"
(focusin)="onFocus()" (focusin)="onFocus()"
[matAutocomplete]="keyAutocomplete" [matAutocomplete]="keyAutocomplete"
[matAutocompleteDisabled]="isEntityCountDatasource"
[matChipInputFor]="chipList" [matChipInputFor]="chipList"
[matChipInputSeparatorKeyCodes]="separatorKeysCodes" [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
(matChipInputTokenEnd)="add($event)"> (matChipInputTokenEnd)="add($event)">
@ -91,7 +93,7 @@
[displayWith]="displayKeyFn"> [displayWith]="displayKeyFn">
<mat-option *ngFor="let key of filteredKeys | async" [value]="key"> <mat-option *ngFor="let key of filteredKeys | async" [value]="key">
<span style="white-space: nowrap;"> <span style="white-space: nowrap;">
<span *ngIf="datasourceType !== datasourceTypes.function && datasourceType !== datasourceTypes.entityCount"> <span *ngIf="datasourceType === datasourceTypes.entity">
<span *ngIf="key.type === dataKeyTypes.alarm" <span *ngIf="key.type === dataKeyTypes.alarm"
matTooltip="{{'datakey.alarm' | translate }}" matTooltip="{{'datakey.alarm' | translate }}"
matTooltipPosition="above"> matTooltipPosition="above">
@ -128,7 +130,7 @@
{{ translate.get('entity.no-key-matching', {{ translate.get('entity.no-key-matching',
{key: truncate.transform(searchText, true, 6, &apos;...&apos;)}) | async }} {key: truncate.transform(searchText, true, 6, &apos;...&apos;)}) | async }}
</span> </span>
<span *ngIf="datasourceType === datasourceTypes.function || datasourceType === datasourceTypes.entityCount; else createEntityKey"> <span *ngIf="datasourceType !== datasourceTypes.entity; else createEntityKey">
<a translate (click)="createKey(searchText)">entity.create-new-key</a> <a translate (click)="createKey(searchText)">entity.create-new-key</a>
</span> </span>
<ng-template #createEntityKey> <ng-template #createEntityKey>

42
ui-ngx/src/app/modules/home/components/widget/data-keys.component.ts

@ -121,7 +121,7 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
private requiredValue: boolean; private requiredValue: boolean;
get required(): boolean { get required(): boolean {
return this.requiredValue || !this.optDataKeys || this.datasourceType === DatasourceType.entityCount; return this.requiredValue || !this.optDataKeys || this.isEntityCountDatasource;
} }
@Input() @Input()
set required(value: boolean) { set required(value: boolean) {
@ -217,7 +217,7 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
if (this.maxDataKeys !== null && this.maxDataKeys > -1) { if (this.maxDataKeys !== null && this.maxDataKeys > -1) {
if (this.datasourceType === DatasourceType.function) { if (this.datasourceType === DatasourceType.function) {
return this.translate.instant('datakey.maximum-function-types', {count: this.maxDataKeys}); return this.translate.instant('datakey.maximum-function-types', {count: this.maxDataKeys});
} else if (this.datasourceType !== DatasourceType.entityCount) { } else if (!this.isEntityCountDatasource) {
return this.translate.instant('datakey.maximum-timeseries-or-attributes', {count: this.maxDataKeys}); return this.translate.instant('datakey.maximum-timeseries-or-attributes', {count: this.maxDataKeys});
} else { } else {
return ''; return '';
@ -250,7 +250,7 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
private reset() { private reset() {
if (this.widgetType === widgetType.alarm) { if (this.widgetType === widgetType.alarm) {
this.keys = this.utils.getDefaultAlarmDataKeys(); this.keys = this.utils.getDefaultAlarmDataKeys();
} else if (this.datasourceType === DatasourceType.entityCount) { } else if (this.isEntityCountDatasource) {
this.keys = [this.callbacks.generateDataKey('count', DataKeyType.count)]; this.keys = [this.callbacks.generateDataKey('count', DataKeyType.count)];
} else { } else {
this.keys = []; this.keys = [];
@ -271,11 +271,10 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
const change = changes[propName]; const change = changes[propName];
if (!change.firstChange && change.currentValue !== change.previousValue) { if (!change.firstChange && change.currentValue !== change.previousValue) {
if (propName === 'entityAliasId') { if (propName === 'entityAliasId') {
this.searchText = ''; this.clearSearchCache();
this.fetchObservable$ = null;
this.latestSearchTextResult = null;
this.dirty = true; this.dirty = true;
} else if (['widgetType', 'datasourceType'].includes(propName)) { } else if (['widgetType', 'datasourceType'].includes(propName)) {
this.clearSearchCache();
this.updateParams(); this.updateParams();
setTimeout(() => { setTimeout(() => {
this.reset(); this.reset();
@ -436,20 +435,18 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
if (this.datasourceType === DatasourceType.function) { if (this.datasourceType === DatasourceType.function) {
const targetKeysList = this.widgetType === widgetType.alarm ? this.alarmKeys : this.functionTypeKeys; const targetKeysList = this.widgetType === widgetType.alarm ? this.alarmKeys : this.functionTypeKeys;
fetchObservable = of(targetKeysList); fetchObservable = of(targetKeysList);
} else { } else if (this.datasourceType === DatasourceType.entity && this.entityAliasId) {
if (this.datasourceType !== DatasourceType.entityCount && this.entityAliasId) { const dataKeyTypes = [DataKeyType.timeseries];
const dataKeyTypes = [DataKeyType.timeseries]; if (this.widgetType === widgetType.latest || this.widgetType === widgetType.alarm) {
if (this.widgetType === widgetType.latest || this.widgetType === widgetType.alarm) { dataKeyTypes.push(DataKeyType.attribute);
dataKeyTypes.push(DataKeyType.attribute); dataKeyTypes.push(DataKeyType.entityField);
dataKeyTypes.push(DataKeyType.entityField); if (this.widgetType === widgetType.alarm) {
if (this.widgetType === widgetType.alarm) { dataKeyTypes.push(DataKeyType.alarm);
dataKeyTypes.push(DataKeyType.alarm);
}
} }
fetchObservable = this.callbacks.fetchEntityKeys(this.entityAliasId, dataKeyTypes);
} else {
fetchObservable = of([]);
} }
fetchObservable = this.callbacks.fetchEntityKeys(this.entityAliasId, dataKeyTypes);
} else {
fetchObservable = of([]);
} }
this.fetchObservable$ = fetchObservable.pipe( this.fetchObservable$ = fetchObservable.pipe(
publishReplay(1), publishReplay(1),
@ -477,4 +474,13 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
}, 0); }, 0);
} }
get isEntityCountDatasource(): boolean {
return this.datasourceType === DatasourceType.entityCount;
}
private clearSearchCache() {
this.searchText = '';
this.fetchObservable$ = null;
this.latestSearchTextResult = null;
}
} }

Loading…
Cancel
Save