Refactor menu panel
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good

This commit is contained in:
Willem Dantuma 2020-01-07 16:33:56 +01:00
parent 58f7c99ddc
commit e077aa34df
4 changed files with 145 additions and 110 deletions

View File

@ -46,6 +46,8 @@ export const FAIL = '[AppCommon] Fail';
export const UPLOADEDFILECLICK = '[AppCommon] UploadedFileClick'; export const UPLOADEDFILECLICK = '[AppCommon] UploadedFileClick';
export const TOGGLEMENU = '[AppCommon] ToggleMenu';
export class InitUser implements Action { export class InitUser implements Action {
readonly type = INITUSER; readonly type = INITUSER;
@ -212,6 +214,12 @@ export class UploadedFileClick implements Action {
readonly type = UPLOADEDFILECLICK; readonly type = UPLOADEDFILECLICK;
constructor(public itemCode:string) { } constructor(public itemCode:string) { }
} }
export class ToggleMenu implements Action {
readonly type = TOGGLEMENU;
constructor() { }
}
export type Actions = OpenModal export type Actions = OpenModal
@ -240,4 +248,5 @@ export type Actions = OpenModal
| TaskStartEvent | TaskStartEvent
| TaskEndEvent | TaskEndEvent
| TaskErrorEvent | TaskErrorEvent
| DeviceUpdateEvent; | DeviceUpdateEvent
| ToggleMenu;

View File

@ -1,14 +1,27 @@
<div class="app fullscreen" (click)="handleClick($event)" [ngClass]="{'fullscreen' :(fullScreen|async)}"> <div class="app fullscreen" (click)="handleClick($event)" [ngClass]="{'fullscreen' :(fullScreen|async)}">
<nav class="navbar navbar-expand-lg navbar-dark bg-primary"> <nav class="navbar navbar-expand-lg navbar-dark bg-primary">
<a class="navbar-brand" [routerLink]="['/']">Farm Maps <span *ngIf="routeLoading|async"><i class="fa fa-spinner fa-spin"></i></span></a> <a class="navbar-brand" [routerLink]="['/']">Farm Maps <span *ngIf="routeLoading|async"><i class="fa fa-spinner fa-spin"></i></span></a>
<ul class="navbar-nav"> <ul class="navbar-nav">
<li class="nav-item py-0"><a [routerLinkActive]="['active']" [routerLink]="['/map']" class="nav-link"><span><i class="fa fa-globe" aria-hidden="true"></i> Map</span></a></li> <li class="nav-item py-0"><a [routerLinkActive]="['active']" [routerLink]="['/map']" class="nav-link"><span><i class="fa fa-globe" aria-hidden="true"></i> Map</span></a></li>
<li class="nav-item py-0"><a [routerLinkActive]="['active']" [routerLink]="['/explorer']" class="nav-link"><span><i class="fa fa-folder" aria-hidden="true"></i> Explorer</span></a></li> <li class="nav-item py-0"><a [routerLinkActive]="['active']" [routerLink]="['/explorer']" class="nav-link"><span><i class="fa fa-folder" aria-hidden="true"></i> Explorer</span></a></li>
</ul> </ul>
<router-outlet name="menu"></router-outlet> <router-outlet name="menu"></router-outlet>
</nav> </nav>
<div class="body"> <div class="body">
<router-outlet></router-outlet> <router-outlet></router-outlet>
</div> </div>
<fm-resumable-file-upload></fm-resumable-file-upload> <fm-side-panel [visible]="menuVisible|async" class="menu">
</div> <div class="container-fluid">
<div class="body">
<div class="d-flex flex-row">
<div class="mt-2 mb-2 flex-grow-1 logo"><router-outlet name="side-panel-logo"></router-outlet></div>
<div class="mt-2 mb-2 ml-2"><button type="button" class="btn btn-outline-secondary" (click)="handleToggleMenu($event)"><i class="fa fa-times" aria-hidden="true"></i></button></div>
</div>
<div class="d-flex flex-column cards">
<router-outlet name="side-panel-menu"></router-outlet>
</div>
</div>
</div>
</fm-side-panel>
<fm-resumable-file-upload></fm-resumable-file-upload>
</div>

View File

@ -36,6 +36,7 @@ export class AppComponent implements OnInit, OnDestroy {
public fileDroptarget: any; public fileDroptarget: any;
public fullScreen: Observable<boolean>; public fullScreen: Observable<boolean>;
public routeLoading: Observable<boolean>; public routeLoading: Observable<boolean>;
public menuVisible:Observable<boolean>;
constructor( constructor(
private router: Router, private router: Router,
@ -88,6 +89,7 @@ export class AppComponent implements OnInit, OnDestroy {
ngOnInit() { ngOnInit() {
this.fullScreen = this.store.select(appReducers.selectGetFullScreen); this.fullScreen = this.store.select(appReducers.selectGetFullScreen);
this.routeLoading = this.store.select(appReducers.selectGetRouteLoading); this.routeLoading = this.store.select(appReducers.selectGetRouteLoading);
this.menuVisible = this.store.select(appReducers.SelectGetMenuVisible);
this.InstallRouteEventHandler(); this.InstallRouteEventHandler();
this.InstallEventServiceEventHandler(); this.InstallEventServiceEventHandler();
} }
@ -129,5 +131,9 @@ export class AppComponent implements OnInit, OnDestroy {
handleClick(event: MouseEvent) { handleClick(event: MouseEvent) {
this.store.dispatch(new commonActions.Escape(false,true)); this.store.dispatch(new commonActions.Escape(false,true));
} }
handleToggleMenu(event) {
this.store.dispatch(new commonActions.ToggleMenu());
}
} }

View File

@ -1,95 +1,102 @@
import { tassign } from 'tassign'; import { tassign } from 'tassign';
import { IItemTypes} from '../models/item.types'; import { IItemTypes} from '../models/item.types';
import { IListItem } from '../models/list.item'; import { IListItem } from '../models/list.item';
import { IUser } from '../models/user'; import { IUser } from '../models/user';
import * as appCommonActions from '../actions/app-common.actions'; import * as appCommonActions from '../actions/app-common.actions';
import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/store'; import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/store';
import { MODULE_NAME } from '../module-name'; import { MODULE_NAME } from '../module-name';
export interface State { export interface State {
openedModalName: string, openedModalName: string,
initialized: boolean, initialized: boolean,
rootItems: IListItem[], rootItems: IListItem[],
itemTypes: IItemTypes, itemTypes: IItemTypes,
user:IUser, user:IUser,
fullScreen: boolean, fullScreen: boolean,
routeLoading:boolean routeLoading:boolean,
} menuVisible: boolean,
}
export const initialState: State = {
openedModalName: null, export const initialState: State = {
initialized: false, openedModalName: null,
rootItems: [], initialized: false,
itemTypes: {}, rootItems: [],
user:null, itemTypes: {},
fullScreen: true, user:null,
routeLoading: false fullScreen: true,
} routeLoading: false,
menuVisible: true
export function reducer(state = initialState, action: appCommonActions.Actions ): State { }
switch (action.type) {
case appCommonActions.INITUSERSUCCESS: { export function reducer(state = initialState, action: appCommonActions.Actions ): State {
let a = action as appCommonActions.InitUserSuccess; switch (action.type) {
return tassign(state, { user: a.user }); case appCommonActions.INITUSERSUCCESS: {
} let a = action as appCommonActions.InitUserSuccess;
case appCommonActions.INITROOTSUCCESS: { return tassign(state, { user: a.user });
let a = action as appCommonActions.InitRootSuccess; }
return tassign(state, { rootItems:a.items}); case appCommonActions.INITROOTSUCCESS: {
} let a = action as appCommonActions.InitRootSuccess;
case appCommonActions.OPENMODAL: { return tassign(state, { rootItems:a.items});
return tassign(state, { openedModalName: action.modalName }); }
} case appCommonActions.OPENMODAL: {
case appCommonActions.CLOSEMODAL: { return tassign(state, { openedModalName: action.modalName });
return tassign(state, { openedModalName: null }); }
} case appCommonActions.CLOSEMODAL: {
case appCommonActions.INITIALIZED: { return tassign(state, { openedModalName: null });
return tassign(state, { initialized: true }); }
} case appCommonActions.INITIALIZED: {
case appCommonActions.LOADITEMTYPESSUCCESS: { return tassign(state, { initialized: true });
let a = action as appCommonActions.LoadItemTypesSuccess; }
return tassign(state, { itemTypes: a.itemTypes }); case appCommonActions.LOADITEMTYPESSUCCESS: {
} let a = action as appCommonActions.LoadItemTypesSuccess;
case appCommonActions.FULLSCREEN: { return tassign(state, { itemTypes: a.itemTypes });
return tassign(state, { }
fullScreen:true case appCommonActions.FULLSCREEN: {
}); return tassign(state, {
} fullScreen:true
case appCommonActions.SHOWNAVBAR: { });
return tassign(state, { }
fullScreen: false case appCommonActions.SHOWNAVBAR: {
}); return tassign(state, {
} fullScreen: false
case appCommonActions.STARTROUTELOADING: { });
return tassign(state, { }
routeLoading: true case appCommonActions.STARTROUTELOADING: {
}); return tassign(state, {
} routeLoading: true
case appCommonActions.ENDROUTELOADING: { });
return tassign(state, { }
routeLoading: false case appCommonActions.ENDROUTELOADING: {
}); return tassign(state, {
} routeLoading: false
default: { });
return state; }
} case appCommonActions.TOGGLEMENU: {
} return tassign(state, { menuVisible: !state.menuVisible });
} }
default: {
export const getOpenedModalName = (state: State) => state.openedModalName; return state;
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 getOpenedModalName = (state: State) => state.openedModalName;
export const getInitialized = (state: State) => state.initialized;
export const getItemTypes = (state: State) => state.itemTypes;
export const selectAppCommonState = createFeatureSelector<State>(MODULE_NAME); export const getRootItems = (state: State) => state.rootItems;
export const getFullScreen = (state: State) => state.fullScreen;
export const selectOpenedModalName = createSelector(selectAppCommonState, getOpenedModalName); export const getRouteLoading = (state: State) => state.routeLoading;
export const selectGetInitialized = createSelector(selectAppCommonState, getInitialized); export const getMenuVisible = (state: State) => state.menuVisible;
export const selectGetItemTypes = createSelector(selectAppCommonState, getItemTypes);
export const selectGetRootItems = createSelector(selectAppCommonState, getRootItems);
export const selectGetFullScreen = createSelector(selectAppCommonState, getFullScreen); export const selectAppCommonState = createFeatureSelector<State>(MODULE_NAME);
export const selectGetRouteLoading = createSelector(selectAppCommonState, getRouteLoading);
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);