From ee7d1cb9a26bb2f7b0e48591acdb8e23a6bad872 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Tue, 4 Aug 2020 16:09:22 +0200 Subject: [PATCH] AW-1419 --- .../src/fm/actions/app-common.actions.ts | 7 ++++++ .../src/fm/effects/app-common.effects.ts | 25 ++++++++++++++----- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/projects/common/src/fm/actions/app-common.actions.ts b/projects/common/src/fm/actions/app-common.actions.ts index 636d5cb..eeb4fa9 100644 --- a/projects/common/src/fm/actions/app-common.actions.ts +++ b/projects/common/src/fm/actions/app-common.actions.ts @@ -74,6 +74,12 @@ export class InitUserSuccess implements Action { constructor(public user:IUser,public userinfo:UserInfo ) { } } +export class InitUserPackages implements Action { + readonly type = INITUSERPACKAGES; + + constructor() {} +} + export class InitUserPackagesSuccess implements Action { readonly type = INITUSERPACKAGESSUCCESS; @@ -301,6 +307,7 @@ export type Actions = OpenModal | DeviceUpdateEvent | ToggleMenu | SetMenuVisible + | InitUserPackages | InitUserPackagesSuccess | ToggleAccountMenu | CloseAll diff --git a/projects/common/src/fm/effects/app-common.effects.ts b/projects/common/src/fm/effects/app-common.effects.ts index be45a69..38e97d9 100644 --- a/projects/common/src/fm/effects/app-common.effects.ts +++ b/projects/common/src/fm/effects/app-common.effects.ts @@ -57,24 +57,37 @@ export class AppCommonEffects { catchError(error => of(new appCommonActions.Fail(error)))) } )); - + + @Effect() initUserPackages$:Observable = this.actions$.pipe( - ofType(appCommonActions.INITUSERSUCCESS), - switchMap((action) => { - let a = action as appCommonActions.InitUserSuccess; - return this.itemService$.getChildItemList(a.user.code+":USER_PACKAGES","vnd.farmmaps.itemtype.package").pipe( + ofType(appCommonActions.INITUSERPACKAGES), + withLatestFrom(this.store$.select(appCommonReducers.SelectGetUser)), + switchMap(([action,user]) => { + return this.itemService$.getChildItemList(user.code+":USER_PACKAGES","vnd.farmmaps.itemtype.package").pipe( switchMap((items) => of(new appCommonActions.InitUserPackagesSuccess(items))), catchError(error => of(new appCommonActions.Fail(error))) ) }) ); + @Effect() + userPackagesChanged$:Observable = this.actions$.pipe( + ofType(appCommonActions.ITEMCHANGEDEVENT), + switchMap((action) => { + let a = action as appCommonActions.ItemChangedEvent; + if(a.itemCode.endsWith(":USER_PACKAGES")) + return of(new appCommonActions.InitUserPackages()); + else + return of(undefined); + }) + ); + @Effect() initUserSuccess$: Observable = this.actions$.pipe( ofType(appCommonActions.INITUSERSUCCESS), switchMap(() => { - return of(new appCommonActions.InitRoot()); + return [new appCommonActions.InitRoot(),new appCommonActions.InitUserPackages()]; } ));