From 6eeab5fc1ee9680b559807c642fa5f800f8eb5d6 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Tue, 28 May 2019 18:25:41 +0200 Subject: [PATCH] Multi move motions in category - if there is a multiselection, a 'move to' button will be active - TODO: better position/layout for that button and dialogue --- .../sorting-list/sorting-list.component.ts | 18 ++++++++-- .../category-sort.component.html | 7 +++- .../category-sort/category-sort.component.ts | 35 +++++++++++++++++-- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/client/src/app/shared/components/sorting-list/sorting-list.component.ts b/client/src/app/shared/components/sorting-list/sorting-list.component.ts index 8011cb1ae..5da1cb2cc 100644 --- a/client/src/app/shared/components/sorting-list/sorting-list.component.ts +++ b/client/src/app/shared/components/sorting-list/sorting-list.component.ts @@ -162,9 +162,15 @@ export class SortingListComponent implements OnInit, OnDestroy { /** * drop event * @param event the event + * @param dropBehind (optional) toggle explicit 'insert behind'(true) or + * 'insert before' (false) behavior instead of relying on a + * 'natural drop logic' */ - public drop(event: CdkDragDrop): void { - if (this.multiSelectedIndex.length < 2) { + public drop( + event: CdkDragDrop | { currentIndex: number; previousIndex: number }, + dropBehind?: boolean + ): void { + if (!this.multiSelectedIndex.length) { moveItemInArray(this.array, event.previousIndex, event.currentIndex); } else { const before: Selectable[] = []; @@ -177,7 +183,13 @@ export class SortingListComponent implements OnInit, OnDestroy { } else if (i > event.currentIndex) { behind.push(this.array[i]); } else { - event.currentIndex < 1 ? behind.push(this.array[i]) : before.push(this.array[i]); + if (dropBehind === false) { + behind.push(this.array[i]); + } else if (dropBehind === true) { + before.push(this.array[i]); + } else { + event.currentIndex < 1 ? behind.push(this.array[i]) : before.push(this.array[i]); + } } } else { insertions.push(this.array[i]); diff --git a/client/src/app/site/motions/modules/category/components/category-sort/category-sort.component.html b/client/src/app/site/motions/modules/category/components/category-sort/category-sort.component.html index 7b8df5fc7..e2bf477a0 100644 --- a/client/src/app/site/motions/modules/category/components/category-sort/category-sort.component.html +++ b/client/src/app/site/motions/modules/category/components/category-sort/category-sort.component.html @@ -24,7 +24,12 @@ > Number motions - +
+ {{ sortSelector.multiSelectedIndex.length }}  + selected + +
0; + } + /** * @returns an observable for the {@link motionsSubject} */ @@ -89,6 +94,7 @@ export class CategorySortComponent extends BaseViewComponent implements OnInit, * @param repo * @param route * @param motionRepo + * @param choiceService */ public constructor( title: Title, @@ -97,7 +103,8 @@ export class CategorySortComponent extends BaseViewComponent implements OnInit, private promptService: PromptService, private repo: CategoryRepositoryService, private route: ActivatedRoute, - private motionRepo: MotionRepositoryService + private motionRepo: MotionRepositoryService, + private choiceService: ChoiceService ) { super(title, translate, matSnackBar); } @@ -231,4 +238,28 @@ export class CategorySortComponent extends BaseViewComponent implements OnInit, } return true; } + + public async moveToPosition(): Promise { + if (this.sortSelector.multiSelectedIndex.length) { + } + const content = this.translate.instant('Move the selected items behind'); + const choices = this.sortSelector.array + .map((item, index) => { + return { id: index, label: item.getTitle() }; + }) + .filter(f => !this.sortSelector.multiSelectedIndex.includes(f.id)); + const actions = [this.translate.instant('Insert before'), this.translate.instant('Insert behind')]; + const selectedChoice = await this.choiceService.open(content, choices, false, actions); + if (selectedChoice) { + const newIndex = selectedChoice.items as number; + + this.sortSelector.drop( + { + currentIndex: newIndex, + previousIndex: null + }, + selectedChoice.action === actions[1] // true if 'insert behind' + ); + } + } }