corn_starch 1.1.31 → 1.1.32
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16185f8705ad108d7b8eb20cd2f940542bb96ec2
|
4
|
+
data.tar.gz: 6cf6c94a3118a276c713a7963af7d3bda5315b24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ac8f0d0c6b8525a094eca4a2946c12a9fd2953d9073f9df541034e6e560952c03cfbbc0fec5198b4a3bf853802bb34f4a8a75e11ef2e70546559c1101c277e0
|
7
|
+
data.tar.gz: 0f9f90f663b225fba0aae66ac47f7e3409c66ddd1130043ba96299026e0c3c964a68df64c903440ca7836e407bd3d8ab56ccffa0f14fec1297261bf8f30c400c
|
@@ -50,26 +50,19 @@ module CornStarch
|
|
50
50
|
def pagination_filter
|
51
51
|
|
52
52
|
# Create Pagination
|
53
|
-
@
|
53
|
+
@pagination ||= {}
|
54
54
|
session[:pagination] ||= {}
|
55
55
|
|
56
56
|
# Set Records Per Page from Request Arguments
|
57
57
|
session[:pagination][:recs_per_page] = params[:records_per_page].to_i if params[:records_per_page]
|
58
58
|
|
59
59
|
# Init Pagination Vars
|
60
|
-
@
|
61
|
-
@
|
62
|
-
@
|
63
|
-
|
64
|
-
# DEBUG
|
65
|
-
puts "================== FILTER : #{@cs_pagination.inspect} / #{session.inspect} / #{CORNSTARCH_CONF.inspect}"
|
60
|
+
@pagination[:current] = 0
|
61
|
+
@pagination[:links] = []
|
62
|
+
@pagination[:pg_count] = 0
|
66
63
|
|
67
64
|
# Acquire Records per Page from Session / Configuration
|
68
|
-
@
|
69
|
-
|
70
|
-
# DEBUG
|
71
|
-
puts "================== FILTER2 : #{@cs_pagination.inspect}"
|
72
|
-
|
65
|
+
@pagination[:recs_per_page] = (session[:pagination][:recs_per_page] || CORNSTARCH_CONF[:pagination][:records_per_page][:default]).to_i
|
73
66
|
end
|
74
67
|
|
75
68
|
##################
|
@@ -104,7 +97,7 @@ module CornStarch
|
|
104
97
|
|
105
98
|
# Get Records
|
106
99
|
def get_records model, params
|
107
|
-
|
100
|
+
paginate unisearch(model, params[:search]), params
|
108
101
|
end
|
109
102
|
|
110
103
|
# Universal Search
|
@@ -153,30 +146,27 @@ module CornStarch
|
|
153
146
|
end
|
154
147
|
|
155
148
|
# Paginate
|
156
|
-
def
|
149
|
+
def paginate collection, params
|
157
150
|
|
158
151
|
# Acquire Current Page
|
159
152
|
current = (params[:current_page] || 0).to_i
|
160
153
|
|
161
154
|
# Compute Page Count
|
162
155
|
total = collection.count
|
163
|
-
@
|
164
|
-
|
165
|
-
# DEBUG
|
166
|
-
puts "================== PAGINATION : #{@cs_pagination.inspect}"
|
156
|
+
@pagination[:pg_count] = (total / @pagination[:recs_per_page]) + (((total % @pagination[:recs_per_page]) > 0) ? 1 : 0)
|
167
157
|
|
168
158
|
# Compute Page Range
|
169
159
|
range_start = current - (CORNSTARCH_CONF[:pagination][:page_range] / 2)
|
170
160
|
range_start = 0 if range_start < 0
|
171
161
|
range_end = current + (CORNSTARCH_CONF[:pagination][:page_range] / 2)
|
172
|
-
range_end = @
|
162
|
+
range_end = @pagination[:pg_count] - 1 if range_end >= @pagination[:pg_count]
|
173
163
|
|
174
164
|
# Create Page Links
|
175
|
-
@
|
176
|
-
@
|
165
|
+
@pagination[:links] = range_start .. range_end
|
166
|
+
@pagination[:current] = current
|
177
167
|
|
178
168
|
# Fetch Records
|
179
|
-
collection.limit(@
|
169
|
+
collection.limit(@pagination[:recs_per_page]).offset current * @pagination[:recs_per_page]
|
180
170
|
end
|
181
171
|
|
182
172
|
# Generic Notice Messages
|
@@ -14,9 +14,6 @@ CORNSTARCH_CONF = YAML::load_file CORNSTARCH_CONF_FILE if File.exist? CORNSTARCH
|
|
14
14
|
CORNSTARCH_CONF ||= {}
|
15
15
|
CORNSTARCH_CONF.deep_symbolize_keys!
|
16
16
|
|
17
|
-
# DEBUG
|
18
|
-
puts "=========== CONFIG (loaded from file) : #{CORNSTARCH_CONF.inspect}"
|
19
|
-
|
20
17
|
######################
|
21
18
|
# Configure Defaults #
|
22
19
|
######################
|
data/lib/corn_starch/version.rb
CHANGED