Merge pull request #4568 from MaximilianKrambach/motionNextPrev
set surrounding motions according to sorting in list view (fixes #4566)
This commit is contained in:
commit
3c959df374
@ -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
|
* Recreates the sorting function. Is supposed to be called on init and
|
||||||
* every time the sorting (property, ascending/descending) or the language changes
|
* every time the sorting (property, ascending/descending) or the language changes
|
||||||
|
@ -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 { TagRepositoryService } from 'app/core/repositories/tags/tag-repository.service';
|
||||||
import { WorkflowRepositoryService } from 'app/core/repositories/motions/workflow-repository.service';
|
import { WorkflowRepositoryService } from 'app/core/repositories/motions/workflow-repository.service';
|
||||||
import { MotionBlockRepositoryService } from 'app/core/repositories/motions/motion-block-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
|
* Component for the motion detail view
|
||||||
@ -374,6 +375,12 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit,
|
|||||||
* @param categoryRepo access the category repository
|
* @param categoryRepo access the category repository
|
||||||
* @param userRepo Repository for users
|
* @param userRepo Repository for users
|
||||||
* @param notifyService: NotifyService work with notification
|
* @param notifyService: NotifyService work with notification
|
||||||
|
* @param tagRepo
|
||||||
|
* @param mediaFilerepo
|
||||||
|
* @param workflowRepo
|
||||||
|
* @param blockRepo
|
||||||
|
* @param itemRepo
|
||||||
|
* @param motionSortService
|
||||||
*/
|
*/
|
||||||
public constructor(
|
public constructor(
|
||||||
title: Title,
|
title: Title,
|
||||||
@ -404,7 +411,8 @@ export class MotionDetailComponent extends BaseViewComponent implements OnInit,
|
|||||||
private mediaFilerepo: MediafileRepositoryService,
|
private mediaFilerepo: MediafileRepositoryService,
|
||||||
private workflowRepo: WorkflowRepositoryService,
|
private workflowRepo: WorkflowRepositoryService,
|
||||||
private blockRepo: MotionBlockRepositoryService,
|
private blockRepo: MotionBlockRepositoryService,
|
||||||
private itemRepo: ItemRepositoryService
|
private itemRepo: ItemRepositoryService,
|
||||||
|
private motionSortService: MotionSortListService
|
||||||
) {
|
) {
|
||||||
super(title, translate, matSnackBar);
|
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
|
* Sets the previous and next motion. Sorts by the current sorting as used
|
||||||
* then appending motion without identifiers sorted by title
|
* in the {@link MotionSortListService}
|
||||||
*/
|
*/
|
||||||
public setSurroundingMotions(): void {
|
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;
|
return motion === this.motion;
|
||||||
});
|
});
|
||||||
if (indexOfCurrent > -1) {
|
if (indexOfCurrent > -1) {
|
||||||
if (indexOfCurrent > 0) {
|
if (indexOfCurrent > 0) {
|
||||||
this.previousMotion = this.motionObserver.value[indexOfCurrent - 1];
|
this.previousMotion = sortedMotions[indexOfCurrent - 1];
|
||||||
} else {
|
} else {
|
||||||
this.previousMotion = null;
|
this.previousMotion = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (indexOfCurrent < this.motionObserver.value.length - 1) {
|
if (indexOfCurrent < sortedMotions.length - 1) {
|
||||||
this.nextMotion = this.motionObserver.value[indexOfCurrent + 1];
|
this.nextMotion = sortedMotions[indexOfCurrent + 1];
|
||||||
} else {
|
} else {
|
||||||
this.nextMotion = null;
|
this.nextMotion = null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user