Browse Source

UI: Fix handling dashboard page router data

pull/7758/head
Igor Kulikov 4 years ago
parent
commit
3a3771db64
  1. 33
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts
  2. 7
      ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.models.ts

33
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.component.ts

@ -56,7 +56,7 @@ import { WINDOW } from '@core/services/window.service';
import { WindowMessage } from '@shared/models/window-message.model'; import { WindowMessage } from '@shared/models/window-message.model';
import { deepClone, guid, isDefined, isDefinedAndNotNull, isNotEmptyStr } from '@app/core/utils'; import { deepClone, guid, isDefined, isDefinedAndNotNull, isNotEmptyStr } from '@app/core/utils';
import { import {
DashboardContext, DashboardContext, DashboardPageInitData,
DashboardPageLayout, DashboardPageLayout,
DashboardPageLayoutContext, DashboardPageLayoutContext,
DashboardPageLayouts, DashboardPageLayouts,
@ -365,15 +365,23 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
ngOnInit() { ngOnInit() {
this.rxSubscriptions.push(this.route.data.subscribe( this.rxSubscriptions.push(this.route.data.subscribe(
(data) => { (data) => {
let dashboardPageInitData: DashboardPageInitData;
if (this.embedded) { if (this.embedded) {
data.dashboard = this.dashboardUtils.validateAndUpdateDashboard(this.dashboard); dashboardPageInitData = {
data.currentDashboardId = this.dashboard.id ? this.dashboard.id.id : null; dashboard: this.dashboardUtils.validateAndUpdateDashboard(this.dashboard),
data.widgetEditMode = false; currentDashboardId: this.dashboard.id ? this.dashboard.id.id : null,
data.singlePageMode = false; widgetEditMode: false,
singlePageMode: false
};
} else { } else {
data.currentDashboardId = this.route.snapshot.params.dashboardId; dashboardPageInitData = {
dashboard: data.dashboard,
currentDashboardId: this.route.snapshot.params.dashboardId,
widgetEditMode: data.widgetEditMode,
singlePageMode: data.singlePageMode
};
} }
this.init(data); this.init(dashboardPageInitData);
this.runChangeDetection(); this.runChangeDetection();
} }
)); ));
@ -406,7 +414,7 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
} }
} }
private init(data: any) { private init(data: DashboardPageInitData) {
this.reset(); this.reset();
@ -1492,11 +1500,12 @@ export class DashboardPageComponent extends PageComponent implements IDashboardC
versionControlPopover.tbComponentRef.instance.versionRestored.subscribe(() => { versionControlPopover.tbComponentRef.instance.versionRestored.subscribe(() => {
this.dashboardService.getDashboard(this.currentDashboardId).subscribe((dashboard) => { this.dashboardService.getDashboard(this.currentDashboardId).subscribe((dashboard) => {
dashboard = this.dashboardUtils.validateAndUpdateDashboard(dashboard); dashboard = this.dashboardUtils.validateAndUpdateDashboard(dashboard);
const data = { const data: DashboardPageInitData = {
dashboard, dashboard,
widgetEditMode: false, currentDashboardId: this.currentDashboardId,
currentDashboardId: this.currentDashboardId widgetEditMode: this.widgetEditMode,
} as any; singlePageMode: this.singlePageMode
};
this.init(data); this.init(data);
this.dashboardCtx.stateController.cleanupPreservedStates(); this.dashboardCtx.stateController.cleanupPreservedStates();
this.dashboardCtx.stateController.resetState(); this.dashboardCtx.stateController.resetState();

7
ui-ngx/src/app/modules/home/components/dashboard-page/dashboard-page.models.ts

@ -24,6 +24,13 @@ import { Observable } from 'rxjs';
export declare type DashboardPageScope = 'tenant' | 'customer'; export declare type DashboardPageScope = 'tenant' | 'customer';
export interface DashboardPageInitData {
dashboard: Dashboard;
currentDashboardId?: string;
widgetEditMode?: boolean;
singlePageMode?: boolean;
}
export interface DashboardContext { export interface DashboardContext {
instanceId: string; instanceId: string;
state: string; state: string;

Loading…
Cancel
Save