From 9e2faefc797b3c3557586fee454db8d712ab14ed Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Wed, 3 Apr 2019 12:05:43 +0200 Subject: [PATCH] set surrounding according to sorting in list view --- .../ui-services/base-sort-list.service.ts | 10 ++++++++ .../motion-detail/motion-detail.component.ts | 23 +++++++++++++------ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/client/src/app/core/ui-services/base-sort-list.service.ts b/client/src/app/core/ui-services/base-sort-list.service.ts index e20fcf9d1..832ee06a1 100644 --- a/client/src/app/core/ui-services/base-sort-list.service.ts +++ b/client/src/app/core/ui-services/base-sort-list.service.ts @@ -199,6 +199,16 @@ export abstract class BaseSortListService { }); } + /** + * Sorts an array of data synchronously, using the currently configured sorting + * + * @param data + * @returns the data, sorted with the definitions of this service + */ + public sortSync(data: V[]): V[] { + return data.sort(this.sortFn); + } + /** * Recreates the sorting function. Is supposed to be called on init and * every time the sorting (property, ascending/descending) or the language changes 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 14ce9e3d8..8dc1f9ab5 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 @@ -52,6 +52,7 @@ import { ViewUnifiedChange } from 'app/shared/models/motions/view-unified-change import { TagRepositoryService } from 'app/core/repositories/tags/tag-repository.service'; import { WorkflowRepositoryService } from 'app/core/repositories/motions/workflow-repository.service'; import { MotionBlockRepositoryService } from 'app/core/repositories/motions/motion-block-repository.service'; +import { MotionSortListService } from 'app/site/motions/services/motion-sort-list.service'; /** * Component for the motion detail view @@ -374,6 +375,12 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, * @param categoryRepo access the category repository * @param userRepo Repository for users * @param notifyService: NotifyService work with notification + * @param tagRepo + * @param mediaFilerepo + * @param workflowRepo + * @param blockRepo + * @param itemRepo + * @param motionSortService */ public constructor( title: Title, @@ -404,7 +411,8 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, private mediaFilerepo: MediafileRepositoryService, private workflowRepo: WorkflowRepositoryService, private blockRepo: MotionBlockRepositoryService, - private itemRepo: ItemRepositoryService + private itemRepo: ItemRepositoryService, + private motionSortService: MotionSortListService ) { super(title, translate, matSnackBar); } @@ -1127,22 +1135,23 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit, } /** - * Sets the previous and next motion. Sorts ascending by identifier, and - * then appending motion without identifiers sorted by title + * Sets the previous and next motion. Sorts by the current sorting as used + * in the {@link MotionSortListService} */ public setSurroundingMotions(): void { - const indexOfCurrent = this.motionObserver.value.findIndex(motion => { + const sortedMotions = this.motionSortService.sortSync(this.motionObserver.value); + const indexOfCurrent = sortedMotions.findIndex(motion => { return motion === this.motion; }); if (indexOfCurrent > -1) { if (indexOfCurrent > 0) { - this.previousMotion = this.motionObserver.value[indexOfCurrent - 1]; + this.previousMotion = sortedMotions[indexOfCurrent - 1]; } else { this.previousMotion = null; } - if (indexOfCurrent < this.motionObserver.value.length - 1) { - this.nextMotion = this.motionObserver.value[indexOfCurrent + 1]; + if (indexOfCurrent < sortedMotions.length - 1) { + this.nextMotion = sortedMotions[indexOfCurrent + 1]; } else { this.nextMotion = null; }