sortable_tree_rails 0.0.8 → 0.0.9

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: ee8d4e44aec0235ab2e31fc03bde95499d6830c4
4
- data.tar.gz: 18c3ad4cb2516050843f3b89221bfcbb80205f90
3
+ metadata.gz: bef72504ad1bc13fb0862fccc44dfe05249de256
4
+ data.tar.gz: a197b17107b2096dbe764fa1e2edcf18c4ae159a
5
5
  SHA512:
6
- metadata.gz: c062364af1885e36f6d9d632a0bd0a98d2c311cdd665b022136318cc1ed82536add9c9d28a799f2ade4c8757182969a4f0ef8bb226332270ee3e3c4e10a03bdd
7
- data.tar.gz: a774bce0c5707d547047f8fc8fbf4c0eb9f34141b67b5efddf43cfbba25eb9f04c5ce8333547afa5131cc788abd52bedcbb350e03e6864746e72db0d5c9eaab9
6
+ metadata.gz: d4a6ec6f853f22068dd5e8afa5d24ec64277589ad64573176918344ef620b647b2ca372ff3d7d71ed3fcf0e94661e947b33e8b8ec2d9973ddfbf2092010cf99e
7
+ data.tar.gz: 893deeab6c1bd6d83045caf3d4afbcb0d4623899be429736651d82d289c334faf7a6c225828c55e42387888fefb9dce430dcb25b54b9d94040ebe1cb57d9eae1
@@ -15,9 +15,12 @@ module SortableTreeController
15
15
  resource_class = class_name.to_s.camelize.constantize
16
16
 
17
17
  # options
18
- options[:tree] = true
19
- options[:sorting_attribute] ||= 'pos'
20
- options[:parent_method] ||= 'parent'
18
+ #options[:tree] = true
19
+
20
+ sorting_attribute = options.fetch(:sorting_attribute, 'pos')
21
+ parent_method = options.fetch(:parent_method, 'parent')
22
+ #options[:sorting_attribute] ||= 'pos'
23
+ #options[:parent_method] ||= 'parent'
21
24
 
22
25
  records = params[:cat].to_unsafe_h.inject({}) do |res, (resource, parent_resource)|
23
26
  res[resource_class.find(resource)] = resource_class.find(parent_resource) rescue nil
@@ -27,10 +30,15 @@ module SortableTreeController
27
30
  errors = []
28
31
  ActiveRecord::Base.transaction do
29
32
  records.each_with_index do |(record, parent_record), position|
30
- record.send "#{options[:sorting_attribute]}=", position
31
- if options[:tree]
32
- record.send "#{options[:parent_method]}=", parent_record
33
+
34
+ if sorting_attribute
35
+ record.send "#{sorting_attribute}=", position
33
36
  end
37
+
38
+ if parent_method
39
+ record.send "#{parent_method}=", parent_record
40
+ end
41
+
34
42
  errors << {record.id => record.errors} if !record.save
35
43
  end
36
44
  end
@@ -1,3 +1,3 @@
1
1
  module SortableTreeRails
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
data/readme.md CHANGED
@@ -23,6 +23,8 @@ Run page with the tree: `http://localhost:3000/categories/manage`.
23
23
  ### Gemfile
24
24
 
25
25
  ```
26
+ gem 'haml-rails'
27
+
26
28
  gem 'jquery-rails'
27
29
  gem "jquery-ui-rails"
28
30
 
@@ -30,6 +32,8 @@ gem 'ancestry'
30
32
  gem 'sortable_tree_rails'
31
33
  ```
32
34
 
35
+ * the gem uses HAML
36
+
33
37
 
34
38
  ### routes
35
39
 
@@ -153,18 +157,32 @@ in controller:
153
157
 
154
158
 
155
159
  * ClassName - class name (camel case). For example, 'Category'.
156
- * :sorting_attribute - attribute used for sorting (default: 'pos')
157
- * :parent_method - method used to access parent for the item (default: 'parent')
160
+ * :sorting_attribute - attribute used for sorting. Set to nil to disable sorting.
161
+ * :parent_method - method used to access parent for the item. Set to nil to disable tree (not updating parent).
158
162
 
163
+ Examples.
159
164
 
160
- * If you use ancestry in model - set :parent_method to 'parent':
165
+ * Example. For model with ancestry.
166
+ If you use ancestry in model - set :parent_method to 'parent'.
161
167
 
162
168
  ```
163
169
  include SortableTreeController::Sort
164
170
  sortable_tree 'ClassName', {parent_method: 'parent', sorting_attribute: 'pos'}
165
171
  ```
166
172
 
173
+ * Example. Do only sorting, without tree.
174
+
175
+ ```
176
+ include SortableTreeController::Sort
177
+ sortable_tree 'ClassName', {sorting_attribute: 'pos', parent_method: nil}
178
+ ```
179
+
180
+ * Example. No sorting, update only parent.
167
181
 
182
+ ```
183
+ include SortableTreeController::Sort
184
+ sortable_tree 'ClassName', {sorting_attribute: nil, parent_method: 'parent'}
185
+ ```
168
186
 
169
187
 
170
188
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sortable_tree_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Ivak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-22 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails