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
Extract listener for queryParam change into separate service (mainly useful for updates after browser back button)
Henriette Dinger342479463a1b
diff --git a/frontend/src/app/components/wp-query/query-param-listener.service.ts b/frontend/src/app/components/wp-query/query-param-listener.service.tsnew file mode 100644index 00000000000..271ee8bbcc2--- /dev/null+++ b/frontend/src/app/components/wp-query/query-param-listener.service.ts@@ -0,0 +1,70 @@+// -- copyright+// OpenProject is an open source project management software.+// Copyright (C) 2012-2020 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 {Injectable, Injector} from '@angular/core';+import {WorkPackagesListChecksumService} from "core-components/wp-list/wp-list-checksum.service";+import {WorkPackagesListService} from "core-components/wp-list/wp-list.service";+import {TransitionService} from "@uirouter/core";+import {Subject} from "rxjs";++@Injectable()+export class QueryParamListenerService {+ readonly wpListChecksumService:WorkPackagesListChecksumService = this.injector.get(WorkPackagesListChecksumService);+ readonly wpListService:WorkPackagesListService = this.injector.get(WorkPackagesListService);+ readonly $transitions:TransitionService = this.injector.get(TransitionService);++ public observe$ = new Subject<any>();++ constructor(readonly injector:Injector) {+ this.listenForQueryParamsChanged();+ }++ public listenForQueryParamsChanged():any {+ // Listen for param changes+ return this.$transitions.onSuccess({}, (transition):any => {+ let options = transition.options();+ const params = transition.params('to');+ //this.hasQueryProps = !!params.query_props;++ let newChecksum = this.wpListService.getCurrentQueryProps(params);+ let newId:string = params.query_id ? params.query_id.toString() : null;++ // Avoid performing any changes when we're going to reload+ if (options.reload || (options.custom && options.custom.notify === false)) {+ return true;+ }++ return this.wpListChecksumService+ .executeIfOutdated(newId,+ newChecksum,+ () => {+ this.observe$.next(newChecksum);+ });+ });+ }+}diff --git a/frontend/src/app/modules/work_packages/routing/wp-list/wp-list.component.ts b/frontend/src/app/modules/work_packages/routing/wp-list/wp-list.component.tsindex cbef5a2e222..64af9d20a07 100644--- a/frontend/src/app/modules/work_packages/routing/wp-list/wp-list.component.ts+++ b/frontend/src/app/modules/work_packages/routing/wp-list/wp-list.component.ts@@ -39,7 +39,7 @@ import {wpDisplayCardRepresentation} from "core-app/modules/work_packages/routinimport {WorkPackageTableConfigurationObject} from "core-components/wp-table/wp-table-configuration";import {HalResourceNotificationService} from "core-app/modules/hal/services/hal-resource-notification.service";import {WorkPackageNotificationService} from "core-app/modules/work_packages/notifications/work-package-notification.service";-import {scrollHeaderOnMobile} from "core-app/globals/global-listeners/top-menu-scroll";+import {QueryParamListenerService} from "core-components/wp-query/query-param-listener.service";import {InjectField} from "core-app/helpers/angular/inject-field.decorator";@Component({@@ -51,12 +51,14 @@ import {InjectField} from "core-app/helpers/angular/inject-field.decorator";/** We need to provide the wpNotification service here to get correct save notifications for WP resources */{provide: HalResourceNotificationService, useClass: WorkPackageNotificationService},DragAndDropService,- CausedUpdatesService+ CausedUpdatesService,+ QueryParamListenerService]})export class WorkPackagesListComponent extends WorkPackagesViewBase implements OnDestroy {@InjectField() titleService:OpTitleService;@InjectField() bcfDetectorService:BcfDetectorService;+ @InjectField() queryParamListener:QueryParamListenerService;text = {'jump_to_pagination': this.I18n.t('js.work_packages.jump_marks.pagination'),@@ -104,7 +106,9 @@ export class WorkPackagesListComponent extends WorkPackagesViewBase implements Othis.refresh(isFirstLoad, isFirstLoad);// Load query on URL transitions- this.updateQueryOnParamsChanges();+ this.queryParamListener.observe$.pipe().subscribe(() => {+ this.refresh(true, true);+ });// Mark tableInformationLoaded when initially loading donethis.setupInformationLoadedListener();@@ -137,7 +141,8 @@ export class WorkPackagesListComponent extends WorkPackagesViewBase implements OngOnDestroy():void {super.ngOnDestroy();this.unRegisterTitleListener();- this.removeTransitionSubscription();+ // ToDo+ //this.removeTransitionSubscription();}public setAnchorToNextElement() {@@ -229,30 +234,6 @@ export class WorkPackagesListComponent extends WorkPackagesViewBase implements Oreturn this.bcfDetectorService.isBcfActivated;}- protected updateQueryOnParamsChanges() {- // Listen for param changes- this.removeTransitionSubscription = this.$transitions.onSuccess({}, (transition):any => {- let options = transition.options();- const params = transition.params('to');- this.hasQueryProps = !!params.query_props;-- let newChecksum = this.wpListService.getCurrentQueryProps(params);- let newId:string = params.query_id ? params.query_id.toString() : null;-- this.cdRef.detectChanges();-- // Avoid performing any changes when we're going to reload- if (options.reload || (options.custom && options.custom.notify === false)) {- return true;- }-- this.wpListChecksumService- .executeIfOutdated(newId,- newChecksum,- () => this.refresh(true, true));- });- }-protected setupInformationLoadedListener() {this.querySpace