activeadmin_sortable_table 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile.lock +3 -1
- data/README.md +38 -26
- data/activeadmin_sortable_table.gemspec +2 -0
- data/app/assets/javascripts/activeadmin_sortable_table.js +1 -1
- data/app/assets/stylesheets/activeadmin_sortable_table.css +7 -5
- data/lib/active_admin/sortable_table.rb +43 -0
- data/lib/active_admin/sortable_table/handle_column.rb +35 -15
- data/lib/active_admin/sortable_table/version.rb +1 -1
- data/lib/activeadmin_sortable_table.rb +1 -38
- data/spec/dummy/app/admin/categories.rb +2 -2
- data/spec/dummy/db/migrate/20150910072505_create_categories.rb +0 -1
- data/spec/features/drag_and_drop_spec.rb +64 -0
- data/spec/features/move_to_top_spec.rb +47 -0
- metadata +23 -5
- data/spec/features/activeadmin_sortable_table_spec.rb +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2780b4ee0dd39671939f4ded13128f47c2fc89d
|
4
|
+
data.tar.gz: a54c714008eda20f4b25324df87745e2404ebef0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2162c02c4475bee3b894620f56bfabb7ba0bafeccfb255abeb65d85ed148990194e825d0199933ac73349cfd36d3a8cc286d68a014afa702311106a733a77aa
|
7
|
+
data.tar.gz: 8d7f5ca1742a2438e1dd5b14a15c56334885a856321c50f659f1cc767591d361a8b74315d69569d97e3dfae588f2cae78ec70f4414f91d81f1a8de728c22a81c
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -19,8 +19,9 @@ GIT
|
|
19
19
|
PATH
|
20
20
|
remote: .
|
21
21
|
specs:
|
22
|
-
activeadmin_sortable_table (1.
|
22
|
+
activeadmin_sortable_table (1.1.0)
|
23
23
|
activeadmin (>= 1.0.0.pre1)
|
24
|
+
uber (= 0.0.15)
|
24
25
|
|
25
26
|
GEM
|
26
27
|
remote: https://rubygems.org/
|
@@ -218,6 +219,7 @@ GEM
|
|
218
219
|
tilt (2.0.1)
|
219
220
|
tzinfo (1.2.2)
|
220
221
|
thread_safe (~> 0.1)
|
222
|
+
uber (0.0.15)
|
221
223
|
websocket-driver (0.6.2)
|
222
224
|
websocket-extensions (>= 0.1.0)
|
223
225
|
websocket-extensions (0.1.2)
|
data/README.md
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
[![Build Status](https://travis-ci.org/bolshakov/activeadmin_sortable_table.svg?branch=master)](https://travis-ci.org/bolshakov/activeadmin_sortable_table)
|
2
|
+
[![Test Coverage](https://codeclimate.com/github/bolshakov/activeadmin_sortable_table/badges/coverage.svg)](https://codeclimate.com/github/bolshakov/activeadmin_sortable_table/coverage)
|
2
3
|
[![Code Climate](https://codeclimate.com/github/bolshakov/activeadmin_sortable_table/badges/gpa.svg)](https://codeclimate.com/github/bolshakov/activeadmin_sortable_table)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/activeadmin_sortable_table.svg)](http://badge.fury.io/rb/activeadmin_sortable_table)
|
3
5
|
|
4
6
|
# Active Admin Sortable Table
|
5
7
|
|
6
8
|
This gem extends ActiveAdmin so that your index page's table rows can be
|
7
9
|
orderable via a drag-and-drop interface.
|
8
10
|
|
9
|
-
##
|
11
|
+
## Improvements over the @neo version
|
10
12
|
|
11
|
-
|
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)
|
12
17
|
|
13
|
-
|
18
|
+
## Prerequisites
|
14
19
|
|
15
|
-
[acts_as_list](https://github.com/swanandp/acts_as_list)
|
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.
|
16
21
|
|
17
22
|
```ruby
|
18
23
|
class Page < ActiveRecord::Base
|
@@ -22,19 +27,19 @@ end
|
|
22
27
|
|
23
28
|
## Usage
|
24
29
|
|
25
|
-
|
30
|
+
Add it to your Gemfile
|
26
31
|
|
27
32
|
```ruby
|
28
33
|
gem "activeadmin_sortable_table"
|
29
34
|
```
|
30
35
|
|
31
|
-
|
36
|
+
Include the JavaScript in `active_admin.js.coffee`
|
32
37
|
|
33
38
|
```coffeescript
|
34
39
|
#= require activeadmin_sortable_table
|
35
40
|
```
|
36
41
|
|
37
|
-
|
42
|
+
Include the Stylesheet in `active_admin.css.scss`
|
38
43
|
|
39
44
|
```scss
|
40
45
|
@import "activeadmin_sortable_table"
|
@@ -46,16 +51,9 @@ gem "activeadmin_sortable_table"
|
|
46
51
|
ActiveAdmin.register Page do
|
47
52
|
include ActiveAdmin::SortableTable # creates the controller action which handles the sorting
|
48
53
|
config.sort_order = 'position_asc' # assumes you are using 'position' for your acts_as_list column
|
49
|
-
config.paginate = false # optional; drag-and-drop across pages is not supported
|
50
|
-
permit_params :position # do not forget to add `position` attribute to permitted prams
|
51
54
|
|
52
55
|
index do
|
53
|
-
handle_column
|
54
|
-
# use a user-defined URL for ordering
|
55
|
-
handle_column url: :sort_admin_section_path
|
56
|
-
# alternative form with lambda
|
57
|
-
handle_column url: -> (resource) { compute_url_from_resource(resource) }
|
58
|
-
# other columns...
|
56
|
+
handle_column
|
59
57
|
end
|
60
58
|
|
61
59
|
show do |c|
|
@@ -75,23 +73,37 @@ ActiveAdmin.register Page do
|
|
75
73
|
end
|
76
74
|
```
|
77
75
|
|
78
|
-
###
|
76
|
+
### Configure handler
|
77
|
+
|
78
|
+
You can override handler column symbol using handle_column options:
|
79
79
|
|
80
|
-
You can
|
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
|
+
```
|
81
87
|
|
82
|
-
|
83
|
-
/* active_admin.css.scss */
|
84
|
-
@import "activeadmin_sortable_table";
|
88
|
+
The same options available for `move_to_top_url`:
|
85
89
|
|
86
|
-
|
87
|
-
|
88
|
-
|
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'
|
89
99
|
```
|
90
100
|
|
91
101
|
## Contributing
|
92
102
|
|
93
103
|
1. Fork it
|
94
104
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
95
|
-
3.
|
96
|
-
4.
|
97
|
-
5.
|
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
|
@@ -10,6 +10,7 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.email = ['adam@adamlogic.com', 'jcgertig@gmail.com', 'abolshakov@spbtv.com']
|
11
11
|
gem.description = 'Drag and drop reordering interface for ActiveAdmin tables'
|
12
12
|
gem.summary = 'Drag and drop reordering interface for ActiveAdmin tables'
|
13
|
+
gem.license = 'MIT'
|
13
14
|
gem.homepage = 'https://github.com/bolshakov/activeadmin_sortable_table'
|
14
15
|
|
15
16
|
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
@@ -18,6 +19,7 @@ Gem::Specification.new do |gem|
|
|
18
19
|
gem.require_paths = ['lib']
|
19
20
|
|
20
21
|
gem.add_dependency 'activeadmin', '>= 1.0.0.pre1'
|
22
|
+
gem.add_dependency 'uber', '0.0.15'
|
21
23
|
gem.add_development_dependency 'rails', '~> 4.2'
|
22
24
|
gem.add_development_dependency 'capybara'
|
23
25
|
gem.add_development_dependency 'rspec-rails', '~> 3.3'
|
@@ -17,7 +17,7 @@
|
|
17
17
|
$.ajax({
|
18
18
|
url: url,
|
19
19
|
type: 'post',
|
20
|
-
data: $.extend(customParams, { position: ui.item.
|
20
|
+
data: $.extend(customParams, { position: ui.item.find('[data-position]').data('position') - 1 }),
|
21
21
|
error: function() { console.error('Saving sortable error'); },
|
22
22
|
success: function() {
|
23
23
|
if (actionOnSuccess === 'noting') { return; }
|
@@ -1,11 +1,13 @@
|
|
1
1
|
.activeadmin_sortable_table .handle {
|
2
2
|
cursor: ns-resize;
|
3
|
-
|
4
|
-
padding-left: 1.25em;
|
3
|
+
font-size: 1.5em;
|
5
4
|
}
|
6
5
|
|
7
|
-
.activeadmin_sortable_table .
|
8
|
-
|
6
|
+
.activeadmin_sortable_table .move_to_top {
|
7
|
+
padding-left: 1em;
|
8
|
+
/*cursor: pointer;*/
|
9
|
+
text-decoration: none;
|
9
10
|
font-size: 1.5em;
|
10
|
-
|
11
|
+
color: rgb(51, 51, 51);
|
11
12
|
}
|
13
|
+
|
@@ -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)
|
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 :back
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'uber/options'
|
2
|
+
|
1
3
|
module ActiveAdmin
|
2
4
|
#
|
3
5
|
module SortableTable
|
@@ -16,28 +18,46 @@ module ActiveAdmin
|
|
16
18
|
# end
|
17
19
|
#
|
18
20
|
module HandleColumn
|
19
|
-
|
20
|
-
|
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
|
21
34
|
#
|
22
|
-
def handle_column(
|
35
|
+
def handle_column(arguments = {})
|
36
|
+
defined_options = Uber::Options.new(DEFAULT_OPTIONS.merge(arguments))
|
37
|
+
|
23
38
|
column '', class: 'activeadmin_sortable_table' do |resource|
|
24
|
-
|
39
|
+
options = defined_options.evaluate(self, resource)
|
40
|
+
|
41
|
+
sort_handle(options, resource.position) + move_to_top_handle(options)
|
25
42
|
end
|
26
43
|
end
|
27
44
|
|
28
45
|
private
|
29
46
|
|
30
|
-
def
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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') { '' }
|
41
61
|
end
|
42
62
|
end
|
43
63
|
|
@@ -1,38 +1 @@
|
|
1
|
-
require '
|
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)
|
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
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
1
|
+
require 'active_admin/sortable_table'
|
@@ -1,12 +1,12 @@
|
|
1
1
|
ActiveAdmin.register Category do
|
2
2
|
include ActiveAdmin::SortableTable
|
3
|
-
permit_params :
|
3
|
+
permit_params :id, :position
|
4
4
|
config.sort_order = 'position_asc'
|
5
|
+
config.per_page = 3
|
5
6
|
|
6
7
|
index do
|
7
8
|
handle_column
|
8
9
|
id_column
|
9
|
-
column :name
|
10
10
|
actions
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
RSpec.describe ActiveAdmin::SortableTable, 'Drag-and-Drop', type: :feature do
|
2
|
+
before do
|
3
|
+
Category.create!
|
4
|
+
Category.create!
|
5
|
+
Category.create!
|
6
|
+
end
|
7
|
+
|
8
|
+
def ordered_elements
|
9
|
+
Category.order(:position).pluck(:id)
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'first page' do
|
13
|
+
it 'reorder elements by dragging vertically', js: true do
|
14
|
+
expect(ordered_elements).to eq([1, 2, 3])
|
15
|
+
|
16
|
+
visit admin_categories_path
|
17
|
+
|
18
|
+
expect(visible_elements).to eq([1, 2, 3])
|
19
|
+
|
20
|
+
move_higher(2)
|
21
|
+
|
22
|
+
expect(visible_elements).to eq([2, 1, 3])
|
23
|
+
expect(ordered_elements).to eq([2, 1, 3])
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'second page' do
|
28
|
+
before do
|
29
|
+
Category.create!
|
30
|
+
Category.create!
|
31
|
+
Category.create!
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'reorder elements by dragging vertically', js: true do
|
35
|
+
expect(ordered_elements).to eq([1, 2, 3, 4, 5, 6])
|
36
|
+
|
37
|
+
visit admin_categories_path(page: 2)
|
38
|
+
|
39
|
+
expect(visible_elements).to eq([4, 5, 6])
|
40
|
+
|
41
|
+
move_higher(5)
|
42
|
+
|
43
|
+
expect(visible_elements).to eq([5, 4, 6])
|
44
|
+
expect(ordered_elements).to eq([1, 2, 3, 5, 4, 6])
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def visible_elements
|
51
|
+
all('.ui-sortable-handle .col-id').map(&:text).map(&:to_i)
|
52
|
+
end
|
53
|
+
|
54
|
+
def move_higher(element_id)
|
55
|
+
drag_element(element_id, dy: -200)
|
56
|
+
end
|
57
|
+
|
58
|
+
def drag_element(element_id, options)
|
59
|
+
wait_for_ajax do
|
60
|
+
options.reverse_merge! moves: 20
|
61
|
+
page.execute_script(%($("#category_#{element_id} .handle").simulate("drag", #{options.to_json} )))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
RSpec.describe ActiveAdmin::SortableTable, 'Move to top', type: :feature do
|
2
|
+
before do
|
3
|
+
Category.create!
|
4
|
+
Category.create!
|
5
|
+
Category.create!
|
6
|
+
Category.create!
|
7
|
+
end
|
8
|
+
|
9
|
+
def ordered_elements
|
10
|
+
Category.order(:position).pluck(:id)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'push element to top by clicking "move to top"', js: true do
|
14
|
+
expect(ordered_elements).to eq([1, 2, 3, 4])
|
15
|
+
|
16
|
+
# Initially only one element on the second page
|
17
|
+
visit admin_categories_path(page: 2)
|
18
|
+
|
19
|
+
expect(visible_elements).to contain_exactly(4)
|
20
|
+
|
21
|
+
# When I push "move to top" button
|
22
|
+
move_to_top(4)
|
23
|
+
|
24
|
+
# The last element from the previous page should be shown
|
25
|
+
# save_and_open_page
|
26
|
+
expect(visible_elements).to contain_exactly(3)
|
27
|
+
|
28
|
+
# And when I visit previous page
|
29
|
+
visit admin_categories_path(page: 1)
|
30
|
+
|
31
|
+
# I should see pushed elenent on the top
|
32
|
+
expect(visible_elements).to eq([4, 1, 2])
|
33
|
+
expect(ordered_elements).to eq([4, 1, 2, 3])
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
def visible_elements
|
39
|
+
all('.ui-sortable-handle .col-id').map(&:text).map(&:to_i)
|
40
|
+
end
|
41
|
+
|
42
|
+
def move_to_top(element_id)
|
43
|
+
within "#category_#{element_id}" do
|
44
|
+
first('.move_to_top').click
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin_sortable_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam McCrea
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2015-09-
|
13
|
+
date: 2015-09-30 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: activeadmin
|
@@ -26,6 +26,20 @@ dependencies:
|
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
28
|
version: 1.0.0.pre1
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: uber
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - '='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: 0.0.15
|
36
|
+
type: :runtime
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 0.0.15
|
29
43
|
- !ruby/object:Gem::Dependency
|
30
44
|
name: rails
|
31
45
|
requirement: !ruby/object:Gem::Requirement
|
@@ -145,6 +159,7 @@ files:
|
|
145
159
|
- activeadmin_sortable_table.gemspec
|
146
160
|
- app/assets/javascripts/activeadmin_sortable_table.js
|
147
161
|
- app/assets/stylesheets/activeadmin_sortable_table.css
|
162
|
+
- lib/active_admin/sortable_table.rb
|
148
163
|
- lib/active_admin/sortable_table/engine.rb
|
149
164
|
- lib/active_admin/sortable_table/handle_column.rb
|
150
165
|
- lib/active_admin/sortable_table/version.rb
|
@@ -201,12 +216,14 @@ files:
|
|
201
216
|
- spec/dummy/public/422.html
|
202
217
|
- spec/dummy/public/500.html
|
203
218
|
- spec/dummy/public/favicon.ico
|
204
|
-
- spec/features/
|
219
|
+
- spec/features/drag_and_drop_spec.rb
|
220
|
+
- spec/features/move_to_top_spec.rb
|
205
221
|
- spec/rails_helper.rb
|
206
222
|
- spec/spec_helper.rb
|
207
223
|
- spec/support/wait_for_ajax.rb
|
208
224
|
homepage: https://github.com/bolshakov/activeadmin_sortable_table
|
209
|
-
licenses:
|
225
|
+
licenses:
|
226
|
+
- MIT
|
210
227
|
metadata: {}
|
211
228
|
post_install_message:
|
212
229
|
rdoc_options: []
|
@@ -281,7 +298,8 @@ test_files:
|
|
281
298
|
- spec/dummy/public/422.html
|
282
299
|
- spec/dummy/public/500.html
|
283
300
|
- spec/dummy/public/favicon.ico
|
284
|
-
- spec/features/
|
301
|
+
- spec/features/drag_and_drop_spec.rb
|
302
|
+
- spec/features/move_to_top_spec.rb
|
285
303
|
- spec/rails_helper.rb
|
286
304
|
- spec/spec_helper.rb
|
287
305
|
- spec/support/wait_for_ajax.rb
|
@@ -1,31 +0,0 @@
|
|
1
|
-
RSpec.describe 'ActiveAdmin::SortableTable', type: :feature do
|
2
|
-
let!(:bottom) { Category.create!(name: 'bottom', position: 0) }
|
3
|
-
let!(:top) { Category.create!(name: 'top', position: 1) }
|
4
|
-
let!(:middle) { Category.create!(name: 'middle', position: 2) }
|
5
|
-
|
6
|
-
before do
|
7
|
-
visit admin_categories_path
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'reorder elements by dragging vertically', js: true do
|
11
|
-
expect(displayed_names).to eq(%w(top middle bottom))
|
12
|
-
|
13
|
-
drag_element(middle, dy: -200)
|
14
|
-
|
15
|
-
expect(displayed_names).to eq(%w(middle top bottom))
|
16
|
-
expect(Category.order(:position).map(&:name)).to eq(%w(middle top bottom))
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def displayed_names
|
22
|
-
all('.ui-sortable-handle .col-name').map(&:text)
|
23
|
-
end
|
24
|
-
|
25
|
-
def drag_element(element, options)
|
26
|
-
wait_for_ajax do
|
27
|
-
options.reverse_merge! moves: 20
|
28
|
-
page.execute_script(%($("#category_#{element.id} .handle").simulate("drag", #{options.to_json} )))
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|