active_admin-sortable_tree 0.3.0 → 1.0.0

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: 14193c9d47cefbf3d0d4e5f8b7516cbcee6892fa
4
- data.tar.gz: 31735e6f582782438eddfa77610e72e742f22e19
3
+ metadata.gz: 126d784b9ce06a5c29ba502eb96104ef3108d7f0
4
+ data.tar.gz: 50aa4cbe40c74b9c19354da0444456130c283569
5
5
  SHA512:
6
- metadata.gz: e1c81ec8ea138a8820231d3d943d3c7ad023a1bf9e022e113fe76bbef46493ac1340ed843df7df6837f2f01bdbd4d991aa53c36ebd67a827cab2be6f0145c2b1
7
- data.tar.gz: fabab663a38ed21d7ec87e08f90cc19b8f756363d94efdf8d02f86ccaf5c0d5cc3ed4783d1d918f43a82689650b724ef5ff1b76fa98449a01399325ca3de65cd
6
+ metadata.gz: d2755222fb58155f57c43ba3bf257eb0d7ef0aac652d2f8243af10d2c23c0c8f0ec972f5b4d77c18e530a2d2a9a49c596ef0accc1e808734d0bb7615b39f47c7
7
+ data.tar.gz: a3732fc8fe9ec410f7d1ab94e28aa8676f29ef1837f27db0d16950d5efc06d8c6230d8b5d4e0f7001c6a2a984f1aa338b62d4023fcaae34e7566545e4f04a031
@@ -2,7 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
- ## [Unreleased]
5
+ ## [1.0.0] - 2017-06-01
6
+
7
+ ### Added
8
+
9
+ - Support for Rails 5.0 and 5.1 by conditionally invoking `parameterize` with its
10
+ expected parameters.
11
+
12
+ ### Changed
13
+
14
+ - Relax dependency on `jquery-ui-rails` to be `>= 5.0` (previously `~> 5.0`).
15
+
16
+ ### Removed
17
+
18
+ - Ruby 1.9.3, 2.1, and 2.2 are no longer explicitly supported.
6
19
 
7
20
  ## [0.3.0] - 2016-09-08
8
21
 
@@ -32,8 +45,9 @@ All notable changes to this project will be documented in this file.
32
45
  - Published to Rubygems.
33
46
 
34
47
 
35
- [unreleased]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.2.0...HEAD
48
+ [unreleased]: https://github.com/zorab47/active_admin-sortable_tree/compare/v1.0.0...HEAD
36
49
  [0.1.0]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.0.1...v0.1.0
37
50
  [0.2.0]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.1.0...v0.2.0
38
51
  [0.2.1]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.2.0...v0.2.1
39
- [0.2.1]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.2.1...v0.3.0
52
+ [0.3.0]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.2.1...v0.3.0
53
+ [1.0.0]: https://github.com/zorab47/active_admin-sortable_tree/compare/v0.3.0...v1.0.0
data/README.md CHANGED
@@ -15,6 +15,13 @@ sortable via drag'n'drop.
15
15
  gem "active_admin-sortable_tree"
16
16
  ```
17
17
 
18
+ Note: If you experience issues with drag and drop capability, you may need to specify the version for your ActiveAdmin installation. It is reported working using v0.6.6, or if you are using v1.0.0.pre, it is reported working on this commit [b3a9f4b](https://github.com/activeadmin/activeadmin/commit/b3a9f4b3e4051447d011c59649a73f876989a199) or later.
19
+
20
+ ```ruby
21
+ # Gemfile
22
+ gem 'activeadmin', github: 'activeadmin', ref: 'b3a9f4b'
23
+ ```
24
+
18
25
  ## Usage (Tree)
19
26
 
20
27
  **Admin**:
@@ -1,72 +1,2 @@
1
- #= require jquery-ui/sortable
2
- #= require jquery.mjs.nestedSortable
3
-
4
- window.ActiveAdminSortableEvent = do ->
5
- eventToListeners = {}
6
-
7
- return {
8
- add: (event, callback) ->
9
- if not eventToListeners.hasOwnProperty(event)
10
- eventToListeners[event] = []
11
- eventToListeners[event].push(callback)
12
-
13
- trigger: (event, args) ->
14
- if eventToListeners.hasOwnProperty(event)
15
- for callback in eventToListeners[event]
16
- try
17
- callback.call(null, args)
18
- catch e
19
- console.error(e) if console and console.error
20
- }
21
-
22
- $ ->
23
- $('.disclose').bind 'click', (event) ->
24
- $(this).closest('li').toggleClass('mjs-nestedSortable-collapsed').toggleClass('mjs-nestedSortable-expanded')
25
-
26
- $(".index_as_sortable [data-sortable-type]").each ->
27
- $this = $(@)
28
-
29
- if $this.data('sortable-type') == "tree"
30
- max_levels = $this.data('max-levels')
31
- tab_hack = 20 # nestedSortable default
32
- else
33
- max_levels = 1
34
- tab_hack = 99999
35
-
36
- $this.nestedSortable
37
- forcePlaceholderSize: true
38
- forceHelperSizeType: true
39
- errorClass: 'cantdoit'
40
- disableNesting: 'cantdoit'
41
- handle: '> .item'
42
- listType: 'ol'
43
- items: 'li'
44
- opacity: .6
45
- placeholder: 'placeholder'
46
- revert: 250
47
- maxLevels: max_levels,
48
- tabSize: tab_hack
49
- protectRoot: $this.data('protect-root')
50
- # prevent drag flickers
51
- tolerance: 'pointer'
52
- toleranceElement: '> div'
53
- isTree: true
54
- startCollapsed: $this.data("start-collapsed")
55
- update: ->
56
- $this.nestedSortable("disable")
57
- $.ajax
58
- url: $this.data("sortable-url")
59
- type: "post"
60
- data: $this.nestedSortable("serialize")
61
- .always ->
62
- $this.find('.item').each (index) ->
63
- if index % 2
64
- $(this).removeClass('odd').addClass('even')
65
- else
66
- $(this).removeClass('even').addClass('odd')
67
- $this.nestedSortable("enable")
68
- ActiveAdminSortableEvent.trigger('ajaxAlways')
69
- .done ->
70
- ActiveAdminSortableEvent.trigger('ajaxDone')
71
- .fail ->
72
- ActiveAdminSortableEvent.trigger('ajaxFail')
1
+ #= require jquery-ui/widgets/sortable
2
+ #= require active_admin/sortable_core
@@ -0,0 +1,71 @@
1
+ #= require jquery.mjs.nestedSortable
2
+
3
+ window.ActiveAdminSortableEvent = do ->
4
+ eventToListeners = {}
5
+
6
+ return {
7
+ add: (event, callback) ->
8
+ if not eventToListeners.hasOwnProperty(event)
9
+ eventToListeners[event] = []
10
+ eventToListeners[event].push(callback)
11
+
12
+ trigger: (event, args) ->
13
+ if eventToListeners.hasOwnProperty(event)
14
+ for callback in eventToListeners[event]
15
+ try
16
+ callback.call(null, args)
17
+ catch e
18
+ console.error(e) if console and console.error
19
+ }
20
+
21
+ $ ->
22
+ $('.disclose').bind 'click', (event) ->
23
+ $(this).closest('li').toggleClass('mjs-nestedSortable-collapsed').toggleClass('mjs-nestedSortable-expanded')
24
+
25
+ $(".index_as_sortable [data-sortable-type]").each ->
26
+ $this = $(@)
27
+
28
+ if $this.data('sortable-type') == "tree"
29
+ max_levels = $this.data('max-levels')
30
+ tab_hack = 20 # nestedSortable default
31
+ else
32
+ max_levels = 1
33
+ tab_hack = 99999
34
+
35
+ $this.nestedSortable
36
+ forcePlaceholderSize: true
37
+ forceHelperSizeType: true
38
+ errorClass: 'cantdoit'
39
+ disableNesting: 'cantdoit'
40
+ handle: '> .item'
41
+ listType: 'ol'
42
+ items: 'li'
43
+ opacity: .6
44
+ placeholder: 'placeholder'
45
+ revert: 250
46
+ maxLevels: max_levels,
47
+ tabSize: tab_hack
48
+ protectRoot: $this.data('protect-root')
49
+ # prevent drag flickers
50
+ tolerance: 'pointer'
51
+ toleranceElement: '> div'
52
+ isTree: true
53
+ startCollapsed: $this.data("start-collapsed")
54
+ update: ->
55
+ $this.nestedSortable("disable")
56
+ $.ajax
57
+ url: $this.data("sortable-url")
58
+ type: "post"
59
+ data: $this.nestedSortable("serialize")
60
+ .always ->
61
+ $this.find('.item').each (index) ->
62
+ if index % 2
63
+ $(this).removeClass('odd').addClass('even')
64
+ else
65
+ $(this).removeClass('even').addClass('odd')
66
+ $this.nestedSortable("enable")
67
+ ActiveAdminSortableEvent.trigger('ajaxAlways')
68
+ .done ->
69
+ ActiveAdminSortableEvent.trigger('ajaxDone')
70
+ .fail ->
71
+ ActiveAdminSortableEvent.trigger('ajaxFail')
@@ -0,0 +1,2 @@
1
+ #= require jquery-ui/sortable
2
+ #= require active_admin/sortable_core
@@ -1,3 +1,4 @@
1
+ require 'active_admin/sortable_tree/compatibility'
1
2
  require 'active_admin/sortable_tree/engine'
2
3
  require 'active_admin/sortable_tree/controller_actions'
3
4
  require 'active_admin/views/index_as_sortable'
@@ -0,0 +1,11 @@
1
+ module ActiveAdmin::SortableTree
2
+ class Compatibility
3
+ def self.normalized_resource_name(resource_name)
4
+ if Rails::VERSION::MAJOR >= 5
5
+ resource_name.to_s.underscore.parameterize(separator: "_".freeze)
6
+ else
7
+ resource_name.to_s.underscore.parameterize("_".freeze)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -22,12 +22,14 @@ module ActiveAdmin::SortableTree
22
22
  config.paginate = false
23
23
 
24
24
  collection_action :sort, :method => :post do
25
- resource_name = active_admin_config.resource_name.to_s.underscore.parameterize('_')
25
+ resource_name = ActiveAdmin::SortableTree::Compatibility.normalized_resource_name(active_admin_config.resource_name)
26
26
 
27
- records = params[resource_name].inject({}) do |res, (resource, parent_resource)|
28
- res[resource_class.find(resource)] = resource_class.find(parent_resource) rescue nil
29
- res
27
+ records = []
28
+ params[resource_name].each_pair do |resource, parent_resource|
29
+ parent_resource = resource_class.find(parent_resource) rescue nil
30
+ records << [resource_class.find(resource), parent_resource]
30
31
  end
32
+
31
33
  errors = []
32
34
  ActiveRecord::Base.transaction do
33
35
  records.each_with_index do |(record, parent_record), position|
@@ -1,18 +1,32 @@
1
1
  require 'activeadmin'
2
+ require "rubygems"
2
3
 
3
4
  module ActiveAdmin
4
5
  module SortableTree
5
6
  class Engine < ::Rails::Engine
6
7
  engine_name 'active_admin-sortable_tree'
7
8
 
9
+
10
+ def jquery_ui_six?
11
+ Gem::Version.new(Jquery::Ui::Rails::VERSION) >= Gem::Version.new("6.0.0")
12
+ end
13
+
14
+ def sortable_js
15
+ if jquery_ui_six?
16
+ "active_admin/sortable.js"
17
+ else
18
+ "active_admin/sortable_ui5.js"
19
+ end
20
+ end
21
+
8
22
  initializer "Rails precompile hook", group: :all do |app|
9
23
  app.config.assets.precompile += [ "active_admin/sortable.css",
10
- "active_admin/sortable.js" ]
24
+ sortable_js ]
11
25
  end
12
26
 
13
27
  initializer "add assets" do
14
28
  ActiveAdmin.application.register_stylesheet "active_admin/sortable.css"
15
- ActiveAdmin.application.register_javascript "active_admin/sortable.js"
29
+ ActiveAdmin.application.register_javascript sortable_js
16
30
  end
17
31
  end
18
32
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveAdmin
2
2
  module SortableTree
3
- VERSION = "0.3.0"
3
+ VERSION = "1.0.0"
4
4
  end
5
5
  end
@@ -13,7 +13,8 @@ module ActiveAdmin
13
13
  @collection = @collection.sort_by do |a|
14
14
  a.send(options[:sorting_attribute]) || 1
15
15
  end
16
- @resource_name = active_admin_config.resource_name.to_s.underscore.parameterize('_')
16
+
17
+ @resource_name = ActiveAdmin::SortableTree::Compatibility.normalized_resource_name(active_admin_config.resource_name)
17
18
 
18
19
  # Call the block passed in. This will set the
19
20
  # title and body methods
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_admin-sortable_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Disperati
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-09-09 00:00:00.000000000 Z
12
+ date: 2017-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -43,14 +43,14 @@ dependencies:
43
43
  name: jquery-ui-rails
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - "~>"
46
+ - - ">="
47
47
  - !ruby/object:Gem::Version
48
48
  version: '5.0'
49
49
  type: :runtime
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - "~>"
53
+ - - ">="
54
54
  - !ruby/object:Gem::Version
55
55
  version: '5.0'
56
56
  - !ruby/object:Gem::Dependency
@@ -136,8 +136,11 @@ files:
136
136
  - MIT-LICENSE
137
137
  - README.md
138
138
  - app/assets/javascripts/active_admin/sortable.js.coffee
139
+ - app/assets/javascripts/active_admin/sortable_core.js.coffee
140
+ - app/assets/javascripts/active_admin/sortable_ui5.js.coffee
139
141
  - app/assets/stylesheets/active_admin/sortable.sass
140
142
  - lib/active_admin/sortable_tree.rb
143
+ - lib/active_admin/sortable_tree/compatibility.rb
141
144
  - lib/active_admin/sortable_tree/controller_actions.rb
142
145
  - lib/active_admin/sortable_tree/engine.rb
143
146
  - lib/active_admin/sortable_tree/version.rb
@@ -165,7 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
168
  version: '0'
166
169
  requirements: []
167
170
  rubyforge_project:
168
- rubygems_version: 2.5.1
171
+ rubygems_version: 2.5.2
169
172
  signing_key:
170
173
  specification_version: 4
171
174
  summary: Add drag and drop sorting to ActiveAdmin resources