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

Use EventEmitter do avoid uneccssary API calls

Henriette Dargee6ce5f8a8777
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 35aeb286c67..7d042087fe1 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
@@ -1,4 +1,4 @@
-import { Injectable } from '@angular/core';
+import { EventEmitter, Injectable } from '@angular/core';
import { applyTransaction, ID, setLoading } from '@datorama/akita';
import { Observable } from 'rxjs';
import { APIV3Service } from 'core-app/core/apiv3/api-v3.service';
@@ -9,7 +9,6 @@ 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' })
@@ -22,7 +21,7 @@ export class InAppNotificationsService {
) {
}
- public notificationsOfWpLoaded:Observable<IHALCollection<InAppNotification>>;
+ public notificationsOfWpLoaded:EventEmitter<IHALCollection<InAppNotification>> = new EventEmitter<IHALCollection<InAppNotification>>();
get():void {
this.store.setLoading(true);
@@ -110,7 +109,7 @@ export class InAppNotificationsService {
}
loadNotificationsOfWorkPackage(workPackageId:string):void {
- this.notificationsOfWpLoaded = this
+ this
.apiV3Service
.notifications
.facet(
@@ -122,7 +121,9 @@ export class InAppNotificationsService {
['resourceType', '=', ['WorkPackage']],
],
},
- );
+ ).subscribe((notificationCollection) => {
+ this.notificationsOfWpLoaded.emit(notificationCollection);
+ });
}
private sideLoadInvolvedWorkPackages(elements:InAppNotification[]) {
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.ts
index d6d51dc67e7..1e88addfb91 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
@@ -37,6 +37,7 @@ import { 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, 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';
@Directive()
export class ActivityPanelBaseController extends UntilDestroyedMixin implements OnInit {
@@ -65,11 +66,14 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implements
showAll: this.I18n.t('js.label_activity_show_all'),
};
- constructor(readonly apiV3Service:APIV3Service,
+ constructor(
+ readonly apiV3Service:APIV3Service,
readonly I18n:I18nService,
readonly cdRef:ChangeDetectorRef,
readonly $transition:Transition,
- readonly wpActivity:WorkPackagesActivityService) {
+ readonly wpActivity:WorkPackagesActivityService,
+ readonly ianService:InAppNotificationsService,
+ ) {
super();
this.reverse = wpActivity.isReversed;
@@ -77,35 +81,24 @@ export class ActivityPanelBaseController extends UntilDestroyedMixin implements
}
ngOnInit() {
- combineLatest([
- this
- .apiV3Service
- .work_packages
- .id(this.workPackageId)
- .requireAndStream()
- .pipe(this.untilDestroyed()),
- this
- .apiV3Service
- .notifications
- .facet(
- 'unread',
- {
- pageSize: NOTIFICATIONS_MAX_SIZE,
- filters: [
- ['resourceId', '=', [this.workPackageId]],
- ['resourceType', '=', ['WorkPackage']],
- ],
- },
- ),
- ])
- .subscribe(([wp, notificationCollection]) => {
- this.notifications = notificationCollection._embedded.elements;
+ this
+ .apiV3Service
+ .work_packages
+ .id(this.workPackageId)
+ .requireAndStream()
+ .pipe(this.untilDestroyed())
+ .subscribe((wp) => {
this.workPackage = wp;
this.wpActivity.require(this.workPackage).then((activities:any) => {
this.updateActivities(activities);
this.cdRef.detectChanges();
});
});
+
+ this.ianService.loadNotificationsOfWorkPackage(this.workPackageId);
+ this.ianService.notificationsOfWpLoaded.subscribe((notificationCollection) => {
+ this.notifications = notificationCollection._embedded.elements;
+ });
}
protected updateActivities(activities:HalResource[]) {
diff --git a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-on-overview.html b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-on-overview.html
index 950822a2c49..bf663c8dc1b 100644
--- a/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-on-overview.html
+++ b/frontend/src/app/features/work-packages/components/wp-single-view-tabs/activity-panel/activity-on-overview.html
@@ -6,6 +6,7 @@
<activity-entry [workPackage]="workPackage"
[activity]="inf.activity"
[activityNo]="inf.number(inf.isReversed)"
+ [hasUnreadNotification]="hasUnreadNotification(inf.href)"
[isInitial]="inf.isInitial()">
</activity-entry>
</div>
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.ts
index 34bfd313a90..760cb61a804 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
@@ -4,26 +4,16 @@ 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';
export function workPackageNotificationsCount(
workPackage:WorkPackageResource,
injector:Injector,
):Observable<number> {
- const apiV3Service = injector.get(APIV3Service);
- const wpId = workPackage.id?.toString() || '';
+ const ianService = injector.get(InAppNotificationsService);
- return apiV3Service
- .notifications
- .facet(
- 'unread',
- {
- pageSize: NOTIFICATIONS_MAX_SIZE,
- filters: [
- ['resourceId', '=', [wpId]],
- ['resourceType', '=', ['WorkPackage']],
- ],
- },
- )
+ return ianService
+ .notificationsOfWpLoaded
.pipe(
map((data) => data._embedded.elements.length),
);
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 92b7a67da03..88d0f8bd31a 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
@@ -93,7 +93,6 @@ export class WorkPackagesFullViewComponent extends WorkPackageSingleViewBase imp
this.isWatched = wp.hasOwnProperty('unwatch');
this.displayWatchButton = wp.hasOwnProperty('unwatch') || wp.hasOwnProperty('watch');
- // Todo check for User logged in
this
.ianService
.notificationsOfWpLoaded
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 c2cb41a24f1..aded989e169 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
@@ -120,7 +120,6 @@ export class WorkPackageSplitViewComponent extends WorkPackageSingleViewBase imp
}
showNotificationsButton():boolean {
- // Todo check for User logged in
return this.displayNotificationsButton && this.keepTab.currentTabIdentifier === 'activity';
}
}