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.
Files changed (76) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +22 -0
  3. data/.rspec +2 -0
  4. data/.rubocop.yml +15 -0
  5. data/.travis.yml +29 -0
  6. data/CHANGELOG.md +16 -0
  7. data/Gemfile +11 -0
  8. data/LICENSE.txt +22 -0
  9. data/README.md +109 -0
  10. data/Rakefile +27 -0
  11. data/activeadmin_sortable_table.gemspec +30 -0
  12. data/app/assets/javascripts/activeadmin_sortable_table.js +48 -0
  13. data/app/assets/stylesheets/activeadmin_sortable_table.css +13 -0
  14. data/lib/active_admin/sortable_table.rb +43 -0
  15. data/lib/active_admin/sortable_table/engine.rb +9 -0
  16. data/lib/active_admin/sortable_table/handle_column.rb +66 -0
  17. data/lib/active_admin/sortable_table/version.rb +6 -0
  18. data/lib/activeadmin_sortable_table.rb +1 -0
  19. data/spec/dummy/README.rdoc +28 -0
  20. data/spec/dummy/Rakefile +6 -0
  21. data/spec/dummy/app/admin/categories.rb +13 -0
  22. data/spec/dummy/app/admin/dashboard.rb +32 -0
  23. data/spec/dummy/app/assets/images/.keep +0 -0
  24. data/spec/dummy/app/assets/javascripts/active_admin.js +3 -0
  25. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  26. data/spec/dummy/app/assets/javascripts/jquery.simulate.drag-sortable.js +235 -0
  27. data/spec/dummy/app/assets/stylesheets/active_admin.scss +17 -0
  28. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  29. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  30. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  31. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  32. data/spec/dummy/app/mailers/.keep +0 -0
  33. data/spec/dummy/app/models/.keep +0 -0
  34. data/spec/dummy/app/models/category.rb +3 -0
  35. data/spec/dummy/app/models/concerns/.keep +0 -0
  36. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  37. data/spec/dummy/bin/bundle +3 -0
  38. data/spec/dummy/bin/rails +4 -0
  39. data/spec/dummy/bin/rake +4 -0
  40. data/spec/dummy/bin/setup +29 -0
  41. data/spec/dummy/config.ru +4 -0
  42. data/spec/dummy/config/application.rb +30 -0
  43. data/spec/dummy/config/boot.rb +5 -0
  44. data/spec/dummy/config/database.yml +25 -0
  45. data/spec/dummy/config/environment.rb +5 -0
  46. data/spec/dummy/config/environments/development.rb +41 -0
  47. data/spec/dummy/config/environments/production.rb +79 -0
  48. data/spec/dummy/config/environments/test.rb +42 -0
  49. data/spec/dummy/config/initializers/active_admin.rb +262 -0
  50. data/spec/dummy/config/initializers/assets.rb +11 -0
  51. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  52. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  53. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  54. data/spec/dummy/config/initializers/inflections.rb +16 -0
  55. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  56. data/spec/dummy/config/initializers/session_store.rb +3 -0
  57. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  58. data/spec/dummy/config/locales/en.yml +23 -0
  59. data/spec/dummy/config/routes.rb +3 -0
  60. data/spec/dummy/config/secrets.yml +22 -0
  61. data/spec/dummy/db/development.sqlite3 +0 -0
  62. data/spec/dummy/db/migrate/20150910072150_create_active_admin_comments.rb +19 -0
  63. data/spec/dummy/db/migrate/20150910072505_create_categories.rb +7 -0
  64. data/spec/dummy/db/schema.rb +36 -0
  65. data/spec/dummy/lib/assets/.keep +0 -0
  66. data/spec/dummy/log/.keep +0 -0
  67. data/spec/dummy/public/404.html +67 -0
  68. data/spec/dummy/public/422.html +67 -0
  69. data/spec/dummy/public/500.html +66 -0
  70. data/spec/dummy/public/favicon.ico +0 -0
  71. data/spec/features/drag_and_drop_spec.rb +158 -0
  72. data/spec/features/move_to_top_spec.rb +55 -0
  73. data/spec/rails_helper.rb +62 -0
  74. data/spec/spec_helper.rb +92 -0
  75. data/spec/support/wait_for_ajax.rb +20 -0
  76. metadata +305 -0
@@ -0,0 +1,6 @@
1
+ module ActiveAdmin
2
+ #
3
+ module SortableTable
4
+ VERSION = '1.3.0'
5
+ end
6
+ end
@@ -0,0 +1 @@
1
+ require 'active_admin/sortable_table'
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ ActiveAdmin.register Category do
2
+ include ActiveAdmin::SortableTable
3
+ permit_params :id, :number
4
+ config.sort_order = 'number_asc'
5
+ config.per_page = 3
6
+
7
+ index do
8
+ handle_column
9
+ id_column
10
+ column :number
11
+ actions
12
+ end
13
+ end
@@ -0,0 +1,32 @@
1
+ ActiveAdmin.register_page 'Dashboard' do
2
+ menu priority: 1, label: proc { I18n.t('active_admin.dashboard') }
3
+
4
+ content title: proc { I18n.t('active_admin.dashboard') } do
5
+ div class: 'blank_slate_container', id: 'dashboard_default_message' do
6
+ span class: 'blank_slate' do
7
+ span I18n.t('active_admin.dashboard_welcome.welcome')
8
+ small I18n.t('active_admin.dashboard_welcome.call_to_action')
9
+ end
10
+ end
11
+
12
+ # Here is an example of a simple dashboard with columns and panels.
13
+ #
14
+ # columns do
15
+ # column do
16
+ # panel "Recent Posts" do
17
+ # ul do
18
+ # Post.recent(5).map do |post|
19
+ # li link_to(post.title, admin_post_path(post))
20
+ # end
21
+ # end
22
+ # end
23
+ # end
24
+
25
+ # column do
26
+ # panel "Info" do
27
+ # para "Welcome to ActiveAdmin."
28
+ # end
29
+ # end
30
+ # end
31
+ end # content
32
+ end
File without changes
@@ -0,0 +1,3 @@
1
+ //= require active_admin/base
2
+ //= require jquery.simulate.drag-sortable
3
+ //= require activeadmin_sortable_table
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,235 @@
1
+ (function($) {
2
+ /*
3
+ * Simulate drag of a JQuery UI sortable list
4
+ * Repository: https://github.com/mattheworiordan/jquery.simulate.drag-sortable.js
5
+ * Author: http://mattheworiordan.com
6
+ *
7
+ * options are:
8
+ * - move: move item up (positive) or down (negative) by Integer amount
9
+ * - dropOn: move item to a new linked list, move option now represents position in the new list (zero indexed)
10
+ * - handle: selector for the draggable handle element (optional)
11
+ * - listItem: selector to limit which sibling items can be used for reordering
12
+ * - placeHolder: if a placeholder is used during dragging, we need to consider it's height
13
+ * - tolerance: (optional) number of pixels to overlap by instead of the default 50% of the element height
14
+ *
15
+ */
16
+ $.fn.simulateDragSortable = function(options) {
17
+ // build main options before element iteration
18
+ var opts = $.extend({}, $.fn.simulateDragSortable.defaults, options);
19
+
20
+ applyDrag = function(options) {
21
+ // allow for a drag handle if item is not draggable
22
+ var that = this,
23
+ options = options || opts, // default to plugin opts unless options explicitly provided
24
+ handle = options.handle ? $(this).find(options.handle)[0] : $(this)[0],
25
+ listItem = options.listItem,
26
+ placeHolder = options.placeHolder,
27
+ sibling = $(this),
28
+ moveCounter = Math.floor(options.move),
29
+ direction = moveCounter > 0 ? 'down' : 'up',
30
+ moveVerticalAmount = 0,
31
+ initialVerticalPosition = 0,
32
+ extraDrag = !isNaN(parseInt(options.tolerance, 10)) ? function() { return Number(options.tolerance); } : function(obj) { return ($(obj).outerHeight() / 2) + 5; },
33
+ dragPastBy = 0, // represents the additional amount one drags past an element and bounce back
34
+ dropOn = options.dropOn ? $(options.dropOn) : false,
35
+ center = findCenter(handle),
36
+ x = Math.floor(center.x),
37
+ y = Math.floor(center.y),
38
+ mouseUpAfter = (opts.debug ? 2500 : 10);
39
+
40
+ if (dropOn) {
41
+ if (dropOn.length === 0) {
42
+ if (console && console.log) { console.log('simulate.drag-sortable.js ERROR: Drop on target could not be found'); console.log(options.dropOn); }
43
+ return;
44
+ }
45
+ sibling = dropOn.find('>*:last');
46
+ moveCounter = -(dropOn.find('>*').length + 1) + (moveCounter + 1); // calculate length of list after this move, use moveCounter as a positive index position in list to reverse back up
47
+ if (dropOn.offset().top - $(this).offset().top < 0) {
48
+ // moving to a list above this list, so move to just above top of last item (tried moving to top but JQuery UI wouldn't bite)
49
+ initialVerticalPosition = sibling.offset().top - $(this).offset().top - extraDrag(this);
50
+ } else {
51
+ // moving to a list below this list, so move to bottom and work up (JQuery UI does not trigger new list below unless you move past top item first)
52
+ initialVerticalPosition = sibling.offset().top - $(this).offset().top - $(this).height();
53
+ }
54
+ } else if (moveCounter === 0) {
55
+ if (console && console.log) { console.log('simulate.drag-sortable.js WARNING: Drag with move set to zero has no effect'); }
56
+ return;
57
+ } else {
58
+ while (moveCounter !== 0) {
59
+ if (direction === 'down') {
60
+ if (sibling.next(listItem).length) {
61
+ sibling = sibling.next(listItem);
62
+ moveVerticalAmount += sibling.outerHeight();
63
+ }
64
+ moveCounter -= 1;
65
+ } else {
66
+ if (sibling.prev(listItem).length) {
67
+ sibling = sibling.prev(listItem);
68
+ moveVerticalAmount -= sibling.outerHeight();
69
+ }
70
+ moveCounter += 1;
71
+ }
72
+ }
73
+ }
74
+
75
+ dispatchEvent(handle, 'mousedown', createEvent('mousedown', handle, { clientX: x, clientY: y }));
76
+ // simulate drag start
77
+ dispatchEvent(document, 'mousemove', createEvent('mousemove', document, { clientX: x+1, clientY: y+1 }));
78
+
79
+ if (dropOn) {
80
+ // jump to top or bottom of new list but do it in increments so that JQuery UI registers the drag events
81
+ slideUpTo(x, y, initialVerticalPosition);
82
+
83
+ // reset y position to top or bottom of list and move from there
84
+ y += initialVerticalPosition;
85
+
86
+ // now call regular shift/down in a list
87
+ options = jQuery.extend(options, { move: moveCounter });
88
+ delete options.dropOn;
89
+
90
+ // add some delays to allow JQuery UI to catch up
91
+ setTimeout(function() {
92
+ dispatchEvent(document, 'mousemove', createEvent('mousemove', document, { clientX: x, clientY: y }));
93
+ }, 5);
94
+ setTimeout(function() {
95
+ dispatchEvent(handle, 'mouseup', createEvent('mouseup', handle, { clientX: x, clientY: y }));
96
+ setTimeout(function() {
97
+ if (options.move) {
98
+ applyDrag.call(that, options);
99
+ }
100
+ }, 5);
101
+ }, mouseUpAfter);
102
+
103
+ // stop execution as applyDrag has been called again
104
+ return;
105
+ }
106
+
107
+ // Sortable is using a fixed height placeholder meaning items jump up and down as you drag variable height items into fixed height placeholder
108
+ placeHolder = placeHolder && $(this).parent().find(placeHolder);
109
+
110
+ if (!placeHolder && (direction === 'down')) {
111
+ // need to move at least as far as this item and or the last sibling
112
+ if ($(this).outerHeight() > $(sibling).outerHeight()) {
113
+ moveVerticalAmount += $(this).outerHeight() - $(sibling).outerHeight();
114
+ }
115
+ moveVerticalAmount += extraDrag(sibling);
116
+ dragPastBy += extraDrag(sibling);
117
+ } else if (direction === 'up') {
118
+ // move a little extra to ensure item clips into next position
119
+ moveVerticalAmount -= Math.max(extraDrag(this), 5);
120
+ } else if (direction === 'down') {
121
+ // moving down with a place holder
122
+ if (placeHolder.height() < $(this).height()) {
123
+ moveVerticalAmount += Math.max(placeHolder.height(), 5);
124
+ } else {
125
+ moveVerticalAmount += extraDrag(sibling);
126
+ }
127
+ }
128
+
129
+ if (sibling[0] !== $(this)[0]) {
130
+ // step through so that the UI controller can determine when to show the placeHolder
131
+ slideUpTo(x, y, moveVerticalAmount, dragPastBy);
132
+ } else {
133
+ if (window.console) {
134
+ console.log('simulate.drag-sortable.js WARNING: Could not move as at top or bottom already');
135
+ }
136
+ }
137
+
138
+ setTimeout(function() {
139
+ dispatchEvent(document, 'mousemove', createEvent('mousemove', document, { clientX: x, clientY: y + moveVerticalAmount }));
140
+ }, 5);
141
+ setTimeout(function() {
142
+ dispatchEvent(handle, 'mouseup', createEvent('mouseup', handle, { clientX: x, clientY: y + moveVerticalAmount }));
143
+ }, mouseUpAfter);
144
+ };
145
+
146
+ // iterate and move each matched element
147
+ return this.each(applyDrag);
148
+ };
149
+
150
+ // fire mouse events, go half way, then the next half, so small mouse movements near target and big at the start
151
+ function slideUpTo(x, y, targetOffset, goPastBy) {
152
+ var moveBy, offset;
153
+
154
+ if (!goPastBy) { goPastBy = 0; }
155
+ if ((targetOffset < 0) && (goPastBy > 0)) { goPastBy = -goPastBy; } // ensure go past is in the direction as often passed in from object height so always positive
156
+
157
+ // go forwards including goPastBy
158
+ for (offset = 0; Math.abs(offset) + 1 < Math.abs(targetOffset + goPastBy); offset += ((targetOffset + goPastBy - offset)/2) ) {
159
+ dispatchEvent(document, 'mousemove', createEvent('mousemove', document, { clientX: x, clientY: y + Math.ceil(offset) }));
160
+ }
161
+ offset = targetOffset + goPastBy;
162
+ dispatchEvent(document, 'mousemove', createEvent('mousemove', document, { clientX: x, clientY: y + offset }));
163
+
164
+ // now bounce back
165
+ for (; Math.abs(offset) - 1 >= Math.abs(targetOffset); offset += ((targetOffset - offset)/2) ) {
166
+ dispatchEvent(document, 'mousemove', createEvent('mousemove', document, { clientX: x, clientY: y + Math.ceil(offset) }));
167
+ }
168
+ dispatchEvent(document, 'mousemove', createEvent('mousemove', document, { clientX: x, clientY: y + targetOffset }));
169
+ }
170
+
171
+ function createEvent(type, target, options) {
172
+ var evt;
173
+ var e = $.extend({
174
+ target: target,
175
+ preventDefault: function() { },
176
+ stopImmediatePropagation: function() { },
177
+ stopPropagation: function() { },
178
+ isPropagationStopped: function() { return true; },
179
+ isImmediatePropagationStopped: function() { return true; },
180
+ isDefaultPrevented: function() { return true; },
181
+ bubbles: true,
182
+ cancelable: (type != "mousemove"),
183
+ view: window,
184
+ detail: 0,
185
+ screenX: 0,
186
+ screenY: 0,
187
+ clientX: 0,
188
+ clientY: 0,
189
+ ctrlKey: false,
190
+ altKey: false,
191
+ shiftKey: false,
192
+ metaKey: false,
193
+ button: 0,
194
+ relatedTarget: undefined
195
+ }, options || {});
196
+
197
+ if ($.isFunction(document.createEvent)) {
198
+ evt = document.createEvent("MouseEvents");
199
+ evt.initMouseEvent(type, e.bubbles, e.cancelable, e.view, e.detail,
200
+ e.screenX, e.screenY, e.clientX, e.clientY,
201
+ e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
202
+ e.button, e.relatedTarget || document.body.parentNode);
203
+ } else if (document.createEventObject) {
204
+ evt = document.createEventObject();
205
+ $.extend(evt, e);
206
+ evt.button = { 0:1, 1:4, 2:2 }[evt.button] || evt.button;
207
+ }
208
+ return evt;
209
+ }
210
+
211
+ function dispatchEvent(el, type, evt) {
212
+ if (el.dispatchEvent) {
213
+ el.dispatchEvent(evt);
214
+ } else if (el.fireEvent) {
215
+ el.fireEvent('on' + type, evt);
216
+ }
217
+ return evt;
218
+ }
219
+
220
+ function findCenter(el) {
221
+ var elm = $(el),
222
+ o = elm.offset();
223
+ return {
224
+ x: o.left + elm.outerWidth() / 2,
225
+ y: o.top + elm.outerHeight() / 2
226
+ };
227
+ }
228
+
229
+ //
230
+ // plugin defaults
231
+ //
232
+ $.fn.simulateDragSortable.defaults = {
233
+ move: 0
234
+ };
235
+ })(jQuery);
@@ -0,0 +1,17 @@
1
+ // SASS variable overrides must be declared before loading up Active Admin's styles.
2
+ //
3
+ // To view the variables that Active Admin provides, take a look at
4
+ // `app/assets/stylesheets/active_admin/mixins/_variables.css.scss` in the
5
+ // Active Admin source.
6
+ //
7
+ // For example, to change the sidebar width:
8
+ // $sidebar-width: 242px;
9
+
10
+ // Active Admin's got SASS!
11
+ @import "active_admin/mixins";
12
+ @import "active_admin/base";
13
+ @import "activeadmin_sortable_table.css";
14
+ // Overriding any non-variable SASS must be done after the fact.
15
+ // For example, to change the default status-tag color:
16
+ //
17
+ // .status_tag { background: #6090DB; }
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ class Category < ActiveRecord::Base
2
+ acts_as_list column: :number
3
+ end
File without changes
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts '== Installing dependencies =='
12
+ system 'gem install bundler --conservative'
13
+ system 'bundle check || bundle install'
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system 'bin/rake db:setup'
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system 'rm -f log/*'
25
+ system 'rm -rf tmp/cache'
26
+
27
+ puts "\n== Restarting application server =="
28
+ system 'touch tmp/restart.txt'
29
+ end