activesorting 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -3
- data/lib/active_sorting/model.rb +5 -5
- data/lib/active_sorting/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c24c8e9fbc1fecc4dc1e2e96d8c0580ceb5eab7f
|
4
|
+
data.tar.gz: a043f97b256be42f1b73a86068a804af1177030c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba29eb87ce28ba1b4b70543b89acb16677be1a1e71f93e2b2f449b879624d8cb073a516af34eaa86c61893bbb06d28c59caa6a0517c87c3da9e8f766113e3d59
|
7
|
+
data.tar.gz: f5f2b3adce2f2282d1615e560759651274a1b45ff525dc5071802de13085dc5ad8f7d4b5d27c04a6142ab2593537baf1f45bab6fd053123f3f5f19b6d1294dfa
|
data/README.md
CHANGED
@@ -52,9 +52,11 @@ To sort by a model field `position`:
|
|
52
52
|
You can customize the sorting behavior by
|
53
53
|
passing an options hash. The following keys are supported:
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
`
|
55
|
+
`:order` sorting direction, can be one of `:asc` or `:desc`, defaults to __:asc__
|
56
|
+
|
57
|
+
`:step` stepping value, only `integers` allowed, defaults to __500__
|
58
|
+
|
59
|
+
`:scope` scopes, defines the `ActiveRecord` `scope` applied before calculating the `position` field value. Defaults to __[]__
|
58
60
|
|
59
61
|
## Development
|
60
62
|
|
data/lib/active_sorting/model.rb
CHANGED
@@ -34,10 +34,10 @@ module ActiveSorting
|
|
34
34
|
raise ArgumentError, "Sortable list should not be empty" unless new_list.count
|
35
35
|
conditions = {}
|
36
36
|
conditions[id_column] = new_list
|
37
|
-
old_list = unscoped.where(conditions).pluck(id_column)
|
37
|
+
old_list = unscoped.active_sorting_default_scope.where(conditions).pluck(id_column)
|
38
38
|
raise ArgumentError, "Sortable list should be persisted to database" unless old_list.count
|
39
39
|
changes = active_sorting_changes_required(old_list, new_list)
|
40
|
-
active_sorting_make_changes(new_list, changes, id_column)
|
40
|
+
active_sorting_make_changes(old_list, new_list, changes, id_column)
|
41
41
|
end
|
42
42
|
|
43
43
|
# Default sorting options
|
@@ -107,7 +107,7 @@ module ActiveSorting
|
|
107
107
|
end
|
108
108
|
|
109
109
|
# Commit changes to database
|
110
|
-
def active_sorting_make_changes(new_list, changes, id_column)
|
110
|
+
def active_sorting_make_changes(old_list, new_list, changes, id_column)
|
111
111
|
new_list.each_with_index do |id, index|
|
112
112
|
next unless changes.include?(id)
|
113
113
|
if index == new_list.count.pred
|
@@ -119,8 +119,8 @@ module ActiveSorting
|
|
119
119
|
elsif index == 0
|
120
120
|
# We're moving an item to first position
|
121
121
|
# Calculate the gap between following 2 items
|
122
|
-
n1 =
|
123
|
-
n2 = active_sorting_find_by(id_column,
|
122
|
+
n1 = 0
|
123
|
+
n2 = active_sorting_find_by(id_column, old_list[index]).active_sorting_value
|
124
124
|
else
|
125
125
|
# We're moving a non-terminal item
|
126
126
|
n1 = active_sorting_find_by(id_column, new_list[index.pred]).active_sorting_value
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activesorting
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Omar Abdel-Wahab
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|