activeadmin_reorderable 0.3.1 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/activeadmin_reorderable.js +17 -6
- data/config/importmap.rb +1 -0
- data/lib/activeadmin_reorderable/version.rb +1 -1
- data/package.json +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5d2078b647c1ba2fff85693c3ddca69049127474e6dc4ea742ebfe13afd0785
|
4
|
+
data.tar.gz: e7029690575b2600dcdba74f6122f8e7b3519ab3dc9c181b2aac6107a585cdaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 418c67cd8f3057f91a9926ef8b8a0d1f43b13017fff242449e2205d50d0eb1ad398c55b52d1b88eb4955722592cd622288ffc2d5a4fa216222a2cc94494b7747
|
7
|
+
data.tar.gz: 9d49b162efd928e36a61dbdb3e89e67a9dec13926f0674d066bfc5e35efcacfe226dc0c973fa5e330e6759b66fae6aa229e744628f6f11b1c8dbc4c9f9a6ede8
|
@@ -1,7 +1,8 @@
|
|
1
|
-
const setupReorderable = ({ table,
|
1
|
+
const setupReorderable = ({ table, onDragover, onDragEnd }) => {
|
2
2
|
const rows = table.getElementsByTagName('tbody')[0].rows
|
3
3
|
|
4
4
|
let dragSrc = null
|
5
|
+
let srcIndex = null
|
5
6
|
|
6
7
|
for (var i = 0; i < rows.length; i++) {
|
7
8
|
const row = rows[i]
|
@@ -15,6 +16,7 @@ const setupReorderable = ({ table, onUpdate }) => {
|
|
15
16
|
e.dataTransfer.effectAllowed = "move"
|
16
17
|
|
17
18
|
dragSrc = row
|
19
|
+
srcIndex = row.rowIndex
|
18
20
|
|
19
21
|
// Apply styling a millisecond later, so the dragging image shows up correctly
|
20
22
|
setTimeout(() => { row.classList.add("dragged-row") }, 1)
|
@@ -34,7 +36,7 @@ const setupReorderable = ({ table, onUpdate }) => {
|
|
34
36
|
} else {
|
35
37
|
table.tBodies[0].insertBefore(dragSrc, row)
|
36
38
|
}
|
37
|
-
|
39
|
+
onDragover(dragSrc)
|
38
40
|
}
|
39
41
|
})
|
40
42
|
|
@@ -42,7 +44,13 @@ const setupReorderable = ({ table, onUpdate }) => {
|
|
42
44
|
// Disable dragging, so only the handle can start the dragging again
|
43
45
|
row.setAttribute("draggable", "false")
|
44
46
|
row.classList.remove("dragged-row")
|
47
|
+
|
48
|
+
if (srcIndex != row.rowIndex) {
|
49
|
+
onDragEnd(dragSrc)
|
50
|
+
}
|
51
|
+
|
45
52
|
dragSrc = null
|
53
|
+
srcIndex = null
|
46
54
|
})
|
47
55
|
}
|
48
56
|
}
|
@@ -85,11 +93,8 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
85
93
|
document.querySelectorAll("table.aa-reorderable").forEach((table) => {
|
86
94
|
setupReorderable({
|
87
95
|
table,
|
88
|
-
|
96
|
+
onDragover: (_row) => {
|
89
97
|
const allRows = table.getElementsByTagName('tbody')[0].rows
|
90
|
-
const handle = row.querySelector(".reorder-handle")
|
91
|
-
const url = handle.dataset["reorderUrl"]
|
92
|
-
const rowIndex = Array.prototype.indexOf.call(allRows, row)
|
93
98
|
|
94
99
|
for (var i = 0; i < allRows.length; i++) {
|
95
100
|
const loopRow = allRows[i]
|
@@ -97,6 +102,12 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
97
102
|
updateEvenOddClasses(loopRow, index)
|
98
103
|
updatePositionText(loopRow, index)
|
99
104
|
}
|
105
|
+
},
|
106
|
+
onDragEnd: (row) => {
|
107
|
+
const handle = row.querySelector(".reorder-handle")
|
108
|
+
const url = handle.dataset["reorderUrl"]
|
109
|
+
const allRows = table.getElementsByTagName('tbody')[0].rows
|
110
|
+
const rowIndex = Array.prototype.indexOf.call(allRows, row)
|
100
111
|
|
101
112
|
updateBackend(url, rowIndex + 1)
|
102
113
|
}
|
data/config/importmap.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pin "activeadmin_reorderable", to: "activeadmin_reorderable.js"
|
data/package.json
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_reorderable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Kniffin
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2024-07-
|
13
|
+
date: 2024-07-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activeadmin
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- README.md
|
198
198
|
- app/assets/javascripts/activeadmin_reorderable.js
|
199
199
|
- app/assets/stylesheets/activeadmin_reorderable.scss
|
200
|
+
- config/importmap.rb
|
200
201
|
- lib/active_admin/reorderable/dsl.rb
|
201
202
|
- lib/active_admin/reorderable/table_methods.rb
|
202
203
|
- lib/active_admin/views/index_as_reorderable_table.rb
|