2020-01-07 15:33:56 +00:00
|
|
|
import { tassign } from 'tassign';
|
|
|
|
import { IItemTypes} from '../models/item.types';
|
|
|
|
import { IListItem } from '../models/list.item';
|
|
|
|
import { IUser } from '../models/user';
|
2020-05-13 10:30:09 +00:00
|
|
|
import { IPackage,IPackages} from '../models/package';
|
2020-01-07 15:33:56 +00:00
|
|
|
import * as appCommonActions from '../actions/app-common.actions';
|
|
|
|
import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/store';
|
|
|
|
|
|
|
|
import { MODULE_NAME } from '../module-name';
|
|
|
|
|
|
|
|
export interface State {
|
|
|
|
openedModalName: string,
|
|
|
|
initialized: boolean,
|
|
|
|
rootItems: IListItem[],
|
|
|
|
itemTypes: IItemTypes,
|
|
|
|
user:IUser,
|
|
|
|
fullScreen: boolean,
|
|
|
|
routeLoading:boolean,
|
|
|
|
menuVisible: boolean,
|
2020-06-24 11:08:13 +00:00
|
|
|
userPackages: IPackages,
|
2020-07-22 06:52:41 +00:00
|
|
|
accountMenuVisible: boolean,
|
|
|
|
isOnline: boolean
|
2020-01-07 15:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export const initialState: State = {
|
|
|
|
openedModalName: null,
|
|
|
|
initialized: false,
|
|
|
|
rootItems: [],
|
|
|
|
itemTypes: {},
|
|
|
|
user:null,
|
|
|
|
fullScreen: true,
|
|
|
|
routeLoading: false,
|
2020-05-13 10:30:09 +00:00
|
|
|
menuVisible: false,
|
2020-06-24 13:07:11 +00:00
|
|
|
userPackages: {},
|
2020-07-22 06:52:41 +00:00
|
|
|
accountMenuVisible: false,
|
2020-07-23 09:28:07 +00:00
|
|
|
isOnline: true
|
2020-01-07 15:33:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function reducer(state = initialState, action: appCommonActions.Actions ): State {
|
|
|
|
switch (action.type) {
|
2020-07-23 07:42:44 +00:00
|
|
|
case appCommonActions.INITUSER: {
|
|
|
|
return tassign(state,{initialized: true});
|
|
|
|
}
|
2020-01-07 15:33:56 +00:00
|
|
|
case appCommonActions.INITUSERSUCCESS: {
|
|
|
|
let a = action as appCommonActions.InitUserSuccess;
|
2020-06-23 15:51:47 +00:00
|
|
|
let claims = {}
|
|
|
|
Object.getOwnPropertyNames(a.userinfo).forEach((k) => {
|
|
|
|
claims[k] = a.userinfo[k];
|
|
|
|
});
|
2020-06-10 19:53:54 +00:00
|
|
|
var user:IUser = {
|
|
|
|
code:a.user.code,
|
|
|
|
email:a.userinfo["email"],
|
2020-06-23 15:51:47 +00:00
|
|
|
name:a.userinfo["name"],
|
|
|
|
claims:claims
|
2020-06-10 19:53:54 +00:00
|
|
|
};
|
2020-07-23 07:42:44 +00:00
|
|
|
return tassign(state, { user: user });
|
2020-01-07 15:33:56 +00:00
|
|
|
}
|
|
|
|
case appCommonActions.INITROOTSUCCESS: {
|
|
|
|
let a = action as appCommonActions.InitRootSuccess;
|
|
|
|
return tassign(state, { rootItems:a.items});
|
|
|
|
}
|
|
|
|
case appCommonActions.OPENMODAL: {
|
|
|
|
return tassign(state, { openedModalName: action.modalName });
|
|
|
|
}
|
|
|
|
case appCommonActions.CLOSEMODAL: {
|
|
|
|
return tassign(state, { openedModalName: null });
|
2020-02-05 13:57:12 +00:00
|
|
|
}
|
2020-01-07 15:33:56 +00:00
|
|
|
case appCommonActions.LOADITEMTYPESSUCCESS: {
|
|
|
|
let a = action as appCommonActions.LoadItemTypesSuccess;
|
|
|
|
return tassign(state, { itemTypes: a.itemTypes });
|
|
|
|
}
|
|
|
|
case appCommonActions.FULLSCREEN: {
|
|
|
|
return tassign(state, {
|
|
|
|
fullScreen:true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
case appCommonActions.SHOWNAVBAR: {
|
|
|
|
return tassign(state, {
|
|
|
|
fullScreen: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
case appCommonActions.STARTROUTELOADING: {
|
|
|
|
return tassign(state, {
|
|
|
|
routeLoading: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
case appCommonActions.ENDROUTELOADING: {
|
|
|
|
return tassign(state, {
|
|
|
|
routeLoading: false
|
|
|
|
});
|
|
|
|
}
|
|
|
|
case appCommonActions.TOGGLEMENU: {
|
2020-06-26 06:22:31 +00:00
|
|
|
return tassign(state, { menuVisible: !state.menuVisible,accountMenuVisible:!state.menuVisible?false:state.accountMenuVisible });
|
2020-01-07 15:33:56 +00:00
|
|
|
}
|
2020-06-24 13:07:11 +00:00
|
|
|
case appCommonActions.TOGGLEACCOUNTMENU: {
|
|
|
|
return tassign(state, { accountMenuVisible: !state.accountMenuVisible });
|
|
|
|
}
|
2020-01-07 20:43:48 +00:00
|
|
|
case appCommonActions.ESCAPE: {
|
2020-06-24 13:07:11 +00:00
|
|
|
return tassign(state, { menuVisible: false,accountMenuVisible:false });
|
2020-01-07 20:43:48 +00:00
|
|
|
}
|
|
|
|
case appCommonActions.SETMENUVISIBLE: {
|
|
|
|
let a = action as appCommonActions.SetMenuVisible;
|
2020-06-26 06:22:31 +00:00
|
|
|
return tassign(state, { menuVisible: a.visible,accountMenuVisible:a.visible?false:state.accountMenuVisible });
|
2020-01-07 20:43:48 +00:00
|
|
|
}
|
2020-05-13 10:30:09 +00:00
|
|
|
case appCommonActions.INITUSERPACKAGESSUCCESS:{
|
|
|
|
let a = action as appCommonActions.InitUserPackagesSuccess;
|
|
|
|
let packages = {}
|
|
|
|
a.items.forEach((item) => {
|
|
|
|
packages[item.data.id]=item.data;
|
|
|
|
});
|
|
|
|
|
|
|
|
return tassign(state,{userPackages:packages});
|
|
|
|
}
|
2020-06-25 16:52:13 +00:00
|
|
|
case appCommonActions.LOGOUT:{
|
2020-06-25 17:04:40 +00:00
|
|
|
return tassign(state,{user:null,initialized:false});
|
2020-06-25 16:52:13 +00:00
|
|
|
}
|
2020-06-26 06:22:31 +00:00
|
|
|
case appCommonActions.CLOSEALL: {
|
|
|
|
return tassign(state,{accountMenuVisible:false,menuVisible:false });
|
|
|
|
}
|
2020-07-22 06:52:41 +00:00
|
|
|
case appCommonActions.ONLINE:{
|
|
|
|
return tassign(state,{isOnline:true});
|
|
|
|
}
|
|
|
|
case appCommonActions.OFFLINE:{
|
|
|
|
return tassign(state,{isOnline:false});
|
|
|
|
}
|
2020-01-07 15:33:56 +00:00
|
|
|
default: {
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getOpenedModalName = (state: State) => state.openedModalName;
|
|
|
|
export const getInitialized = (state: State) => state.initialized;
|
|
|
|
export const getItemTypes = (state: State) => state.itemTypes;
|
|
|
|
export const getRootItems = (state: State) => state.rootItems;
|
|
|
|
export const getFullScreen = (state: State) => state.fullScreen;
|
|
|
|
export const getRouteLoading = (state: State) => state.routeLoading;
|
|
|
|
export const getMenuVisible = (state: State) => state.menuVisible;
|
2020-05-04 12:47:04 +00:00
|
|
|
export const getUser = (state: State) => state.user;
|
2020-05-13 10:30:09 +00:00
|
|
|
export const getUserPackages = (state: State) => state.userPackages;
|
2020-06-24 13:07:11 +00:00
|
|
|
export const getAccountMenuVisible = (state: State) => state.accountMenuVisible;
|
2020-07-22 06:52:41 +00:00
|
|
|
export const getIsOnline = (state: State) => state.isOnline;
|
2020-01-07 15:33:56 +00:00
|
|
|
|
|
|
|
export const selectAppCommonState = createFeatureSelector<State>(MODULE_NAME);
|
|
|
|
|
|
|
|
export const selectOpenedModalName = createSelector(selectAppCommonState, getOpenedModalName);
|
|
|
|
export const selectGetInitialized = createSelector(selectAppCommonState, getInitialized);
|
|
|
|
export const selectGetItemTypes = createSelector(selectAppCommonState, getItemTypes);
|
|
|
|
export const selectGetRootItems = createSelector(selectAppCommonState, getRootItems);
|
|
|
|
export const selectGetFullScreen = createSelector(selectAppCommonState, getFullScreen);
|
|
|
|
export const selectGetRouteLoading = createSelector(selectAppCommonState, getRouteLoading);
|
|
|
|
export const SelectGetMenuVisible = createSelector(selectAppCommonState,getMenuVisible);
|
2020-05-04 12:47:04 +00:00
|
|
|
export const SelectGetUser = createSelector(selectAppCommonState,getUser);
|
2020-05-13 10:30:09 +00:00
|
|
|
export const SelectGetUserPackages = createSelector(selectAppCommonState,getUserPackages);
|
2020-06-24 13:07:11 +00:00
|
|
|
export const SelectGetAccountMenuVisible = createSelector(selectAppCommonState,getAccountMenuVisible);
|
2020-07-22 06:52:41 +00:00
|
|
|
export const SelectGetIsOnline = createSelector(selectAppCommonState,getIsOnline);
|
2020-01-07 15:33:56 +00:00
|
|
|
|