Skip to content

Commit 1d137c8

Browse files
Copilotrenemadsen
andcommitted
Fix nested drag-drop in visual editor and add cdkDragHandle to all drag elements
Co-authored-by: renemadsen <[email protected]>
1 parent a3d2b52 commit 1d137c8

File tree

6 files changed

+28
-6
lines changed

6 files changed

+28
-6
lines changed

eform-client/src/app/modules/advanced/modules/navigation-menu/components/menu-item/navigation-menu-item/navigation-menu-item.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<mat-card class="mb-2 mt-2" id="menuItemTemplate">
22
<mat-card-header class="py-2 d-flex align-items-center justify-content-start">
33
<mat-icon
4+
cdkDragHandle
45
style="cursor: all-scroll"
56
id="drag_handle{{firstLevelIndex}}_{{secondLevelIndex}}"
67
class="md-36 dragula-handle align-middle"

eform-client/src/app/modules/advanced/modules/navigation-menu/components/menu-item/navigation-menu-template-item/navigation-menu-template-item.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<mat-card class="mb-2 mt-2">
22
<mat-card-header class="py-3 d-flex align-items-center justify-content-start">
33
<mat-icon
4+
cdkDragHandle
45
id="dragHandle{{templateIndex}}_{{itemIndex}}"
56
class="dragula-handle align-middle"
67
style="cursor: all-scroll">

eform-client/src/app/modules/eforms/eform-visual-editor/components/eform-visual-editor-elements/checklist/visual-editor-checklist/visual-editor-checklist.component.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<div class="d-flex justify-content-between align-items-center">
66
<div style="display: flex; flex-grow: 2; align-items: center;">
77
<mat-icon
8+
cdkDragHandle
89
class="dragula-handle align-middle"
910
style="cursor: pointer"
1011
id="moveBtn"
@@ -63,9 +64,9 @@
6364
</mat-card-header>
6465
<div class="card-body">
6566
<div
66-
dragula="FIELDS"
67-
[dragulaModel]="checklist.fields"
68-
(dragulaModelChange)="onNestedFieldPositionChanged($event)"
67+
cdkDropList
68+
[cdkDropListData]="checklist.fields"
69+
(cdkDropListDropped)="dropNestedField($event)"
6970
id="fields_{{ checklistIndex }}"
7071
class="editor-fields"
7172
>
@@ -74,6 +75,7 @@
7475
</div>-->
7576
<app-visual-editor-field
7677
*ngFor="let field of checklist.fields; let fieldIndex = index"
78+
cdkDrag
7779
[fieldIndex]="fieldIndex"
7880
[field]="field"
7981
[checklistRecursionIndexes]="checklistRecursionIndexes"

eform-client/src/app/modules/eforms/eform-visual-editor/components/eform-visual-editor-elements/checklist/visual-editor-checklist/visual-editor-checklist.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, inject } from '@angular/core';
2+
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
23
import {
34
EformVisualEditorFieldsDnDRecursionModel,
45
EformVisualEditorFieldModel,
@@ -127,6 +128,13 @@ export class VisualEditorChecklistComponent implements OnInit, OnDestroy {
127128
});
128129
}
129130

131+
dropNestedField(event: CdkDragDrop<EformVisualEditorFieldModel[]>) {
132+
if (event.previousIndex !== event.currentIndex) {
133+
moveItemInArray(this.checklist.fields, event.previousIndex, event.currentIndex);
134+
this.onNestedFieldPositionChanged(this.checklist.fields);
135+
}
136+
}
137+
130138
onEditNestedField(fieldIndex: number, field: EformVisualEditorFieldModel) {
131139
this.editNestedField.emit({
132140
checklistRecursionIndexes: this.checklistRecursionIndexes,

eform-client/src/app/modules/eforms/eform-visual-editor/components/eform-visual-editor-elements/field/visual-editor-field/visual-editor-field.component.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
>
1212
<div style="display: flex; flex-grow: 6; align-items: center;">
1313
<mat-icon
14+
cdkDragHandle
1415
class="dragula-handle align-middle"
1516
style="cursor: pointer"
1617
[id]="fieldIsNested ? 'moveNestedFieldBtn' : 'moveFieldBtn'"
@@ -92,13 +93,14 @@
9293
*ngIf="field.fieldType == fieldTypes.FieldGroup"
9394
class="field-group-container section-collapse pl-3 nested-fields"
9495
[ngClass]="{'p-1 pt-3' : !field.collapsed, 'collapsed' : field.collapsed}"
95-
dragula="FIELDS"
96-
[dragulaModel]="field.fields"
96+
cdkDropList
97+
[cdkDropListData]="field.fields"
9798
id="nestedFields"
98-
(dragulaModelChange)="onFieldPositionChangedOnNestedField($event)"
99+
(cdkDropListDropped)="dropNestedField($event)"
99100
>
100101
<app-visual-editor-field
101102
*ngFor="let nestedField of field.fields; let i = index"
103+
cdkDrag
102104
[ngClass]="{'collapsed' : field.collapsed}"
103105
[field]="nestedField"
104106
[checklistRecursionIndexes]="checklistRecursionIndexes"

eform-client/src/app/modules/eforms/eform-visual-editor/components/eform-visual-editor-elements/field/visual-editor-field/visual-editor-field.component.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Component, EventEmitter, Input, OnDestroy, OnInit, Output, inject } from '@angular/core';
2+
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
23
import {
34
EformFieldTypesEnum,
45
} from 'src/app/common/const';
@@ -164,6 +165,13 @@ export class VisualEditorFieldComponent implements OnInit, OnDestroy {
164165
});
165166
}
166167

168+
dropNestedField(event: CdkDragDrop<EformVisualEditorFieldModel[]>) {
169+
if (event.previousIndex !== event.currentIndex) {
170+
moveItemInArray(this.field.fields, event.previousIndex, event.currentIndex);
171+
this.onFieldPositionChangedOnNestedField(this.field.fields);
172+
}
173+
}
174+
167175
get fieldTranslationAndType() {
168176
const type = this.fieldTypeTranslation(this.field.fieldType);
169177
let strForReturn = this.getTranslation;

0 commit comments

Comments
 (0)