activeadmin_reorderable 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 432b1bf79ccce9af126f1d991c7a00a926a80d2e6aa3544c93650a2860591628
4
- data.tar.gz: 71d1daeb82bb9c9631c5e947a98437478b6c347d0e55846c84b5d653dbe02aaf
3
+ metadata.gz: d5d2078b647c1ba2fff85693c3ddca69049127474e6dc4ea742ebfe13afd0785
4
+ data.tar.gz: e7029690575b2600dcdba74f6122f8e7b3519ab3dc9c181b2aac6107a585cdaf
5
5
  SHA512:
6
- metadata.gz: 9969c5d1b405bbc2f00530a08b97c182a35460295f3929befc05a6288756fc908df1a8e2ad9ce9d281667b65d3bd698452248cfe712cce94fb563a0f3ba1b348
7
- data.tar.gz: 9778aaf69204141275c167df461034b75c40033c9ab91b92db45d1a00138f573251090d0b40f5a5934e43d6dbe45e5befca8a3c28d05e9b47f7313bdfbe5e89a
6
+ metadata.gz: 418c67cd8f3057f91a9926ef8b8a0d1f43b13017fff242449e2205d50d0eb1ad398c55b52d1b88eb4955722592cd622288ffc2d5a4fa216222a2cc94494b7747
7
+ data.tar.gz: 9d49b162efd928e36a61dbdb3e89e67a9dec13926f0674d066bfc5e35efcacfe226dc0c973fa5e330e6759b66fae6aa229e744628f6f11b1c8dbc4c9f9a6ede8
@@ -1,7 +1,8 @@
1
- const setupReorderable = ({ table, onUpdate }) => {
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
- onUpdate(dragSrc)
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
- onUpdate: (row) => {
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
  }
@@ -0,0 +1 @@
1
+ pin "activeadmin_reorderable", to: "activeadmin_reorderable.js"
@@ -1,3 +1,3 @@
1
1
  module ActiveadminReorderable
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.3"
3
3
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "activeadmin_reorderable",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Drag and drop to reorder your ActiveAdmin tables.",
5
5
  "main": "app/assets/javascripts/activeadmin_reorderable.js",
6
6
  "files": [
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.1
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-15 00:00:00.000000000 Z
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