corn_starch 1.1.28 → 1.1.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/corn_starch/corn_starch_controller.rb +14 -14
- data/lib/corn_starch/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1f37a1cfabdef11f3e988c6d0448845acc95500
|
4
|
+
data.tar.gz: 341cbd345a63aebc9b6454c236d4ca5b0cb76a8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da221456ae55916d8f5d8153f0831e6d43a24ef660f61973c2a2d5442aaa64fd0231f4cc50647bd412137032693aa1462bcabb56d8df78dacabba917e5270d34
|
7
|
+
data.tar.gz: f01e223cb548173fba91fa3b0eb48a4884acbca59346d75d9c392c3e9a06cb647484e16226e0080e6574b86b1b94e1948c13852e9f85fee7582983c4d4bfc9db
|
@@ -50,21 +50,21 @@ module CornStarch
|
|
50
50
|
def pagination_filter
|
51
51
|
|
52
52
|
# Create Pagination
|
53
|
-
@
|
53
|
+
@cs_pagination ||= {}
|
54
54
|
|
55
55
|
# Set Records Per Page from Request Arguments
|
56
56
|
session[:pagination][:recs_per_page] = params[:records_per_page].to_i if params[:records_per_page]
|
57
57
|
|
58
58
|
# Init Pagination Vars
|
59
|
-
@
|
60
|
-
@
|
61
|
-
@
|
59
|
+
@cs_pagination[:current] = 0
|
60
|
+
@cs_pagination[:links] = []
|
61
|
+
@cs_pagination[:pg_count] = 0
|
62
62
|
|
63
63
|
# Acquire Records per Page from Session / Configuration
|
64
|
-
@
|
64
|
+
@cs_pagination[:recs_per_page] = (session[:pagination][:recs_per_page] || CORNSTARCH_CONF[:pagination][:records_per_page][:default]).to_i
|
65
65
|
|
66
66
|
# DEBUG
|
67
|
-
puts "================== FILTER : #{@
|
67
|
+
puts "================== FILTER : #{@cs_pagination.inspect}"
|
68
68
|
|
69
69
|
end
|
70
70
|
|
@@ -100,7 +100,7 @@ module CornStarch
|
|
100
100
|
|
101
101
|
# Get Records
|
102
102
|
def get_records model, params
|
103
|
-
|
103
|
+
cs_paginate unisearch(model, params[:search]), params
|
104
104
|
end
|
105
105
|
|
106
106
|
# Universal Search
|
@@ -149,30 +149,30 @@ module CornStarch
|
|
149
149
|
end
|
150
150
|
|
151
151
|
# Paginate
|
152
|
-
def
|
152
|
+
def cs_paginate collection, params
|
153
153
|
|
154
154
|
# Acquire Current Page
|
155
155
|
current = (params[:current_page] || 0).to_i
|
156
156
|
|
157
157
|
# Compute Page Count
|
158
158
|
total = collection.count
|
159
|
-
@
|
159
|
+
@cs_pagination[:pg_count] = (total / @cs_pagination[:recs_per_page]) + (((total % @cs_pagination[:recs_per_page]) > 0) ? 1 : 0)
|
160
160
|
|
161
161
|
# DEBUG
|
162
|
-
puts "================== PAGINATION : #{@
|
162
|
+
puts "================== PAGINATION : #{@cs_pagination.inspect}"
|
163
163
|
|
164
164
|
# Compute Page Range
|
165
165
|
range_start = current - (CORNSTARCH_CONF[:pagination][:page_range] / 2)
|
166
166
|
range_start = 0 if range_start < 0
|
167
167
|
range_end = current + (CORNSTARCH_CONF[:pagination][:page_range] / 2)
|
168
|
-
range_end = @
|
168
|
+
range_end = @cs_pagination[:pg_count] - 1 if range_end >= @cs_pagination[:pg_count]
|
169
169
|
|
170
170
|
# Create Page Links
|
171
|
-
@
|
172
|
-
@
|
171
|
+
@cs_pagination[:links] = range_start .. range_end
|
172
|
+
@cs_pagination[:current] = current
|
173
173
|
|
174
174
|
# Fetch Records
|
175
|
-
collection.limit(@
|
175
|
+
collection.limit(@cs_pagination[:recs_per_page]).offset current * @cs_pagination[:recs_per_page]
|
176
176
|
end
|
177
177
|
|
178
178
|
# Generic Notice Messages
|
data/lib/corn_starch/version.rb
CHANGED