Commit 51b5fee7b7a84ef08823cc43129b6934c059de62

Authored by Vladyslav_Prykhodko
1 parent 953054fa

UI: Fixed init dataKeys widget autocomplete after change datasourceType

@@ -20,7 +20,7 @@ @@ -20,7 +20,7 @@
20 <mat-chip 20 <mat-chip
21 *ngFor="let key of keys; let $index = index" 21 *ngFor="let key of keys; let $index = index"
22 [selectable]="!disabled" 22 [selectable]="!disabled"
23 - [removable]="!disabled && datasourceType !== datasourceTypes.entityCount" 23 + [removable]="!disabled && !isEntityCountDatasource"
24 (removed)="remove(key)"> 24 (removed)="remove(key)">
25 <div fxLayout="row" fxLayoutAlign="start center" class="tb-attribute-chip"> 25 <div fxLayout="row" fxLayoutAlign="start center" class="tb-attribute-chip">
26 <div *ngIf="!disabled" class="tb-chip-drag-handle" style="margin-right: 5px;"> 26 <div *ngIf="!disabled" class="tb-chip-drag-handle" style="margin-right: 5px;">
@@ -31,7 +31,7 @@ @@ -31,7 +31,7 @@
31 </div> 31 </div>
32 <div class="tb-chip-labels"> 32 <div class="tb-chip-labels">
33 <div class="tb-chip-label"> 33 <div class="tb-chip-label">
34 - <span *ngIf="datasourceType !== datasourceTypes.function && datasourceType !== datasourceTypes.entityCount"> 34 + <span *ngIf="datasourceType === datasourceTypes.entity">
35 <span *ngIf="key.type === dataKeyTypes.alarm" 35 <span *ngIf="key.type === dataKeyTypes.alarm"
36 matTooltip="{{'datakey.alarm' | translate }}" 36 matTooltip="{{'datakey.alarm' | translate }}"
37 matTooltipPosition="above"> 37 matTooltipPosition="above">
@@ -70,7 +70,7 @@ @@ -70,7 +70,7 @@
70 (click)="editDataKey(key, $index)" mat-button mat-icon-button class="tb-mat-32"> 70 (click)="editDataKey(key, $index)" mat-button mat-icon-button class="tb-mat-32">
71 <mat-icon class="tb-mat-20">edit</mat-icon> 71 <mat-icon class="tb-mat-20">edit</mat-icon>
72 </button> 72 </button>
73 - <mat-icon matChipRemove *ngIf="!disabled && datasourceType !== datasourceTypes.entityCount">close</mat-icon> 73 + <mat-icon matChipRemove *ngIf="!disabled && !isEntityCountDatasource">close</mat-icon>
74 </div> 74 </div>
75 </mat-chip> 75 </mat-chip>
76 <input matInput type="text" placeholder="{{ !disabled ? placeholder : '' }}" 76 <input matInput type="text" placeholder="{{ !disabled ? placeholder : '' }}"
@@ -78,10 +78,12 @@ @@ -78,10 +78,12 @@
78 #keyInput 78 #keyInput
79 formControlName="key" 79 formControlName="key"
80 matAutocompleteOrigin 80 matAutocompleteOrigin
  81 + [readonly]="isEntityCountDatasource"
81 #origin="matAutocompleteOrigin" 82 #origin="matAutocompleteOrigin"
82 [matAutocompleteConnectedTo]="origin" 83 [matAutocompleteConnectedTo]="origin"
83 (focusin)="onFocus()" 84 (focusin)="onFocus()"
84 [matAutocomplete]="keyAutocomplete" 85 [matAutocomplete]="keyAutocomplete"
  86 + [matAutocompleteDisabled]="isEntityCountDatasource"
85 [matChipInputFor]="chipList" 87 [matChipInputFor]="chipList"
86 [matChipInputSeparatorKeyCodes]="separatorKeysCodes" 88 [matChipInputSeparatorKeyCodes]="separatorKeysCodes"
87 (matChipInputTokenEnd)="add($event)"> 89 (matChipInputTokenEnd)="add($event)">
@@ -91,7 +93,7 @@ @@ -91,7 +93,7 @@
91 [displayWith]="displayKeyFn"> 93 [displayWith]="displayKeyFn">
92 <mat-option *ngFor="let key of filteredKeys | async" [value]="key"> 94 <mat-option *ngFor="let key of filteredKeys | async" [value]="key">
93 <span style="white-space: nowrap;"> 95 <span style="white-space: nowrap;">
94 - <span *ngIf="datasourceType !== datasourceTypes.function && datasourceType !== datasourceTypes.entityCount"> 96 + <span *ngIf="datasourceType === datasourceTypes.entity">
95 <span *ngIf="key.type === dataKeyTypes.alarm" 97 <span *ngIf="key.type === dataKeyTypes.alarm"
96 matTooltip="{{'datakey.alarm' | translate }}" 98 matTooltip="{{'datakey.alarm' | translate }}"
97 matTooltipPosition="above"> 99 matTooltipPosition="above">
@@ -128,7 +130,7 @@ @@ -128,7 +130,7 @@
128 {{ translate.get('entity.no-key-matching', 130 {{ translate.get('entity.no-key-matching',
129 {key: truncate.transform(searchText, true, 6, &apos;...&apos;)}) | async }} 131 {key: truncate.transform(searchText, true, 6, &apos;...&apos;)}) | async }}
130 </span> 132 </span>
131 - <span *ngIf="datasourceType === datasourceTypes.function || datasourceType === datasourceTypes.entityCount; else createEntityKey"> 133 + <span *ngIf="datasourceType !== datasourceTypes.entity; else createEntityKey">
132 <a translate (click)="createKey(searchText)">entity.create-new-key</a> 134 <a translate (click)="createKey(searchText)">entity.create-new-key</a>
133 </span> 135 </span>
134 <ng-template #createEntityKey> 136 <ng-template #createEntityKey>
@@ -121,7 +121,7 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie @@ -121,7 +121,7 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
121 121
122 private requiredValue: boolean; 122 private requiredValue: boolean;
123 get required(): boolean { 123 get required(): boolean {
124 - return this.requiredValue || !this.optDataKeys || this.datasourceType === DatasourceType.entityCount; 124 + return this.requiredValue || !this.optDataKeys || this.isEntityCountDatasource;
125 } 125 }
126 @Input() 126 @Input()
127 set required(value: boolean) { 127 set required(value: boolean) {
@@ -217,7 +217,7 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie @@ -217,7 +217,7 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
217 if (this.maxDataKeys !== null && this.maxDataKeys > -1) { 217 if (this.maxDataKeys !== null && this.maxDataKeys > -1) {
218 if (this.datasourceType === DatasourceType.function) { 218 if (this.datasourceType === DatasourceType.function) {
219 return this.translate.instant('datakey.maximum-function-types', {count: this.maxDataKeys}); 219 return this.translate.instant('datakey.maximum-function-types', {count: this.maxDataKeys});
220 - } else if (this.datasourceType !== DatasourceType.entityCount) { 220 + } else if (!this.isEntityCountDatasource) {
221 return this.translate.instant('datakey.maximum-timeseries-or-attributes', {count: this.maxDataKeys}); 221 return this.translate.instant('datakey.maximum-timeseries-or-attributes', {count: this.maxDataKeys});
222 } else { 222 } else {
223 return ''; 223 return '';
@@ -250,7 +250,7 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie @@ -250,7 +250,7 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
250 private reset() { 250 private reset() {
251 if (this.widgetType === widgetType.alarm) { 251 if (this.widgetType === widgetType.alarm) {
252 this.keys = this.utils.getDefaultAlarmDataKeys(); 252 this.keys = this.utils.getDefaultAlarmDataKeys();
253 - } else if (this.datasourceType === DatasourceType.entityCount) { 253 + } else if (this.isEntityCountDatasource) {
254 this.keys = [this.callbacks.generateDataKey('count', DataKeyType.count)]; 254 this.keys = [this.callbacks.generateDataKey('count', DataKeyType.count)];
255 } else { 255 } else {
256 this.keys = []; 256 this.keys = [];
@@ -271,11 +271,10 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie @@ -271,11 +271,10 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
271 const change = changes[propName]; 271 const change = changes[propName];
272 if (!change.firstChange && change.currentValue !== change.previousValue) { 272 if (!change.firstChange && change.currentValue !== change.previousValue) {
273 if (propName === 'entityAliasId') { 273 if (propName === 'entityAliasId') {
274 - this.searchText = '';  
275 - this.fetchObservable$ = null;  
276 - this.latestSearchTextResult = null; 274 + this.clearSearchCache();
277 this.dirty = true; 275 this.dirty = true;
278 } else if (['widgetType', 'datasourceType'].includes(propName)) { 276 } else if (['widgetType', 'datasourceType'].includes(propName)) {
  277 + this.clearSearchCache();
279 this.updateParams(); 278 this.updateParams();
280 setTimeout(() => { 279 setTimeout(() => {
281 this.reset(); 280 this.reset();
@@ -436,20 +435,18 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie @@ -436,20 +435,18 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
436 if (this.datasourceType === DatasourceType.function) { 435 if (this.datasourceType === DatasourceType.function) {
437 const targetKeysList = this.widgetType === widgetType.alarm ? this.alarmKeys : this.functionTypeKeys; 436 const targetKeysList = this.widgetType === widgetType.alarm ? this.alarmKeys : this.functionTypeKeys;
438 fetchObservable = of(targetKeysList); 437 fetchObservable = of(targetKeysList);
439 - } else {  
440 - if (this.datasourceType !== DatasourceType.entityCount && this.entityAliasId) {  
441 - const dataKeyTypes = [DataKeyType.timeseries];  
442 - if (this.widgetType === widgetType.latest || this.widgetType === widgetType.alarm) {  
443 - dataKeyTypes.push(DataKeyType.attribute);  
444 - dataKeyTypes.push(DataKeyType.entityField);  
445 - if (this.widgetType === widgetType.alarm) {  
446 - dataKeyTypes.push(DataKeyType.alarm);  
447 - } 438 + } else if (this.datasourceType === DatasourceType.entity && this.entityAliasId) {
  439 + const dataKeyTypes = [DataKeyType.timeseries];
  440 + if (this.widgetType === widgetType.latest || this.widgetType === widgetType.alarm) {
  441 + dataKeyTypes.push(DataKeyType.attribute);
  442 + dataKeyTypes.push(DataKeyType.entityField);
  443 + if (this.widgetType === widgetType.alarm) {
  444 + dataKeyTypes.push(DataKeyType.alarm);
448 } 445 }
449 - fetchObservable = this.callbacks.fetchEntityKeys(this.entityAliasId, dataKeyTypes);  
450 - } else {  
451 - fetchObservable = of([]);  
452 } 446 }
  447 + fetchObservable = this.callbacks.fetchEntityKeys(this.entityAliasId, dataKeyTypes);
  448 + } else {
  449 + fetchObservable = of([]);
453 } 450 }
454 this.fetchObservable$ = fetchObservable.pipe( 451 this.fetchObservable$ = fetchObservable.pipe(
455 publishReplay(1), 452 publishReplay(1),
@@ -477,4 +474,13 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie @@ -477,4 +474,13 @@ export class DataKeysComponent implements ControlValueAccessor, OnInit, AfterVie
477 }, 0); 474 }, 0);
478 } 475 }
479 476
  477 + get isEntityCountDatasource(): boolean {
  478 + return this.datasourceType === DatasourceType.entityCount;
  479 + }
  480 +
  481 + private clearSearchCache() {
  482 + this.searchText = '';
  483 + this.fetchObservable$ = null;
  484 + this.latestSearchTextResult = null;
  485 + }
480 } 486 }