fixed_activeadmin_sortable_table 1.3.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 +7 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.rubocop.yml +15 -0
- data/.travis.yml +29 -0
- data/CHANGELOG.md +16 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +22 -0
- data/README.md +109 -0
- data/Rakefile +27 -0
- data/activeadmin_sortable_table.gemspec +30 -0
- data/app/assets/javascripts/activeadmin_sortable_table.js +48 -0
- data/app/assets/stylesheets/activeadmin_sortable_table.css +13 -0
- data/lib/active_admin/sortable_table.rb +43 -0
- data/lib/active_admin/sortable_table/engine.rb +9 -0
- data/lib/active_admin/sortable_table/handle_column.rb +66 -0
- data/lib/active_admin/sortable_table/version.rb +6 -0
- data/lib/activeadmin_sortable_table.rb +1 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/admin/categories.rb +13 -0
- data/spec/dummy/app/admin/dashboard.rb +32 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/active_admin.js +3 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/javascripts/jquery.simulate.drag-sortable.js +235 -0
- data/spec/dummy/app/assets/stylesheets/active_admin.scss +17 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/category.rb +3 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/bin/setup +29 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +30 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +41 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +42 -0
- data/spec/dummy/config/initializers/active_admin.rb +262 -0
- data/spec/dummy/config/initializers/assets.rb +11 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/db/development.sqlite3 +0 -0
- data/spec/dummy/db/migrate/20150910072150_create_active_admin_comments.rb +19 -0
- data/spec/dummy/db/migrate/20150910072505_create_categories.rb +7 -0
- data/spec/dummy/db/schema.rb +36 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/features/drag_and_drop_spec.rb +158 -0
- data/spec/features/move_to_top_spec.rb +55 -0
- data/spec/rails_helper.rb +62 -0
- data/spec/spec_helper.rb +92 -0
- data/spec/support/wait_for_ajax.rb +20 -0
- metadata +305 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 20c81aea75523dcfcb51564c1e26aeb1664daebace8fe10f89f10929faf7d51c
|
|
4
|
+
data.tar.gz: 612672399b7ccb86476c8d09ad2dbd572321760a415dfdaa7dd9004fe0a0303a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ed246864dea02ade91c658df5be1f20a3d170dc255739abf9fb34cead27b7610a70aaeecadd792f631aeac8554094843e67dfff7a8ec9bbf21f640fe738a303c
|
|
7
|
+
data.tar.gz: adfa43dca3b1b4eed74e10e4c030f84ea57811c753a7988497e86cfdade55c8062ff44130c16aa9c254e82050e3215b53ca4812fdbaf3e02b7d1349a26b3a6b9
|
data/.gitignore
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
spec/dummy/log/*.log
|
|
2
|
+
spec/dummy/tmp/
|
|
3
|
+
spec/dummy/public/assets
|
|
4
|
+
spec/dummy/.sass-cache
|
|
5
|
+
spec/dummy/db/test.sqlite3
|
|
6
|
+
*.gem
|
|
7
|
+
*.rbc
|
|
8
|
+
.bundle
|
|
9
|
+
.config
|
|
10
|
+
.yardoc
|
|
11
|
+
InstalledFiles
|
|
12
|
+
_yardoc
|
|
13
|
+
coverage
|
|
14
|
+
doc/
|
|
15
|
+
lib/bundler/man
|
|
16
|
+
pkg
|
|
17
|
+
rdoc
|
|
18
|
+
spec/reports
|
|
19
|
+
test/tmp
|
|
20
|
+
test/version_tmp
|
|
21
|
+
tmp
|
|
22
|
+
Gemfile.lock
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# This configuration was generated by
|
|
2
|
+
# `rubocop --auto-gen-config`
|
|
3
|
+
# on 2015-09-29 11:38:23 +0300 using RuboCop version 0.34.2.
|
|
4
|
+
# The point is for the user to remove these configuration records
|
|
5
|
+
# one by one as the offenses are removed from the code base.
|
|
6
|
+
# Note that changes in the inspected code, or installation of new
|
|
7
|
+
# versions of RuboCop, may require this file to be generated again.
|
|
8
|
+
|
|
9
|
+
AllCops:
|
|
10
|
+
Exclude:
|
|
11
|
+
- spec/dummy/**/*
|
|
12
|
+
|
|
13
|
+
# Configuration parameters: AllowURI, URISchemes.
|
|
14
|
+
Metrics/LineLength:
|
|
15
|
+
Max: 120
|
data/.travis.yml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
sudo: false
|
|
2
|
+
language: ruby
|
|
3
|
+
|
|
4
|
+
rvm:
|
|
5
|
+
- 2.3.7
|
|
6
|
+
- 2.4.4
|
|
7
|
+
- 2.5.1
|
|
8
|
+
|
|
9
|
+
env:
|
|
10
|
+
matrix:
|
|
11
|
+
- RAILS_VERSION=4.2.10
|
|
12
|
+
- RAILS_VERSION=5.2.1
|
|
13
|
+
|
|
14
|
+
matrix:
|
|
15
|
+
allow_failures:
|
|
16
|
+
- rvm: ruby-head
|
|
17
|
+
fast_finish: true
|
|
18
|
+
|
|
19
|
+
before_install: gem update --remote bundler
|
|
20
|
+
install:
|
|
21
|
+
- bundle install --retry=3
|
|
22
|
+
script:
|
|
23
|
+
- bundle exec rake dummy:prepare
|
|
24
|
+
- bundle exec rspec
|
|
25
|
+
- bundle exec rubocop
|
|
26
|
+
|
|
27
|
+
addons:
|
|
28
|
+
code_climate:
|
|
29
|
+
repo_token: 085c9fc58ac3efcd9a8b311ee77bcec0b5c048575cde8a2234f7c63550910969
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
1.3.0
|
|
2
|
+
|
|
3
|
+
* Test against latest supported ruby versions: 2.3.7, 2.4.4, 2.5.1 and rails versions: 4.2.10, 5.2.1.
|
|
4
|
+
* Add Rails 5 support
|
|
5
|
+
|
|
6
|
+
1.2.0
|
|
7
|
+
|
|
8
|
+
* **Feature**. Now it is possible to specify an acts_as_list column other than position @faucct
|
|
9
|
+
|
|
10
|
+
1.1.3
|
|
11
|
+
|
|
12
|
+
* **Fix**. Reordering was broken.
|
|
13
|
+
|
|
14
|
+
1.1.2
|
|
15
|
+
|
|
16
|
+
* **Fix**. Reload page after drug-and-dropping rows, so it recalculates positions properly.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2012 Adam McCrea
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
[](https://travis-ci.org/bolshakov/activeadmin_sortable_table)
|
|
2
|
+
[](https://codeclimate.com/github/bolshakov/activeadmin_sortable_table/coverage)
|
|
3
|
+
[](https://codeclimate.com/github/bolshakov/activeadmin_sortable_table)
|
|
4
|
+
[](http://badge.fury.io/rb/activeadmin_sortable_table)
|
|
5
|
+
|
|
6
|
+
# Active Admin Sortable Table
|
|
7
|
+
|
|
8
|
+
This gem extends ActiveAdmin so that your index page's table rows can be
|
|
9
|
+
orderable via a drag-and-drop interface.
|
|
10
|
+
|
|
11
|
+
## Improvements over the @neo version
|
|
12
|
+
|
|
13
|
+
1. Test coverage
|
|
14
|
+
2. Configurable labels for handler
|
|
15
|
+
3. Move to top button allows to push any item from any page to the top of the list
|
|
16
|
+
4. Sorting works on all pages ( not only on the first one)
|
|
17
|
+
|
|
18
|
+
## Prerequisites
|
|
19
|
+
|
|
20
|
+
This extension assumes that you're using [acts_as_list](https://github.com/swanandp/acts_as_list) on any model you want to be sortable.
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
class Page < ActiveRecord::Base
|
|
24
|
+
acts_as_list
|
|
25
|
+
end
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Usage
|
|
29
|
+
|
|
30
|
+
Add it to your Gemfile
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
gem "activeadmin_sortable_table"
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Include the JavaScript in `active_admin.js.coffee`
|
|
37
|
+
|
|
38
|
+
```coffeescript
|
|
39
|
+
#= require activeadmin_sortable_table
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Include the Stylesheet in `active_admin.css.scss`
|
|
43
|
+
|
|
44
|
+
```scss
|
|
45
|
+
@import "activeadmin_sortable_table"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Configure your ActiveAdmin Resource
|
|
49
|
+
|
|
50
|
+
```ruby
|
|
51
|
+
ActiveAdmin.register Page do
|
|
52
|
+
include ActiveAdmin::SortableTable # creates the controller action which handles the sorting
|
|
53
|
+
config.sort_order = 'position_asc' # assumes you are using 'position' for your acts_as_list column
|
|
54
|
+
|
|
55
|
+
index do
|
|
56
|
+
handle_column
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
show do |c|
|
|
60
|
+
attributes_table do
|
|
61
|
+
row :id
|
|
62
|
+
row :name
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
panel 'Contents' do
|
|
66
|
+
table_for c.collection_memberships do
|
|
67
|
+
handle_column
|
|
68
|
+
column :position
|
|
69
|
+
column :collectable
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Configure handler
|
|
77
|
+
|
|
78
|
+
You can override handler column symbol using handle_column options:
|
|
79
|
+
|
|
80
|
+
You can configure `sort_url` using handle column options by providing static value, symbolized instance method name, or blocks.
|
|
81
|
+
|
|
82
|
+
```ruby
|
|
83
|
+
handle_column sort_url: ->(category) { compute_url_for_category(category) }
|
|
84
|
+
handle_column sort_url: '/admin/categories/1/sort'
|
|
85
|
+
handle_column sort_url: :sort_category
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
The same options available for `move_to_top_url`:
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
handle_column move_to_top_url: '/admin/categories/1/move_to_top
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
It's also possible to override handle lables:
|
|
95
|
+
|
|
96
|
+
```ruby
|
|
97
|
+
handle_column sort_handle: '☰'.html_safe
|
|
98
|
+
handle_column move_to_top_handle: 'Move to top'
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Contributing
|
|
102
|
+
|
|
103
|
+
1. Fork it
|
|
104
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
105
|
+
3. Prepare tests database (`bundle exec rake dummy:prepare`)
|
|
106
|
+
4. Make your changes and runs specs (`bundle exec rspec`)
|
|
107
|
+
5. Commit your changes (`git commit -am 'Add some feature'`)
|
|
108
|
+
6. Push to the branch (`git push origin my-new-feature`)
|
|
109
|
+
7. Create Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
2
|
+
|
|
3
|
+
require 'rspec/core/rake_task'
|
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
5
|
+
task default: ['dummy:prepare', :spec]
|
|
6
|
+
|
|
7
|
+
require 'rake/clean'
|
|
8
|
+
CLEAN.include 'spec/dummy/db/*sqlite3', 'spec/dummy/log/*', 'spec/dummy/public/assets/*', 'spec/dummy/tmp/**/*'
|
|
9
|
+
|
|
10
|
+
namespace :dummy do
|
|
11
|
+
desc 'Setup dummy app database'
|
|
12
|
+
task :prepare do
|
|
13
|
+
# File.expand_path is executed directory of generated Rails app
|
|
14
|
+
rakefile = File.expand_path('Rakefile', dummy_path)
|
|
15
|
+
command = format("rake -f '%s' db:schema:load RAILS_ENV=test", rakefile)
|
|
16
|
+
sh(command) unless ENV['DISABLE_CREATE']
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def dummy_path
|
|
20
|
+
rel_path = ENV['DUMMY_APP_PATH'] || 'spec/dummy'
|
|
21
|
+
if @current_path.to_s.include?(rel_path)
|
|
22
|
+
@current_path
|
|
23
|
+
else
|
|
24
|
+
@current_path = File.expand_path(rel_path)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'active_admin/sortable_table/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |gem|
|
|
7
|
+
gem.name = 'fixed_activeadmin_sortable_table'
|
|
8
|
+
gem.version = ActiveAdmin::SortableTable::VERSION
|
|
9
|
+
gem.authors = ['Adam McCrea', 'Jonathan Gertig', 'Artyom Bolshakov']
|
|
10
|
+
gem.email = ['adam@adamlogic.com', 'jcgertig@gmail.com', 'abolshakov@spbtv.com']
|
|
11
|
+
gem.description = 'Drag and drop reordering interface for ActiveAdmin tables'
|
|
12
|
+
gem.summary = 'Drag and drop reordering interface for ActiveAdmin tables'
|
|
13
|
+
gem.license = 'MIT'
|
|
14
|
+
gem.homepage = 'https://github.com/bolshakov/activeadmin_sortable_table'
|
|
15
|
+
|
|
16
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
|
17
|
+
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
|
|
18
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
gem.require_paths = ['lib']
|
|
20
|
+
|
|
21
|
+
gem.add_dependency 'activeadmin', '>= 1.0.0.pre1'
|
|
22
|
+
gem.add_dependency 'uber', '0.0.15'
|
|
23
|
+
gem.add_development_dependency 'rails', '~> 4.2'
|
|
24
|
+
gem.add_development_dependency 'capybara'
|
|
25
|
+
gem.add_development_dependency 'rspec-rails', '~> 3.3'
|
|
26
|
+
gem.add_development_dependency 'phantomjs'
|
|
27
|
+
gem.add_development_dependency 'poltergeist'
|
|
28
|
+
gem.add_development_dependency 'database_cleaner'
|
|
29
|
+
gem.add_development_dependency 'launchy'
|
|
30
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
(function($) {
|
|
2
|
+
$(document).ready(function() {
|
|
3
|
+
$('.handle').closest('tbody').activeAdminSortableTable();
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
$.fn.activeAdminSortableTable = function() {
|
|
7
|
+
this.sortable({
|
|
8
|
+
handle: ".handle",
|
|
9
|
+
update: function(event, ui) {
|
|
10
|
+
var item = ui.item.find('[data-sort-url]');
|
|
11
|
+
var url = item.data('sort-url');
|
|
12
|
+
var customParams = {};
|
|
13
|
+
if (typeof item.data('sort-custom-params') === 'object') {
|
|
14
|
+
customParams = item.data('sort-custom-params');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
var nextElement = ui.item[0].nextElementSibling;
|
|
18
|
+
|
|
19
|
+
var nextPosition = $(nextElement).find('[data-position]').data('position');
|
|
20
|
+
var currentPosition = ui.item.find('[data-position]').data('position');
|
|
21
|
+
var authToken = $('meta[name=csrf-token]').attr('content');
|
|
22
|
+
|
|
23
|
+
if(nextPosition === undefined || nextPosition > currentPosition) {
|
|
24
|
+
// moved down
|
|
25
|
+
var previousElement = ui.item[0].previousElementSibling;
|
|
26
|
+
var previousPosition = $(previousElement).find('[data-position]').data('position');
|
|
27
|
+
var newPosition = previousPosition;
|
|
28
|
+
} else {
|
|
29
|
+
// moved up
|
|
30
|
+
var newPosition = nextPosition;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
$.ajax({
|
|
34
|
+
url: url,
|
|
35
|
+
type: 'post',
|
|
36
|
+
data: $.extend(customParams, { position: newPosition, authenticity_token: authToken }),
|
|
37
|
+
error: function () { console.error('Saving sortable error'); },
|
|
38
|
+
success: function () {
|
|
39
|
+
location.href = location.href;
|
|
40
|
+
},
|
|
41
|
+
async: false
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
this.disableSelection();
|
|
47
|
+
}
|
|
48
|
+
})(jQuery);
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'activeadmin'
|
|
2
|
+
|
|
3
|
+
module ActiveAdmin
|
|
4
|
+
# Include this module to registered page to enable
|
|
5
|
+
# ActiveAdmin Sortable Table extension
|
|
6
|
+
# @example
|
|
7
|
+
#
|
|
8
|
+
# ActiveAdmin.register Category do
|
|
9
|
+
# include ActiveAdmin::SortableTable
|
|
10
|
+
# config.sort_order = 'position_asc'
|
|
11
|
+
# permit_params :position
|
|
12
|
+
#
|
|
13
|
+
# index do
|
|
14
|
+
# handle_column
|
|
15
|
+
# id_column
|
|
16
|
+
# end
|
|
17
|
+
# end
|
|
18
|
+
#
|
|
19
|
+
module SortableTable
|
|
20
|
+
require 'active_admin/sortable_table/version'
|
|
21
|
+
require 'active_admin/sortable_table/engine'
|
|
22
|
+
require 'active_admin/sortable_table/handle_column'
|
|
23
|
+
|
|
24
|
+
class << self
|
|
25
|
+
# @param [ActiveAdmin::DSL] dsl
|
|
26
|
+
# @return [void]
|
|
27
|
+
#
|
|
28
|
+
def included(dsl) # rubocop:disable Metrics/AbcSize
|
|
29
|
+
dsl.instance_eval do
|
|
30
|
+
member_action :sort, method: :post do
|
|
31
|
+
resource.insert_at params[:position].to_i
|
|
32
|
+
head 200
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
member_action :move_to_top, method: :post do
|
|
36
|
+
resource.move_to_top
|
|
37
|
+
redirect_to request.headers['HTTP_REFERER'] || collection_path
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'uber/options'
|
|
2
|
+
|
|
3
|
+
module ActiveAdmin
|
|
4
|
+
#
|
|
5
|
+
module SortableTable
|
|
6
|
+
# Adds `handle_column` method to `TableFor` dsl.
|
|
7
|
+
# @example on index page
|
|
8
|
+
# index do
|
|
9
|
+
# handle_column
|
|
10
|
+
# id_column
|
|
11
|
+
# # other columns...
|
|
12
|
+
# end
|
|
13
|
+
#
|
|
14
|
+
# @example table_for
|
|
15
|
+
# table_for c.collection_memberships do
|
|
16
|
+
# handle_column
|
|
17
|
+
# # other columns...
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
module HandleColumn
|
|
21
|
+
DEFAULT_OPTIONS = {
|
|
22
|
+
move_to_top_url: ->(resource) { url_for([:move_to_top, :admin, resource]) },
|
|
23
|
+
move_to_top_handle: '⤒'.html_safe,
|
|
24
|
+
show_move_to_top_handle: ->(resource) { !resource.first? },
|
|
25
|
+
sort_url: ->(resource) { url_for([:sort, :admin, resource]) },
|
|
26
|
+
sort_handle: '☰'.html_safe
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
# @param [Hash] arguments
|
|
30
|
+
# @option arguments [Symbol, Proc, String] :sort_url
|
|
31
|
+
# @option arguments [Symbol, Proc, String] :sort_handle
|
|
32
|
+
# @option arguments [Symbol, Proc, String] :move_to_top_url
|
|
33
|
+
# @option arguments [Symbol, Proc, String] :move_to_top_handle
|
|
34
|
+
#
|
|
35
|
+
def handle_column(arguments = {})
|
|
36
|
+
defined_options = Uber::Options.new(DEFAULT_OPTIONS.merge(arguments))
|
|
37
|
+
|
|
38
|
+
column '', class: 'activeadmin_sortable_table' do |resource|
|
|
39
|
+
options = defined_options.evaluate(self, resource)
|
|
40
|
+
|
|
41
|
+
sort_handle(options, resource.send(resource.position_column)) + move_to_top_handle(options)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
def sort_handle(options, position)
|
|
48
|
+
content_tag(:span, options[:sort_handle],
|
|
49
|
+
class: 'handle',
|
|
50
|
+
'data-sort-url' => options[:sort_url],
|
|
51
|
+
'data-position' => position,
|
|
52
|
+
title: 'Drag to reorder'
|
|
53
|
+
)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def move_to_top_handle(options)
|
|
57
|
+
link_to_if(options[:show_move_to_top_handle], options[:move_to_top_handle], options[:move_to_top_url],
|
|
58
|
+
method: :post,
|
|
59
|
+
class: 'move_to_top',
|
|
60
|
+
title: 'Move to top') { '' }
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
::ActiveAdmin::Views::TableFor.send(:include, HandleColumn)
|
|
65
|
+
end
|
|
66
|
+
end
|