Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / store / states / workspace.state.ts
1 /**
2  * Created by ob0695 on 7/17/2018.
3  */
4 import {State, Action, StateContext} from '@ngxs/store';
5 import {UpdateIsDesigner, UpdateIsViewOnly} from "../actions/workspace.action";
6 import {Selector} from "@ngxs/store";
7
8 export interface WorkspaceStateModel {
9     isViewOnly: boolean;
10     isDesigner: boolean;
11 }
12
13 @State<WorkspaceStateModel>({
14     name: 'workspace',
15     defaults: {
16         isViewOnly: false,
17         isDesigner: true
18     }
19 })
20
21 export class WorkspaceState {
22
23     constructor(){}
24
25     @Selector() static isViewOnly(state: WorkspaceStateModel):boolean {
26         return state.isViewOnly;
27     }
28     @Selector() static isDesigner(state: WorkspaceStateModel): boolean {
29         return state.isDesigner;
30     }
31
32     @Action(UpdateIsViewOnly)
33     updateIsViewOnly({getState, setState}: StateContext<WorkspaceStateModel>, action:UpdateIsViewOnly) {
34         const state = getState();
35         setState({
36             ...state,
37             isViewOnly: action.isViewOnly
38         });
39     }
40
41     @Action(UpdateIsDesigner)
42     updateIsDesigner({getState, patchState}: StateContext<WorkspaceStateModel>, action:UpdateIsDesigner) {
43         const state = getState();
44         patchState({
45             isDesigner: action.isDesigner
46         });
47     }
48 }