activeadmin_sortable_table 1.1.0 → 1.1.1

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
  SHA1:
3
- metadata.gz: d2780b4ee0dd39671939f4ded13128f47c2fc89d
4
- data.tar.gz: a54c714008eda20f4b25324df87745e2404ebef0
3
+ metadata.gz: ff2920f60aff67fdac3ec70b48d4d5210a835da2
4
+ data.tar.gz: 262a555140d2385c54f1de47b6cdf841039dffcb
5
5
  SHA512:
6
- metadata.gz: d2162c02c4475bee3b894620f56bfabb7ba0bafeccfb255abeb65d85ed148990194e825d0199933ac73349cfd36d3a8cc286d68a014afa702311106a733a77aa
7
- data.tar.gz: 8d7f5ca1742a2438e1dd5b14a15c56334885a856321c50f659f1cc767591d361a8b74315d69569d97e3dfae588f2cae78ec70f4414f91d81f1a8de728c22a81c
6
+ metadata.gz: 683dc3e1766264211cd93c433444adf5282effc9dede49e752d8a47baab9b6aa53d80a087775d2bfcea3b6545cda538cc5947901db109b6ef68a3d6be90059f9
7
+ data.tar.gz: d2c833437e3b94461d0843c453b67e61e0cdaa0d03510a4a93b2e04c90edd6f492cfb2511df9189f73ee9282f984ecb302bccbb011eb93672f9f87622c4bd7b2
@@ -19,7 +19,7 @@ GIT
19
19
  PATH
20
20
  remote: .
21
21
  specs:
22
- activeadmin_sortable_table (1.1.0)
22
+ activeadmin_sortable_table (1.1.1)
23
23
  activeadmin (>= 1.0.0.pre1)
24
24
  uber (= 0.0.15)
25
25
 
@@ -5,6 +5,7 @@
5
5
 
6
6
  $.fn.activeAdminSortableTable = function() {
7
7
  this.sortable({
8
+ handle: ".handle",
8
9
  update: function(event, ui) {
9
10
  var item = ui.item.find('[data-sort-url]');
10
11
  var url = item.data('sort-url');
@@ -1,6 +1,6 @@
1
1
  module ActiveAdmin
2
2
  #
3
3
  module SortableTable
4
- VERSION = '1.1.0'
4
+ VERSION = '1.1.1'
5
5
  end
6
6
  end
@@ -10,18 +10,31 @@ RSpec.describe ActiveAdmin::SortableTable, 'Drag-and-Drop', type: :feature do
10
10
  end
11
11
 
12
12
  context 'first page' do
13
- it 'reorder elements by dragging vertically', js: true do
13
+ it 'reorders elements by dragging vertically by handle', js: true do
14
14
  expect(ordered_elements).to eq([1, 2, 3])
15
15
 
16
16
  visit admin_categories_path
17
17
 
18
18
  expect(visible_elements).to eq([1, 2, 3])
19
19
 
20
- move_higher(2)
20
+ move_higher(2, by_handle: true)
21
21
 
22
22
  expect(visible_elements).to eq([2, 1, 3])
23
23
  expect(ordered_elements).to eq([2, 1, 3])
24
24
  end
25
+
26
+ it 'does not reorder elements by dragging vertically by row', js: true do
27
+ expect(ordered_elements).to eq([1, 2, 3])
28
+
29
+ visit admin_categories_path
30
+
31
+ expect(visible_elements).to eq([1, 2, 3])
32
+
33
+ move_higher(2, by_handle: false)
34
+
35
+ expect(visible_elements).to eq([1, 2, 3])
36
+ expect(ordered_elements).to eq([1, 2, 3])
37
+ end
25
38
  end
26
39
 
27
40
  context 'second page' do
@@ -31,34 +44,51 @@ RSpec.describe ActiveAdmin::SortableTable, 'Drag-and-Drop', type: :feature do
31
44
  Category.create!
32
45
  end
33
46
 
34
- it 'reorder elements by dragging vertically', js: true do
47
+ it 'reorders elements by dragging vertically by handle', js: true do
35
48
  expect(ordered_elements).to eq([1, 2, 3, 4, 5, 6])
36
49
 
37
50
  visit admin_categories_path(page: 2)
38
51
 
39
52
  expect(visible_elements).to eq([4, 5, 6])
40
53
 
41
- move_higher(5)
54
+ move_higher(5, by_handle: true)
42
55
 
43
56
  expect(visible_elements).to eq([5, 4, 6])
44
57
  expect(ordered_elements).to eq([1, 2, 3, 5, 4, 6])
45
58
  end
59
+
60
+ it 'does not reorder elements by dragging vertically by row', js: true do
61
+ expect(ordered_elements).to eq([1, 2, 3, 4, 5, 6])
62
+
63
+ visit admin_categories_path(page: 2)
64
+
65
+ expect(visible_elements).to eq([4, 5, 6])
66
+
67
+ move_higher(5, by_handle: false)
68
+
69
+ expect(visible_elements).to eq([4, 5, 6])
70
+ expect(ordered_elements).to eq([1, 2, 3, 4, 5, 6])
71
+ end
46
72
  end
47
73
 
48
74
  private
49
75
 
50
76
  def visible_elements
51
- all('.ui-sortable-handle .col-id').map(&:text).map(&:to_i)
77
+ all('.ui-sortable .col-id').map(&:text).map(&:to_i)
52
78
  end
53
79
 
54
- def move_higher(element_id)
55
- drag_element(element_id, dy: -200)
80
+ def move_higher(element_id, by_handle:)
81
+ drag_element(element_id, by_handle, dy: -200)
56
82
  end
57
83
 
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} )))
84
+ def drag_element(element_id, by_handle, options)
85
+ options.reverse_merge! moves: 20
86
+ if by_handle
87
+ wait_for_ajax do
88
+ page.execute_script(%($("#category_#{element_id} .handle").simulate("drag", #{options.to_json})))
89
+ end
90
+ else
91
+ page.execute_script(%($("#category_#{element_id}").simulate("drag", #{options.to_json})))
62
92
  end
63
93
  end
64
94
  end
@@ -36,7 +36,7 @@ RSpec.describe ActiveAdmin::SortableTable, 'Move to top', type: :feature do
36
36
  private
37
37
 
38
38
  def visible_elements
39
- all('.ui-sortable-handle .col-id').map(&:text).map(&:to_i)
39
+ all('.ui-sortable .col-id').map(&:text).map(&:to_i)
40
40
  end
41
41
 
42
42
  def move_to_top(element_id)
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.1.0
4
+ version: 1.1.1
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-30 00:00:00.000000000 Z
13
+ date: 2015-10-14 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activeadmin