diff --git a/projects/common/src/fm/actions/app-common.actions.ts b/projects/common/src/fm/actions/app-common.actions.ts index 5198e54..99afe44 100644 --- a/projects/common/src/fm/actions/app-common.actions.ts +++ b/projects/common/src/fm/actions/app-common.actions.ts @@ -12,6 +12,9 @@ export const INITUSERSUCCESS = '[AppCommon] InitUserSuccess'; export const INITUSERPACKAGES = '[AppCommon] InitUserPackages'; export const INITUSERPACKAGESSUCCESS = '[AppCommon] InitUserPackagesSuccess'; +export const INITUSERSETTINGSROOT = '[AppCommon] InitUserSettingsRoot'; +export const INITUSERSETTINGSROOTSUCCESS = '[AppCommon] InitUserSettingsRootSuccess'; + export const INITROOT = '[Explorer] InitRoot'; export const INITROOTSUCCESS = '[Explorer] InitRootSuccess'; @@ -87,6 +90,18 @@ export class InitUserPackagesSuccess implements Action { constructor(public items:IItem[] ) { } } +export class InitUserSettingsRoot implements Action { + readonly type = INITUSERSETTINGSROOT; + + constructor() {} +} + +export class InitUserSettingsRootSuccess implements Action { + readonly type = INITUSERSETTINGSROOTSUCCESS; + + constructor(public item: IItem ) { } +} + export class InitRoot implements Action { readonly type = INITROOT; @@ -317,6 +332,8 @@ export type Actions = OpenModal | SetMenuVisible | InitUserPackages | InitUserPackagesSuccess + | InitUserSettingsRoot + | InitUserSettingsRootSuccess | ToggleAccountMenu | CloseAll | Online diff --git a/projects/common/src/fm/effects/app-common.effects.ts b/projects/common/src/fm/effects/app-common.effects.ts index 2fe1dac..da8d852 100644 --- a/projects/common/src/fm/effects/app-common.effects.ts +++ b/projects/common/src/fm/effects/app-common.effects.ts @@ -81,12 +81,36 @@ export class AppCommonEffects { return []; }) ); + + @Effect() + initUserSettingsRoot$:Observable = this.actions$.pipe( + ofType(appCommonActions.INITUSERSETTINGSROOT), + withLatestFrom(this.store$.select(appCommonReducers.SelectGetUser)), + switchMap(([, user]) => { + return this.itemService$.getItem(user.code + ':USER_SETTINGS').pipe( + switchMap((item) => of(new appCommonActions.InitUserSettingsRootSuccess(item))), + catchError(error => of(new appCommonActions.Fail(error))) + ) + }) + ); + + @Effect() + initUserSettingsRootChanged$:Observable = this.actions$.pipe( + ofType(appCommonActions.ITEMCHANGEDEVENT), + switchMap((action) => { + let a = action as appCommonActions.ItemChangedEvent; + if(a.itemCode.endsWith(":USER_SETTINGS")) + return of(new appCommonActions.InitUserSettingsRoot()); + else + return []; + }) + ); @Effect() initUserSuccess$: Observable = this.actions$.pipe( ofType(appCommonActions.INITUSERSUCCESS), switchMap(() => { - return [new appCommonActions.InitRoot(),new appCommonActions.InitUserPackages()]; + return [new appCommonActions.InitRoot(),new appCommonActions.InitUserPackages(),new appCommonActions.InitUserSettingsRoot()]; } )); diff --git a/projects/common/src/fm/reducers/app-common.reducer.ts b/projects/common/src/fm/reducers/app-common.reducer.ts index 0e27053..ee780ab 100644 --- a/projects/common/src/fm/reducers/app-common.reducer.ts +++ b/projects/common/src/fm/reducers/app-common.reducer.ts @@ -7,6 +7,7 @@ import * as appCommonActions from '../actions/app-common.actions'; import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/store'; import { MODULE_NAME } from '../module-name'; +import { IItem } from '../models/item'; export interface State { openedModalName: string, @@ -18,6 +19,7 @@ export interface State { routeLoading:boolean, menuVisible: boolean, userPackages: IPackages, + userSettingsRoot: IItem, accountMenuVisible: boolean, isOnline: boolean } @@ -32,6 +34,7 @@ export const initialState: State = { routeLoading: false, menuVisible: false, userPackages: {}, + userSettingsRoot: null, accountMenuVisible: false, isOnline: true } @@ -111,6 +114,10 @@ export function reducer(state = initialState, action: appCommonActions.Actions ) return tassign(state,{userPackages:packages}); } + case appCommonActions.INITUSERSETTINGSROOTSUCCESS:{ + let a = action as appCommonActions.InitUserSettingsRootSuccess; + return tassign(state, { userSettingsRoot : a.item }); + } case appCommonActions.LOGOUT:{ return tassign(state,{user:null,initialized:false}); }