2ea51d94ef
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good
122 lines
4.4 KiB
TypeScript
122 lines
4.4 KiB
TypeScript
import { tassign } from 'tassign';
|
|
import { IItemTypes} from '../models/item.types';
|
|
import { IListItem } from '../models/list.item';
|
|
import { IUser } from '../models/user';
|
|
import { IPackage,IPackages} from '../models/package';
|
|
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,
|
|
userPackages: IPackages
|
|
}
|
|
|
|
export const initialState: State = {
|
|
openedModalName: null,
|
|
initialized: false,
|
|
rootItems: [],
|
|
itemTypes: {},
|
|
user:null,
|
|
fullScreen: true,
|
|
routeLoading: false,
|
|
menuVisible: false,
|
|
userPackages: {}
|
|
}
|
|
|
|
export function reducer(state = initialState, action: appCommonActions.Actions ): State {
|
|
switch (action.type) {
|
|
case appCommonActions.INITUSERSUCCESS: {
|
|
let a = action as appCommonActions.InitUserSuccess;
|
|
return tassign(state, { user: a.user,initialized: true });
|
|
}
|
|
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 });
|
|
}
|
|
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: {
|
|
return tassign(state, { menuVisible: !state.menuVisible });
|
|
}
|
|
case appCommonActions.ESCAPE: {
|
|
return tassign(state, { menuVisible: false });
|
|
}
|
|
case appCommonActions.SETMENUVISIBLE: {
|
|
let a = action as appCommonActions.SetMenuVisible;
|
|
return tassign(state, { menuVisible: a.visible });
|
|
}
|
|
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});
|
|
}
|
|
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;
|
|
export const getUser = (state: State) => state.user;
|
|
export const getUserPackages = (state: State) => state.userPackages;
|
|
|
|
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);
|
|
export const SelectGetUser = createSelector(selectAppCommonState,getUser);
|
|
export const SelectGetUserPackages = createSelector(selectAppCommonState,getUserPackages);
|
|
|