|
|
|
@ -14,23 +14,24 @@ |
|
|
|
/// limitations under the License.
|
|
|
|
///
|
|
|
|
|
|
|
|
import { Component, Input, OnInit } from '@angular/core'; |
|
|
|
import { Component, Input, OnDestroy, OnInit } from '@angular/core'; |
|
|
|
import { PageComponent } from '@shared/components/page.component'; |
|
|
|
import { Store } from '@ngrx/store'; |
|
|
|
import { AppState } from '@core/core.state'; |
|
|
|
import { Dashboard } from '@shared/models/dashboard.models'; |
|
|
|
import { StateObject, StateParams } from '@core/api/widget-api.models'; |
|
|
|
import { updateEntityParams, WidgetContext } from '../../models/widget-component.models'; |
|
|
|
import { StateObject } from '@core/api/widget-api.models'; |
|
|
|
import { updateEntityParams, WidgetContext } from '@home/models/widget-component.models'; |
|
|
|
import { deepClone, objToBase64 } from '@core/utils'; |
|
|
|
import { IDashboardComponent } from '@home/models/dashboard-component.models'; |
|
|
|
import { EntityId } from '@shared/models/id/entity-id'; |
|
|
|
import { Subscription } from 'rxjs'; |
|
|
|
|
|
|
|
@Component({ |
|
|
|
selector: 'tb-dashboard-state', |
|
|
|
templateUrl: './dashboard-state.component.html', |
|
|
|
styleUrls: [] |
|
|
|
}) |
|
|
|
export class DashboardStateComponent extends PageComponent implements OnInit { |
|
|
|
export class DashboardStateComponent extends PageComponent implements OnInit, OnDestroy { |
|
|
|
|
|
|
|
@Input() |
|
|
|
ctx: WidgetContext; |
|
|
|
@ -38,6 +39,9 @@ export class DashboardStateComponent extends PageComponent implements OnInit { |
|
|
|
@Input() |
|
|
|
stateId: string; |
|
|
|
|
|
|
|
@Input() |
|
|
|
syncParentStateParams = false; |
|
|
|
|
|
|
|
@Input() |
|
|
|
entityParamName: string; |
|
|
|
|
|
|
|
@ -50,12 +54,31 @@ export class DashboardStateComponent extends PageComponent implements OnInit { |
|
|
|
|
|
|
|
parentDashboard: IDashboardComponent; |
|
|
|
|
|
|
|
private stateSubscription: Subscription; |
|
|
|
|
|
|
|
constructor(protected store: Store<AppState>) { |
|
|
|
super(store); |
|
|
|
} |
|
|
|
|
|
|
|
ngOnInit(): void { |
|
|
|
this.dashboard = deepClone(this.ctx.stateController.dashboardCtrl.dashboardCtx.getDashboard()); |
|
|
|
this.updateCurrentState(); |
|
|
|
this.parentDashboard = this.ctx.parentDashboard ? |
|
|
|
this.ctx.parentDashboard : this.ctx.dashboard; |
|
|
|
if (this.syncParentStateParams) { |
|
|
|
this.stateSubscription = this.ctx.stateController.stateChanged().subscribe(() => { |
|
|
|
this.updateCurrentState(); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ngOnDestroy(): void { |
|
|
|
if (this.stateSubscription) { |
|
|
|
this.stateSubscription.unsubscribe(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private updateCurrentState(): void { |
|
|
|
const stateObject: StateObject = {}; |
|
|
|
const params = deepClone(this.ctx.stateController.getStateParams()); |
|
|
|
updateEntityParams(params, this.entityParamName, this.entityId); |
|
|
|
@ -64,7 +87,5 @@ export class DashboardStateComponent extends PageComponent implements OnInit { |
|
|
|
stateObject.id = this.stateId; |
|
|
|
} |
|
|
|
this.currentState = objToBase64([stateObject]); |
|
|
|
this.parentDashboard = this.ctx.parentDashboard ? |
|
|
|
this.ctx.parentDashboard : this.ctx.dashboard; |
|
|
|
} |
|
|
|
} |
|
|
|
|