OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Migrate to global notification store + local component stores
Oliver Günthera4ace6ce8e23
diff --git a/frontend/package-lock.json b/frontend/package-lock.jsonindex 1e4ae8bc4a4..b9449ad228b 100644--- a/frontend/package-lock.json+++ b/frontend/package-lock.json@@ -1878,6 +1878,15 @@"schematics-utilities": "^2.0.3"}},+ "@datorama/akita-ng-effects": {+ "version": "1.0.5",+ "resolved": "https://registry.npmjs.org/@datorama/akita-ng-effects/-/akita-ng-effects-1.0.5.tgz",+ "integrity": "sha512-nP5BSNY2ubOcyMFSIAjd4oyIslUVYj+H7imzoZP62w6Firt+4YZVJ3EreuVkthEVcGN0y85NqdJ4SjvWcSgGMQ==",+ "requires": {+ "ts-action": "^11.0.0",+ "ts-action-operators": "^9.1.1"+ }+ },"@discoveryjs/json-ext": {"version": "0.5.2","resolved": "https://registry.npmjs.org/@discoveryjs/json-ext/-/json-ext-0.5.2.tgz",@@ -16498,6 +16507,16 @@"integrity": "sha512-L0Orpi8qGpRG//Nd+H90vFB+3iHnue1zSSGmNOOCh1GLJ7rUKVwV2HvijphGQS2UmhUZewS9VgvxYIdgr+fG1A==","dev": true},+ "ts-action": {+ "version": "11.0.0",+ "resolved": "https://registry.npmjs.org/ts-action/-/ts-action-11.0.0.tgz",+ "integrity": "sha512-TDxvzZ5UtKsBuw0McRs/L+iASj80m60nV8EXCP680ZdIl+oRHPGnBk85sZJWXLzqQwb6yQ+CcMzPTfBr0dEaAA=="+ },+ "ts-action-operators": {+ "version": "9.1.2",+ "resolved": "https://registry.npmjs.org/ts-action-operators/-/ts-action-operators-9.1.2.tgz",+ "integrity": "sha512-DZ+sJvBdOluThwCBcCdDnz0NiVeQxEwveL+cmkJGLO1ps+x/D0xwSefmOIa1S7p2nXFHH52ZPr/8VEvxZHaNgg=="+ },"ts-node": {"version": "8.3.0","resolved": "https://registry.npmjs.org/ts-node/-/ts-node-8.3.0.tgz",diff --git a/frontend/package.json b/frontend/package.jsonindex f6a28770bfb..3a260d98bd9 100644--- a/frontend/package.json+++ b/frontend/package.json@@ -71,6 +71,7 @@"@angular/platform-browser-dynamic": "~12.0.2","@angular/router": "~12.0.2","@datorama/akita": "^6.2.0",+ "@datorama/akita-ng-effects": "^1.0.5","@fullcalendar/angular": "5.5.0","@fullcalendar/core": "5.5.0","@fullcalendar/daygrid": "5.5.0",@@ -125,6 +126,7 @@"screenfull": "^4.2.1","swagger-ui": "^3.50.0","tablesorter": "^2.31.3",+ "ts-action": "^11.0.0","typedjson": "^1.5.1","urijs": "^1.19.2","zone.js": "~0.11.4"diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.tsindex 002260ed63c..e34506a52b4 100644--- a/frontend/src/app/app.module.ts+++ b/frontend/src/app/app.module.ts@@ -82,6 +82,8 @@ import { LinkedPluginsModule } from 'core-app/features/plugins/linked-plugins.moimport { OpenProjectInAppNotificationsModule } from 'core-app/features/in-app-notifications/in-app-notifications.module';import { OpenProjectBackupService } from './core/backup/op-backup.service';import { OpenProjectDirectFileUploadService } from './core/file-upload/op-direct-file-upload.service';+import { AkitaNgEffectsModule } from '@datorama/akita-ng-effects';+import { OpenProjectStateModule } from 'core-app/core/state/openproject-state.module';export function initializeServices(injector:Injector) {return () => {@@ -105,6 +107,8 @@ export function initializeServices(injector:Injector) {BrowserModule,// CommonsOPSharedModule,+ // State module+ OpenProjectStateModule,// Router moduleOpenprojectRouterModule,// Hal Modulediff --git a/frontend/src/app/core/apiv3/endpoints/notifications/apiv3-notification-paths.ts b/frontend/src/app/core/apiv3/endpoints/notifications/apiv3-notification-paths.tsindex 92ce808b697..3f2b10c2a30 100644--- a/frontend/src/app/core/apiv3/endpoints/notifications/apiv3-notification-paths.ts+++ b/frontend/src/app/core/apiv3/endpoints/notifications/apiv3-notification-paths.ts@@ -28,9 +28,9 @@import { APIv3GettableResource } from 'core-app/core/apiv3/paths/apiv3-resource';import { Observable } from 'rxjs';-import { InAppNotification } from 'core-app/features/in-app-notifications/store/in-app-notification.model';import { HttpClient } from '@angular/common/http';import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';+import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';export class Apiv3NotificationPaths extends APIv3GettableResource<InAppNotification> {@InjectField() http:HttpClient;diff --git a/frontend/src/app/core/apiv3/endpoints/notifications/apiv3-notifications-paths.ts b/frontend/src/app/core/apiv3/endpoints/notifications/apiv3-notifications-paths.tsindex b913cc96827..e56d501c232 100644--- a/frontend/src/app/core/apiv3/endpoints/notifications/apiv3-notifications-paths.ts+++ b/frontend/src/app/core/apiv3/endpoints/notifications/apiv3-notifications-paths.ts@@ -34,12 +34,12 @@ import {ApiV3ListFilter,listParamsString,} from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';-import { InAppNotification } from 'core-app/features/in-app-notifications/store/in-app-notification.model';import { Apiv3NotificationPaths } from 'core-app/core/apiv3/endpoints/notifications/apiv3-notification-paths';import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';import { HttpClient } from '@angular/common/http';import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';import { ID } from '@datorama/akita';+import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';export class Apiv3NotificationsPathsextends APIv3ResourceCollection<InAppNotification, Apiv3NotificationPaths> {@@ -67,6 +67,10 @@ export class Apiv3NotificationsPaths.get<IHALCollection<InAppNotification>>(this.path + listParamsString(params));}+ public listPath(params?:Apiv3ListParameters):string {+ return this.path + listParamsString(params);+ }+/*** Load unread events*/diff --git a/frontend/src/app/core/state/actions/actions.service.ts b/frontend/src/app/core/state/actions/actions.service.tsnew file mode 100644index 00000000000..44b38a2b41a--- /dev/null+++ b/frontend/src/app/core/state/actions/actions.service.ts@@ -0,0 +1,33 @@+import { Injectable } from '@angular/core';+import {+ Observable,+ Subject,+} from 'rxjs';+import { Action } from '@datorama/akita-ng-effects/lib/types';+import { ofType } from '@datorama/akita-ng-effects';+import { ActionCreator } from 'ts-action/action';+import { ActionType } from 'ts-action';++@Injectable({ providedIn: 'root' })+export class ActionsService {+ private actions = new Subject<Action>();++ /** Entire event stream */+ public actions$ = this.actions.asObservable();++ /**+ * Observe one or more event type+ * @param action The set of action creators to listen for+ * */+ ofType<C extends ActionCreator>(action:C):Observable<ActionType<C>> {+ return this+ .actions$+ .pipe(+ ofType(action),+ );+ }++ dispatch(action:Action):void {+ this.actions.next(action);+ }+}diff --git a/frontend/src/app/core/state/collection-store.type.ts b/frontend/src/app/core/state/collection-store.type.tsnew file mode 100644index 00000000000..b4be16f843b--- /dev/null+++ b/frontend/src/app/core/state/collection-store.type.ts@@ -0,0 +1,74 @@+import { EntityState, ID, QueryEntity } from '@datorama/akita';+import { Apiv3ListParameters, listParamsString } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import { Observable } from 'rxjs';+import { filter, switchMap } from 'rxjs/operators';++export interface CollectionResponse {+ ids:ID[];+}++export interface CollectionState<T> extends EntityState<T> {+ /** Loaded notification collections */+ collections:Record<string, CollectionResponse>;+}++export interface CollectionService<T> {+ query:QueryEntity<CollectionState<T>>;+}++export interface CollectionItem {+ id:ID;+}++/**+ * Initialize the collection part of the entity store+ */+export function createInitialCollectionState():{ collections:Record<string, CollectionResponse> } {+ return {+ collections: {},+ };+}++/**+ * Returns the collection key for the given APIv3 parameters+ *+ * @param params list params+ */+export function collectionKey(params:Apiv3ListParameters):string {+ return listParamsString(params);+}++/**+ * Retrieve a collection from the given parameter set.+ *+ * @param service+ * @param params+ */+export function selectCollection$<T extends CollectionItem>(service:CollectionService<T>, params:Apiv3ListParameters):Observable<CollectionResponse> {+ return service+ .query+ .select((state) => {+ const collection = collectionKey(params);+ return state?.collections[collection];+ })+ .pipe(+ filter((collection) => !!collection),+ );+}++/**+ * Retrieve the entities from the collection a given parameter set produces.+ *+ * @param service+ * @param params+ */+export function selectCollectionEntities$<T extends CollectionItem>(service:CollectionService<T>, params:Apiv3ListParameters):Observable<T[]> {+ return selectCollection$<T>(service, params)+ .pipe(+ switchMap((collection:CollectionResponse) => (+ service.query.selectAll({+ filterBy: ({ id }) => collection.ids.includes(id),+ })+ )),+ );+}diff --git a/frontend/src/app/core/state/effects/effect-handler.decorator.ts b/frontend/src/app/core/state/effects/effect-handler.decorator.tsnew file mode 100644index 00000000000..1e9764ebfd0--- /dev/null+++ b/frontend/src/app/core/state/effects/effect-handler.decorator.ts@@ -0,0 +1,61 @@+import 'reflect-metadata';+import { debugLog } from 'core-app/shared/helpers/debug_output';+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';+import { untilComponentDestroyed } from '@w11k/ngx-componentdestroyed';+import { Action } from '@datorama/akita-ng-effects/lib/types';+import { ActionsService } from 'core-app/core/state/actions/actions.service';+import { ActionCreator } from 'ts-action/action';+import { Injector } from '@angular/core';++// We're opening a baseclass through the decorator, the decorator enforces using any */+/* eslint-disable @typescript-eslint/no-explicit-any */+/* eslint-disable @typescript-eslint/no-unsafe-member-access */+/* eslint-disable no-param-reassign */++export interface EffectClass extends UntilDestroyedMixin {+ injector:Injector;+}+const EffectHandlers = Symbol('EffectHandlers');++type EffectHandlerItem = { callback:(action:Action) => void, action:ActionCreator };++export function EffectHandler<T extends { new(...args:any[]):EffectClass }>(constructor:T):any {+ return class extends constructor {+ constructor(...args:any[]) {+ super(...args);+ const handlers = constructor.prototype[EffectHandlers] as Map<string, EffectHandlerItem>;+ if (handlers) {+ handlers.forEach((item:EffectHandlerItem, key:string) => {+ debugLog(`Subscribing to effect ${key}`);++ const actions$ = this.injector.get(ActionsService);++ actions$+ .ofType(item.action)+ .pipe(untilComponentDestroyed(this))+ .subscribe((instance) => {+ try {+ item.callback.call(this, instance);+ } catch (e) {+ // eslint-disable-next-line @typescript-eslint/restrict-template-expressions+ console.error(`Error thrown in effect callback ${key}: ${e}`);+ }+ });+ });+ }+ }+ };+}++export function EffectCallback(action:ActionCreator) {+ // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types+ return (target:any, property:string, descriptor:PropertyDescriptor):void => {+ if (!target[EffectHandlers]) {+ target[EffectHandlers] = new Map();+ }++ // Here we just add some information that class decorator will use+ // eslint-disable-next-line @typescript-eslint/no-unsafe-call+ target[EffectHandlers].set(property, { action, callback: descriptor.value as (action:Action) => void });+ };+}diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notification.model.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notification.model.tssimilarity index 94%rename from frontend/src/app/features/in-app-notifications/store/in-app-notification.model.tsrename to frontend/src/app/core/state/in-app-notifications/in-app-notification.model.tsindex b98afe8806a..2a6d379ce9b 100644--- a/frontend/src/app/features/in-app-notifications/store/in-app-notification.model.ts+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notification.model.ts@@ -8,8 +8,6 @@ export type InAppNotificationFormat = 'markdown'|'custom';export const NOTIFICATIONS_MAX_SIZE = 100;-export const IAN_FACETS = ['unread', 'all'];-export interface InAppNotificationDetail {format:InAppNotificationFormat;raw:string|null;diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.actions.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.actions.tsnew file mode 100644index 00000000000..3a0fd289335--- /dev/null+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.actions.ts@@ -0,0 +1,12 @@+import { createAction, props } from '@datorama/akita-ng-effects';+import { ID } from '@datorama/akita';++export const markNotificationsAsRead = createAction(+ '[IAN] Mark notifications as read',+ props<{ caller:{ id:string }, notifications:ID[] }>(),+);++export const notificationsMarkedRead = createAction(+ '[IAN] Notifications were marked as read',+ props<{ caller:{ id:string }, notifications:ID[] }>(),+);diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.query.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.query.tsnew file mode 100644index 00000000000..75a8ef88457--- /dev/null+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.query.ts@@ -0,0 +1,5 @@+import { QueryEntity } from '@datorama/akita';+import { InAppNotificationsState } from './in-app-notifications.store';++export class InAppNotificationsQuery extends QueryEntity<InAppNotificationsState> {+}diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.tsnew file mode 100644index 00000000000..cad57ef31e9--- /dev/null+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts@@ -0,0 +1,128 @@+import {+ Injectable,+ Injector,+} from '@angular/core';+import {+ catchError,+ tap,+} from 'rxjs/operators';+import { Observable } from 'rxjs';+import {+ applyTransaction,+ ID,+} from '@datorama/akita';+import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';+import { NotificationsService } from 'core-app/shared/components/notifications/notifications.service';+import { HalResource } from 'core-app/features/hal/resources/hal-resource';+import { InAppNotificationsStore } from './in-app-notifications.store';+import { InAppNotification } from './in-app-notification.model';+import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';+import { HttpClient } from '@angular/common/http';+import { Actions } from '@datorama/akita-ng-effects';+import { InAppNotificationsQuery } from 'core-app/core/state/in-app-notifications/in-app-notifications.query';+import { Apiv3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import { collectionKey } from 'core-app/core/state/collection-store.type';+import {+ markNotificationsAsRead,+ notificationsMarkedRead,+} from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';+import {+ EffectCallback,+ EffectHandler,+} from 'core-app/core/state/effects/effect-handler.decorator';+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';+import { ActionsService } from 'core-app/core/state/actions/actions.service';++@EffectHandler+@Injectable()+export class InAppNotificationsService extends UntilDestroyedMixin {+ protected store = new InAppNotificationsStore();++ readonly query = new InAppNotificationsQuery(this.store);++ constructor(+ readonly injector:Injector,+ private http:HttpClient,+ private apiV3Service:APIV3Service,+ private notifications:NotificationsService,+ private actions$:ActionsService,+ ) {+ super();+ }++ fetchNotifications(params:Apiv3ListParameters):Observable<IHALCollection<InAppNotification>> {+ const collectionURL = collectionKey(params);++ return this+ .http+ .get<IHALCollection<InAppNotification>>(this.notificationsPath + collectionURL)+ .pipe(+ tap((events) => {+ applyTransaction(() => {+ this.store.add(events._embedded.elements);+ this.store.update(({ collections }) => (+ {+ collections: {+ ...collections,+ [collectionURL]: {+ ids: events._embedded.elements.map((el) => el.id),+ },+ },+ }+ ));+ });+ }),+ catchError((error) => {+ this.notifications.addError(error);+ throw error;+ }),+ );+ }++ update(id:ID, inAppNotification:Partial<InAppNotification>):void {+ this.store.update(id, inAppNotification);+ }++ markAsRead(notifications:ID[]):Observable<unknown> {+ return this+ .apiV3Service+ .notifications+ .markRead(notifications)+ .pipe(+ tap(() => {+ this.store.update(notifications, { readIAN: true });+ }),+ );+ }++ private get notificationsPath():string {+ return this+ .apiV3Service+ .notifications+ .path;+ }++ private sideLoadInvolvedWorkPackages(elements:InAppNotification[]):void {+ const wpIds = elements.map((element) => {+ const href = element._links.resource?.href;+ return href && HalResource.matchFromLink(href, 'work_packages');+ });++ void this+ .apiV3Service+ .work_packages+ .requireAll(_.compact(wpIds));+ }++ /**+ * Mark the given notification IDs as read through the API.+ */+ @EffectCallback(markNotificationsAsRead)+ private markNotificationsAsRead(action:ReturnType<typeof markNotificationsAsRead>) {+ this+ .markAsRead(action.notifications)+ .subscribe(() => (+ this.actions$.dispatch(notificationsMarkedRead(action))+ ));+ }+}diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.store.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.store.tsnew file mode 100644index 00000000000..6d7503a6764--- /dev/null+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.store.ts@@ -0,0 +1,13 @@+import { EntityStore, StoreConfig } from '@datorama/akita';+import { InAppNotification } from './in-app-notification.model';+import { CollectionState, createInitialCollectionState } from 'core-app/core/state/collection-store.type';++export interface InAppNotificationsState extends CollectionState<InAppNotification> {+}++@StoreConfig({ name: 'in-app-notifications' })+export class InAppNotificationsStore extends EntityStore<InAppNotificationsState> {+ constructor() {+ super(createInitialCollectionState());+ }+}diff --git a/frontend/src/app/core/state/openproject-state.module.ts b/frontend/src/app/core/state/openproject-state.module.tsnew file mode 100644index 00000000000..e2a1d247347--- /dev/null+++ b/frontend/src/app/core/state/openproject-state.module.ts@@ -0,0 +1,46 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2021 the OpenProject GmbH+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License version 3.+//+// OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+// Copyright (C) 2006-2013 Jean-Philippe Lang+// Copyright (C) 2010-2013 the ChiliProject Team+//+// This program is free software; you can redistribute it and/or+// modify it under the terms of the GNU General Public License+// as published by the Free Software Foundation; either version 2+// of the License, or (at your option) any later version.+//+// This program is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+// GNU General Public License for more details.+//+// You should have received a copy of the GNU General Public License+// along with this program; if not, write to the Free Software+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+//+// See docs/COPYRIGHT.rdoc for more details.+//++++import {+ Injector,+ NgModule,+} from '@angular/core';+import { AkitaNgEffectsModule } from '@datorama/akita-ng-effects';+import { InAppNotificationsService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';++@NgModule({+ imports: [+ // Global effects+ AkitaNgEffectsModule.forRoot(),+ ],+ providers: [+ InAppNotificationsService,+ ]+})+export class OpenProjectStateModule {+}diff --git a/frontend/src/app/features/in-app-notifications/bell/in-app-notification-bell.component.ts b/frontend/src/app/features/in-app-notifications/bell/in-app-notification-bell.component.tsindex 9d0570947f0..cee0d80092b 100644--- a/frontend/src/app/features/in-app-notifications/bell/in-app-notification-bell.component.ts+++ b/frontend/src/app/features/in-app-notifications/bell/in-app-notification-bell.component.ts@@ -1,16 +1,22 @@-import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';-import { InAppNotificationsQuery } from 'core-app/features/in-app-notifications/store/in-app-notifications.query';-import { InAppNotificationsStore } from 'core-app/features/in-app-notifications/store/in-app-notifications.store';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';+import {+ ChangeDetectionStrategy,+ Component,+ OnInit,+} from '@angular/core';import { OpModalService } from 'core-app/shared/components/modal/modal.service';-import { timer, combineLatest } from 'rxjs';+import {+ combineLatest,+ timer,+} from 'rxjs';import {filter,- switchMap,map,+ switchMap,} from 'rxjs/operators';import { ActiveWindowService } from 'core-app/core/active-window/active-window.service';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';+import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';+import { IanBellService } from 'core-app/features/in-app-notifications/bell/state/ian-bell.service';export const opInAppNotificationBellSelector = 'op-in-app-notification-bell';const POLLING_INTERVAL = 10000;@@ -21,34 +27,28 @@ const POLLING_INTERVAL = 10000;styleUrls: ['./in-app-notification-bell.component.sass'],changeDetection: ChangeDetectionStrategy.OnPush,providers: [- InAppNotificationsService,- InAppNotificationsStore,- InAppNotificationsQuery,+ IanBellService,],})-export class InAppNotificationBellComponent implements OnInit {+export class InAppNotificationBellComponent {polling$ = timer(10, POLLING_INTERVAL).pipe(filter(() => this.activeWindow.isActive),- switchMap(() => this.inAppService.fetchNotifications()),+ switchMap(() => this.storeService.fetchUnread()),);unreadCount$ = combineLatest([- this.inAppQuery.notLoaded$,+ this.storeService.unread$,this.polling$,]).pipe(map(([count]) => count));constructor(- readonly inAppQuery:InAppNotificationsQuery,- readonly inAppService:InAppNotificationsService,+ readonly storeService:IanBellService,+ readonly apiV3Service:APIV3Service,readonly activeWindow:ActiveWindowService,readonly modalService:OpModalService,readonly pathHelper:PathHelperService,) { }- ngOnInit():void {- this.inAppService.setPageSize(0);- }-notificationsPath():string {return this.pathHelper.notificationsPath();}diff --git a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.query.ts b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.query.tsnew file mode 100644index 00000000000..e55490094de--- /dev/null+++ b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.query.ts@@ -0,0 +1,11 @@+import { Query } from '@datorama/akita';+import {+ IanBellState,+ IanBellStore,+} from 'core-app/features/in-app-notifications/bell/state/ian-bell.store';++export class IanBellQuery extends Query<IanBellState> {+ constructor(protected store:IanBellStore) {+ super(store);+ }+}\ No newline at end of filediff --git a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.tsnew file mode 100644index 00000000000..455e5dfb50c--- /dev/null+++ b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts@@ -0,0 +1,58 @@+import {+ Injectable,+ Injector,+} from '@angular/core';+import { IanBellStore } from './ian-bell.store';+import { InAppNotificationsService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';+import { IAN_FACET_FILTERS } from 'core-app/features/in-app-notifications/center/state/ian-center.store';+import {+ map,+ tap,+} from 'rxjs/operators';+import { Observable } from 'rxjs';+import { IanBellQuery } from 'core-app/features/in-app-notifications/bell/state/ian-bell.query';+import {+ EffectCallback,+ EffectHandler,+} from 'core-app/core/state/effects/effect-handler.decorator';+import { notificationsMarkedRead } from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';++@Injectable()+@EffectHandler+export class IanBellService extends UntilDestroyedMixin {+ readonly id = 'ian-center';++ readonly store = new IanBellStore();++ readonly query = new IanBellQuery(this.store);++ unread$ = this.query.select('totalUnread');++ constructor(+ readonly injector:Injector,+ readonly ianService:InAppNotificationsService,+ ) {+ super();+ }++ fetchUnread():Observable<number> {+ return this.ianService+ .fetchNotifications({ filters: IAN_FACET_FILTERS.unread, pageSize: 0 })+ .pipe(+ map((result) => result.total),+ tap((count) => {+ this.store.update({ totalUnread: count });+ }),+ );+ }++ markRead(count:number):void {+ this.store.update(({ totalUnread }) => ({ totalUnread: totalUnread - count }));+ }++ @EffectCallback(notificationsMarkedRead)+ private reloadOnNotificationRead(action:ReturnType<typeof notificationsMarkedRead>) {+ this.markRead(action.notifications.length);+ }+}diff --git a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.store.ts b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.store.tsnew file mode 100644index 00000000000..a82b9c484cf--- /dev/null+++ b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.store.ts@@ -0,0 +1,23 @@+import { Injectable } from '@angular/core';+import {+ Store,+ StoreConfig,+} from '@datorama/akita';++export interface IanBellState {+ totalUnread:number;+}++export function createInitialState():IanBellState {+ return {+ totalUnread: 0,+ };+}++@Injectable({ providedIn: 'root' })+@StoreConfig({ name: 'ian-bell' })+export class IanBellStore extends Store<IanBellState> {+ constructor() {+ super(createInitialState());+ }+}diff --git a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center-page.component.ts b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center-page.component.tsindex 36a5e710fa3..4d5867d8761 100644--- a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center-page.component.ts+++ b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center-page.component.ts@@ -1,18 +1,9 @@-import {- ChangeDetectionStrategy,- ChangeDetectorRef,- Component,- Injector,- OnInit,-} from '@angular/core';+import { ChangeDetectionStrategy, ChangeDetectorRef, Component, Injector, OnInit } from '@angular/core';import {ToolbarButtonComponentDefinition,ViewPartitionState,} from 'core-app/features/work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component';-import {- StateService,- TransitionService,-} from '@uirouter/core';+import { StateService, TransitionService } from '@uirouter/core';import { NotificationsService } from 'core-app/shared/components/notifications/notifications.service';import { I18nService } from 'core-app/core/i18n/i18n.service';import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';@@ -20,25 +11,18 @@ import { NotificationSettingsButtonComponent } from 'core-app/features/in-app-noimport { ActivateFacetButtonComponent } from 'core-app/features/in-app-notifications/center/toolbar/facet/activate-facet-button.component';import { MarkAllAsReadButtonComponent } from 'core-app/features/in-app-notifications/center/toolbar/mark-all-as-read/mark-all-as-read-button.component';import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';-import { InAppNotificationsQuery } from 'core-app/features/in-app-notifications/store/in-app-notifications.query';-import { InAppNotificationsStore } from 'core-app/features/in-app-notifications/store/in-app-notifications.store';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';-import {- BackRouteOptions,- BackRoutingService,-} from 'core-app/features/work-packages/components/back-routing/back-routing.service';+import { BackRoutingService } from 'core-app/features/work-packages/components/back-routing/back-routing.service';+import { IanCenterService } from 'core-app/features/in-app-notifications/center/state/ian-center.service';@Component({templateUrl: '../../work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.html',styleUrls: ['../../work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.sass',],- changeDetection: ChangeDetectionStrategy.OnPush,providers: [- InAppNotificationsService,- InAppNotificationsStore,- InAppNotificationsQuery,+ IanCenterService,],+ changeDetection: ChangeDetectionStrategy.OnPush,})export class InAppNotificationCenterPageComponent extends UntilDestroyedMixin implements OnInit {text = {diff --git a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.ts b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.tsindex 96b420d7fd8..f303ac91cd8 100644--- a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.ts+++ b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.ts@@ -6,13 +6,15 @@ import {OnInit,} from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { NOTIFICATIONS_MAX_SIZE } from 'core-app/features/in-app-notifications/store/in-app-notification.model';-import { map } from 'rxjs/operators';+import {+ filter,+ map,+} from 'rxjs/operators';import { StateService } from '@uirouter/angular';-import { InAppNotificationsQuery } from 'core-app/features/in-app-notifications/store/in-app-notifications.query';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import { UIRouterGlobals } from '@uirouter/core';+import { IanCenterService } from 'core-app/features/in-app-notifications/center/state/ian-center.service';+import { NOTIFICATIONS_MAX_SIZE } from 'core-app/core/state/in-app-notifications/in-app-notification.model';@Component({selector: 'op-in-app-notification-center',@@ -21,19 +23,29 @@ import { UIRouterGlobals } from '@uirouter/core';changeDetection: ChangeDetectionStrategy.OnPush,})export class InAppNotificationCenterComponent implements OnInit {- activeFacet$ = this.ianQuery.activeFacet$;+ maxSize = NOTIFICATIONS_MAX_SIZE;++ activeFacet$ = this.storeService.activeFacet$;notifications$ = this- .ianService- .query- .aggregatedNotifications$+ .storeService+ .aggregatedCenterNotifications$.pipe(map((items) => Object.values(items)),);- hasNotifications$ = this.ianService.query.hasNotifications$;+ hasNotifications$ = this+ .notifications$+ .pipe(+ map((items) => items.length > 0),+ );- hasMoreThanPageSize$ = this.ianService.query.hasMoreThanPageSize$;+ hasMoreThanPageSize$ = this+ .storeService+ .notLoaded$+ .pipe(+ map((notLoaded) => notLoaded > 0),+ );noResultText$ = this.activeFacet$@@ -42,20 +54,16 @@ export class InAppNotificationCenterComponent implements OnInit {);totalCountWarning$ = this- .ianService- .query+ .storeService.notLoaded$.pipe(+ filter((notLoaded) => notLoaded > 0),map((notLoaded:number) => this.I18n.t('js.notifications.center.total_count_warning',- { newest_count: NOTIFICATIONS_MAX_SIZE, more_count: notLoaded },+ { newest_count: this.maxSize, more_count: notLoaded },)),);- maxSize = NOTIFICATIONS_MAX_SIZE;-- facets:string[] = ['unread', 'all'];-originalOrder = ():number => 0;text = {@@ -71,15 +79,13 @@ export class InAppNotificationCenterComponent implements OnInit {readonly cdRef:ChangeDetectorRef,readonly elementRef:ElementRef,readonly I18n:I18nService,- readonly ianService:InAppNotificationsService,- readonly ianQuery:InAppNotificationsQuery,+ readonly storeService:IanCenterService,readonly uiRouterGlobals:UIRouterGlobals,readonly state:StateService,) { }ngOnInit():void {- this.ianService.setActiveFacet('unread');- this.ianService.setActiveFilters([]);+ this.storeService.setFacet('unread');}openSplitView($event:WorkPackageResource):void {diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.query.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.query.tsnew file mode 100644index 00000000000..827b2363931--- /dev/null+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.query.ts@@ -0,0 +1,15 @@+import { Query } from '@datorama/akita';+import {+ IanCenterState,+ IanCenterStore,+} from 'core-app/features/in-app-notifications/center/state/ian-center.store';+import { InAppNotificationsService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';++export class IanCenterQuery extends Query<IanCenterState> {+ constructor(+ protected store:IanCenterStore,+ protected ianService:InAppNotificationsService,+ ) {+ super(store);+ }+}diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.tsnew file mode 100644index 00000000000..c802b34b27c--- /dev/null+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.service.ts@@ -0,0 +1,121 @@+import {+ Injectable,+ Injector,+} from '@angular/core';+import {+ IAN_FACET_FILTERS,+ IanCenterStore,+ InAppNotificationFacet,+} from './ian-center.store';+import {+ map,+ switchMap,+ take,+} from 'rxjs/operators';+import {+ selectCollection$,+ selectCollectionEntities$,+} from 'core-app/core/state/collection-store.type';+import { InAppNotificationsService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';+import {+ markNotificationsAsRead,+ notificationsMarkedRead,+} from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';+import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';+import { IanCenterQuery } from 'core-app/features/in-app-notifications/center/state/ian-center.query';+import { ID } from '@datorama/akita';+import {+ EffectCallback,+ EffectHandler,+} from 'core-app/core/state/effects/effect-handler.decorator';+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';+import { Apiv3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import { ActionsService } from 'core-app/core/state/actions/actions.service';++@Injectable()+@EffectHandler+export class IanCenterService extends UntilDestroyedMixin {+ readonly id = 'ian-center';++ readonly store = new IanCenterStore();++ readonly query = new IanCenterQuery(this.store, this.ianService);++ activeFacet$ = this.query.select('activeFacet');++ notLoaded$ = this.query.select('notLoaded');++ paramsChanges$ = this+ .query+ .select(['params', 'activeFacet']);++ selectCollection$ = this+ .paramsChanges$+ .pipe(+ switchMap(() => selectCollection$(this.ianService, this.params)),+ );++ selectNotifications$ = this+ .paramsChanges$+ .pipe(+ switchMap(() => selectCollectionEntities$<InAppNotification>(this.ianService, this.params)),+ );++ aggregatedCenterNotifications$ = this+ .selectNotifications$+ .pipe(+ map((notifications) => (+ _.groupBy(notifications, (notification) => notification._links.resource?.href || 'none')+ )),+ );++ constructor(+ readonly injector:Injector,+ readonly ianService:InAppNotificationsService,+ readonly actions$:ActionsService,+ ) {+ super();+ }++ setFacet(facet:InAppNotificationFacet):void {+ this.store.update({ activeFacet: facet });+ this.reload();+ }++ markAsRead(notifications:ID[]):void {+ this.actions$.dispatch(+ markNotificationsAsRead({ caller: this, notifications }),+ );+ }++ markAllAsRead():void {+ selectCollection$(this.ianService, this.store.getValue().params)+ .pipe(+ take(1),+ )+ .subscribe((collection) => {+ this.markAsRead(collection.ids);+ });+ }++ /**+ * Reload after notifications were successfully marked as read+ */+ @EffectCallback(notificationsMarkedRead)+ private reloadOnNotificationRead(action:ReturnType<typeof notificationsMarkedRead>) {+ if (action.caller !== this) {+ this.reload();+ }+ }++ private reload() {+ this.ianService+ .fetchNotifications(this.params)+ .subscribe();+ }++ private get params():Apiv3ListParameters {+ const state = this.store.getValue();+ return { ...state.params, filters: IAN_FACET_FILTERS[state.activeFacet] };+ }+}diff --git a/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.ts b/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.tsnew file mode 100644index 00000000000..e2b32b4c8cb--- /dev/null+++ b/frontend/src/app/features/in-app-notifications/center/state/ian-center.store.ts@@ -0,0 +1,40 @@+import { Store, StoreConfig } from '@datorama/akita';+import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import { NOTIFICATIONS_MAX_SIZE } from 'core-app/core/state/in-app-notifications/in-app-notification.model';++export interface IanCenterState {+ params:{+ page:number;+ pageSize:number;+ };+ activeFacet:InAppNotificationFacet;++ /** Number of elements not showing after max values loaded */+ notLoaded:number;+}++export type InAppNotificationFacet = 'unread'|'all';++export const IAN_FACET_FILTERS:Record<InAppNotificationFacet, ApiV3ListFilter[]> = {+ unread: [['readIAN', '=', false]],+ all: [],+};++export function createInitialState():IanCenterState {+ return {+ params: {+ pageSize: NOTIFICATIONS_MAX_SIZE,+ page: 1,+ },+ activeFacet: 'unread',+ notLoaded: 0,+ };+}++@StoreConfig({ name: 'ian-center' })+export class IanCenterStore extends Store<IanCenterState> {++ constructor() {+ super(createInitialState());+ }+}diff --git a/frontend/src/app/features/in-app-notifications/center/toolbar/facet/activate-facet-button.component.ts b/frontend/src/app/features/in-app-notifications/center/toolbar/facet/activate-facet-button.component.tsindex a005c620de7..184c889940f 100644--- a/frontend/src/app/features/in-app-notifications/center/toolbar/facet/activate-facet-button.component.ts+++ b/frontend/src/app/features/in-app-notifications/center/toolbar/facet/activate-facet-button.component.ts@@ -1,8 +1,11 @@-import { Component, ChangeDetectionStrategy } from '@angular/core';-import { IAN_FACETS } from 'core-app/features/in-app-notifications/store/in-app-notification.model';+import { ChangeDetectionStrategy, Component } from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { InAppNotificationsQuery } from 'core-app/features/in-app-notifications/store/in-app-notifications.query';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';+import { Actions } from '@datorama/akita-ng-effects';+import { IanCenterService } from 'core-app/features/in-app-notifications/center/state/ian-center.service';+import {+ IAN_FACET_FILTERS,+ InAppNotificationFacet,+} from 'core-app/features/in-app-notifications/center/state/ian-center.store';@Component({selector: 'op-activate-facet',@@ -10,8 +13,6 @@ import { InAppNotificationsService } from 'core-app/features/in-app-notificationchangeDetection: ChangeDetectionStrategy.OnPush,})export class ActivateFacetButtonComponent {- activeFacet$ = this.ianQuery.activeFacet$;-text = {facets: {unread: this.I18n.t('js.notifications.facets.unread'),@@ -19,16 +20,18 @@ export class ActivateFacetButtonComponent {},};- availableFacets = IAN_FACETS;+ availableFacets = Object.keys(IAN_FACET_FILTERS);++ activeFacet$ = this.storeService.activeFacet$;constructor(private I18n:I18nService,- private ianQuery:InAppNotificationsQuery,- private ianService:InAppNotificationsService,+ private storeService:IanCenterService,+ private actions$:Actions,) {}- activateFacet(facet:string):void {- this.ianService.setActiveFacet(facet);+ activateFacet(facet:InAppNotificationFacet):void {+ this.storeService.setFacet(facet);}}diff --git a/frontend/src/app/features/in-app-notifications/center/toolbar/mark-all-as-read/mark-all-as-read-button.component.ts b/frontend/src/app/features/in-app-notifications/center/toolbar/mark-all-as-read/mark-all-as-read-button.component.tsindex e7a1792f708..b6eca373f23 100644--- a/frontend/src/app/features/in-app-notifications/center/toolbar/mark-all-as-read/mark-all-as-read-button.component.ts+++ b/frontend/src/app/features/in-app-notifications/center/toolbar/mark-all-as-read/mark-all-as-read-button.component.ts@@ -1,6 +1,9 @@-import { Component, ChangeDetectionStrategy } from '@angular/core';+import {+ ChangeDetectionStrategy,+ Component,+} from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';+import { IanCenterService } from 'core-app/features/in-app-notifications/center/state/ian-center.service';@Component({selector: 'op-mark-all-as-read-button',@@ -15,11 +18,11 @@ export class MarkAllAsReadButtonComponent {constructor(private I18n:I18nService,- private ianService:InAppNotificationsService,+ private storeService:IanCenterService,) {}markAllRead():void {- this.ianService.markAllRead();+ this.storeService.markAllAsRead();}}diff --git a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.tsindex 15ce19b1d33..b129a81e232 100644--- a/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts+++ b/frontend/src/app/features/in-app-notifications/entry/in-app-notification-entry.component.ts@@ -1,15 +1,11 @@import {- EventEmitter,ChangeDetectionStrategy,Component,+ EventEmitter,Input,OnInit,Output,} from '@angular/core';-import {- InAppNotification,- InAppNotificationDetail,-} from 'core-app/features/in-app-notifications/store/in-app-notification.model';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import {Observable,@@ -18,7 +14,6 @@ import {import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';import idFromLink from 'core-app/features/hal/helpers/id-from-link';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';import { TimezoneService } from 'core-app/core/datetime/timezone.service';import {distinctUntilChanged,@@ -28,9 +23,13 @@ import { PrincipalLike } from 'core-app/shared/components/principal/principal-tyimport { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { take } from 'rxjs/internal/operators/take';import { StateService } from '@uirouter/angular';-import { InAppNotificationsQuery } from 'core-app/features/in-app-notifications/store/in-app-notifications.query';import { HalResource } from 'core-app/features/hal/resources/hal-resource';import { BackRouteOptions } from 'core-app/features/work-packages/components/back-routing/back-routing.service';+import {+ InAppNotification,+ InAppNotificationDetail,+} from 'core-app/core/state/in-app-notifications/in-app-notification.model';+import { IanCenterService } from 'core-app/features/in-app-notifications/center/state/ian-center.service';@Component({selector: 'op-in-app-notification-entry',@@ -47,7 +46,7 @@ export class InAppNotificationEntryComponent implements OnInit {workPackage$:Observable<WorkPackageResource>|null = null;- loading$ = this.ianQuery.selectLoading();+ loading$ = this.storeService.query.selectLoading();// Formattable body, if anybody:InAppNotificationDetail[];@@ -82,8 +81,7 @@ export class InAppNotificationEntryComponent implements OnInit {constructor(readonly apiV3Service:APIV3Service,readonly I18n:I18nService,- readonly ianService:InAppNotificationsService,- readonly ianQuery:InAppNotificationsQuery,+ readonly storeService:IanCenterService,readonly timezoneService:TimezoneService,readonly pathHelper:PathHelperService,readonly state:StateService,@@ -154,10 +152,7 @@ export class InAppNotificationEntryComponent implements OnInit {markAsRead(event:MouseEvent, notifications:InAppNotification[]):void {event.stopPropagation();-- this- .ianService- .markAsRead(notifications);+ this.storeService.markAsRead(notifications.map((el) => el.id));}private buildActors() {diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.tsdeleted file mode 100644index 4ef2e8044ea..00000000000--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.query.ts+++ /dev/null@@ -1,74 +0,0 @@-import { Injectable } from '@angular/core';-import { QueryEntity } from '@datorama/akita';-import { map, switchMap } from 'rxjs/operators';-import { Observable, throwError } from 'rxjs';-import {- InAppNotificationsState,- InAppNotificationsStore,-} from './in-app-notifications.store';-import { InAppNotification } from 'core-app/features/in-app-notifications/store/in-app-notification.model';--@Injectable()-export class InAppNotificationsQuery extends QueryEntity<InAppNotificationsState> {- /** Select the active filter facet */- activeFacet$ = this.select('activeFacet');-- activeFetchParameters$ = this.select(['activeFacet', 'pageSize', 'activeFilters']);-- /** Select the active filter facet */- notLoaded$ = this.select('notLoaded');-- /** Get the faceted items */- faceted$ = this.activeFacet$- .pipe(- switchMap((facet) => {- switch (facet) {- case 'unread':- return this.unreadOrKept$;- case 'all':- return this.selectAll();- default:- return throwError(new Error(`Invalid facet ${facet}`));- }- }),- );-- /** Notifications grouped by resource */- aggregatedNotifications$:Observable<{ [key:string]:InAppNotification[] }> = this- .faceted$- .pipe(- map((notifications) => (- _.groupBy(notifications, (notification) => notification._links.resource?.href || 'none')- )),- );-- /** Get the unread items */- unread$ = this.selectAll({- filterBy: ({ readIAN }) => !readIAN,- });-- /** Get the number of unread items */- unreadCount$ = this.unread$.pipe(map((notifications) => notifications.length));-- /** Do we have any unread items? */- hasUnread$ = this.unreadCount$.pipe(map((count) => count > 0));-- /** Get all items that shall be kept in the notification center */- unreadOrKept$ = this.selectAll({- filterBy: ({ readIAN, keep }) => !readIAN || !!keep,- });-- /** Do we have any notification that shall be visible the notification center? */- hasNotifications$ = this.selectCount().pipe(map((count) => count > 0));-- /** Determine whether the pageSize is not sufficient to load all notifications */- hasMoreThanPageSize$ = this- .select()- .pipe(- map(({ notLoaded }) => notLoaded > 0),- );-- constructor(protected store:InAppNotificationsStore) {- super(store);- }-}diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.tsdeleted file mode 100644index bfb993c4010..00000000000--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.service.ts+++ /dev/null@@ -1,130 +0,0 @@-import { Injectable } from '@angular/core';-import {- debounceTime,- switchMap,- take,- tap,- catchError,-} from 'rxjs/operators';-import { Subscription, Observable } from 'rxjs';-import { applyTransaction, ID, setLoading } from '@datorama/akita';-import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';-import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';-import { NotificationsService } from 'core-app/shared/components/notifications/notifications.service';-import { InAppNotificationsQuery } from 'core-app/features/in-app-notifications/store/in-app-notifications.query';-import { HalResource } from 'core-app/features/hal/resources/hal-resource';-import { InAppNotificationsStore } from './in-app-notifications.store';-import { InAppNotification } from './in-app-notification.model';-import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';--@Injectable()-export class InAppNotificationsService {- constructor(- private store:InAppNotificationsStore,- public query:InAppNotificationsQuery,- private apiV3Service:APIV3Service,- private notifications:NotificationsService,- ) {- this.query.activeFetchParameters$- .pipe(- debounceTime(0),- switchMap(() => this.fetchNotifications()),- ).subscribe();- }-- fetchNotifications():Observable<IHALCollection<InAppNotification>> {- this.store.setLoading(true);-- const {- activeFacet,- activeFilters,- pageSize,- } = this.query.getValue();-- return this- .apiV3Service- .notifications- .facet(activeFacet, {- pageSize,- filters: activeFilters,- })- .pipe(- tap((events) => {- this.sideLoadInvolvedWorkPackages(events._embedded.elements);- applyTransaction(() => {- this.store.set(events._embedded.elements);- this.store.update({ notLoaded: events.total - events.count });- });- this.store.setLoading(false);- }),- catchError((error) => {- this.notifications.addError(error);- throw error;- }),- );- }-- update(id:ID, inAppNotification:Partial<InAppNotification>):void {- this.store.update(id, inAppNotification);- }-- setPageSize(pageSize:number):void {- this.store.update((state) => ({ ...state, pageSize }));- }-- setActiveFacet(facet:string):void {- this.store.update((state) => ({ ...state, activeFacet: facet }));- }-- setActiveFilters(filters:ApiV3ListFilter[]):void {- this.store.update((state) => ({ ...state, activeFilters: filters }));- }-- markAllRead():Subscription {- return this.query- .unread$- .pipe(- take(1),- switchMap((events) => this.apiV3Service.notifications.markRead(events.map((event) => event.id))),- setLoading(this.store),- )- .subscribe(() => {- applyTransaction(() => {- this.store.update(null, { readIAN: true });- this.store.update({ unreadCount: 0 });- });- });- }-- markAsRead(notifications:InAppNotification[], keep = false):Subscription {- const ids = notifications.map((n) => n.id);-- return this- .apiV3Service- .notifications- .markRead(ids)- .pipe(- setLoading(this.store),- )- .subscribe(() => {- applyTransaction(() => {- this.store.update(ids, { readIAN: true, keep });- this.store.update(- ({ unreadCount }) => ({ unreadCount: unreadCount - ids.length }),- );- });- });- }-- private sideLoadInvolvedWorkPackages(elements:InAppNotification[]):void {- const wpIds = elements.map((element) => {- const href = element._links.resource?.href;- return href && HalResource.matchFromLink(href, 'work_packages');- });-- void this- .apiV3Service- .work_packages- .requireAll(_.compact(wpIds));- }-}diff --git a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.ts b/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.tsdeleted file mode 100644index 97968fc52df..00000000000--- a/frontend/src/app/features/in-app-notifications/store/in-app-notifications.store.ts+++ /dev/null@@ -1,31 +0,0 @@-import { Injectable } from '@angular/core';-import { EntityState, EntityStore, StoreConfig } from '@datorama/akita';-import { InAppNotification, NOTIFICATIONS_MAX_SIZE } from './in-app-notification.model';-import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';--export interface InAppNotificationsState extends EntityState<InAppNotification> {- /** Number of elements not showing after max values loaded */- notLoaded:number;- pageSize:number;- activeFacet:string;- activeFilters:ApiV3ListFilter[];- expanded:boolean;-}--export function createInitialState():InAppNotificationsState {- return {- notLoaded: 0,- pageSize: NOTIFICATIONS_MAX_SIZE,- activeFacet: 'unread',- activeFilters: [],- expanded: false,- };-}--@Injectable()-@StoreConfig({ name: 'in-app-notifications' })-export class InAppNotificationsStore extends EntityStore<InAppNotificationsState> {- constructor() {- super(createInitialState());- }-}diff --git a/frontend/src/app/features/work-packages/components/wp-buttons/wp-mark-notification-button/work-package-mark-notification-button.component.ts b/frontend/src/app/features/work-packages/components/wp-buttons/wp-mark-notification-button/work-package-mark-notification-button.component.tsindex 9567dbd5b43..8ee12ee3d66 100644--- a/frontend/src/app/features/work-packages/components/wp-buttons/wp-mark-notification-button/work-package-mark-notification-button.component.ts+++ b/frontend/src/app/features/work-packages/components/wp-buttons/wp-mark-notification-button/work-package-mark-notification-button.component.ts@@ -1,9 +1,7 @@-import {- Component, ChangeDetectionStrategy, Input,-} from '@angular/core';+import { ChangeDetectionStrategy, Component, Input } from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';+import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';@Component({selector: 'op-work-package-mark-notification-button',@@ -21,11 +19,11 @@ export class WorkPackageMarkNotificationButtonComponent {constructor(private I18n:I18nService,- private ianService:InAppNotificationsService,+ private storeService:WpSingleViewService,) {}markAllBelongingNotificationsAsRead():void {- this.ianService.markAllRead();+ this.storeService.markAllAsRead();}}diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.tsindex d34daf2c890..25a05871709 100644--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-base.controller.ts@@ -26,7 +26,11 @@// See docs/COPYRIGHT.rdoc for more details.//++-import { ChangeDetectorRef, Directive, OnInit } from '@angular/core';+import {+ ChangeDetectorRef,+ Directive,+ OnInit,+} from '@angular/core';import { Transition } from '@uirouter/core';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';import { HalResource } from 'core-app/features/hal/resources/hal-resource';@@ -35,10 +39,9 @@ import { WorkPackagesActivityService } from 'core-app/features/work-packages/comimport { I18nService } from 'core-app/core/i18n/i18n.service';import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';-import { InAppNotification } from 'core-app/features/in-app-notifications/store/in-app-notification.model';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';import { Observable } from 'rxjs';import { map } from 'rxjs/operators';+import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';@Directive()export class ActivityPanelBaseController extends UntilDestroyedMixin implements OnInit {@@ -52,8 +55,6 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implements// Visible activitiespublic visibleActivities:ActivityEntryInfo[] = [];- public notifications:InAppNotification[] = [];-public reverse:boolean;public showToggler:boolean;@@ -73,7 +74,7 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implementsreadonly cdRef:ChangeDetectorRef,readonly $transition:Transition,readonly wpActivity:WorkPackagesActivityService,- readonly ianService:InAppNotificationsService,+ readonly storeService:WpSingleViewService,) {super();@@ -95,12 +96,6 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implementsthis.cdRef.detectChanges();});});-- this.ianService.setActiveFacet('unread');- this.ianService.setActiveFilters([- ['resourceId', '=', [this.workPackageId]],- ['resourceType', '=', ['WorkPackage']],- ]);}protected updateActivities(activities:HalResource[]) {@@ -112,12 +107,12 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implements}protected shouldShowToggler() {- const count_all = this.unfilteredActivities.length;- const count_with_comments = this.getActivitiesWithComments().length;+ const countAll = this.unfilteredActivities.length;+ const countWithComments = this.getActivitiesWithComments().length;- return count_all > 1- && count_with_comments > 0- && count_with_comments < this.unfilteredActivities.length;+ return countAll > 1+ && countWithComments > 0+ && countWithComments < this.unfilteredActivities.length;}protected getVisibleActivities() {@@ -134,11 +129,12 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implementsprotected hasUnreadNotification(activityHref:string):Observable<boolean> {return this- .ianService- .query- .unread$+ .storeService+ .selectNotifications$.pipe(- map((notifications) => !!notifications.find((notification) => notification._links.activity?.href === activityHref)),+ map((notifications) => (+ !!notifications.find((notification) => notification._links.activity?.href === activityHref)+ )),);}diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/wp-activity.service.ts b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/wp-activity.service.tsindex 54d93307487..b9a396a6794 100644--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/wp-activity.service.ts+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/wp-activity.service.ts@@ -45,8 +45,8 @@ export class WorkPackagesActivityService extends WorkPackageLinkedResourceCache<return this.isReversed ? 'desc' : 'asc';}- public get isReversed() {- return this.ConfigurationService.commentsSortedInDescendingOrder();+ public get isReversed():boolean {+ return !!this.ConfigurationService.commentsSortedInDescendingOrder();}/**diff --git a/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-notifications-count.function.ts b/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-notifications-count.function.tsindex 8137662cdc3..5ca6e08c746 100644--- a/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-notifications-count.function.ts+++ b/frontend/src/app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-notifications-count.function.ts@@ -1,19 +1,12 @@import { Injector } from '@angular/core';import { Observable } from 'rxjs';-import { map } from 'rxjs/operators';import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';-import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';-import { NOTIFICATIONS_MAX_SIZE } from 'core-app/features/in-app-notifications/store/in-app-notification.model';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';+import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';export function workPackageNotificationsCount(workPackage:WorkPackageResource,injector:Injector,):Observable<number> {- const ianService = injector.get(InAppNotificationsService);-- return ianService.query.unread$- .pipe(- map((data) => data.length),- );+ const storeService = injector.get(WpSingleViewService);+ return storeService.selectNotificationsCount$;}diff --git a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.tsindex f2d49bd0506..261fe829120 100644--- a/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts+++ b/frontend/src/app/features/work-packages/routing/wp-full-view/wp-full-view.component.ts@@ -32,11 +32,9 @@ import { Component, Injector, OnInit } from '@angular/core';import { Observable, of } from 'rxjs';import { WorkPackageViewSelectionService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-selection.service';import { WorkPackageSingleViewBase } from 'core-app/features/work-packages/routing/wp-view-base/work-package-single-view.base';-import { InAppNotificationsQuery } from 'core-app/features/in-app-notifications/store/in-app-notifications.query';-import { InAppNotificationsStore } from 'core-app/features/in-app-notifications/store/in-app-notifications.store';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';import { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';+import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';@Component({templateUrl: './wp-full-view.html',@@ -44,10 +42,8 @@ import { WorkPackageNotificationService } from 'core-app/features/work-packages/// Required class to support inner scrolling on pagehost: { class: 'work-packages-page--ui-view' },providers: [+ WpSingleViewService,{ provide: HalResourceNotificationService, useExisting: WorkPackageNotificationService },- InAppNotificationsService,- InAppNotificationsStore,- InAppNotificationsQuery,],})export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase implements OnInit {@@ -56,8 +52,6 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imppublic displayWatchButton:boolean;- public displayNotificationsButton$:Observable<boolean> = this.ianService.query.hasUnread$;-public watchers:any;stateName$ = of('work-packages.new');@@ -66,7 +60,6 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imppublic injector:Injector,public wpTableSelection:WorkPackageViewSelectionService,readonly $state:StateService,- readonly ianService:InAppNotificationsService,) {super(injector, $state.params.workPackageId);}@@ -89,14 +82,6 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp// Set Focused WPthis.wpTableFocus.updateFocus(this.workPackage.id!);- if (this.workPackage.id) {- this.ianService.setActiveFacet('unread');- this.ianService.setActiveFilters([- ['resourceId', '=', [this.workPackage.id]],- ['resourceType', '=', ['WorkPackage']],- ]);- }-this.setWorkPackageScopeProperties(this.workPackage);}diff --git a/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts b/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.tsindex ac9d31fcdcd..fab1d5c44a9 100644--- a/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts+++ b/frontend/src/app/features/work-packages/routing/wp-split-view/wp-split-view.component.ts@@ -26,18 +26,10 @@// See docs/COPYRIGHT.rdoc for more details.//++-import {- ChangeDetectionStrategy,- Component,- Injector,- OnInit,-} from '@angular/core';+import { ChangeDetectionStrategy, Component, Injector, OnInit } from '@angular/core';import { StateService } from '@uirouter/core';import { WorkPackageViewFocusService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-focus.service';import { States } from 'core-app/core/states/states.service';-import { InAppNotificationsQuery } from 'core-app/features/in-app-notifications/store/in-app-notifications.query';-import { InAppNotificationsStore } from 'core-app/features/in-app-notifications/store/in-app-notifications.store';-import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';import { FirstRouteService } from 'core-app/core/routing/first-route-service';import { KeepTabService } from 'core-app/features/work-packages/components/wp-single-view-tabs/keep-tab/keep-tab.service';import { WorkPackageViewSelectionService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-selection.service';@@ -45,25 +37,21 @@ import { WorkPackageSingleViewBase } from 'core-app/features/work-packages/routiimport { HalResourceNotificationService } from 'core-app/features/hal/services/hal-resource-notification.service';import { WorkPackageNotificationService } from 'core-app/features/work-packages/services/notifications/work-package-notification.service';import { BackRoutingService } from 'core-app/features/work-packages/components/back-routing/back-routing.service';-import { Observable } from 'rxjs';+import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';@Component({templateUrl: './wp-split-view.html',changeDetection: ChangeDetectionStrategy.OnPush,selector: 'wp-split-view-entry',providers: [+ WpSingleViewService,{ provide: HalResourceNotificationService, useClass: WorkPackageNotificationService },- InAppNotificationsService,- InAppNotificationsStore,- InAppNotificationsQuery,],})export class WorkPackageSplitViewComponent extends WorkPackageSingleViewBase implements OnInit {/** Reference to the base route e.g., work-packages.partitioned.list or bim.partitioned.split */private baseRoute:string = this.$state.current.data.baseRoute;- public displayNotificationsButton$:Observable<boolean> = this.ianService.query.hasUnread$;-constructor(public injector:Injector,public states:States,@@ -73,7 +61,6 @@ export class WorkPackageSplitViewComponent extends WorkPackageSingleViewBase imppublic wpTableFocus:WorkPackageViewFocusService,readonly $state:StateService,readonly backRouting:BackRoutingService,- readonly ianService:InAppNotificationsService,) {super(injector, $state.params.workPackageId);}@@ -110,14 +97,6 @@ export class WorkPackageSplitViewComponent extends WorkPackageSingleViewBase imp);}});-- if (wpId) {- this.ianService.setActiveFacet('unread');- this.ianService.setActiveFilters([- ['resourceId', '=', [wpId]],- ['resourceType', '=', ['WorkPackage']],- ]);- }}get shouldFocus():boolean {diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.query.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.query.tsnew file mode 100644index 00000000000..a4903569fb0--- /dev/null+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.query.ts@@ -0,0 +1,6 @@+import { Query } from '@datorama/akita';+import { WpSingleViewState } from './wp-single-view.store';++export class WpSingleViewQuery extends Query<WpSingleViewState> {++}diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.tsnew file mode 100644index 00000000000..7903c820cd2--- /dev/null+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.service.ts@@ -0,0 +1,116 @@+import {+ Injectable,+ Injector,+} from '@angular/core';+import { WpSingleViewStore } from './wp-single-view.store';+import { WpSingleViewQuery } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.query';+import {+ filter,+ map,+ switchMap,+ take,+} from 'rxjs/operators';+import {+ selectCollection$,+ selectCollectionEntities$,+} from 'core-app/core/state/collection-store.type';+import { InAppNotification } from 'core-app/core/state/in-app-notifications/in-app-notification.model';+import { InAppNotificationsService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';+import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';+import {+ markNotificationsAsRead,+ notificationsMarkedRead,+} from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';+import { ActionsService } from 'core-app/core/state/actions/actions.service';+import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';+import {+ EffectCallback,+ EffectHandler,+} from 'core-app/core/state/effects/effect-handler.decorator';++@EffectHandler+@Injectable()+export class WpSingleViewService extends UntilDestroyedMixin {+ id = 'WorkPackage Activity Store';++ protected store = new WpSingleViewStore();++ readonly query = new WpSingleViewQuery(this.store);++ selectNotifications$ = this+ .query+ .select((state) => state.notifications.filters)+ .pipe(+ filter((filters) => filters.length > 0),+ switchMap((filters) => selectCollectionEntities$<InAppNotification>(this.ianService, { filters })),+ );++ selectNotificationsCount$ = this+ .selectNotifications$+ .pipe(+ map((notifications) => notifications.length),+ );++ hasNotifications$ = this+ .selectNotificationsCount$+ .pipe(+ map((count) => count > 0),+ );++ constructor(+ readonly injector:Injector,+ private ianService:InAppNotificationsService,+ private actions$:ActionsService,+ ) {+ super();+ }++ setFilters(workPackageId:string):void {+ const filters:ApiV3ListFilter[] = [+ ['readIAN', '=', false],+ ['resourceId', '=', [workPackageId]],+ ['resourceType', '=', ['WorkPackage']],+ ];++ this.store.update(({ notifications }) => (+ {+ notifications: {+ ...notifications,+ filters,+ },+ }+ ));++ this.reload(filters);+ }++ markAllAsRead():void {+ selectCollection$(this.ianService, { filters: this.store.getValue().notifications.filters })+ .pipe(+ take(1),+ )+ .subscribe((collection) => {+ this.actions$.dispatch(+ markNotificationsAsRead({ caller: this, notifications: collection.ids }),+ );+ });+ }++ private reload(filters:ApiV3ListFilter[]) {+ this+ .ianService+ .fetchNotifications({ filters })+ .subscribe();+ }++ /**+ * Reload after notifications were successfully marked as read+ */+ @EffectCallback(notificationsMarkedRead)+ private reloadOnNotificationRead(action:ReturnType<typeof notificationsMarkedRead>) {+ if (action.caller !== this) {+ const { filters } = this.store.getValue().notifications;+ this.reload(filters);+ }+ }+}diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.store.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.store.tsnew file mode 100644index 00000000000..5ffa86395a8--- /dev/null+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/state/wp-single-view.store.ts@@ -0,0 +1,23 @@+import { Store, StoreConfig } from '@datorama/akita';+import { ApiV3ListFilter } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';++export interface WpSingleViewState {+ notifications:{+ filters:ApiV3ListFilter[];+ }+}++export function createInitialState():WpSingleViewState {+ return {+ notifications: {+ filters: [],+ },+ };+}++@StoreConfig({ name: 'wp-single-view' })+export class WpSingleViewStore extends Store<WpSingleViewState> {+ constructor() {+ super(createInitialState());+ }+}diff --git a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.tsindex 322bf12046b..faaf395d2ec 100644--- a/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts+++ b/frontend/src/app/features/work-packages/routing/wp-view-base/work-package-single-view.base.ts@@ -26,7 +26,10 @@// See docs/COPYRIGHT.rdoc for more details.//++-import { ChangeDetectorRef, Injector } from '@angular/core';+import {+ ChangeDetectorRef,+ Injector,+} from '@angular/core';import { I18nService } from 'core-app/core/i18n/i18n.service';import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';import { WorkPackageViewFocusService } from 'core-app/features/work-packages/routing/wp-view-base/view-services/wp-view-focus.service';@@ -41,6 +44,9 @@ import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decoraimport { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destroyed.mixin';import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';import { HookService } from 'core-app/features/plugins/hook-service';+import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';+import { Observable } from 'rxjs';+import { ActionsService } from 'core-app/core/state/actions/actions.service';export class WorkPackageSingleViewBase extends UntilDestroyedMixin {@InjectField() states:States;@@ -67,6 +73,10 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {@InjectField() readonly hooks:HookService;+ @InjectField() readonly actions$:ActionsService;++ @InjectField() readonly storeService:WpSingleViewService;+// Static textspublic text:any = {};@@ -79,6 +89,8 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {public showStaticPagePath:string;+ public displayNotificationsButton$:Observable<boolean>;+constructor(public injector:Injector,protected workPackageId:string) {super();@@ -132,6 +144,9 @@ export class WorkPackageSingleViewBase extends UntilDestroyedMixin {this.cdRef.detectChanges();});+ this.displayNotificationsButton$ = this.storeService.hasNotifications$;+ this.storeService.setFilters(this.workPackage.id as string);+// Set authorisation datathis.authorisationService.initModelAuth('work_package', this.workPackage.$links);