Skip to content
Snippets Groups Projects
Commit 595e3f2f authored by Florent POITTEVIN's avatar Florent POITTEVIN
Browse files

fix: counter update on preservation space tab

parent d3289409
No related branches found
No related tags found
No related merge requests found
...@@ -9,16 +9,18 @@ import { ...@@ -9,16 +9,18 @@ import {
RoutesEnum, RoutesEnum,
} from "@app/shared/enums/routes.enum"; } from "@app/shared/enums/routes.enum";
import {LocalStateModel} from "@app/shared/models/local-state.model"; import {LocalStateModel} from "@app/shared/models/local-state.model";
import {AppNotificationInboxState} from "@app/stores/notification-inbox/app-notification-inbox.state";
import {Enums} from "@enums"; import {Enums} from "@enums";
import {Navigate} from "@ngxs/router-plugin"; import {Navigate} from "@ngxs/router-plugin";
import {Store} from "@ngxs/store"; import {Store} from "@ngxs/store";
import {Tab} from "@shared/components/containers/shared-tabs/shared-tabs.container"; import {Tab} from "@shared/components/containers/shared-tabs/shared-tabs.container";
import {DataTestEnum} from "@shared/enums/data-test.enum"; import {DataTestEnum} from "@shared/enums/data-test.enum";
import {IconNameEnum} from "@shared/enums/icon-name.enum"; import {IconNameEnum} from "@shared/enums/icon-name.enum";
import {SessionStorageEnum} from "@shared/enums/session-storage.enum";
import {SessionStorageHelper} from "@shared/helpers/session-storage.helper";
import {Observable} from "rxjs"; import {Observable} from "rxjs";
import {MARK_AS_TRANSLATABLE} from "solidify-frontend"; import {
MARK_AS_TRANSLATABLE,
MemoizedUtil,
} from "solidify-frontend";
@Component({ @Component({
selector: "dlcm-preservation-space-home-routable", selector: "dlcm-preservation-space-home-routable",
...@@ -63,7 +65,7 @@ export class PreservationSpaceHomeRoutable extends SharedAbstractPresentational ...@@ -63,7 +65,7 @@ export class PreservationSpaceHomeRoutable extends SharedAbstractPresentational
titleToTranslate: MARK_AS_TRANSLATABLE("preservationSpace.notificationInbox.home.title"), titleToTranslate: MARK_AS_TRANSLATABLE("preservationSpace.notificationInbox.home.title"),
suffixUrl: PreservationSpaceRoutesEnum.notificationInbox, suffixUrl: PreservationSpaceRoutesEnum.notificationInbox,
route: () => [...this.rootUrl, PreservationSpaceRoutesEnum.notificationInbox], route: () => [...this.rootUrl, PreservationSpaceRoutesEnum.notificationInbox],
numberNew: () => SessionStorageHelper.getListItem(SessionStorageEnum.notificationInboxPending).length, numberNew: () => MemoizedUtil.total(this.store, AppNotificationInboxState),
dataTest: DataTestEnum.preservationSpaceTabRequestReceived, dataTest: DataTestEnum.preservationSpaceTabRequestReceived,
}, },
{ {
......
...@@ -8,6 +8,7 @@ import { ...@@ -8,6 +8,7 @@ import {
PreservationSpaceNotificationStatusHistoryState, PreservationSpaceNotificationStatusHistoryState,
PreservationSpaceNotificationStatusHistoryStateModel, PreservationSpaceNotificationStatusHistoryStateModel,
} from "@app/features/preservation-space/notification/stores/status-history/preservation-space-notification-status-history.state"; } from "@app/features/preservation-space/notification/stores/status-history/preservation-space-notification-status-history.state";
import {AppAction} from "@app/stores/app.action";
import {Enums} from "@enums"; import {Enums} from "@enums";
import {NotificationDlcm} from "@models"; import {NotificationDlcm} from "@models";
import {Navigate} from "@ngxs/router-plugin"; import {Navigate} from "@ngxs/router-plugin";
...@@ -247,6 +248,7 @@ export class PreservationSpaceNotificationState extends ResourceState<Preservati ...@@ -247,6 +248,7 @@ export class PreservationSpaceNotificationState extends ResourceState<Preservati
this.notificationService.showSuccess(MARK_AS_TRANSLATABLE("preservationSpace.notifications.setRead.success")); this.notificationService.showSuccess(MARK_AS_TRANSLATABLE("preservationSpace.notifications.setRead.success"));
} }
SessionStorageHelper.removeItemInList(SessionStorageEnum.notificationInboxPending, (action.parentAction as PreservationSpaceNotificationAction.SetProcessed).notificationId); SessionStorageHelper.removeItemInList(SessionStorageEnum.notificationInboxPending, (action.parentAction as PreservationSpaceNotificationAction.SetProcessed).notificationId);
this.store.dispatch(new AppAction.UpdateNotificationInbox);
} }
@Action(PreservationSpaceNotificationAction.SetProcessedFail) @Action(PreservationSpaceNotificationAction.SetProcessedFail)
...@@ -276,6 +278,7 @@ export class PreservationSpaceNotificationState extends ResourceState<Preservati ...@@ -276,6 +278,7 @@ export class PreservationSpaceNotificationState extends ResourceState<Preservati
this.removeNotificationPendingListAndRefresh(ctx, (action.parentAction as PreservationSpaceNotificationAction.SetRefuse).notificationId, (action.parentAction as PreservationSpaceNotificationAction.SetRefuse).mode); this.removeNotificationPendingListAndRefresh(ctx, (action.parentAction as PreservationSpaceNotificationAction.SetRefuse).notificationId, (action.parentAction as PreservationSpaceNotificationAction.SetRefuse).mode);
this.notificationService.showSuccess(MARK_AS_TRANSLATABLE("preservationSpace.notifications.setRefuse.success")); this.notificationService.showSuccess(MARK_AS_TRANSLATABLE("preservationSpace.notifications.setRefuse.success"));
SessionStorageHelper.removeItemInList(SessionStorageEnum.notificationInboxPending, (action.parentAction as PreservationSpaceNotificationAction.SetRefuse).notificationId); SessionStorageHelper.removeItemInList(SessionStorageEnum.notificationInboxPending, (action.parentAction as PreservationSpaceNotificationAction.SetRefuse).notificationId);
this.store.dispatch(new AppAction.UpdateNotificationInbox);
} }
@Action(PreservationSpaceNotificationAction.SetRefuseFail) @Action(PreservationSpaceNotificationAction.SetRefuseFail)
...@@ -305,6 +308,7 @@ export class PreservationSpaceNotificationState extends ResourceState<Preservati ...@@ -305,6 +308,7 @@ export class PreservationSpaceNotificationState extends ResourceState<Preservati
this.notificationService.showSuccess(MARK_AS_TRANSLATABLE("preservationSpace.notifications.setUnread.success")); this.notificationService.showSuccess(MARK_AS_TRANSLATABLE("preservationSpace.notifications.setUnread.success"));
} }
SessionStorageHelper.addItemInList(SessionStorageEnum.notificationInboxPending, (action.parentAction as PreservationSpaceNotificationAction.SetPending).notificationId); SessionStorageHelper.addItemInList(SessionStorageEnum.notificationInboxPending, (action.parentAction as PreservationSpaceNotificationAction.SetPending).notificationId);
this.store.dispatch(new AppAction.UpdateNotificationInbox);
} }
private removeNotificationPendingListAndRefresh(ctx: StateContext<PreservationSpaceNotificationStateModel>, private removeNotificationPendingListAndRefresh(ctx: StateContext<PreservationSpaceNotificationStateModel>,
......
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
> >
</dlcm-shared-icon> </dlcm-shared-icon>
<span class="label" <span class="label"
[matBadge]="(tab.numberNew | isNullOrUndefined) || tab.numberNew()" [matBadge]="(tab.numberNew | isNullOrUndefined) || (tab.numberNew() | solidifyAsync)"
matBadgeColor="primary" matBadgeColor="primary"
matBadgeSize="small" matBadgeSize="small"
matBadgeOverlap="false" matBadgeOverlap="false"
[matBadgeHidden]="(tab.numberNew | isNullOrUndefined) || tab.numberNew() === 0" [matBadgeHidden]="(tab.numberNew | isNullOrUndefined) || (tab.numberNew() | solidifyAsync) === 0"
>{{tab.titleToTranslate | translate}}</span> >{{tab.titleToTranslate | translate}}</span>
</li> </li>
</ul> </ul>
......
...@@ -16,6 +16,7 @@ import {Store} from "@ngxs/store"; ...@@ -16,6 +16,7 @@ import {Store} from "@ngxs/store";
import {SharedAbstractContainer} from "@shared/components/containers/shared-abstract/shared-abstract.container"; import {SharedAbstractContainer} from "@shared/components/containers/shared-abstract/shared-abstract.container";
import {DataTestEnum} from "@shared/enums/data-test.enum"; import {DataTestEnum} from "@shared/enums/data-test.enum";
import {IconNameEnum} from "@shared/enums/icon-name.enum"; import {IconNameEnum} from "@shared/enums/icon-name.enum";
import {ObservableOrPromiseOrValue} from "@shared/models/extra-button-toolbar.model";
import { import {
BehaviorSubject, BehaviorSubject,
Observable, Observable,
...@@ -141,6 +142,6 @@ export interface Tab { ...@@ -141,6 +142,6 @@ export interface Tab {
titleToTranslate: string; titleToTranslate: string;
conditionDisplay?: () => boolean | Observable<boolean> | undefined; conditionDisplay?: () => boolean | Observable<boolean> | undefined;
route?: () => string | string[]; route?: () => string | string[];
numberNew?: () => number; numberNew?: () => ObservableOrPromiseOrValue<number>;
dataTest?: DataTestEnum; dataTest?: DataTestEnum;
} }
...@@ -98,6 +98,10 @@ export namespace AppAction { ...@@ -98,6 +98,10 @@ export namespace AppAction {
static readonly type: string = `[${state}] Start Polling Notification`; static readonly type: string = `[${state}] Start Polling Notification`;
} }
export class UpdateNotificationInbox {
static readonly type: string = `[${state}] Update Notification Inbox`;
}
export class Login extends BaseAction { export class Login extends BaseAction {
static readonly type: string = `[${state}] Login`; static readonly type: string = `[${state}] Login`;
} }
......
...@@ -418,47 +418,56 @@ export class AppState extends BasicState<AppStateModel> { ...@@ -418,47 +418,56 @@ export class AppState extends BasicState<AppStateModel> {
@Action(AppAction.StartPollingNotification) @Action(AppAction.StartPollingNotification)
startPollingNotification(ctx: StateContext<AppStateModel>, action: AppAction.StartPollingNotification): void { startPollingNotification(ctx: StateContext<AppStateModel>, action: AppAction.StartPollingNotification): void {
if (ctx.getState().isLoggedIn) {
this.store.dispatch(new AppAction.UpdateNotificationInbox);
}
PollingHelper.startPollingObs({ PollingHelper.startPollingObs({
intervalRefreshInSecond: environment.refreshNotificationInboxAvailableIntervalInSecond, intervalRefreshInSecond: environment.refreshNotificationInboxAvailableIntervalInSecond,
filter: () => ctx.getState().isLoggedIn, filter: () => ctx.getState().isLoggedIn,
actionToDo: () => { actionToDo: () => {
const queryParameters = new QueryParameters(environment.maximalPageSizeToRetrievePaginationInfo); this.store.dispatch(new AppAction.UpdateNotificationInbox);
const searchItems = queryParameters.search.searchItems;
const NOTIFICATION_STATUS: keyof NotificationDlcm = "notificationStatus";
MappingObjectUtil.set(searchItems, NOTIFICATION_STATUS, Enums.Notification.StatusEnum.PENDING);
this._actions$.pipe(
ofActionCompleted(AppNotificationInboxAction.GetAllSuccess),
take(1),
tap(result => {
if (!result.result.successful) {
return;
}
const actionSuccess = (result.action as AppNotificationInboxAction.GetAllSuccess);
const listNewNotificationInboxPending = actionSuccess.list._data.map(newNotification => newNotification.resId);
const listOldNotificationInboxPending = SessionStorageHelper.getListItem(SessionStorageEnum.notificationInboxPending);
let counterNewNotification = 0;
listNewNotificationInboxPending.forEach(newNotificationId => {
if (!listOldNotificationInboxPending.includes(newNotificationId)) {
counterNewNotification++;
}
});
if (counterNewNotification > 0) {
const actionNotification = {
text: MARK_AS_TRANSLATABLE("app.notification.action.see"),
callback: () => this.store.dispatch(new Navigate([RoutesEnum.preservationSpaceNotificationInbox])),
};
this.notificationService.showSuccess(MARK_AS_TRANSLATABLE("app.notification.notificationInbox.newIncoming"), {"number": counterNewNotification}, actionNotification);
}
SessionStorageHelper.initItemInList(SessionStorageEnum.notificationInboxPending, listNewNotificationInboxPending);
}),
).subscribe();
this.store.dispatch(new AppNotificationInboxAction.GetAll(queryParameters));
}, },
}).subscribe(); }).subscribe();
} }
@Action(AppAction.UpdateNotificationInbox)
updateNotificationInbox(ctx: StateContext<AppStateModel>, action: AppAction.UpdateNotificationInbox): void {
const queryParameters = new QueryParameters(environment.maximalPageSizeToRetrievePaginationInfo);
const searchItems = queryParameters.search.searchItems;
const NOTIFICATION_STATUS: keyof NotificationDlcm = "notificationStatus";
MappingObjectUtil.set(searchItems, NOTIFICATION_STATUS, Enums.Notification.StatusEnum.PENDING);
this._actions$.pipe(
ofActionCompleted(AppNotificationInboxAction.GetAllSuccess),
take(1),
tap(result => {
if (!result.result.successful) {
return;
}
const actionSuccess = (result.action as AppNotificationInboxAction.GetAllSuccess);
const listNewNotificationInboxPending = actionSuccess.list._data.map(newNotification => newNotification.resId);
const listOldNotificationInboxPending = SessionStorageHelper.getListItem(SessionStorageEnum.notificationInboxPending);
let counterNewNotification = 0;
listNewNotificationInboxPending.forEach(newNotificationId => {
if (!listOldNotificationInboxPending.includes(newNotificationId)) {
counterNewNotification++;
}
});
if (counterNewNotification > 0) {
const actionNotification = {
text: MARK_AS_TRANSLATABLE("app.notification.action.see"),
callback: () => this.store.dispatch(new Navigate([RoutesEnum.preservationSpaceNotificationInbox])),
};
this.notificationService.showSuccess(MARK_AS_TRANSLATABLE("app.notification.notificationInbox.newIncoming"), {"number": counterNewNotification}, actionNotification);
}
SessionStorageHelper.initItemInList(SessionStorageEnum.notificationInboxPending, listNewNotificationInboxPending);
}),
).subscribe();
this.store.dispatch(new AppNotificationInboxAction.GetAll(queryParameters));
}
@Action(AppAction.Login) @Action(AppAction.Login)
login(ctx: StateContext<AppStateModel>, action: AppAction.Login): Observable<boolean> { login(ctx: StateContext<AppStateModel>, action: AppAction.Login): Observable<boolean> {
return this.oauthService.tryLogin() return this.oauthService.tryLogin()
......
...@@ -2,10 +2,7 @@ import {Injectable} from "@angular/core"; ...@@ -2,10 +2,7 @@ import {Injectable} from "@angular/core";
import {AdminResourceApiEnum} from "@app/shared/enums/api.enum"; import {AdminResourceApiEnum} from "@app/shared/enums/api.enum";
import {LocalStateEnum} from "@app/shared/enums/local-state.enum"; import {LocalStateEnum} from "@app/shared/enums/local-state.enum";
import {appNotificationInboxActionNameSpace} from "@app/stores/notification-inbox/app-notification-inbox.action"; import {appNotificationInboxActionNameSpace} from "@app/stores/notification-inbox/app-notification-inbox.action";
import { import {NotificationDlcm} from "@models";
NotificationDlcm,
Person,
} from "@models";
import { import {
Actions, Actions,
State, State,
...@@ -32,7 +29,7 @@ export interface AppNotificationInboxStateModel extends ResourceStateModel<Notif ...@@ -32,7 +29,7 @@ export interface AppNotificationInboxStateModel extends ResourceStateModel<Notif
queryParameters: new QueryParameters(environment.defaultEnumValuePageSizeOption), queryParameters: new QueryParameters(environment.defaultEnumValuePageSizeOption),
}, },
}) })
export class AppNotificationInboxState extends ResourceState<AppNotificationInboxStateModel, Person> { export class AppNotificationInboxState extends ResourceState<AppNotificationInboxStateModel, NotificationDlcm> {
constructor(protected apiService: ApiService, constructor(protected apiService: ApiService,
protected store: Store, protected store: Store,
protected notificationService: NotificationService, protected notificationService: NotificationService,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment