Commit db48d900ae193b4dd96361fad215468eaed9b999

Authored by Igor Kulikov
Committed by GitHub
2 parents 104d0344 7f256b42

Merge pull request #5170 from vvlladd28/bug/widget-bundle-select

UI: When clicking the button "Show on widget", the default widget bun…
... ... @@ -112,8 +112,8 @@
112 112 fxFlex
113 113 [selectFirstBundle]="false"
114 114 [selectBundleAlias]="selectedWidgetsBundleAlias"
115   - [(ngModel)]="widgetsBundle"
116   - (ngModelChange)="onWidgetsBundleChanged()">
  115 + [ngModel]="null"
  116 + (ngModelChange)="onWidgetsBundleChanged($event)">
117 117 </tb-widgets-bundle-select>
118 118 </div>
119 119 <button mat-raised-button [fxShow]="widgetsList.length > 0"
... ... @@ -245,11 +245,11 @@
245 245 </ngx-hm-carousel>
246 246 <span translate *ngIf="mode === 'widget' && widgetsLoaded &&
247 247 widgetsList.length === 0 &&
248   - widgetsBundle"
  248 + widgetBundleSet"
249 249 fxFlex fxLayoutAlign="center center"
250 250 style="display: flex;"
251 251 class="mat-headline">widgets-bundle.empty</span>
252   - <span translate *ngIf="mode === 'widget' && !widgetsBundle"
  252 + <span translate *ngIf="mode === 'widget' && !widgetBundleSet"
253 253 fxFlex fxLayoutAlign="center center"
254 254 style="display: flex;"
255 255 class="mat-headline">widget.select-widgets-bundle</span>
... ...
... ... @@ -17,6 +17,7 @@
17 17 import {
18 18 AfterViewInit,
19 19 ChangeDetectionStrategy,
  20 + ChangeDetectorRef,
20 21 Component,
21 22 ElementRef,
22 23 Injector,
... ... @@ -118,7 +119,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
118 119 viewsInited = false;
119 120
120 121 selectedWidgetsBundleAlias: string = null;
121   - widgetsBundle: WidgetsBundle = null;
  122 + widgetBundleSet = false;
122 123 widgetsLoaded = false;
123 124 widgetsCarouselIndex = 0;
124 125 widgetsList: Array<Array<Widget>> = [];
... ... @@ -182,7 +183,8 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
182 183 private utils: UtilsService,
183 184 private dashboardUtils: DashboardUtilsService,
184 185 private widgetService: WidgetService,
185   - private zone: NgZone) {
  186 + private zone: NgZone,
  187 + private cd: ChangeDetectorRef) {
186 188 super(store);
187 189 this.dirtyValue = !this.activeValue;
188 190 const sortOrder: SortOrder = { property: 'key', direction: Direction.ASC };
... ... @@ -380,8 +382,8 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
380 382 this.widgetsList = [];
381 383 this.widgetsListCache = [];
382 384 this.widgetsLoaded = false;
  385 + this.widgetBundleSet = false;
383 386 this.widgetsCarouselIndex = 0;
384   - this.widgetsBundle = null;
385 387 this.selectedWidgetsBundleAlias = 'cards';
386 388
387 389 const entityAlias: EntityAlias = {
... ... @@ -440,15 +442,16 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
440 442 }
441 443 }
442 444
443   - onWidgetsBundleChanged() {
  445 + onWidgetsBundleChanged(widgetsBundle: WidgetsBundle) {
  446 + this.widgetBundleSet = !!widgetsBundle;
444 447 if (this.mode === 'widget') {
445 448 this.widgetsList = [];
446 449 this.widgetsListCache = [];
447   - this.widgetsCarouselIndex = 0;
448   - if (this.widgetsBundle) {
  450 + this.widgetsCarouselIndex = 0;
  451 + if (widgetsBundle) {
449 452 this.widgetsLoaded = false;
450   - const bundleAlias = this.widgetsBundle.alias;
451   - const isSystem = this.widgetsBundle.tenantId.id === NULL_UUID;
  453 + const bundleAlias = widgetsBundle.alias;
  454 + const isSystem = widgetsBundle.tenantId.id === NULL_UUID;
452 455 this.widgetService.getBundleWidgetTypes(bundleAlias, isSystem).subscribe(
453 456 (widgetTypes) => {
454 457 widgetTypes = widgetTypes.sort((a, b) => {
... ... @@ -486,6 +489,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI
486 489 }
487 490 }
488 491 this.widgetsLoaded = true;
  492 + this.cd.markForCheck();
489 493 }
490 494 );
491 495 }
... ...
... ... @@ -140,6 +140,9 @@ export class WidgetsBundleSelectComponent implements ControlValueAccessor, OnIni
140 140 this.widgetsBundle = found;
141 141 this.updateView();
142 142 }
  143 + } else if (this.widgetsBundle) {
  144 + this.widgetsBundle = null;
  145 + this.updateView();
143 146 }
144 147 }
145 148
... ...