Skip to content

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

Load belonging Notifications of a WP in order to be able to mark them as read when clicking on the button. Further show the button only when notifications are available for the WorkPackage

Henriette Darge71da8071b109
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.ts
index c50d263e14f..35aeb286c67 100644
--- 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.ts
@@ -9,6 +9,8 @@ import { take } from 'rxjs/internal/operators/take';
import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { InAppNotificationsStore } from './in-app-notifications.store';
import { InAppNotification, NOTIFICATIONS_MAX_SIZE } from './in-app-notification.model';
+import { WorkPackageResource } from 'core-app/features/hal/resources/work-package-resource';
+import { IHALCollection } from 'core-app/core/apiv3/types/hal-collection.type';
@Injectable({ providedIn: 'root' })
export class InAppNotificationsService {
@@ -20,6 +22,8 @@ export class InAppNotificationsService {
) {
}
+ public notificationsOfWpLoaded:Observable<IHALCollection<InAppNotification>>;
+
get():void {
this.store.setLoading(true);
@@ -105,6 +109,22 @@ export class InAppNotificationsService {
});
}
+ loadNotificationsOfWorkPackage(workPackageId:string):void {
+ this.notificationsOfWpLoaded = this
+ .apiV3Service
+ .notifications
+ .facet(
+ 'unread',
+ {
+ pageSize: NOTIFICATIONS_MAX_SIZE,
+ filters: [
+ ['resourceId', '=', [workPackageId]],
+ ['resourceType', '=', ['WorkPackage']],
+ ],
+ },
+ );
+ }
+
private sideLoadInvolvedWorkPackages(elements:InAppNotification[]) {
const wpIds = elements.map((element) => {
const href = element._links.resource?.href;
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.ts
index 3628a7aaaa2..de1631841a3 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,18 +1,21 @@
-import { Component, ChangeDetectionStrategy, Input } from '@angular/core';
+import { Component, ChangeDetectionStrategy, Input, OnInit } 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 { InAppNotification } from 'core-app/features/in-app-notifications/store/in-app-notification.model';
@Component({
selector: 'op-work-package-mark-notification-button',
templateUrl: './work-package-mark-notification-button.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class WorkPackageMarkNotificationButtonComponent {
+export class WorkPackageMarkNotificationButtonComponent implements OnInit {
@Input() public workPackage:WorkPackageResource;
@Input() public buttonClasses:string;
+ private belongingNotifications:InAppNotification[];
+
text = {
mark_as_read: this.I18n.t('js.notifications.center.mark_as_read'),
};
@@ -23,8 +26,16 @@ export class WorkPackageMarkNotificationButtonComponent {
) {
}
+ ngOnInit():void {
+ this
+ .ianService
+ .notificationsOfWpLoaded
+ .subscribe((notifications) => {
+ this.belongingNotifications = notifications._embedded.elements;
+ });
+ }
+
markAllBelongingWPsAsRead():void {
- // TODO
- this.ianService.markAllRead();
+ this.ianService.markAsRead(this.belongingNotifications);
}
}
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.ts
index 0e0a4157234..92b7a67da03 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
@@ -34,6 +34,7 @@ import { WorkPackageSingleViewBase } from 'core-app/features/work-packages/routi
import { of } from 'rxjs';
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 { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';
@Component({
templateUrl: './wp-full-view.html',
@@ -56,9 +57,12 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
stateName$ = of('work-packages.new');
- constructor(public injector:Injector,
+ constructor(
+ public injector:Injector,
public wpTableSelection:WorkPackageViewSelectionService,
- readonly $state:StateService) {
+ readonly $state:StateService,
+ readonly ianService:InAppNotificationsService,
+ ) {
super(injector, $state.params.workPackageId);
}
@@ -80,6 +84,8 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
// Set Focused WP
this.wpTableFocus.updateFocus(this.workPackage.id!);
+ this.ianService.loadNotificationsOfWorkPackage(this.workPackage.id || '');
+
this.setWorkPackageScopeProperties(this.workPackage);
}
@@ -87,9 +93,13 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
this.isWatched = wp.hasOwnProperty('unwatch');
this.displayWatchButton = wp.hasOwnProperty('unwatch') || wp.hasOwnProperty('watch');
- // Todo check for hasUnreadNotifications
// Todo check for User logged in
- this.displayNotificationsButton = true;
+ this
+ .ianService
+ .notificationsOfWpLoaded
+ .subscribe((notifications) => {
+ this.displayNotificationsButton = notifications.count > 0;
+ });
// watchers
if (wp.watchers) {
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.ts
index dc2c2b0a9af..c2cb41a24f1 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,9 +26,7 @@
// 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';
@@ -39,6 +37,7 @@ import { WorkPackageSingleViewBase } from 'core-app/features/work-packages/routi
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 { BackRoutingService } from 'core-app/features/work-packages/components/back-routing/back-routing.service';
+import { InAppNotificationsService } from 'core-app/features/in-app-notifications/store/in-app-notifications.service';
@Component({
templateUrl: './wp-split-view.html',
@@ -52,14 +51,19 @@ export class WorkPackageSplitViewComponent extends WorkPackageSingleViewBase imp
/** Reference to the base route e.g., work-packages.partitioned.list or bim.partitioned.split */
private baseRoute:string = this.$state.current.data.baseRoute;
- constructor(public injector:Injector,
+ private displayNotificationsButton:boolean;
+
+ constructor(
+ public injector:Injector,
public states:States,
public firstRoute:FirstRouteService,
public keepTab:KeepTabService,
public wpTableSelection:WorkPackageViewSelectionService,
public wpTableFocus:WorkPackageViewFocusService,
readonly $state:StateService,
- readonly backRouting:BackRoutingService) {
+ readonly backRouting:BackRoutingService,
+ readonly ianService:InAppNotificationsService,
+ ) {
super(injector, $state.params.workPackageId);
}
@@ -95,6 +99,12 @@ export class WorkPackageSplitViewComponent extends WorkPackageSingleViewBase imp
);
}
});
+
+ this.ianService.loadNotificationsOfWorkPackage(wpId.toString());
+
+ this.ianService.notificationsOfWpLoaded.subscribe((notifications) => {
+ this.displayNotificationsButton = notifications.count > 0;
+ });
}
get shouldFocus() {
@@ -110,8 +120,7 @@ export class WorkPackageSplitViewComponent extends WorkPackageSingleViewBase imp
}
showNotificationsButton():boolean {
- // Todo check for hasUnreadNotifications
// Todo check for User logged in
- return this.keepTab.currentTabIdentifier === 'activity';
+ return this.displayNotificationsButton && this.keepTab.currentTabIdentifier === 'activity';
}
}