Derp, no re-ordering

This commit is contained in:
shamoon
2026-08-18 13:25:16 -07:00
parent 12ea5d92c7
commit fb2a4d5db7
6 changed files with 55 additions and 66 deletions
@@ -6,15 +6,11 @@
<p>{{message}}</p>
<div class="form-group">
<label class="form-label" i18n>Versions:</label>
<ul class="list-group"
cdkDropList
[cdkDropListData]="draggableDocumentIDs()"
(cdkDropListDropped)="onDrop($event)">
@for (documentID of draggableDocumentIDs(); track documentID) {
<ul class="list-group">
@for (documentID of versionDocumentIDs(); track documentID) {
@let document = getDocument(documentID);
@if (document) {
<li class="list-group-item d-flex align-items-center" cdkDrag>
<i-bs name="grip-vertical" class="me-2"></i-bs>
<li class="list-group-item d-flex align-items-center">
<div class="d-flex flex-column">
<div>
@if (document.correspondent) {
@@ -2,7 +2,6 @@ import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
import { provideHttpClientTesting } from '@angular/common/http/testing'
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { NgxBootstrapIconsModule, allIcons } from 'ngx-bootstrap-icons'
import { of } from 'rxjs'
import { DocumentService } from 'src/app/services/rest/document.service'
import { MergeAsVersionsConfirmDialogComponent } from './merge-as-versions-confirm-dialog.component'
@@ -14,10 +13,7 @@ describe('MergeAsVersionsConfirmDialogComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [
NgxBootstrapIconsModule.pick(allIcons),
MergeAsVersionsConfirmDialogComponent,
],
imports: [MergeAsVersionsConfirmDialogComponent],
providers: [
NgbActiveModal,
provideHttpClient(withInterceptorsFromDi()),
@@ -55,16 +51,6 @@ describe('MergeAsVersionsConfirmDialogComponent', () => {
component.documentIDs.set([1, 2, 3])
component.rootDocumentID.set(2)
expect(component.draggableDocumentIDs()).toEqual([1, 3])
})
it('should move draggable documents while keeping the root fixed', () => {
component.documentIDs.set([1, 2, 3])
component.rootDocumentID.set(1)
component.onDrop({ previousIndex: 1, currentIndex: 0 } as any)
expect(component.documentIDs()).toEqual([1, 3, 2])
expect(component.draggableDocumentIDs()).toEqual([3, 2])
expect(component.versionDocumentIDs()).toEqual([1, 3])
})
})
@@ -1,12 +1,6 @@
import {
CdkDragDrop,
DragDropModule,
moveItemInArray,
} from '@angular/cdk/drag-drop'
import { AsyncPipe } from '@angular/common'
import { Component, OnInit, computed, inject, signal } from '@angular/core'
import { FormsModule } from '@angular/forms'
import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons'
import { takeUntil } from 'rxjs'
import { Document } from 'src/app/data/document'
import { CorrespondentNamePipe } from 'src/app/pipes/correspondent-name.pipe'
@@ -17,15 +11,7 @@ import { ConfirmDialogComponent } from '../confirm-dialog.component'
@Component({
selector: 'pngx-merge-as-versions-confirm-dialog',
templateUrl: './merge-as-versions-confirm-dialog.component.html',
styleUrl: './merge-as-versions-confirm-dialog.component.scss',
imports: [
AsyncPipe,
CorrespondentNamePipe,
CustomDatePipe,
DragDropModule,
FormsModule,
NgxBootstrapIconsModule,
],
imports: [AsyncPipe, CorrespondentNamePipe, CustomDatePipe, FormsModule],
})
export class MergeAsVersionsConfirmDialogComponent
extends ConfirmDialogComponent
@@ -36,7 +22,7 @@ export class MergeAsVersionsConfirmDialogComponent
readonly documentIDs = signal<number[]>([])
readonly documents = signal<Document[]>([])
readonly rootDocumentID = signal(-1)
readonly draggableDocumentIDs = computed(() =>
readonly versionDocumentIDs = computed(() =>
this.documentIDs().filter(
(documentID) => documentID !== this.rootDocumentID()
)
@@ -49,24 +35,6 @@ export class MergeAsVersionsConfirmDialogComponent
.subscribe((response) => this.documents.set(response.results))
}
onDrop(event: CdkDragDrop<number[]>) {
const draggableDocumentIDs = this.draggableDocumentIDs().concat()
moveItemInArray(
draggableDocumentIDs,
event.previousIndex,
event.currentIndex
)
let draggableIndex = 0
this.documentIDs.update((documentIDs) =>
documentIDs.map((documentID) =>
documentID === this.rootDocumentID()
? documentID
: draggableDocumentIDs[draggableIndex++]
)
)
}
getDocument(documentID: number): Document {
return this.documents().find((document) => document.id === documentID)
}