diff --git a/client/src/app/core/ui-services/routing-state.service.ts b/client/src/app/core/ui-services/routing-state.service.ts index c2c2e4e87..f0c38f427 100644 --- a/client/src/app/core/ui-services/routing-state.service.ts +++ b/client/src/app/core/ui-services/routing-state.service.ts @@ -17,6 +17,11 @@ export class RoutingStateService { */ private _previousUrl: string; + /** + * Stores the routing state + */ + private _customOrigin: string; + /** * Unsafe paths that the user should not go "back" to * TODO: Might also work using Routing parameters @@ -39,6 +44,10 @@ export class RoutingStateService { return this._previousUrl; } + public get customOrigin(): string { + return this._customOrigin; + } + /** * Watch routing changes and save the last visited URL * @@ -52,10 +61,33 @@ export class RoutingStateService { ) .subscribe((event: any[]) => { this._previousUrl = event[0].urlAfterRedirects; + if ( + this.router.getCurrentNavigation().extras && + this.router.getCurrentNavigation().extras.state && + this.router.getCurrentNavigation().extras.state.back + ) { + this._customOrigin = this._previousUrl; + } else if ( + this._customOrigin && + !this.isSameComponent(event[0].urlAfterRedirects, event[1].urlAfterRedirects) + ) { + this._customOrigin = null; + } }); } public goBack(): void { this.location.back(); } + + /** + * Analyse the URL to check if you were navigating using the same components + */ + private isSameComponent(urlA: string, urlB: string): boolean { + const pathA = urlA.slice(0, urlA.lastIndexOf('/')); + const pathB = urlB.slice(0, urlB.lastIndexOf('/')); + const paramA = urlA.slice(urlA.lastIndexOf('/') + 1); + const paramB = urlB.slice(urlA.lastIndexOf('/') + 1); + return pathA === pathB && !isNaN(+paramA) && !isNaN(+paramB); + } } diff --git a/client/src/app/shared/components/head-bar/head-bar.component.ts b/client/src/app/shared/components/head-bar/head-bar.component.ts index 103758cca..3af38b0b6 100644 --- a/client/src/app/shared/components/head-bar/head-bar.component.ts +++ b/client/src/app/shared/components/head-bar/head-bar.component.ts @@ -222,6 +222,8 @@ export class HeadBarComponent implements OnInit { public onBackButton(): void { if (this.goBack) { this.routingState.goBack(); + } else if (this.routingState.customOrigin && this.routingState.customOrigin !== this.router.url) { + this.router.navigate([this.routingState.customOrigin], { relativeTo: this.route }); } else { this.router.navigate([this.prevUrl], { relativeTo: this.route }); } diff --git a/client/src/app/site/motions/modules/amendment-list/amendment-list.component.html b/client/src/app/site/motions/modules/amendment-list/amendment-list.component.html index bab4014c1..3b3acf27b 100644 --- a/client/src/app/site/motions/modules/amendment-list/amendment-list.component.html +++ b/client/src/app/site/motions/modules/amendment-list/amendment-list.component.html @@ -1,4 +1,4 @@ - +

Amendments

@@ -38,7 +38,7 @@ >
- +
diff --git a/client/src/app/site/motions/modules/category/components/category-detail/category-detail.component.html b/client/src/app/site/motions/modules/category/components/category-detail/category-detail.component.html index fd3bc8dee..5c5b6201d 100644 --- a/client/src/app/site/motions/modules/category/components/category-detail/category-detail.component.html +++ b/client/src/app/site/motions/modules/category/components/category-detail/category-detail.component.html @@ -55,7 +55,7 @@ - + diff --git a/client/src/app/site/motions/modules/motion-block/components/motion-block-detail/motion-block-detail.component.html b/client/src/app/site/motions/modules/motion-block/components/motion-block-detail/motion-block-detail.component.html index 906d13d70..80c70702a 100644 --- a/client/src/app/site/motions/modules/motion-block/components/motion-block-detail/motion-block-detail.component.html +++ b/client/src/app/site/motions/modules/motion-block/components/motion-block-detail/motion-block-detail.component.html @@ -40,7 +40,12 @@ >
- +
diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html index c49f097c3..27e443011 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.html @@ -1,7 +1,7 @@ ·  - Amendment to {{ - motion.parent.identifier || motion.parent.title - }} + Amendment to  + {{ motion.parent.identifier || motion.parent.title }} + @@ -440,7 +443,7 @@

Amendments

- + {{ amendments.length }} Amendment Amendments @@ -621,12 +624,7 @@
- + {{ 'The title is required' | translate }}
@@ -839,11 +837,7 @@
- +
diff --git a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts index 8539a1fff..d0a21b58b 100644 --- a/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts +++ b/client/src/app/site/motions/modules/motion-detail/components/motion-detail/motion-detail.component.ts @@ -35,7 +35,6 @@ import { DiffLinesInParagraph, LineRange } from 'app/core/ui-services/diff.servi import { LinenumberingService } from 'app/core/ui-services/linenumbering.service'; import { PersonalNoteService } from 'app/core/ui-services/personal-note.service'; import { PromptService } from 'app/core/ui-services/prompt.service'; -import { RoutingStateService } from 'app/core/ui-services/routing-state.service'; import { ViewportService } from 'app/core/ui-services/viewport.service'; import { Mediafile } from 'app/shared/models/mediafiles/mediafile'; import { Motion } from 'app/shared/models/motions/motion'; @@ -451,7 +450,6 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, private itemRepo: ItemRepositoryService, private motionSortService: MotionSortListService, private motionFilterService: MotionFilterListService, - private routingStateService: RoutingStateService, private cd: ChangeDetectorRef ) { super(title, translate, matSnackBar); @@ -1538,30 +1536,6 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, this.raiseError(error); } - /** - * Tries to determine the previous URL if it's considered unsafe - * - * @returns the target to navigate to - */ - public getPrevUrl(): string { - if (this.motion && this.motion.parent_id) { - if (this.routingStateService.previousUrl && this.routingStateService.isSafePrevUrl) { - if ( - (this.previousMotion && - this.routingStateService.previousUrl === this.previousMotion.getDetailStateURL()) || - (this.nextMotion && this.routingStateService.previousUrl === this.nextMotion.getDetailStateURL()) - ) { - return '../..'; - } else { - return this.routingStateService.previousUrl; - } - } else { - return this.motion.parent.getDetailStateURL(); - } - } - return '../..'; - } - /** * Function to prevent automatically closing the window/tab, * if the user is editing a motion.