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