activeadmin_reorderable 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 24e42e395b381a8fa33bce9aa9e8fb26e337b3f67519d5a998e720c94dac7f7e
4
- data.tar.gz: 90475575d7098a30e8dc43b8a3536dcd6b4a9f42cf2a696face953002d504c9c
3
+ metadata.gz: b0cdf7b48ce9d9b388c2140c1278d5626386139523b4d5505a1a2b4186c9b401
4
+ data.tar.gz: 43d51f9f8abcd5519224855536a737cfb2bc6b5e9f6b607babbd36ac264809bd
5
5
  SHA512:
6
- metadata.gz: 399ec9fb0d7bd3217a40577e4ed3e3c980405cde55de5291db6a1d643c1881adcef7fcf33a9fc86cc47a234a50e7c3a9682ebd9ac805e39f84b431a35d5a832b
7
- data.tar.gz: 5a29b1301e0e8477754ad4262aad074d58dd86770e0d9f167b396edf380c92f3e41e17cc33ca62d4e040f77538c55194ecfcd11877170da8e984b4e632e6df53
6
+ metadata.gz: 6ad7ef181efc4d8cb1b3b636ec14a12adef97efd0c6ed1a33e8c52dea4cb4ce18438979a4f42cd67fe018fbd1afc9a33e20b69eaff8fd21cfe2d13d53a701601
7
+ data.tar.gz: 52bcb5b1dc53133d2e5cb39b6d7c4c4bbfe562f2061a3cc49f4a76df9aa662613650434dff80368a1c347999318c6a1bd9ef09f65ab906374e08398362df398a
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2013 Viget Labs
1
+ Copyright 2022 Derek Kniffin
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -9,14 +9,14 @@ Your resource classes must respond to `insert_at` ala the [`acts_as_list`](https
9
9
 
10
10
  ## Installation
11
11
  ### Sprockets
12
- - Add `gem 'activeadmin_reorderable'` to `Gemfile`
12
+ - Add `gem 'activeadmin_reorderable'` to `Gemfile` and run `bundle install`
13
13
  - Add `#= require activeadmin_reorderable` to `app/assets/javascripts/active_admin.js.coffee`
14
14
  - Add `@import "activeadmin_reorderable";` as the last `@import` statement in `app/assets/stylesheets/active_admin.css.scss`
15
15
 
16
16
  ### Webpacker / npm
17
17
  - `npm install --save activeadmin_reorderable` or `yarn add activeadmin_reorderable`
18
18
  - Add `import "activeadmin_reorderable"` to your JS pack file
19
- - Add `@import "activeadmin_reorderable/app/assets/styleseehts/activeadmin_reorderable.scss"";` to your CSS style file
19
+ - Add `@import "activeadmin_reorderable/app/assets/styleseehts/activeadmin_reorderable.scss";` to your CSS style file
20
20
 
21
21
  ## Use
22
22
  `parts.rb`
@@ -70,3 +70,22 @@ end
70
70
  ### Issue and PR reviews
71
71
 
72
72
  Another way you can help is by reviewing issues, trying to reproduce bugs, and providing feedback on PRs.
73
+
74
+ ## Pushing a new version
75
+
76
+ First, you must be authorized on both rubygems.org and npmjs.com. Then:
77
+
78
+ Update the ruby gem:
79
+ - Update the version in `lib/activeadmin_reorderable/version.rb`
80
+ - `gem build activeadmin_reorderable.gemspec`
81
+ - `gem push activeadmin_reorderable-X.Y.Z.gem`
82
+
83
+ Update the npm package:
84
+ - Update the version in `package.json`
85
+ - `npm publish`
86
+
87
+ Tag the version in git:
88
+ - `git tag X.Y.Z`
89
+ - `git push origin X.Y.Z`
90
+
91
+ Update the changelog
@@ -1,73 +1,102 @@
1
- $.fn.reorderable = function (opts) {
2
- // This helper fixes the table row width collapsing when being dragged
3
- function reorderableTableHelper(e, ui) {
4
- ui.children().each(function () {
5
- var $cell = $(this);
1
+ const setupReorderable = ({ table, onUpdate }) => {
2
+ const rows = table.getElementsByTagName('tbody')[0].rows
6
3
 
7
- $cell.width($cell.width());
8
- });
4
+ let dragSrc = null
9
5
 
10
- return ui;
11
- }
6
+ for (var i = 0; i < rows.length; i++) {
7
+ const row = rows[i]
8
+ const handle = row.querySelector(".reorder-handle")
12
9
 
13
- // This helper sets the table row placeholder height to the height of the row being moved
14
- function reorderableTableStart(e, ui) {
15
- ui.placeholder.height(ui.helper.outerHeight());
10
+ // Add draggable only when the handle is clicked, to prevent dragging from the rest of the row
11
+ handle.addEventListener("mousedown", () => row.setAttribute("draggable", "true"))
12
+ handle.addEventListener("mouseup", () => row.setAttribute("draggable", "false"))
16
13
 
17
- return ui;
18
- }
14
+ row.addEventListener("dragstart", (e) => {
15
+ e.dataTransfer.effectAllowed = "move"
19
16
 
20
- function reorderableTableStop(e, ui) {
21
- var $row = ui.item,
22
- $rows = $row.parent().children('tr'),
23
- $table = $row.closest('table'),
24
- $handle = $row.find('.reorder-handle'),
25
- url = $handle.data('reorder-url'),
17
+ dragSrc = row
26
18
 
27
- index = function (i) { return $rows.index(i) + 1; };
19
+ // Apply styling a millisecond later, so the dragging image shows up correctly
20
+ setTimeout(() => { row.classList.add("dragged-row") }, 1)
21
+ })
28
22
 
29
- $table.find('tbody tr').each(function (index) {
30
- var $row = $(this),
31
- newClass = ''
23
+ row.addEventListener("dragover", (e) => {
24
+ e.preventDefault()
25
+ e.dataTransfer.dropEffect = "move"
32
26
 
33
- $row.removeClass('odd').removeClass('even');
27
+ // If dragged to a new location, move the dragged row
28
+ if (dragSrc != row) {
29
+ const sourceIndex = dragSrc.rowIndex
30
+ const targetIndex = row.rowIndex
34
31
 
35
- if ((index + 1) % 2 == 0) {
36
- newClass = 'even';
37
- } else {
38
- newClass = 'odd';
32
+ if (sourceIndex < targetIndex) {
33
+ table.tBodies[0].insertBefore(dragSrc, row.nextSibling)
34
+ } else {
35
+ table.tBodies[0].insertBefore(dragSrc, row)
36
+ }
37
+ onUpdate(dragSrc)
39
38
  }
39
+ })
40
+
41
+ row.addEventListener("dragend", () => {
42
+ // Disable dragging, so only the handle can start the dragging again
43
+ row.setAttribute("draggable", "false")
44
+ row.classList.remove("dragged-row")
45
+ dragSrc = null
46
+ })
47
+ }
48
+ }
49
+
50
+ const updateEvenOddClasses = (row, index) => {
51
+ row.classList.remove("odd")
52
+ row.classList.remove("even")
53
+
54
+ if ((index + 1) % 2 == 0) {
55
+ row.classList.add("even")
56
+ } else {
57
+ row.classList.add("odd")
58
+ }
59
+ }
40
60
 
41
- $row.addClass(newClass);
42
- });
61
+ const updatePositionText = (row, index) => {
62
+ row.querySelector(".position").textContent = index
63
+ }
43
64
 
44
- $rows.each(function () {
45
- $(this).find('.position').text(index($(this)));
46
- });
47
- var top_id = $row.prev().find('.reorder-handle').data("reorderId")
48
- var bottom_id = $row.next().find('.reorder-handle').data("reorderId")
65
+ const updateBackend = (url, rowIndex) => {
66
+ let headers = { }
49
67
 
50
- $.post(url, {
51
- position: index($row),
52
- top_id: top_id,
53
- bottom_id: bottom_id
54
- });
68
+ const csrfElement = document.querySelector("meta[name=csrf-token]")
69
+ if (csrfElement) {
70
+ headers["X-CSRF-Token"] = csrfElement.getAttribute("content")
71
+ } else {
72
+ console.warn("Rails CSRF element not present. AJAX requests may fail due to CORS issues.")
55
73
  }
56
74
 
57
- return this.each(function () {
58
- var opts = $.extend({
59
- items: 'tbody tr',
60
- handle: '.reorder-handle',
61
- axis: 'y',
62
- helper: reorderableTableHelper,
63
- start: reorderableTableStart,
64
- stop: reorderableTableStop,
65
- }, opts || {});
66
-
67
- $(this).sortable(opts);
68
- });
69
- };
70
-
71
- $(function () {
72
- $('.aa-reorderable').reorderable();
73
- });
75
+ const formData = new FormData()
76
+ formData.append("position", rowIndex)
77
+
78
+ fetch(url, { method: "POST", headers, body: formData })
79
+ }
80
+
81
+ document.addEventListener("DOMContentLoaded", () => {
82
+ document.querySelectorAll(".aa-reorderable").forEach((table) => {
83
+ setupReorderable({
84
+ table,
85
+ onUpdate: (row) => {
86
+ const allRows = table.getElementsByTagName('tbody')[0].rows
87
+ const handle = row.querySelector(".reorder-handle")
88
+ const url = handle.dataset["reorderUrl"]
89
+ const rowIndex = Array.prototype.indexOf.call(allRows, row)
90
+
91
+ for (var i = 0; i < allRows.length; i++) {
92
+ const loopRow = allRows[i]
93
+ const index = i + 1
94
+ updateEvenOddClasses(loopRow, index)
95
+ updatePositionText(loopRow, index)
96
+ }
97
+
98
+ updateBackend(url, rowIndex + 1)
99
+ }
100
+ })
101
+ })
102
+ })
@@ -3,4 +3,8 @@
3
3
  @include light-button;
4
4
  cursor: move;
5
5
  }
6
+
7
+ .dragged-row {
8
+ opacity: 0;
9
+ }
6
10
  }
@@ -14,7 +14,7 @@ module ActiveAdmin
14
14
  aa_resource = active_admin_namespace.resource_for(resource.class)
15
15
  url = aa_resource.route_member_action_path(:reorder, resource)
16
16
 
17
- span(reorder_handle_content, :class => 'reorder-handle', 'data-reorder-url' => url, 'data-reorder-id' => resource.id)
17
+ span(reorder_handle_content, :class => 'reorder-handle', 'data-reorder-url' => url)
18
18
  end
19
19
 
20
20
  def reorder_handle_content
@@ -1,3 +1,3 @@
1
1
  module ActiveadminReorderable
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
data/package.json CHANGED
@@ -1,17 +1,15 @@
1
1
  {
2
2
  "name": "activeadmin_reorderable",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "Drag and drop to reorder your ActiveAdmin tables.",
5
5
  "main": "app/assets/javascripts/activeadmin_reorderable.js",
6
6
  "files": [
7
7
  "app/**/*"
8
8
  ],
9
9
  "repository": "https://github.com/dkniffin/activeadmin_reorderable",
10
- "author": "Viget <hello@viget.com>",
10
+ "author": "Derek Kniffin <derek.kniffin@gmail.com>",
11
11
  "license": "MIT",
12
12
  "scripts": { },
13
13
  "devDependencies": { },
14
- "dependencies": {
15
- "jquery": "^3.5.1"
16
- }
14
+ "dependencies": { }
17
15
  }
metadata CHANGED
@@ -1,44 +1,214 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_reorderable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Derek Kniffin
7
8
  - Chris Jones
8
9
  - Lawson Kurtz
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2022-03-10 00:00:00.000000000 Z
13
+ date: 2024-07-11 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: activeadmin
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '3.0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: acts_as_list
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ type: :development
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ - !ruby/object:Gem::Dependency
44
+ name: capybara
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :development
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: database_cleaner
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :development
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: factory_bot_rails
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: pry
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :development
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: puma
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: rails
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '6.1'
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: 6.1.4.4
123
+ type: :development
124
+ prerelease: false
125
+ version_requirements: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '6.1'
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: 6.1.4.4
133
+ - !ruby/object:Gem::Dependency
134
+ name: rspec-rails
135
+ requirement: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ type: :development
141
+ prerelease: false
142
+ version_requirements: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - ">="
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ - !ruby/object:Gem::Dependency
148
+ name: selenium-webdriver
149
+ requirement: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - "~>"
152
+ - !ruby/object:Gem::Version
153
+ version: '4.10'
154
+ type: :development
155
+ prerelease: false
156
+ version_requirements: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - "~>"
159
+ - !ruby/object:Gem::Version
160
+ version: '4.10'
161
+ - !ruby/object:Gem::Dependency
162
+ name: site_prism
163
+ requirement: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ type: :development
169
+ prerelease: false
170
+ version_requirements: !ruby/object:Gem::Requirement
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ version: '0'
175
+ - !ruby/object:Gem::Dependency
176
+ name: sqlite3
177
+ requirement: !ruby/object:Gem::Requirement
178
+ requirements:
179
+ - - "~>"
180
+ - !ruby/object:Gem::Version
181
+ version: '1.4'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - "~>"
187
+ - !ruby/object:Gem::Version
188
+ version: '1.4'
189
+ - !ruby/object:Gem::Dependency
190
+ name: sassc-rails
16
191
  requirement: !ruby/object:Gem::Requirement
17
192
  requirements:
18
193
  - - ">="
19
194
  - !ruby/object:Gem::Version
20
- version: '0.6'
195
+ version: '0'
21
196
  type: :development
22
197
  prerelease: false
23
198
  version_requirements: !ruby/object:Gem::Requirement
24
199
  requirements:
25
200
  - - ">="
26
201
  - !ruby/object:Gem::Version
27
- version: '0.6'
202
+ version: '0'
28
203
  description: Add drag and drop reordering to ActiveAdmin tables.
29
204
  email:
30
- - lawson.kurtz@viget.com
205
+ - derek.kniffin@gmail.com
31
206
  executables: []
32
207
  extensions: []
33
208
  extra_rdoc_files: []
34
209
  files:
35
- - ".gitignore"
36
- - CHANGELOG.md
37
- - CONTRIBUTING.md
38
- - Gemfile
39
210
  - MIT-LICENSE
40
211
  - README.md
41
- - activeadmin_reorderable.gemspec
42
212
  - app/assets/javascripts/activeadmin_reorderable.js
43
213
  - app/assets/stylesheets/activeadmin_reorderable.scss
44
214
  - lib/active_admin/reorderable/dsl.rb
@@ -49,7 +219,7 @@ files:
49
219
  - lib/activeadmin_reorderable/engine.rb
50
220
  - lib/activeadmin_reorderable/version.rb
51
221
  - package.json
52
- homepage: http://www.github.com/vigetlabs/activeadmin_reorderable
222
+ homepage: http://www.github.com/dkniffin/activeadmin_reorderable
53
223
  licenses:
54
224
  - MIT
55
225
  metadata: {}
@@ -68,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
238
  - !ruby/object:Gem::Version
69
239
  version: '0'
70
240
  requirements: []
71
- rubygems_version: 3.1.2
241
+ rubygems_version: 3.3.26
72
242
  signing_key:
73
243
  specification_version: 4
74
244
  summary: Drag and drop reordering for ActiveAdmin tables
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- builds/*
2
- Gemfile.lock
3
- node_modules
4
- *.gem
data/CHANGELOG.md DELETED
@@ -1,9 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.1.0
4
-
5
- - Replace deprecated `render :nothing` with `head :ok` (thanks @zharikovpro)
6
-
7
- ## 0.0.3
8
-
9
- - Removed a console.log within the reordering JavaScript.
data/CONTRIBUTING.md DELETED
@@ -1,27 +0,0 @@
1
- # Contributing
2
-
3
- Thank you for considering a contribution to this project!
4
-
5
- ## Deployment
6
-
7
- `activeadmin_reorderable` is published on http://rubygems.org. The
8
- following steps are necessary to push a new version:
9
-
10
- ### Build the gem
11
-
12
- `gem build activeadmin_reorderable.gemspec`
13
-
14
- This will produce an artifact named roughly
15
- `activeadmin_reorderable-<version>.gem`.
16
-
17
- ### Publish the gem
18
-
19
- `gem push activeadmin_reorderable-<version>.gem`
20
-
21
- You may bump into permissions issues if you have not been added as an
22
- owner on the gem. Consult the Viget development team for acess.
23
-
24
- ## Reviews
25
-
26
- All changes should be submitted through pull request. Ideally, at
27
- least two :+1:s should be given before a pull request is merge.
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
@@ -1,18 +0,0 @@
1
- $:.push File.expand_path("../lib", __FILE__)
2
-
3
- require "activeadmin_reorderable/version"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "activeadmin_reorderable"
7
- s.version = ActiveadminReorderable::VERSION
8
- s.authors = ["Chris Jones", "Lawson Kurtz"]
9
- s.email = ["lawson.kurtz@viget.com"]
10
- s.homepage = "http://www.github.com/vigetlabs/activeadmin_reorderable"
11
- s.summary = "Drag and drop reordering for ActiveAdmin tables"
12
- s.description = "Add drag and drop reordering to ActiveAdmin tables."
13
- s.license = "MIT"
14
-
15
- s.files = `git ls-files`.split($/)
16
-
17
- s.add_development_dependency "activeadmin", ">= 0.6"
18
- end