Commit 499a6dbe7f1c69ae16177e1c40985bbcbc325a91

Authored by Vladyslav_Prykhodko
1 parent bde3ff84

UI: Refactoring attributes-table component, add changeDetection for load widget bundle

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