Merge pull request #4568 from MaximilianKrambach/motionNextPrev

set surrounding motions according to sorting in list view (fixes #4566)
This commit is contained in:
Emanuel Schütze 2019-04-04 23:23:17 +02:00 committed by GitHub
commit 3c959df374
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 7 deletions

View File

@ -199,6 +199,16 @@ export abstract class BaseSortListService<V extends BaseViewModel> {
});
}
/**
* 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

View File

@ -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);
}
@ -1129,22 +1137,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;
}