Commit 499a6dbe7f1c69ae16177e1c40985bbcbc325a91
1 parent
bde3ff84
UI: Refactoring attributes-table component, add changeDetection for load widget bundle
Showing
3 changed files
with
18 additions
and
11 deletions
... | ... | @@ -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,17 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI |
440 | 442 | } |
441 | 443 | } |
442 | 444 | |
443 | - onWidgetsBundleChanged() { | |
445 | + onWidgetsBundleChanged(widgetsBundle: WidgetsBundle) { | |
444 | 446 | if (this.mode === 'widget') { |
445 | 447 | this.widgetsList = []; |
446 | 448 | this.widgetsListCache = []; |
447 | 449 | this.widgetsCarouselIndex = 0; |
448 | - if (this.widgetsBundle) { | |
450 | + this.widgetBundleSet = false; | |
451 | + if (widgetsBundle) { | |
449 | 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 | 456 | this.widgetService.getBundleWidgetTypes(bundleAlias, isSystem).subscribe( |
453 | 457 | (widgetTypes) => { |
454 | 458 | widgetTypes = widgetTypes.sort((a, b) => { |
... | ... | @@ -486,6 +490,7 @@ export class AttributeTableComponent extends PageComponent implements AfterViewI |
486 | 490 | } |
487 | 491 | } |
488 | 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 | 515 | |
511 | 516 | exitWidgetMode() { |
512 | 517 | this.selectedWidgetsBundleAlias = null; |
518 | + this.widgetBundleSet = false; | |
513 | 519 | this.mode = 'default'; |
514 | 520 | } |
515 | 521 | ... | ... |