Showing
4 changed files
with
46 additions
and
12 deletions
... | ... | @@ -19,7 +19,7 @@ import { |
19 | 19 | Component, |
20 | 20 | DoCheck, |
21 | 21 | Input, |
22 | - IterableDiffers, | |
22 | + IterableDiffers, KeyValueDiffers, | |
23 | 23 | NgZone, |
24 | 24 | OnChanges, |
25 | 25 | OnDestroy, |
... | ... | @@ -42,7 +42,7 @@ import { |
42 | 42 | IDashboardComponent |
43 | 43 | } from '../../models/dashboard-component.models'; |
44 | 44 | import { ReplaySubject, Subject, Subscription } from 'rxjs'; |
45 | -import { WidgetLayouts } from '@shared/models/dashboard.models'; | |
45 | +import { WidgetLayout, WidgetLayouts } from '@shared/models/dashboard.models'; | |
46 | 46 | import { DialogService } from '@core/services/dialog.service'; |
47 | 47 | import { animatedScroll, deepClone, isDefined } from '@app/core/utils'; |
48 | 48 | import { BreakpointObserver } from '@angular/cdk/layout'; |
... | ... | @@ -154,7 +154,8 @@ export class DashboardComponent extends PageComponent implements IDashboardCompo |
154 | 154 | dashboardWidgets = new DashboardWidgets(this, |
155 | 155 | this.differs.find([]).create<Widget>((index, item) => { |
156 | 156 | return item; |
157 | - }) | |
157 | + }), | |
158 | + this.kvDiffers.find([]).create<string, WidgetLayout>() | |
158 | 159 | ); |
159 | 160 | |
160 | 161 | breakpointObserverSubscription: Subscription; |
... | ... | @@ -168,6 +169,7 @@ export class DashboardComponent extends PageComponent implements IDashboardCompo |
168 | 169 | private dialogService: DialogService, |
169 | 170 | private breakpointObserver: BreakpointObserver, |
170 | 171 | private differs: IterableDiffers, |
172 | + private kvDiffers: KeyValueDiffers, | |
171 | 173 | private ngZone: NgZone) { |
172 | 174 | super(store); |
173 | 175 | this.authUser = getCurrentAuthUser(store); | ... | ... |
... | ... | @@ -529,7 +529,9 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI |
529 | 529 | this.cafs.reinit = null; |
530 | 530 | } |
531 | 531 | this.cafs.reinit = this.raf.raf(() => { |
532 | - this.reInitImpl(); | |
532 | + this.ngZone.run(() => { | |
533 | + this.reInitImpl(); | |
534 | + }); | |
533 | 535 | }); |
534 | 536 | } |
535 | 537 | |
... | ... | @@ -541,6 +543,7 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI |
541 | 543 | if (this.destroyed) { |
542 | 544 | this.onDestroy(); |
543 | 545 | } else { |
546 | + this.widgetContext.reset(); | |
544 | 547 | this.subscriptionInited = true; |
545 | 548 | this.configureDynamicWidgetComponent(); |
546 | 549 | this.cd.detectChanges(); |
... | ... | @@ -551,12 +554,14 @@ export class WidgetComponent extends PageComponent implements OnInit, AfterViewI |
551 | 554 | if (this.destroyed) { |
552 | 555 | this.onDestroy(); |
553 | 556 | } else { |
557 | + this.widgetContext.reset(); | |
554 | 558 | this.subscriptionInited = true; |
555 | 559 | this.onInit(); |
556 | 560 | } |
557 | 561 | } |
558 | 562 | ); |
559 | 563 | } else { |
564 | + this.widgetContext.reset(); | |
560 | 565 | this.subscriptionInited = true; |
561 | 566 | this.configureDynamicWidgetComponent(); |
562 | 567 | this.cd.detectChanges(); | ... | ... |
... | ... | @@ -101,15 +101,16 @@ export class DashboardWidgets implements Iterable<DashboardWidget> { |
101 | 101 | } |
102 | 102 | |
103 | 103 | constructor(private dashboard: IDashboardComponent, |
104 | - private widgetsDiffer: IterableDiffer<Widget>) { | |
104 | + private widgetsDiffer: IterableDiffer<Widget>, | |
105 | + private widgetLayoutsDiffer: KeyValueDiffer<string, WidgetLayout>) { | |
105 | 106 | } |
106 | 107 | |
107 | 108 | doCheck() { |
108 | 109 | const widgetChange = this.widgetsDiffer.diff(this.widgets); |
109 | - if (widgetChange !== null) { | |
110 | - | |
111 | - const updateRecords: Array<DashboardWidgetUpdateRecord> = []; | |
110 | + const widgetLayoutChange = this.widgetLayoutsDiffer.diff(this.widgetLayouts); | |
111 | + const updateRecords: Array<DashboardWidgetUpdateRecord> = []; | |
112 | 112 | |
113 | + if (widgetChange !== null) { | |
113 | 114 | widgetChange.forEachAddedItem((added) => { |
114 | 115 | updateRecords.push({ |
115 | 116 | widget: added.item, |
... | ... | @@ -130,6 +131,25 @@ export class DashboardWidgets implements Iterable<DashboardWidget> { |
130 | 131 | updateRecords.push(operation); |
131 | 132 | } |
132 | 133 | }); |
134 | + } | |
135 | + if (widgetLayoutChange !== null) { | |
136 | + widgetLayoutChange.forEachChangedItem((changed) => { | |
137 | + let operation = updateRecords.find((record) => record.widgetId === changed.key); | |
138 | + if (!operation) { | |
139 | + let index = this.dashboardWidgets.findIndex((dashboardWidget) => dashboardWidget.widgetId === changed.key); | |
140 | + if (index > -1) { | |
141 | + const widget = this.dashboardWidgets[index]; | |
142 | + updateRecords.push({ | |
143 | + widget: widget.widget, | |
144 | + widgetId: changed.key, | |
145 | + widgetLayout: changed.currentValue, | |
146 | + operation: 'update' | |
147 | + }); | |
148 | + } | |
149 | + } | |
150 | + }); | |
151 | + } | |
152 | + if (updateRecords.length) { | |
133 | 153 | updateRecords.forEach((record) => { |
134 | 154 | switch (record.operation) { |
135 | 155 | case 'add': |
... | ... | @@ -147,7 +167,7 @@ export class DashboardWidgets implements Iterable<DashboardWidget> { |
147 | 167 | index = this.dashboardWidgets.findIndex((dashboardWidget) => dashboardWidget.widgetId === record.widgetId); |
148 | 168 | if (index > -1) { |
149 | 169 | const prevDashboardWidget = this.dashboardWidgets[index]; |
150 | - if (!deepEqual(prevDashboardWidget.widget, record.widget)) { | |
170 | + if (!deepEqual(prevDashboardWidget.widget, record.widget) || !deepEqual(prevDashboardWidget.widgetLayout, record.widgetLayout)) { | |
151 | 171 | this.dashboardWidgets[index] = new DashboardWidget(this.dashboard, record.widget, record.widgetLayout); |
152 | 172 | this.dashboardWidgets[index].highlighted = prevDashboardWidget.highlighted; |
153 | 173 | this.dashboardWidgets[index].selected = prevDashboardWidget.selected; |
... | ... | @@ -159,9 +179,7 @@ export class DashboardWidgets implements Iterable<DashboardWidget> { |
159 | 179 | break; |
160 | 180 | } |
161 | 181 | }); |
162 | - if (updateRecords.length) { | |
163 | - this.updateRowsAndSort(); | |
164 | - } | |
182 | + this.updateRowsAndSort(); | |
165 | 183 | } |
166 | 184 | } |
167 | 185 | ... | ... |
... | ... | @@ -130,6 +130,15 @@ export class WidgetContext { |
130 | 130 | } |
131 | 131 | } |
132 | 132 | |
133 | + reset() { | |
134 | + this.destroyed = false; | |
135 | + this.hideTitlePanel = false; | |
136 | + this.widgetTitleTemplate = undefined; | |
137 | + this.widgetTitle = undefined; | |
138 | + this.customHeaderActions = undefined; | |
139 | + this.widgetActions = undefined; | |
140 | + } | |
141 | + | |
133 | 142 | inited = false; |
134 | 143 | destroyed = false; |
135 | 144 | ... | ... |