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

Watch for url changes

Oliver Günthera6008ce0d958
diff --git a/frontend/package-lock.json b/frontend/package-lock.json
index 37527cf7c53..662c2c7e46f 100644
--- a/frontend/package-lock.json
+++ b/frontend/package-lock.json
@@ -117,6 +117,7 @@
"@html-eslint/parser": "^0.24.1",
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
"@types/codemirror": "5.60.5",
+ "@types/dom-navigation": "^1.0.3",
"@types/dragula": "^3.7.0",
"@types/hammerjs": "^2.0.36",
"@types/jasmine": "~3.6.0",
@@ -5456,6 +5457,13 @@
"@types/node": "*"
}
},
+ "node_modules/@types/dom-navigation": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/@types/dom-navigation/-/dom-navigation-1.0.3.tgz",
+ "integrity": "sha512-nbkhQ2o6UUBn1uLwSrA//rFkqs8XRk5d7cE6jzzTl8MAIUs/nFMtFqVESwiYY1HGZxflzbFlXsZ8NNzTaoFs1Q==",
+ "dev": true,
+ "license": "MIT"
+ },
"node_modules/@types/dragula": {
"version": "3.7.5",
"resolved": "https://registry.npmjs.org/@types/dragula/-/dragula-3.7.5.tgz",
@@ -25828,6 +25836,12 @@
"@types/node": "*"
}
},
+ "@types/dom-navigation": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/@types/dom-navigation/-/dom-navigation-1.0.3.tgz",
+ "integrity": "sha512-nbkhQ2o6UUBn1uLwSrA//rFkqs8XRk5d7cE6jzzTl8MAIUs/nFMtFqVESwiYY1HGZxflzbFlXsZ8NNzTaoFs1Q==",
+ "dev": true
+ },
"@types/dragula": {
"version": "3.7.5",
"resolved": "https://registry.npmjs.org/@types/dragula/-/dragula-3.7.5.tgz",
diff --git a/frontend/package.json b/frontend/package.json
index 732dd0afedb..3a7da44185e 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -16,6 +16,7 @@
"@html-eslint/parser": "^0.24.1",
"@jsdevtools/coverage-istanbul-loader": "3.0.5",
"@types/codemirror": "5.60.5",
+ "@types/dom-navigation": "^1.0.3",
"@types/dragula": "^3.7.0",
"@types/hammerjs": "^2.0.36",
"@types/jasmine": "~3.6.0",
diff --git a/frontend/src/app/core/navigation/navigation.service.ts b/frontend/src/app/core/navigation/navigation.service.ts
new file mode 100644
index 00000000000..0b775e55f0f
--- /dev/null
+++ b/frontend/src/app/core/navigation/navigation.service.ts
@@ -0,0 +1,59 @@
+// -- copyright
+// OpenProject is an open source project management software.
+// Copyright (C) 2012-2024 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 COPYRIGHT and LICENSE files for more details.
+//++
+
+/// <reference types="dom-navigation" />
+
+import { Injectable } from '@angular/core';
+import { Subject } from 'rxjs';
+
+@Injectable({ providedIn: 'root' })
+export class NavigationService {
+ private _currentURL = document.location.href;
+
+ private _urlChanged$:Subject<string> = new Subject();
+
+ public urlChanged$ = this._urlChanged$.asObservable();
+
+ constructor() {
+ if ('navigation' in window) {
+ window.navigation.addEventListener('navigate', (event:NavigateEvent) => {
+ this.handleURLChange(event.destination.url);
+ });
+ } else {
+ // Browser does not support navigation API, use a slower setInterval
+ setInterval(() => this.handleURLChange(document.location.href), 250);
+ }
+ }
+
+ private handleURLChange(url:string):void {
+ if (url !== this._currentURL) {
+ this._urlChanged$.next(url);
+ this._currentURL = url;
+ }
+ }
+}
diff --git a/frontend/src/app/core/url-params/url-params.service.ts b/frontend/src/app/core/navigation/url-params.service.ts
similarity index 72%
rename from frontend/src/app/core/url-params/url-params.service.ts
rename to frontend/src/app/core/navigation/url-params.service.ts
index b7edc01b5d5..735d4fe3143 100644
--- a/frontend/src/app/core/url-params/url-params.service.ts
+++ b/frontend/src/app/core/navigation/url-params.service.ts
@@ -27,15 +27,32 @@
//++
import { Injectable } from '@angular/core';
+import { Observable } from 'rxjs';
+import { map, shareReplay, startWith } from 'rxjs/operators';
+import { NavigationService } from 'core-app/core/navigation/navigation.service';
@Injectable({ providedIn: 'root' })
export class UrlParamsService {
+ constructor(private navigation:NavigationService) {
+ }
+
public get(key:string):string|null {
return this.searchParams.get(key);
}
- public pathMatching(key:RegExp):string|null {
- return window.location.pathname.match(key)?.[1] || null;
+ public pathMatching(key:RegExp, url = window.location.pathname):string|null {
+ return url.match(key)?.[1] || null;
+ }
+
+ public pathMatching$(key:RegExp):Observable<string|null> {
+ return this
+ .navigation
+ .urlChanged$
+ .pipe(
+ startWith(document.location.href),
+ map((url) => this.pathMatching(key, url)),
+ shareReplay(1),
+ );
}
public has(key:string):boolean {
diff --git a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html
index 892942591bd..a8fc623d1df 100644
--- a/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html
+++ b/frontend/src/app/features/in-app-notifications/center/in-app-notification-center.component.html
@@ -14,12 +14,12 @@
class="op-ian-item"
[class.op-ian-item_expanded]="records[0].expanded"
[class.op-ian-item_read]="records[0].readIAN === true"
- [class.op-ian-item_selected]="(stateChanged$ | async) === idFromLink(records[0]._links.resource.href)"
+ [class.op-ian-item_selected]="(selectedWorkPackage$ | async) === idFromLink(records[0]._links.resource.href)"
[notification]="records[0]"
[aggregatedNotifications]="records"
attr.data-test-selector="op-ian-notification-item-{{records[0].id}}"
[attr.data-qa-ian-read]="records[0].readIAN === true || undefined"
- [attr.data-qa-ian-selected]="(stateChanged$ | async) === idFromLink(records[0]._links.resource.href)"
+ [attr.data-qa-ian-selected]="(selectedWorkPackage$ | async) === idFromLink(records[0]._links.resource.href)"
></op-in-app-notification-entry>
</cdk-virtual-scroll-viewport>
</ng-container>
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.ts
index 4efabcd7e16..8b2a2dcfaae 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
@@ -39,7 +39,7 @@ import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
import { IanBellService } from 'core-app/features/in-app-notifications/bell/state/ian-bell.service';
import { imagePath } from 'core-app/shared/helpers/images/path-helper';
-import { UrlParamsService } from 'core-app/core/url-params/url-params.service';
+import { UrlParamsService } from 'core-app/core/navigation/url-params.service';
import idFromLink from 'core-app/features/hal/helpers/id-from-link';
@Component({
@@ -71,7 +71,7 @@ export class InAppNotificationCenterComponent implements OnInit {
)),
);
- stateChanged$ = this.storeService.stateChanged$;
+ selectedWorkPackage$ = this.storeService.selectedWorkPackage$;
reasonMenuItems = [
{
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.ts
index 951969b5806..3f6cb5df94e 100644
--- 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.ts
@@ -28,7 +28,7 @@
import { Injectable, Injector } from '@angular/core';
import { debounceTime, defaultIfEmpty, distinctUntilChanged, map, mapTo, switchMap, take, tap } from 'rxjs/operators';
-import { forkJoin, from, Observable, of, Subject } from 'rxjs';
+import { forkJoin, from, Observable, Subject } from 'rxjs';
import { ID, Query } from '@datorama/akita';
import { StateService } from '@uirouter/angular';
@@ -60,7 +60,7 @@ import { DeviceService } from 'core-app/core/browser/device.service';
import { ApiV3ListFilter, ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
import { FrameElement } from '@hotwired/turbo';
import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { UrlParamsService } from 'core-app/core/url-params/url-params.service';
+import { UrlParamsService } from 'core-app/core/navigation/url-params.service';
import { TurboRequestsService } from "core-app/core/turbo/turbo-requests.service";
export interface INotificationPageQueryParameters {
@@ -180,7 +180,7 @@ export class IanCenterService extends UntilDestroyedMixin {
public selectedNotification:INotification;
- stateChanged$ = of(this.urlParams.pathMatching(/\/details\/(\d+)/));
+ selectedWorkPackage$ = this.urlParams.pathMatching$(/\/details\/(\d+)/);
constructor(
readonly I18n:I18nService,
@@ -198,11 +198,9 @@ export class IanCenterService extends UntilDestroyedMixin {
super();
this.reload.subscribe();
- if (this.stateChanged$) {
- this.stateChanged$.subscribe(() => {
- this.updateSelectedNotification();
- });
- }
+ this.selectedWorkPackage$.subscribe(() => {
+ this.updateSelectedNotification();
+ });
}
setFilters(filters:INotificationPageQueryParameters):void {
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.ts
index ee65c13541b..762fdc75730 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
@@ -10,7 +10,7 @@ import { HalResource } from 'core-app/features/hal/resources/hal-resource';
import { INotification } 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';
import { DeviceService } from 'core-app/core/browser/device.service';
-import { UrlParamsService } from 'core-app/core/url-params/url-params.service';
+import { UrlParamsService } from 'core-app/core/navigation/url-params.service';
@Component({
selector: 'op-in-app-notification-entry',
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 0179e09455a..f409ca6cfb5 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
@@ -50,7 +50,7 @@ import { BackRoutingService } from 'core-app/features/work-packages/components/b
import { WpSingleViewService } from 'core-app/features/work-packages/routing/wp-view-base/state/wp-single-view.service';
import { CommentService } from 'core-app/features/work-packages/components/wp-activity/comment-service';
import { RecentItemsService } from 'core-app/core/recent-items.service';
-import { UrlParamsService } from 'core-app/core/url-params/url-params.service';
+import { UrlParamsService } from 'core-app/core/navigation/url-params.service';
import {
WorkPackageTabsService,
} from 'core-app/features/work-packages/components/wp-tabs/services/wp-tabs/wp-tabs.service';
diff --git a/spec/features/notifications/notification_center/notification_center_spec.rb b/spec/features/notifications/notification_center/notification_center_spec.rb
index 806e74e2bb3..3a409b36823 100644
--- a/spec/features/notifications/notification_center/notification_center_spec.rb
+++ b/spec/features/notifications/notification_center/notification_center_spec.rb
@@ -149,10 +149,15 @@ RSpec.describe "Notification center", :js, :with_cuprite,
center.click_item notification
split_screen.expect_open
+ center.expect_item_selected notification
center.expect_item_not_read notification
center.expect_work_package_item notification2
+ center.click_item notification2
+ split_screen2.expect_open
+ center.expect_item_selected notification2
+
center.mark_notification_as_read notification
wait_for_network_idle
retry_block do