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
This commit is contained in:
parent
ce701333a2
commit
6eeab5fc1e
@ -162,9 +162,15 @@ export class SortingListComponent implements OnInit, OnDestroy {
|
|||||||
/**
|
/**
|
||||||
* drop event
|
* drop event
|
||||||
* @param event the 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<Selectable[]>): void {
|
public drop(
|
||||||
if (this.multiSelectedIndex.length < 2) {
|
event: CdkDragDrop<Selectable[]> | { currentIndex: number; previousIndex: number },
|
||||||
|
dropBehind?: boolean
|
||||||
|
): void {
|
||||||
|
if (!this.multiSelectedIndex.length) {
|
||||||
moveItemInArray(this.array, event.previousIndex, event.currentIndex);
|
moveItemInArray(this.array, event.previousIndex, event.currentIndex);
|
||||||
} else {
|
} else {
|
||||||
const before: Selectable[] = [];
|
const before: Selectable[] = [];
|
||||||
@ -177,7 +183,13 @@ export class SortingListComponent implements OnInit, OnDestroy {
|
|||||||
} else if (i > event.currentIndex) {
|
} else if (i > event.currentIndex) {
|
||||||
behind.push(this.array[i]);
|
behind.push(this.array[i]);
|
||||||
} else {
|
} 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 {
|
} else {
|
||||||
insertions.push(this.array[i]);
|
insertions.push(this.array[i]);
|
||||||
|
@ -24,7 +24,12 @@
|
|||||||
>
|
>
|
||||||
<span translate>Number motions</span>
|
<span translate>Number motions</span>
|
||||||
</button>
|
</button>
|
||||||
|
<div *ngIf="isMultiSelect">
|
||||||
|
<span> {{ sortSelector.multiSelectedIndex.length }} </span>
|
||||||
|
<span translate>selected</span>
|
||||||
|
<button mat-button (click)="moveToPosition()"><span translate>move ...</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<os-sorting-list
|
<os-sorting-list
|
||||||
(sortEvent)="onListUpdate($event)"
|
(sortEvent)="onListUpdate($event)"
|
||||||
[input]="motionObservable"
|
[input]="motionObservable"
|
||||||
|
@ -6,13 +6,14 @@ import { TranslateService } from '@ngx-translate/core';
|
|||||||
|
|
||||||
import { BaseViewComponent } from 'app/site/base/base-view';
|
import { BaseViewComponent } from 'app/site/base/base-view';
|
||||||
import { CategoryRepositoryService } from 'app/core/repositories/motions/category-repository.service';
|
import { CategoryRepositoryService } from 'app/core/repositories/motions/category-repository.service';
|
||||||
|
import { CanComponentDeactivate } from 'app/shared/utils/watch-sorting-tree.guard';
|
||||||
|
import { ChoiceService } from 'app/core/ui-services/choice.service';
|
||||||
import { MatSnackBar } from '@angular/material';
|
import { MatSnackBar } from '@angular/material';
|
||||||
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service';
|
import { MotionRepositoryService } from 'app/core/repositories/motions/motion-repository.service';
|
||||||
import { PromptService } from 'app/core/ui-services/prompt.service';
|
import { PromptService } from 'app/core/ui-services/prompt.service';
|
||||||
import { SortingListComponent } from 'app/shared/components/sorting-list/sorting-list.component';
|
import { SortingListComponent } from 'app/shared/components/sorting-list/sorting-list.component';
|
||||||
import { ViewCategory } from 'app/site/motions/models/view-category';
|
import { ViewCategory } from 'app/site/motions/models/view-category';
|
||||||
import { ViewMotion } from 'app/site/motions/models/view-motion';
|
import { ViewMotion } from 'app/site/motions/models/view-motion';
|
||||||
import { CanComponentDeactivate } from 'app/shared/utils/watch-sorting-tree.guard';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* View for rearranging and renumbering the motions of a category. The {@link onNumberMotions}
|
* View for rearranging and renumbering the motions of a category. The {@link onNumberMotions}
|
||||||
@ -56,6 +57,10 @@ export class CategorySortComponent extends BaseViewComponent implements OnInit,
|
|||||||
*/
|
*/
|
||||||
private motionsBackup: ViewMotion[] = [];
|
private motionsBackup: ViewMotion[] = [];
|
||||||
|
|
||||||
|
public get isMultiSelect(): boolean {
|
||||||
|
return this.sortSelector.multiSelectedIndex.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @returns an observable for the {@link motionsSubject}
|
* @returns an observable for the {@link motionsSubject}
|
||||||
*/
|
*/
|
||||||
@ -89,6 +94,7 @@ export class CategorySortComponent extends BaseViewComponent implements OnInit,
|
|||||||
* @param repo
|
* @param repo
|
||||||
* @param route
|
* @param route
|
||||||
* @param motionRepo
|
* @param motionRepo
|
||||||
|
* @param choiceService
|
||||||
*/
|
*/
|
||||||
public constructor(
|
public constructor(
|
||||||
title: Title,
|
title: Title,
|
||||||
@ -97,7 +103,8 @@ export class CategorySortComponent extends BaseViewComponent implements OnInit,
|
|||||||
private promptService: PromptService,
|
private promptService: PromptService,
|
||||||
private repo: CategoryRepositoryService,
|
private repo: CategoryRepositoryService,
|
||||||
private route: ActivatedRoute,
|
private route: ActivatedRoute,
|
||||||
private motionRepo: MotionRepositoryService
|
private motionRepo: MotionRepositoryService,
|
||||||
|
private choiceService: ChoiceService
|
||||||
) {
|
) {
|
||||||
super(title, translate, matSnackBar);
|
super(title, translate, matSnackBar);
|
||||||
}
|
}
|
||||||
@ -231,4 +238,28 @@ export class CategorySortComponent extends BaseViewComponent implements OnInit,
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async moveToPosition(): Promise<void> {
|
||||||
|
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'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user