-
Notifications
You must be signed in to change notification settings - Fork 460
/
Copy pathdrag-drop.component.ts
122 lines (108 loc) · 2.51 KB
/
drag-drop.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import {Component} from '@angular/core';
import {CdkDragDrop, moveItemInArray, transferArrayItem} from '@angular/cdk/drag-drop';
import {Lesson} from '../model/lesson';
@Component({
selector: 'drag-drop-example',
templateUrl: "drag-drop.component.html",
styleUrls: ["drag-drop.component.scss"]
})
export class DragDropComponent {
lessons = [
{
id: 120,
'description': 'Introduction to Angular Material',
'duration': '4:17',
'seqNo': 1,
courseId: 11
},
{
id: 121,
'description': 'Navigation and Containers',
'duration': '6:37',
'seqNo': 2,
courseId: 11
},
{
id: 122,
'description': 'Data Tables',
'duration': '8:03',
'seqNo': 3,
courseId: 11
},
{
id: 123,
'description': 'Dialogs and Overlays',
'duration': '11:46',
'seqNo': 4,
courseId: 11
},
{
id: 124,
'description': 'Commonly used Form Controls',
'duration': '7:17',
'seqNo': 5,
courseId: 11
},
{
id: 125,
'description': 'Drag and Drop',
'duration': '8:16',
'seqNo': 6,
courseId: 11
},
{
id: 126,
'description': 'Responsive Design',
'duration': '7:28',
'seqNo': 7,
courseId: 11
},
{
id: 127,
'description': 'Tree Component',
'duration': '11:09',
'seqNo': 8,
courseId: 11
},
{
id: 128,
'description': 'Virtual Scrolling',
'duration': '3:44',
'seqNo': 9,
courseId: 11
},
{
id: 129,
'description': 'Custom Themes',
'duration': '8:55',
'seqNo': 10,
courseId: 11
},
{
id: 130,
'description': 'Changing Theme at Runtime',
'duration': '12:37',
'seqNo': 11,
courseId: 11
}
];
done = [];
dropMultiList(event: CdkDragDrop<Lesson[]>) {
if (event.previousContainer == event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
}
else {
transferArrayItem(
event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex
);
}
}
drop(event: CdkDragDrop<Lesson[]>) {
console.log("previousIndex = ", event.previousIndex);
console.log("currentIndex = " + event.currentIndex);
moveItemInArray(this.lessons, event.previousIndex, event.currentIndex);
}
}