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

Make backRoutingFunction smarter to get back from the notifications no matter where you came from

Henriette Darge79a3220f1d1e
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.ts
index e3946f22650..d6c7a5353e6 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
@@ -3,6 +3,7 @@ import {
ChangeDetectorRef,
Component,
Injector,
+ OnInit,
} from '@angular/core';
import {
ToolbarButtonComponentDefinition,
@@ -19,6 +20,10 @@ import { NotificationSettingsButtonComponent } from 'core-app/features/in-app-no
import { 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 {
+ BackRouteOptions,
+ BackRoutingService,
+} from 'core-app/features/work-packages/components/back-routing/back-routing.service';
@Component({
templateUrl: '../../work-packages/routing/partitioned-query-space-page/partitioned-query-space-page.component.html',
@@ -27,14 +32,13 @@ import { UntilDestroyedMixin } from 'core-app/shared/helpers/angular/until-destr
],
changeDetection: ChangeDetectionStrategy.OnPush,
})
-export class InAppNotificationCenterPageComponent extends UntilDestroyedMixin {
+export class InAppNotificationCenterPageComponent extends UntilDestroyedMixin implements OnInit {
text = {
title: this.I18n.t('js.notifications.title'),
};
/** Go back using back-button */
- // TODO: Use better Function which actually leaves the notification page and don't only toggle the split views
- backButtonCallback = ():void => window.history.back();
+ backButtonCallback:() => void = this.backButtonFn.bind(this);
/** Current query title to render */
selectedTitle = this.text.title;
@@ -57,6 +61,7 @@ export class InAppNotificationCenterPageComponent extends UntilDestroyedMixin {
/** Toolbar is always enabled */
toolbarDisabled = false;
+ /** Define the buttons shown in the toolbar */
toolbarButtonComponents:ToolbarButtonComponentDefinition[] = [
{
component: ActivateFacetButtonComponent,
@@ -71,6 +76,12 @@ export class InAppNotificationCenterPageComponent extends UntilDestroyedMixin {
},
];
+ /** Global referrer set when coming from a hard reload */
+ private documentReferer:string;
+
+ /** Local referrer set when coming from an angular route */
+ private backRoute:BackRouteOptions;
+
constructor(
readonly I18n:I18nService,
readonly cdRef:ChangeDetectorRef,
@@ -79,10 +90,16 @@ export class InAppNotificationCenterPageComponent extends UntilDestroyedMixin {
readonly notifications:NotificationsService,
readonly injector:Injector,
readonly apiV3Service:APIV3Service,
+ readonly backRoutingService:BackRoutingService,
) {
super();
}
+ ngOnInit():void {
+ this.backRoute = this.backRoutingService.backRoute;
+ this.documentReferer = document.referrer;
+ }
+
/**
* We need to set the current partition to the grid to ensure
* either side gets expanded to full width if we're not in '-split' mode.
@@ -93,9 +110,23 @@ export class InAppNotificationCenterPageComponent extends UntilDestroyedMixin {
this.currentPartition = state.data?.partition || '-split';
}
- // For Interface compliance
- updateTitleName(val:string) {}
+ // For shared template compliance
+ updateTitleName(val:string):void {}
+
+ // For shared template compliance
+ changeChangesFromTitle(val:string):void {}
- // For Interface compliance
- changeChangesFromTitle(val:string) {}
+ private backButtonFn():void {
+ if (this.backRoute) {
+ void this.backRoutingService.goToOtherState(this.backRoute.name, this.backRoute.params);
+ return;
+ }
+
+ if (this.documentReferer.length > 0) {
+ window.location.href = this.documentReferer;
+ } else {
+ // Default fallback
+ window.history.back();
+ }
+ }
}
diff --git a/frontend/src/app/features/work-packages/components/back-routing/back-routing.service.ts b/frontend/src/app/features/work-packages/components/back-routing/back-routing.service.ts
index 48f795599e1..c8015f1da5e 100644
--- a/frontend/src/app/features/work-packages/components/back-routing/back-routing.service.ts
+++ b/frontend/src/app/features/work-packages/components/back-routing/back-routing.service.ts
@@ -31,7 +31,7 @@ import { StateService, Transition } from '@uirouter/core';
import { KeepTabService } from 'core-app/features/work-packages/components/wp-single-view-tabs/keep-tab/keep-tab.service';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
-interface BackRouteOptions {
+export interface BackRouteOptions {
name:string;
params:{};
parent:string;
@@ -49,7 +49,7 @@ export class BackRoutingService {
constructor(readonly injector:Injector) {
}
- private goToOtherState(route:string, params:{}):Promise<any> {
+ public goToOtherState(route:string, params:{}):Promise<any> {
return this.$state.go(route, params);
}
diff --git a/frontend/src/app/features/work-packages/routing/work-packages-routes.ts b/frontend/src/app/features/work-packages/routing/work-packages-routes.ts
index b3fd2465293..a95093aba83 100644
--- a/frontend/src/app/features/work-packages/routing/work-packages-routes.ts
+++ b/frontend/src/app/features/work-packages/routing/work-packages-routes.ts
@@ -64,6 +64,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [
component: WorkPackageNewFullViewComponent,
reloadOnSearch: false,
data: {
+ parent: 'work-packages',
baseRoute: 'work-packages',
allowMovingInEditMode: true,
bodyClasses: 'router--work-packages-full-create',
@@ -76,6 +77,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [
component: WorkPackageCopyFullViewComponent,
reloadOnSearch: false,
data: {
+ parent: 'work-packages',
baseRoute: 'work-packages',
allowMovingInEditMode: true,
bodyClasses: 'router--work-packages-full-create',
@@ -95,6 +97,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [
},
component: WorkPackagesFullViewComponent,
data: {
+ parent: 'work-packages',
baseRoute: 'work-packages',
bodyClasses: 'router--work-packages-full-view',
newRoute: 'work-packages.new',
@@ -115,6 +118,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [
component: WorkPackageViewPageComponent,
url: '',
data: {
+ parent: 'work-packages',
// This has to be empty to avoid inheriting the parent bodyClasses
bodyClasses: '',
},
@@ -127,6 +131,7 @@ export const WORK_PACKAGES_ROUTES:Ng2StateDeclaration[] = [
'content-left': { component: WorkPackageListViewComponent },
},
data: {
+ parent: 'work-packages.partitioned',
bodyClasses: 'router--work-packages-partitioned-split-view',
menuItem: menuItemClass,
partition: '-left-only',