activeadmin_reorderable 0.1.0 → 0.2.0

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
- SHA1:
3
- metadata.gz: 3ba2baf266f9017eb5aa9b28092cbad248c30296
4
- data.tar.gz: aac13b30bd7e9ceac019916a2dca6b83493f1783
2
+ SHA256:
3
+ metadata.gz: 40ed33ae36cb82f27d5c1d3a63af91e6d57f384c2f3512a9fe9376ea7a36b69f
4
+ data.tar.gz: 7a4c1ade7db39b0c48253cf20c9e46a1f9312ca06a4bbce50c94f1765a8a9845
5
5
  SHA512:
6
- metadata.gz: bc599627c63e489cc162f5e527e50fa209c0df5ce15af88c6c48c4f14e17cd83a126ec6c5bd37afca078ba137510f8d507e15a8f0ba879932ed65127df8b15bd
7
- data.tar.gz: 2b417e98afaaf8e867c17a6a4f06010020590470d76333c77e24a9b668127e122d5ba7e16e0efb97c3c73ff954d809a4690a5564b11fafd7ee0c3a06dbbc2485
6
+ metadata.gz: 8f989e1ccd43c828dcbc74c98a461b3e22a5b3bf0611133b57612dac39bf23c04b8555370f9743f822f98a9fe6af4113980fb56ac23072e3ff3c70b943b9b5c3
7
+ data.tar.gz: 8f492dffaf1499099ef6dfce4e3f4e133b82bb94c31b8ff66fe9e5362795ef6825cbea4a8155bd2b13439ff90346e70c740f653957460ac590e80c5ad500605f
data/.gitignore CHANGED
@@ -1 +1,3 @@
1
1
  builds/*
2
+ Gemfile.lock
3
+ node_modules
data/README.md CHANGED
@@ -8,10 +8,16 @@ Drag and drop to reorder your ActiveAdmin tables.
8
8
  Your resource classes must respond to `insert_at` ala the [`acts_as_list`](https://github.com/swanandp/acts_as_list) API. You don't need to use `acts_as_list`, but if you don't, make sure to define `insert_at`.
9
9
 
10
10
  ## Installation
11
+ ### Sprockets
11
12
  - Add `gem 'activeadmin_reorderable'` to `Gemfile`
12
13
  - Add `#= require activeadmin_reorderable` to `app/assets/javascripts/active_admin.js.coffee`
13
14
  - Add `@import "activeadmin_reorderable";` as the last `@import` statement in `app/assets/stylesheets/active_admin.css.scss`
14
15
 
16
+ ### Webpacker / npm
17
+ - `npm install --save activeadmin_reorderable` or `yarn add activeadmin_reorderable`
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
20
+
15
21
  ## Use
16
22
  `parts.rb`
17
23
  ```ruby
@@ -53,10 +59,14 @@ ActiveAdmin.register Widget do
53
59
  end
54
60
  ```
55
61
 
56
- ***
62
+ ## Contributing
63
+
64
+ 1. Fork it ( https://github.com/[my-github-username]/activeadmin_reorderable/fork )
65
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
66
+ 3. Commit your changes (`git commit -am "Add some feature"`)
67
+ 4. Push to the branch (`git push origin my-new-feature`)
68
+ 5. Create a new Pull Request
57
69
 
58
- <a href="http://code.viget.com">
59
- <img src="http://code.viget.com/github-banner.png" alt="Code At Viget">
60
- </a>
70
+ ### Issue and PR reviews
61
71
 
62
- Visit [code.viget.com](http://code.viget.com) to see more projects from [Viget.](https://viget.com)
72
+ Another way you can help is by reviewing issues, trying to reproduce bugs, and providing feedback on PRs.
Binary file
@@ -1,7 +1,7 @@
1
- $.fn.reorderable = function(opts) {
1
+ $.fn.reorderable = function (opts) {
2
2
  // This helper fixes the table row width collapsing when being dragged
3
3
  function reorderableTableHelper(e, ui) {
4
- ui.children().each(function() {
4
+ ui.children().each(function () {
5
5
  var $cell = $(this);
6
6
 
7
7
  $cell.width($cell.width());
@@ -18,16 +18,17 @@ $.fn.reorderable = function(opts) {
18
18
  }
19
19
 
20
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'),
26
- index = function(i) { return $rows.index(i) + 1; };
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'),
27
26
 
28
- $table.find('tbody tr').each(function(index) {
29
- var $row = $(this),
30
- newClass = ''
27
+ index = function (i) { return $rows.index(i) + 1; };
28
+
29
+ $table.find('tbody tr').each(function (index) {
30
+ var $row = $(this),
31
+ newClass = ''
31
32
 
32
33
  $row.removeClass('odd').removeClass('even');
33
34
 
@@ -40,27 +41,33 @@ $.fn.reorderable = function(opts) {
40
41
  $row.addClass(newClass);
41
42
  });
42
43
 
43
- $rows.each(function() {
44
+ $rows.each(function () {
44
45
  $(this).find('.position').text(index($(this)));
45
46
  });
47
+ var top_id = $row.prev().find('.reorder-handle').data("reorderId")
48
+ var bottom_id = $row.next().find('.reorder-handle').data("reorderId")
46
49
 
47
- $.post(url, { position: index($row) });
50
+ $.post(url, {
51
+ position: index($row),
52
+ top_id: top_id,
53
+ bottom_id: bottom_id
54
+ });
48
55
  }
49
56
 
50
- return this.each(function() {
57
+ return this.each(function () {
51
58
  var opts = $.extend({
52
- items: 'tbody tr',
59
+ items: 'tbody tr',
53
60
  handle: '.reorder-handle',
54
- axis: 'y',
61
+ axis: 'y',
55
62
  helper: reorderableTableHelper,
56
- start: reorderableTableStart,
57
- stop: reorderableTableStop,
63
+ start: reorderableTableStart,
64
+ stop: reorderableTableStop,
58
65
  }, opts || {});
59
66
 
60
67
  $(this).sortable(opts);
61
68
  });
62
69
  };
63
70
 
64
- $(function() {
71
+ $(function () {
65
72
  $('.aa-reorderable').reorderable();
66
73
  });
@@ -11,8 +11,12 @@ module ActiveAdmin
11
11
  private
12
12
 
13
13
  def reorder_handle_for(resource)
14
- url = url_for([:reorder, active_admin_namespace.name, resource])
15
- span(reorder_handle_content, :class => 'reorder-handle', 'data-reorder-url' => url)
14
+ aa_resource = active_admin_namespace.resource_for(resource.class)
15
+ instance_name = aa_resource.resources_configuration[:self][:route_instance_name]
16
+
17
+ url = send([:reorder, aa_resource.route_prefix, instance_name, :path].join('_'), resource)
18
+
19
+ span(reorder_handle_content, :class => 'reorder-handle', 'data-reorder-url' => url, 'data-reorder-id' => resource.id)
16
20
  end
17
21
 
18
22
  def reorder_handle_content
@@ -1,3 +1,3 @@
1
1
  module ActiveadminReorderable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "activeadmin_reorderable",
3
+ "version": "0.2.0",
4
+ "description": "Drag and drop to reorder your ActiveAdmin tables.",
5
+ "main": "app/assets/javascripts/activeadmin_reorderable.js",
6
+ "files": [
7
+ "app/**/*"
8
+ ],
9
+ "repository": "https://github.com/dkniffin/activeadmin_reorderable",
10
+ "author": "Viget <hello@viget.com>",
11
+ "license": "MIT",
12
+ "scripts": { },
13
+ "devDependencies": { },
14
+ "dependencies": {
15
+ "jquery": "^3.5.1"
16
+ }
17
+ }
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_reorderable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Jones
8
8
  - Lawson Kurtz
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-10-19 00:00:00.000000000 Z
12
+ date: 2022-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activeadmin
@@ -38,6 +38,7 @@ files:
38
38
  - Gemfile
39
39
  - MIT-LICENSE
40
40
  - README.md
41
+ - activeadmin_reorderable-0.1.5.gem
41
42
  - activeadmin_reorderable.gemspec
42
43
  - app/assets/javascripts/activeadmin_reorderable.js
43
44
  - app/assets/stylesheets/activeadmin_reorderable.scss
@@ -48,11 +49,12 @@ files:
48
49
  - lib/activeadmin_reorderable.rb
49
50
  - lib/activeadmin_reorderable/engine.rb
50
51
  - lib/activeadmin_reorderable/version.rb
52
+ - package.json
51
53
  homepage: http://www.github.com/vigetlabs/activeadmin_reorderable
52
54
  licenses:
53
55
  - MIT
54
56
  metadata: {}
55
- post_install_message:
57
+ post_install_message:
56
58
  rdoc_options: []
57
59
  require_paths:
58
60
  - lib
@@ -67,9 +69,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
67
69
  - !ruby/object:Gem::Version
68
70
  version: '0'
69
71
  requirements: []
70
- rubyforge_project:
71
- rubygems_version: 2.4.5.1
72
- signing_key:
72
+ rubygems_version: 3.1.2
73
+ signing_key:
73
74
  specification_version: 4
74
75
  summary: Drag and drop reordering for ActiveAdmin tables
75
76
  test_files: []