rails_admin_nestable 0.1.7 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZWFjMGUyNGEwMzc4OWFiOTVhYzlmZWM3YmM0MzcyZjJhNzI2YjQwOA==
5
- data.tar.gz: !binary |-
6
- MTM2YWRiODk0ZmM3NTM4NWE4NWI1ODFlMTcwNTFhZjg5Y2MxYjZkOA==
2
+ SHA1:
3
+ metadata.gz: 77f2ba26c0c2b45db61c79f119a76e7a925d3834
4
+ data.tar.gz: 965559bbcc203cbccd748974266be6bba5323f03
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NDBmN2ViZDRjZWQ0MWMzYWM3YjBlZWM2MzQ4MmIyMTYzMGZhMTNiMzE1MjE0
10
- ZDMxNjMzMmQxYTM5OWE1YTdhZjhhZmU3MzdiODA3NWFmYTM2NGEzOGUyYjY5
11
- N2JhNGEzNWFlNjcxZGUyYTQyMjk0YTI5MDZhNDAzODk5ZDI5YmU=
12
- data.tar.gz: !binary |-
13
- MWJhYjMwZDA5ZDViZjg0YTRmYTAxYzM5ZjA4NTA4YjRlNWM3YTUyMjZiN2Y2
14
- NmJjY2FhMzNiZDI4ZTRjZmM4YTg0Y2U4NzAzYzlkMjQ3ZmJmODYyM2FjZGU4
15
- MWRiYmY3OWQzYjQ4ZWMzZTQ4NmM4NWEwMTU4M2M1ODAzMDY0ZDg=
6
+ metadata.gz: 7c772fb273a6f1ddcd274f05767b89f645bac71d0870a941490553bc252a5a100b52c3820a92ec72447820ef5b7505dd5007a558aef3b4dd857b9bc5bf5975dd
7
+ data.tar.gz: 4eefd1dc75a210dbdae1288157c83e4908893d847943b59033dbb4c265e26896b27609494e6f26195f198a0331aafc50ec7bfc0c76eb61b0c2376ec300833237
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2013 Andrea Dal Ponte
1
+ Copyright 2014 Andrea Dal Ponte
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,10 +1,11 @@
1
1
  # Rails Admin Nestable
2
2
 
3
- Reorganise model data with a drag and drop tree/list structure.
3
+ RailsAdmin Drag and drop tree view for Ancestry gem
4
4
 
5
5
  Sample demo available at: https://github.com/dalpo/rails_admin_nestable_demo
6
6
 
7
7
  [![Gem Version](https://badge.fury.io/rb/rails_admin_nestable.png)](http://badge.fury.io/rb/rails_admin_nestable)
8
+ [![Code Climate](https://codeclimate.com/github/dalpo/rails_admin_nestable.png)](https://codeclimate.com/github/dalpo/rails_admin_nestable)
8
9
 
9
10
  ## Installation
10
11
 
@@ -43,14 +44,15 @@ end
43
44
  You could choose between two different configurations for your model:
44
45
 
45
46
  ### 1. Nestable tree:
46
- To use this configuration, you need to organize your tree model with [Ancestry](https://github.com/stefankroes/ancestry).
47
+ To use this configuration, you need to organize your tree model with [Ancestry](https://github.com/stefankroes/ancestry) or [Mongoid Ancestry](https://github.com/skyeagle/mongoid-ancestry).
47
48
  Otherwise your model have to respond to the `parent`, `arrange` and `children` methods.
48
49
 
49
50
  The `nestable_tree` methods supports the following options:
50
51
  * `position_field`: (symbol) default => `nil`
51
52
  * `max_depth`: (integer) default => `nil`
52
53
  * `enable_callback`: (boolean) default => `false`
53
- * `scope`: (symbol | proc) default => `nil`, must be a `ActiveRecord::Relation` object of models
54
+ * `scope`: (symbol | proc) default => `nil`
55
+ * `live_update`: (boolean | :only) default => true (:only is for live updating only)
54
56
 
55
57
  In your `config/initializers/rails_admin.rb` initializer:
56
58
  ```ruby
@@ -75,7 +77,8 @@ To use this configuration, you need a position field
75
77
  The `nestable_list` methods supports the following options:
76
78
  * `position_field`: (symbol) default `:position`
77
79
  * `enable_callback`: (boolean) default => `false`
78
- * `scope`: (symbol | proc) default => `nil`, must be a `ActiveRecord::Relation` object of models
80
+ * `scope`: (symbol | proc) default => `nil`
81
+ * `live_update`: (boolean | :only) default => true (:only is for live updating only)
79
82
 
80
83
  In your `config/initializers/rails_admin.rb` initializer:
81
84
  ```ruby
@@ -149,7 +152,7 @@ Submitting a Pull Request:
149
152
  ## License
150
153
  **This project rocks and uses MIT-LICENSE.**
151
154
 
152
- Copyright 2013 Andrea Dal Ponte
155
+ Copyright 2014 Andrea Dal Ponte
153
156
 
154
157
  Permission is hereby granted, free of charge, to any person obtaining
155
158
  a copy of this software and associated documentation files (the
@@ -169,4 +172,3 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
169
172
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
170
173
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
171
174
  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
172
-
@@ -25,7 +25,7 @@ jQuery ->
25
25
  $tree_nodes_max_depth = $tree_nodes.data('max-depth')
26
26
  $live_update = $('#rails_admin_nestable input[type=checkbox]')
27
27
  $update_button = $('#rails_admin_nestable button')
28
- live_update_mode = $live_update.prop('checked')
28
+ live_update_mode = if (!$live_update.length && !$update_button.length) then true else $live_update.prop('checked')
29
29
  $('#rails_admin_nestable button').prop('disabled', $live_update.prop('checked'))
30
30
 
31
31
  $live_update.change ->
@@ -1,13 +1,16 @@
1
1
  .row-fluid
2
2
  .span12#rails_admin_nestable
3
- .control-group
4
- %label{:class => 'checkbox inline' }
5
- %input{ :type => 'checkbox' }= t('admin.actions.nestable.live_update')
3
+ - if [false, :only].exclude?(@options[:live_update])
4
+ .control-group
5
+ %label{:class => 'checkbox inline' }
6
+ %input{ :type => 'checkbox' }= t('admin.actions.nestable.live_update')
6
7
  #tree_nodes.dd{:'data-update-path' => nestable_path(model_name: @abstract_model), :'data-max-depth' => tree_max_depth}
7
8
  %ol.dd-list
8
9
  = nested_tree_nodes @tree_nodes
9
- .form-actions
10
- %button{ :type => 'submit', :class => 'btn btn-small btn-primary' }= t('admin.actions.nestable.update')
10
+ - if @options[:live_update] != :only
11
+ .form-actions
12
+ %button{ :type => 'submit', :class => 'btn btn-small btn-primary' }= t('admin.actions.nestable.update')
13
+
11
14
 
12
15
  = stylesheet_link_tag 'rails_admin/rails_admin_nestable'
13
16
  = javascript_include_tag 'rails_admin/jquery.nestable'
@@ -0,0 +1,14 @@
1
+ vi:
2
+ admin:
3
+ actions:
4
+ nestable:
5
+ title: "Sắp xếp cho %{model_label}"
6
+ menu: "Tạo Menu"
7
+ breadcrumb: "Tạo menu"
8
+ link: "Tạo menu"
9
+ bulk_link: "Sắp xếp những %{model_label_plural} đã chọn"
10
+ done: "Đã sắp xếp"
11
+ success: "Thành công"
12
+ error: "Lỗi"
13
+ update: "Cập nhập"
14
+ live_update: "Cập nhật trực tiếp"
@@ -9,5 +9,4 @@ require 'rails_admin/config/model'
9
9
  require 'rails_admin_nestable/configuration'
10
10
  require 'rails_admin_nestable/nestable'
11
11
  require 'rails_admin_nestable/model'
12
- require 'rails_admin_nestable/helper'
13
-
12
+ require 'rails_admin_nestable/helper'
@@ -1,8 +1,8 @@
1
1
  module RailsAdminNestable
2
2
  class Configuration
3
3
 
4
- TREE_DEFAULT_OPTIONS = { enable_callback: false, scope: nil }
5
- LIST_DEFAULT_OPTIONS = { position_field: :position, max_depth: 1, enable_callback: false, scope: nil }
4
+ TREE_DEFAULT_OPTIONS = { live_update: true, enable_callback: false, scope: nil }
5
+ LIST_DEFAULT_OPTIONS = { position_field: :position, max_depth: 1, live_update: true, enable_callback: false, scope: nil }
6
6
 
7
7
  def initialize(abstract_model)
8
8
  @abstract_model = abstract_model
@@ -17,32 +17,30 @@ module RailsAdminNestable
17
17
  end
18
18
 
19
19
  def options
20
- if tree?
21
- @nestable_options ||= self.tree_options
22
- elsif list?
23
- @nestable_options ||= self.list_options
20
+ @nestable_options ||= begin
21
+ options = self.tree_options if tree?
22
+ options = self.list_options if list?
23
+ options || {}
24
24
  end
25
-
26
- @nestable_options || {}
27
25
  end
28
26
 
29
- protected
27
+ protected
30
28
 
31
- def tree_options
32
- tree.class == Hash ? TREE_DEFAULT_OPTIONS.merge(tree) : TREE_DEFAULT_OPTIONS
33
- end
29
+ def tree_options
30
+ tree.class == Hash ? TREE_DEFAULT_OPTIONS.merge(tree) : TREE_DEFAULT_OPTIONS
31
+ end
34
32
 
35
- def list_options
36
- LIST_DEFAULT_OPTIONS.merge(list.class == Hash ? list : {})
37
- end
33
+ def list_options
34
+ LIST_DEFAULT_OPTIONS.merge(list.class == Hash ? list : {})
35
+ end
38
36
 
39
- def tree
40
- @nestable_tree ||= ::RailsAdmin::Config.model(@abstract_model.model).nestable_tree
41
- end
37
+ def tree
38
+ @nestable_tree ||= ::RailsAdmin::Config.model(@abstract_model.model).nestable_tree
39
+ end
42
40
 
43
- def list
44
- @nestable_list ||= ::RailsAdmin::Config.model(@abstract_model.model).nestable_list
45
- end
41
+ def list
42
+ @nestable_list ||= ::RailsAdmin::Config.model(@abstract_model.model).nestable_list
43
+ end
46
44
 
47
45
  end
48
46
  end
File without changes
@@ -1,6 +1,5 @@
1
1
  module RailsAdminNestable
2
2
  module Helper
3
-
4
3
  def nested_tree_nodes(tree_nodes = [])
5
4
  tree_nodes.map do |tree_node, sub_tree_nodes|
6
5
  li_classes = 'dd-item dd3-item'
@@ -8,15 +7,12 @@ module RailsAdminNestable
8
7
  content_tag :li, class: li_classes, :'data-id' => tree_node.id do
9
8
 
10
9
  output = content_tag :div, 'drag', class: 'dd-handle dd3-handle'
11
- output+= content_tag :div, class: 'dd3-content' do
10
+ output += content_tag :div, class: 'dd3-content' do
12
11
  content = link_to @model_config.with(object: tree_node).object_label, edit_path(@abstract_model, tree_node.id)
13
- content+= content_tag :div, action_links(tree_node), class: 'pull-right links'
14
- end
15
-
16
- if sub_tree_nodes && sub_tree_nodes.any?
17
- output+= content_tag :ol, nested_tree_nodes(sub_tree_nodes), class: 'dd-list'
12
+ content += content_tag :div, action_links(tree_node), class: 'pull-right links'
18
13
  end
19
14
 
15
+ output+= content_tag :ol, nested_tree_nodes(sub_tree_nodes), class: 'dd-list' if sub_tree_nodes && sub_tree_nodes.any?
20
16
  output
21
17
  end
22
18
  end.join.html_safe
@@ -31,6 +27,5 @@ module RailsAdminNestable
31
27
  def tree_max_depth
32
28
  @nestable_conf.options[:max_depth] || 'false'
33
29
  end
34
-
35
30
  end
36
- end
31
+ end
@@ -12,4 +12,4 @@ module RailsAdmin
12
12
 
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -5,7 +5,7 @@ module RailsAdmin
5
5
  RailsAdmin::Config::Actions.register(self)
6
6
 
7
7
  register_instance_option :pjax? do
8
- false
8
+ true
9
9
  end
10
10
 
11
11
  register_instance_option :root? do
@@ -23,49 +23,41 @@ module RailsAdmin
23
23
  register_instance_option :controller do
24
24
  Proc.new do |klass|
25
25
  @nestable_conf = ::RailsAdminNestable::Configuration.new @abstract_model
26
+ @position_field = @nestable_conf.options[:position_field]
27
+ @enable_callback = @nestable_conf.options[:enable_callback]
28
+ @nestable_scope = @nestable_conf.options[:scope]
29
+ @options = @nestable_conf.options
30
+ @adapter = @abstract_model.adapter
26
31
 
27
32
  # Methods
28
33
  def update_tree(tree_nodes, parent_node = nil)
29
34
  tree_nodes.each do |key, value|
30
- model = @abstract_model.model.find(value['id'].to_i)
31
-
32
- if parent_node.present?
33
- model.parent = parent_node
34
- else
35
- model.parent = nil
36
- end
37
-
38
- if @nestable_conf.options[:position_field].present?
39
- model.send("#{@nestable_conf.options[:position_field]}=".to_sym, (key.to_i + 1))
40
- end
41
-
42
- model.save!(validate: @nestable_conf.options[:enable_callback])
43
-
44
- if value.has_key?('children')
45
- update_tree(value['children'], model)
46
- end
35
+ model = @abstract_model.model.find(value['id'].to_s)
36
+ model.parent = parent_node || nil
37
+ model.send("#{@position_field}=".to_sym, (key.to_i + 1)) if @position_field.present?
38
+ model.save!(validate: @enable_callback)
39
+ update_tree(value['children'], model) if value.has_key?('children')
47
40
  end
48
41
  end
49
42
 
50
43
  def update_list(model_list)
51
44
  model_list.each do |key, value|
52
- model = @abstract_model.model.find(value['id'].to_i)
53
- model.send("#{@nestable_conf.options[:position_field]}=".to_sym, (key.to_i + 1))
54
- model.save!(validate: @nestable_conf.options[:enable_callback])
45
+ model = @abstract_model.model.find(value['id'].to_s)
46
+ model.send("#{@position_field}=".to_sym, (key.to_i + 1))
47
+ model.save!(validate: @enable_callback)
55
48
  end
56
49
  end
57
50
 
58
51
  if request.post? && params['tree_nodes'].present?
59
52
  begin
60
- ActiveRecord::Base.transaction do
61
- if @nestable_conf.tree?
62
- update_tree params[:tree_nodes]
63
- end
64
-
65
- if @nestable_conf.list?
66
- update_list params[:tree_nodes]
67
- end
68
- end
53
+ update = ->{
54
+ update_tree params[:tree_nodes] if @nestable_conf.tree?
55
+ update_list params[:tree_nodes] if @nestable_conf.list?
56
+ }
57
+
58
+ ActiveRecord::Base.transaction { update.call } if @adapter == :active_record
59
+ update.call if @adapter == :mongoid
60
+
69
61
  message = "<strong>#{I18n.t('admin.actions.nestable.success')}!</strong>"
70
62
  rescue Exception => e
71
63
  message = "<strong>#{I18n.t('admin.actions.nestable.error')}</strong>: #{e}"
@@ -75,26 +67,25 @@ module RailsAdmin
75
67
  end
76
68
 
77
69
  if request.get?
78
- scope = begin
79
- case @nestable_conf.options[:scope].class.to_s
70
+ query = list_entries(@model_config, :nestable, false, false).reorder(nil)
71
+
72
+ case @options[:scope].class.to_s
80
73
  when 'Proc'
81
- @nestable_conf.options[:scope].call
74
+ query.merge(@options[:scope].call)
82
75
  when 'Symbol'
83
- @abstract_model.model.public_send(@nestable_conf.options[:scope])
84
- else
85
- nil
86
- end
76
+ query.merge(@abstract_model.model.public_send(@options[:scope]))
87
77
  end
88
78
 
89
- query = list_entries(@model_config, :nestable, false, false).reorder(nil).merge(scope)
90
- position_field = @nestable_conf.options[:position_field]
91
-
92
79
  if @nestable_conf.tree?
93
- @tree_nodes = position_field.present?? query.arrange(order: position_field) : query.arrange
80
+ @tree_nodes = if @options[:position_field].present?
81
+ query.arrange(order: @options[:position_field])
82
+ else
83
+ query.arrange
84
+ end
94
85
  end
95
86
 
96
87
  if @nestable_conf.list?
97
- @tree_nodes = query.order(position_field)
88
+ @tree_nodes = query.order("#{@options[:position_field]} ASC")
98
89
  end
99
90
 
100
91
  render action: @action.template_name
@@ -103,7 +94,7 @@ module RailsAdmin
103
94
  end
104
95
 
105
96
  register_instance_option :link_icon do
106
- 'icon-move'
97
+ 'icon-move fa fa-arrows'
107
98
  end
108
99
 
109
100
  register_instance_option :http_methods do
@@ -1,3 +1,3 @@
1
1
  module RailsAdminNestable
2
- VERSION = "0.1.7"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,93 +1,96 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin_nestable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Dal Ponte
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-28 00:00:00.000000000 Z
11
+ date: 2014-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails_admin
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: haml-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: coffee-rails
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ! '>='
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ! '>='
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: sass-rails
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ! '>='
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ! '>='
80
+ - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description: Rails Admin plugin to organise Tree/List models with a simple drag and
84
- drop custom action
83
+ description: RailsAdmin Drag and drop tree view for Ancestry gem with ActiveRecord
84
+ and MongoID
85
85
  email:
86
86
  - info@andreadalponte.com
87
87
  executables: []
88
88
  extensions: []
89
89
  extra_rdoc_files: []
90
90
  files:
91
+ - MIT-LICENSE
92
+ - README.md
93
+ - Rakefile
91
94
  - app/assets/javascripts/rails_admin/jquery.nestable.js
92
95
  - app/assets/javascripts/rails_admin/rails_admin_nestable.js.coffee
93
96
  - app/assets/stylesheets/rails_admin/rails_admin_nestable.css.scss
@@ -98,16 +101,14 @@ files:
98
101
  - config/locales/nestable.es.yml
99
102
  - config/locales/nestable.it.yml
100
103
  - config/locales/nestable.sv.yml
104
+ - config/locales/nestable.vi.yml
105
+ - lib/rails_admin_nestable.rb
101
106
  - lib/rails_admin_nestable/configuration.rb
102
107
  - lib/rails_admin_nestable/engine.rb
103
108
  - lib/rails_admin_nestable/helper.rb
104
109
  - lib/rails_admin_nestable/model.rb
105
110
  - lib/rails_admin_nestable/nestable.rb
106
111
  - lib/rails_admin_nestable/version.rb
107
- - lib/rails_admin_nestable.rb
108
- - MIT-LICENSE
109
- - Rakefile
110
- - README.md
111
112
  homepage: https://github.com/dalpo/rails_admin_nestable
112
113
  licenses:
113
114
  - MIT
@@ -118,18 +119,18 @@ require_paths:
118
119
  - lib
119
120
  required_ruby_version: !ruby/object:Gem::Requirement
120
121
  requirements:
121
- - - ! '>='
122
+ - - ">="
122
123
  - !ruby/object:Gem::Version
123
124
  version: '0'
124
125
  required_rubygems_version: !ruby/object:Gem::Requirement
125
126
  requirements:
126
- - - ! '>='
127
+ - - ">="
127
128
  - !ruby/object:Gem::Version
128
129
  version: '0'
129
130
  requirements: []
130
131
  rubyforge_project:
131
- rubygems_version: 2.1.10
132
+ rubygems_version: 2.2.2
132
133
  signing_key:
133
134
  specification_version: 4
134
- summary: Reorganise model data with a drag and drop tree/list structure
135
+ summary: RailsAdmin Drag and drop tree view for Ancestry gem
135
136
  test_files: []