trk_datatables 0.2.15 → 0.2.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Appraisals +23 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +84 -19
- data/README.md +43 -7
- data/Rakefile +6 -5
- data/gemfiles/.bundle/config +2 -0
- data/gemfiles/rails_5.gemfile +12 -0
- data/gemfiles/rails_5.gemfile.lock +224 -0
- data/gemfiles/rails_6.gemfile +8 -0
- data/gemfiles/rails_6.gemfile.lock +228 -0
- data/gemfiles/rails_7.gemfile +8 -0
- data/gemfiles/rails_7.gemfile.lock +235 -0
- data/gemfiles/rails_7_1.gemfile +8 -0
- data/gemfiles/rails_7_1.gemfile.lock +291 -0
- data/lib/generators/templates/trk_datatable.rb +2 -2
- data/lib/generators/trk_datatables/trk_datatables_generator.rb +4 -4
- data/lib/trk_datatables/active_record.rb +37 -20
- data/lib/trk_datatables/base.rb +27 -23
- data/lib/trk_datatables/column_key_options.rb +50 -40
- data/lib/trk_datatables/dt_params.rb +32 -31
- data/lib/trk_datatables/neo4j.rb +3 -4
- data/lib/trk_datatables/preferences.rb +21 -5
- data/lib/trk_datatables/render_html.rb +19 -16
- data/lib/trk_datatables/version.rb +1 -1
- data/lib/trk_datatables.rb +18 -16
- data/trk_datatables.gemspec +33 -33
- metadata +54 -18
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: ..
|
|
3
|
+
specs:
|
|
4
|
+
trk_datatables (0.2.17)
|
|
5
|
+
activesupport
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
actioncable (7.1.6)
|
|
11
|
+
actionpack (= 7.1.6)
|
|
12
|
+
activesupport (= 7.1.6)
|
|
13
|
+
nio4r (~> 2.0)
|
|
14
|
+
websocket-driver (>= 0.6.1)
|
|
15
|
+
zeitwerk (~> 2.6)
|
|
16
|
+
actionmailbox (7.1.6)
|
|
17
|
+
actionpack (= 7.1.6)
|
|
18
|
+
activejob (= 7.1.6)
|
|
19
|
+
activerecord (= 7.1.6)
|
|
20
|
+
activestorage (= 7.1.6)
|
|
21
|
+
activesupport (= 7.1.6)
|
|
22
|
+
mail (>= 2.7.1)
|
|
23
|
+
net-imap
|
|
24
|
+
net-pop
|
|
25
|
+
net-smtp
|
|
26
|
+
actionmailer (7.1.6)
|
|
27
|
+
actionpack (= 7.1.6)
|
|
28
|
+
actionview (= 7.1.6)
|
|
29
|
+
activejob (= 7.1.6)
|
|
30
|
+
activesupport (= 7.1.6)
|
|
31
|
+
mail (~> 2.5, >= 2.5.4)
|
|
32
|
+
net-imap
|
|
33
|
+
net-pop
|
|
34
|
+
net-smtp
|
|
35
|
+
rails-dom-testing (~> 2.2)
|
|
36
|
+
actionpack (7.1.6)
|
|
37
|
+
actionview (= 7.1.6)
|
|
38
|
+
activesupport (= 7.1.6)
|
|
39
|
+
cgi
|
|
40
|
+
nokogiri (>= 1.8.5)
|
|
41
|
+
racc
|
|
42
|
+
rack (>= 2.2.4)
|
|
43
|
+
rack-session (>= 1.0.1)
|
|
44
|
+
rack-test (>= 0.6.3)
|
|
45
|
+
rails-dom-testing (~> 2.2)
|
|
46
|
+
rails-html-sanitizer (~> 1.6)
|
|
47
|
+
actiontext (7.1.6)
|
|
48
|
+
actionpack (= 7.1.6)
|
|
49
|
+
activerecord (= 7.1.6)
|
|
50
|
+
activestorage (= 7.1.6)
|
|
51
|
+
activesupport (= 7.1.6)
|
|
52
|
+
globalid (>= 0.6.0)
|
|
53
|
+
nokogiri (>= 1.8.5)
|
|
54
|
+
actionview (7.1.6)
|
|
55
|
+
activesupport (= 7.1.6)
|
|
56
|
+
builder (~> 3.1)
|
|
57
|
+
cgi
|
|
58
|
+
erubi (~> 1.11)
|
|
59
|
+
rails-dom-testing (~> 2.2)
|
|
60
|
+
rails-html-sanitizer (~> 1.6)
|
|
61
|
+
activejob (7.1.6)
|
|
62
|
+
activesupport (= 7.1.6)
|
|
63
|
+
globalid (>= 0.3.6)
|
|
64
|
+
activemodel (7.1.6)
|
|
65
|
+
activesupport (= 7.1.6)
|
|
66
|
+
activerecord (7.1.6)
|
|
67
|
+
activemodel (= 7.1.6)
|
|
68
|
+
activesupport (= 7.1.6)
|
|
69
|
+
timeout (>= 0.4.0)
|
|
70
|
+
activestorage (7.1.6)
|
|
71
|
+
actionpack (= 7.1.6)
|
|
72
|
+
activejob (= 7.1.6)
|
|
73
|
+
activerecord (= 7.1.6)
|
|
74
|
+
activesupport (= 7.1.6)
|
|
75
|
+
marcel (~> 1.0)
|
|
76
|
+
activesupport (7.1.6)
|
|
77
|
+
base64
|
|
78
|
+
benchmark (>= 0.3)
|
|
79
|
+
bigdecimal
|
|
80
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
81
|
+
connection_pool (>= 2.2.5)
|
|
82
|
+
drb
|
|
83
|
+
i18n (>= 1.6, < 2)
|
|
84
|
+
logger (>= 1.4.2)
|
|
85
|
+
minitest (>= 5.1)
|
|
86
|
+
mutex_m
|
|
87
|
+
securerandom (>= 0.3)
|
|
88
|
+
tzinfo (~> 2.0)
|
|
89
|
+
appraisal (2.5.0)
|
|
90
|
+
bundler
|
|
91
|
+
rake
|
|
92
|
+
thor (>= 0.14.0)
|
|
93
|
+
ast (2.4.3)
|
|
94
|
+
base64 (0.3.0)
|
|
95
|
+
benchmark (0.5.0)
|
|
96
|
+
bigdecimal (4.1.2)
|
|
97
|
+
builder (3.3.0)
|
|
98
|
+
byebug (11.1.3)
|
|
99
|
+
cgi (0.5.2)
|
|
100
|
+
concurrent-ruby (1.3.7)
|
|
101
|
+
connection_pool (2.5.5)
|
|
102
|
+
crass (1.0.7)
|
|
103
|
+
database_cleaner (2.1.0)
|
|
104
|
+
database_cleaner-active_record (>= 2, < 3)
|
|
105
|
+
database_cleaner-active_record (2.2.2)
|
|
106
|
+
activerecord (>= 5.a)
|
|
107
|
+
database_cleaner-core (~> 2.0)
|
|
108
|
+
database_cleaner-core (2.1.0)
|
|
109
|
+
date (3.5.1)
|
|
110
|
+
drb (2.2.3)
|
|
111
|
+
erb (4.0.4.1)
|
|
112
|
+
cgi (>= 0.3.3)
|
|
113
|
+
erubi (1.13.1)
|
|
114
|
+
globalid (1.4.0)
|
|
115
|
+
activesupport (>= 6.1)
|
|
116
|
+
i18n (1.14.8)
|
|
117
|
+
concurrent-ruby (~> 1.0)
|
|
118
|
+
io-console (0.8.2)
|
|
119
|
+
irb (1.18.0)
|
|
120
|
+
pp (>= 0.6.0)
|
|
121
|
+
prism (>= 1.3.0)
|
|
122
|
+
rdoc (>= 4.0.0)
|
|
123
|
+
reline (>= 0.4.2)
|
|
124
|
+
json (2.20.0)
|
|
125
|
+
language_server-protocol (3.17.0.5)
|
|
126
|
+
lint_roller (1.1.0)
|
|
127
|
+
logger (1.7.0)
|
|
128
|
+
loofah (2.25.1)
|
|
129
|
+
crass (~> 1.0.2)
|
|
130
|
+
nokogiri (>= 1.12.0)
|
|
131
|
+
mail (2.9.0)
|
|
132
|
+
logger
|
|
133
|
+
mini_mime (>= 0.1.1)
|
|
134
|
+
net-imap
|
|
135
|
+
net-pop
|
|
136
|
+
net-smtp
|
|
137
|
+
marcel (1.2.1)
|
|
138
|
+
mini_mime (1.1.5)
|
|
139
|
+
mini_portile2 (2.8.9)
|
|
140
|
+
minitest (5.26.1)
|
|
141
|
+
minitest-color (0.0.2)
|
|
142
|
+
minitest (~> 5)
|
|
143
|
+
mutex_m (0.3.0)
|
|
144
|
+
net-imap (0.4.24)
|
|
145
|
+
date
|
|
146
|
+
net-protocol
|
|
147
|
+
net-pop (0.1.2)
|
|
148
|
+
net-protocol
|
|
149
|
+
net-protocol (0.2.2)
|
|
150
|
+
timeout
|
|
151
|
+
net-smtp (0.5.1)
|
|
152
|
+
net-protocol
|
|
153
|
+
nio4r (2.7.5)
|
|
154
|
+
nokogiri (1.17.2)
|
|
155
|
+
mini_portile2 (~> 2.8.2)
|
|
156
|
+
racc (~> 1.4)
|
|
157
|
+
nokogiri (1.17.2-arm64-darwin)
|
|
158
|
+
racc (~> 1.4)
|
|
159
|
+
parallel (1.28.0)
|
|
160
|
+
parser (3.3.11.1)
|
|
161
|
+
ast (~> 2.4.1)
|
|
162
|
+
racc
|
|
163
|
+
pg (1.6.3-arm64-darwin)
|
|
164
|
+
pp (0.6.4)
|
|
165
|
+
prettyprint
|
|
166
|
+
prettyprint (0.2.0)
|
|
167
|
+
prism (1.9.0)
|
|
168
|
+
psych (5.4.0)
|
|
169
|
+
date
|
|
170
|
+
stringio
|
|
171
|
+
racc (1.8.1)
|
|
172
|
+
rack (3.2.6)
|
|
173
|
+
rack-session (2.1.2)
|
|
174
|
+
base64 (>= 0.1.0)
|
|
175
|
+
rack (>= 3.0.0)
|
|
176
|
+
rack-test (2.2.0)
|
|
177
|
+
rack (>= 1.3)
|
|
178
|
+
rackup (2.3.1)
|
|
179
|
+
rack (>= 3)
|
|
180
|
+
rails (7.1.6)
|
|
181
|
+
actioncable (= 7.1.6)
|
|
182
|
+
actionmailbox (= 7.1.6)
|
|
183
|
+
actionmailer (= 7.1.6)
|
|
184
|
+
actionpack (= 7.1.6)
|
|
185
|
+
actiontext (= 7.1.6)
|
|
186
|
+
actionview (= 7.1.6)
|
|
187
|
+
activejob (= 7.1.6)
|
|
188
|
+
activemodel (= 7.1.6)
|
|
189
|
+
activerecord (= 7.1.6)
|
|
190
|
+
activestorage (= 7.1.6)
|
|
191
|
+
activesupport (= 7.1.6)
|
|
192
|
+
bundler (>= 1.15.0)
|
|
193
|
+
railties (= 7.1.6)
|
|
194
|
+
rails-dom-testing (2.3.0)
|
|
195
|
+
activesupport (>= 5.0.0)
|
|
196
|
+
minitest
|
|
197
|
+
nokogiri (>= 1.6)
|
|
198
|
+
rails-html-sanitizer (1.7.0)
|
|
199
|
+
loofah (~> 2.25)
|
|
200
|
+
nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
|
|
201
|
+
railties (7.1.6)
|
|
202
|
+
actionpack (= 7.1.6)
|
|
203
|
+
activesupport (= 7.1.6)
|
|
204
|
+
cgi
|
|
205
|
+
irb
|
|
206
|
+
rackup (>= 1.0.0)
|
|
207
|
+
rake (>= 12.2)
|
|
208
|
+
thor (~> 1.0, >= 1.2.2)
|
|
209
|
+
tsort (>= 0.2)
|
|
210
|
+
zeitwerk (~> 2.6)
|
|
211
|
+
rainbow (3.1.1)
|
|
212
|
+
rake (13.4.2)
|
|
213
|
+
rdoc (7.2.0)
|
|
214
|
+
erb
|
|
215
|
+
psych (>= 4.0.0)
|
|
216
|
+
tsort
|
|
217
|
+
regexp_parser (2.12.0)
|
|
218
|
+
reline (0.6.3)
|
|
219
|
+
io-console (~> 0.5)
|
|
220
|
+
rubocop (1.87.0)
|
|
221
|
+
json (~> 2.3)
|
|
222
|
+
language_server-protocol (~> 3.17.0.2)
|
|
223
|
+
lint_roller (~> 1.1.0)
|
|
224
|
+
parallel (>= 1.10)
|
|
225
|
+
parser (>= 3.3.0.2)
|
|
226
|
+
rainbow (>= 2.2.2, < 4.0)
|
|
227
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
|
228
|
+
rubocop-ast (>= 1.49.0, < 2.0)
|
|
229
|
+
ruby-progressbar (~> 1.7)
|
|
230
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
|
231
|
+
rubocop-ast (1.49.1)
|
|
232
|
+
parser (>= 3.3.7.2)
|
|
233
|
+
prism (~> 1.7)
|
|
234
|
+
rubocop-performance (1.26.1)
|
|
235
|
+
lint_roller (~> 1.1)
|
|
236
|
+
rubocop (>= 1.75.0, < 2.0)
|
|
237
|
+
rubocop-ast (>= 1.47.1, < 2.0)
|
|
238
|
+
ruby-progressbar (1.13.0)
|
|
239
|
+
securerandom (0.3.2)
|
|
240
|
+
sqlite3 (2.0.4)
|
|
241
|
+
mini_portile2 (~> 2.8.0)
|
|
242
|
+
sqlite3 (2.0.4-arm64-darwin)
|
|
243
|
+
standard (1.55.0)
|
|
244
|
+
language_server-protocol (~> 3.17.0.2)
|
|
245
|
+
lint_roller (~> 1.0)
|
|
246
|
+
rubocop (~> 1.87.0)
|
|
247
|
+
standard-custom (~> 1.0.0)
|
|
248
|
+
standard-performance (~> 1.8)
|
|
249
|
+
standard-custom (1.0.2)
|
|
250
|
+
lint_roller (~> 1.0)
|
|
251
|
+
rubocop (~> 1.50)
|
|
252
|
+
standard-performance (1.9.0)
|
|
253
|
+
lint_roller (~> 1.1)
|
|
254
|
+
rubocop-performance (~> 1.26.0)
|
|
255
|
+
stringio (3.2.0)
|
|
256
|
+
thor (1.5.0)
|
|
257
|
+
timecop (0.9.11)
|
|
258
|
+
timeout (0.6.1)
|
|
259
|
+
tsort (0.2.0)
|
|
260
|
+
tzinfo (2.0.6)
|
|
261
|
+
concurrent-ruby (~> 1.0)
|
|
262
|
+
unicode-display_width (3.2.0)
|
|
263
|
+
unicode-emoji (~> 4.1)
|
|
264
|
+
unicode-emoji (4.2.0)
|
|
265
|
+
websocket-driver (0.8.2)
|
|
266
|
+
base64
|
|
267
|
+
websocket-extensions (>= 0.1.0)
|
|
268
|
+
websocket-extensions (0.1.5)
|
|
269
|
+
zeitwerk (2.6.18)
|
|
270
|
+
|
|
271
|
+
PLATFORMS
|
|
272
|
+
arm64-darwin-24
|
|
273
|
+
|
|
274
|
+
DEPENDENCIES
|
|
275
|
+
activerecord (>= 5.0)
|
|
276
|
+
appraisal
|
|
277
|
+
bundler (~> 2.0)
|
|
278
|
+
byebug
|
|
279
|
+
database_cleaner
|
|
280
|
+
minitest (~> 5.0)
|
|
281
|
+
minitest-color
|
|
282
|
+
pg
|
|
283
|
+
rails (~> 7.1.0)
|
|
284
|
+
rake (>= 10.0)
|
|
285
|
+
sqlite3 (>= 2.0.0)
|
|
286
|
+
standard
|
|
287
|
+
timecop
|
|
288
|
+
trk_datatables!
|
|
289
|
+
|
|
290
|
+
BUNDLED WITH
|
|
291
|
+
2.7.2
|
|
@@ -3,7 +3,7 @@ class <%= @trk_class_name %> < TrkDatatables::ActiveRecord
|
|
|
3
3
|
{
|
|
4
4
|
<% @skip_model || class_name.constantize.columns.each do |column| -%>
|
|
5
5
|
<% next if %w[created_at updated_at].include? column.name -%>
|
|
6
|
-
|
|
6
|
+
"<%= table_name %>.<%= column.name %>": {},
|
|
7
7
|
<% end -%>
|
|
8
8
|
}
|
|
9
9
|
end
|
|
@@ -19,7 +19,7 @@ class <%= @trk_class_name %> < TrkDatatables::ActiveRecord
|
|
|
19
19
|
[
|
|
20
20
|
<% @skip_model || class_name.constantize.columns.each do |column| -%>
|
|
21
21
|
<% next if %w[created_at updated_at].include? column.name -%>
|
|
22
|
-
<% if column.name ==
|
|
22
|
+
<% if column.name == "id" -%>
|
|
23
23
|
@view.link_to(<%= singular_table_name %>.id, <%= singular_table_name %>),
|
|
24
24
|
<% else -%>
|
|
25
25
|
<%= singular_table_name %>.<%= column.name %>,
|
|
@@ -2,10 +2,10 @@ module TrkDatatables
|
|
|
2
2
|
module Generators
|
|
3
3
|
class TrkDatatablesGenerator < Rails::Generators::NamedBase
|
|
4
4
|
# we can call with `rails g trk_datatables` instead of: `rails g trk_datatables:trk_datatables`
|
|
5
|
-
namespace
|
|
6
|
-
source_root File.expand_path(
|
|
5
|
+
namespace "trk_datatables"
|
|
6
|
+
source_root File.expand_path("../templates", __dir__)
|
|
7
7
|
|
|
8
|
-
desc
|
|
8
|
+
desc "Generates datatables file for a give NAME"
|
|
9
9
|
def create
|
|
10
10
|
begin
|
|
11
11
|
class_name.constantize
|
|
@@ -18,7 +18,7 @@ module TrkDatatables
|
|
|
18
18
|
@trk_file_name = "#{singular_name}_datatable"
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
template
|
|
21
|
+
template "trk_datatable.rb", "app/datatables/#{@trk_file_name}.rb"
|
|
22
22
|
|
|
23
23
|
say <<~TEXT
|
|
24
24
|
======================================================================
|
|
@@ -6,7 +6,7 @@ module TrkDatatables
|
|
|
6
6
|
# Global search. All columns are typecasted to string. Search string is
|
|
7
7
|
# splited by space and "and"-ed.
|
|
8
8
|
def filter_by_search_all(filtered)
|
|
9
|
-
conditions = @dt_params.search_all.split(
|
|
9
|
+
conditions = @dt_params.search_all.split(" ").first(MAX_NUMBER_OF_STRINGS).map do |search_string|
|
|
10
10
|
@column_key_options.searchable_and_global_search.map do |column_key_option|
|
|
11
11
|
_filter_column_as_string column_key_option, search_string
|
|
12
12
|
end.reduce(:or) # any searchable column is 'or'-ed
|
|
@@ -38,8 +38,8 @@ module TrkDatatables
|
|
|
38
38
|
filter_column_as_in(column_key_option, search_value)
|
|
39
39
|
elsif %i[boolean].include?(column_key_option[:column_type_in_db])
|
|
40
40
|
filter_column_as_boolean(column_key_option, search_value)
|
|
41
|
-
elsif %i[date datetime integer float].include?(column_key_option[:column_type_in_db]) &&
|
|
42
|
-
|
|
41
|
+
elsif %i[date datetime integer float].include?(column_key_option[:column_type_in_db]) &&
|
|
42
|
+
search_value.include?(BETWEEN_SEPARATOR)
|
|
43
43
|
from, to = search_value.split BETWEEN_SEPARATOR
|
|
44
44
|
filter_column_as_between(column_key_option, from, to)
|
|
45
45
|
else
|
|
@@ -48,9 +48,9 @@ module TrkDatatables
|
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
def _filter_column_as_string(column_key_option, search_value)
|
|
51
|
-
search_value.split(
|
|
51
|
+
search_value.split(" ").first(MAX_NUMBER_OF_STRINGS).map do |search_string|
|
|
52
52
|
casted_column = ::Arel::Nodes::NamedFunction.new(
|
|
53
|
-
|
|
53
|
+
"CAST",
|
|
54
54
|
[_arel_column(column_key_option).as(@column_key_options.string_cast)]
|
|
55
55
|
)
|
|
56
56
|
casted_column.matches("%#{search_string}%")
|
|
@@ -59,9 +59,9 @@ module TrkDatatables
|
|
|
59
59
|
|
|
60
60
|
def filter_column_as_boolean(column_key_option, search_value)
|
|
61
61
|
# return true relation in case we ignore
|
|
62
|
-
return Arel::Nodes::SqlLiteral.new(
|
|
62
|
+
return Arel::Nodes::SqlLiteral.new("1").eq(1) if search_value == "any"
|
|
63
63
|
|
|
64
|
-
_arel_column(column_key_option).eq(search_value ==
|
|
64
|
+
_arel_column(column_key_option).eq(search_value == "true")
|
|
65
65
|
end
|
|
66
66
|
|
|
67
67
|
def filter_column_as_between(column_key_option, from, to)
|
|
@@ -83,13 +83,15 @@ module TrkDatatables
|
|
|
83
83
|
|
|
84
84
|
def _parse_from_to(from, to, column_key_option)
|
|
85
85
|
case column_key_option[:column_type_in_db]
|
|
86
|
-
when :integer
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
when :integer
|
|
87
|
+
parsed_from = _parse_integer(from)
|
|
88
|
+
parsed_to = _parse_integer(to)
|
|
89
|
+
when :float
|
|
90
|
+
parsed_from = _parse_float(from)
|
|
91
|
+
parsed_to = _parse_float(to)
|
|
90
92
|
when :date
|
|
91
|
-
parsed_from = _parse_in_zone(from)
|
|
92
|
-
parsed_to = _parse_in_zone(to)
|
|
93
|
+
parsed_from = _parse_in_zone(from)&.to_date
|
|
94
|
+
parsed_to = _parse_in_zone(to)&.to_date&.end_of_day
|
|
93
95
|
when :datetime
|
|
94
96
|
parsed_from = _parse_in_zone(from)
|
|
95
97
|
parsed_to = _parse_in_zone(to)
|
|
@@ -101,6 +103,22 @@ module TrkDatatables
|
|
|
101
103
|
[parsed_from, parsed_to]
|
|
102
104
|
end
|
|
103
105
|
|
|
106
|
+
def _parse_integer(value)
|
|
107
|
+
return nil if value.blank?
|
|
108
|
+
|
|
109
|
+
Integer(value)
|
|
110
|
+
rescue ArgumentError
|
|
111
|
+
nil
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def _parse_float(value)
|
|
115
|
+
return nil if value.blank?
|
|
116
|
+
|
|
117
|
+
Float(value)
|
|
118
|
+
rescue ArgumentError
|
|
119
|
+
nil
|
|
120
|
+
end
|
|
121
|
+
|
|
104
122
|
def _parse_in_zone(time)
|
|
105
123
|
return nil if time.blank?
|
|
106
124
|
|
|
@@ -112,8 +130,7 @@ module TrkDatatables
|
|
|
112
130
|
|
|
113
131
|
def order_and_paginate_items(filtered)
|
|
114
132
|
filtered = order_items filtered
|
|
115
|
-
filtered
|
|
116
|
-
filtered
|
|
133
|
+
filtered.offset(@dt_params.dt_offset).limit(dt_per_page_or_default)
|
|
117
134
|
end
|
|
118
135
|
|
|
119
136
|
def order_items(filtered)
|
|
@@ -122,12 +139,12 @@ module TrkDatatables
|
|
|
122
139
|
next if column_key_option[:column_options][ColumnKeyOptions::ORDER_OPTION] == false
|
|
123
140
|
|
|
124
141
|
queries << if column_key_option[:table_class] < TrkDatatables::CalculatedInDb
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
142
|
+
"#{send(column_key_option[:column_key])} #{direction}"
|
|
143
|
+
else
|
|
144
|
+
"#{column_key_option[:column_key]} #{direction}"
|
|
145
|
+
end
|
|
129
146
|
end
|
|
130
|
-
filtered.order(Arel.sql(order_by.join(
|
|
147
|
+
filtered.order(Arel.sql(order_by.join(", ")))
|
|
131
148
|
end
|
|
132
149
|
|
|
133
150
|
def _arel_column(column_key_option)
|
data/lib/trk_datatables/base.rb
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
module TrkDatatables
|
|
2
2
|
# TODO: extract those to configuration options
|
|
3
|
-
BETWEEN_SEPARATOR =
|
|
4
|
-
MULTIPLE_OPTION_SEPARATOR =
|
|
3
|
+
BETWEEN_SEPARATOR = " - ".freeze
|
|
4
|
+
MULTIPLE_OPTION_SEPARATOR = "|".freeze
|
|
5
5
|
# maximum page length = 100 (we should not believe params)
|
|
6
|
+
ORDER = "order".freeze
|
|
7
|
+
PER_PAGE = "per_page".freeze
|
|
6
8
|
|
|
7
9
|
class Error < StandardError
|
|
8
10
|
end
|
|
@@ -85,16 +87,16 @@ module TrkDatatables
|
|
|
85
87
|
end
|
|
86
88
|
|
|
87
89
|
def filter_by_search_all(_all)
|
|
88
|
-
raise
|
|
90
|
+
raise "filter_by_columns_is_defined_in_specific_orm"
|
|
89
91
|
end
|
|
90
92
|
|
|
91
93
|
def filter_by_columns(_all)
|
|
92
|
-
raise
|
|
94
|
+
raise "filter_by_columns_is_defined_in_specific_orm" \
|
|
93
95
|
"\n Extent from TrkDatatables::ActiveRecord instead of TrkDatatables::Base"
|
|
94
96
|
end
|
|
95
97
|
|
|
96
98
|
def order_and_paginate_items(_filtered_items)
|
|
97
|
-
raise
|
|
99
|
+
raise "order_and_paginate_items_is_defined_in_specific_orm"
|
|
98
100
|
end
|
|
99
101
|
|
|
100
102
|
# Returns dt_orders or default as array of index and direction
|
|
@@ -110,10 +112,12 @@ module TrkDatatables
|
|
|
110
112
|
@dt_orders_or_default = []
|
|
111
113
|
elsif @dt_params.dt_orders.present?
|
|
112
114
|
@dt_orders_or_default = @dt_params.dt_orders
|
|
113
|
-
@preferences.set
|
|
115
|
+
@preferences.set ORDER, @dt_params.dt_orders
|
|
114
116
|
else
|
|
115
|
-
check_value =
|
|
116
|
-
|
|
117
|
+
check_value = lambda { |r|
|
|
118
|
+
r.is_a?(Array) && r[0].is_a?(Array) && r[0][0].is_a?(Integer) && r[0][0] < @column_key_options.size
|
|
119
|
+
}
|
|
120
|
+
@dt_orders_or_default = @preferences.get(ORDER, check_value) || default_order
|
|
117
121
|
end
|
|
118
122
|
@dt_orders_or_default
|
|
119
123
|
end
|
|
@@ -129,12 +133,12 @@ module TrkDatatables
|
|
|
129
133
|
def dt_per_page_or_default
|
|
130
134
|
return @dt_per_page_or_default if defined? @dt_per_page_or_default
|
|
131
135
|
|
|
132
|
-
@dt_per_page_or_default =
|
|
136
|
+
@dt_per_page_or_default =
|
|
133
137
|
if @dt_params.dt_per_page.present?
|
|
134
|
-
@preferences.set
|
|
138
|
+
@preferences.set PER_PAGE, @dt_params.dt_per_page
|
|
135
139
|
@dt_params.dt_per_page
|
|
136
140
|
else
|
|
137
|
-
@preferences.get(
|
|
141
|
+
@preferences.get(PER_PAGE) || default_page_length
|
|
138
142
|
end
|
|
139
143
|
end
|
|
140
144
|
|
|
@@ -216,31 +220,31 @@ module TrkDatatables
|
|
|
216
220
|
end
|
|
217
221
|
|
|
218
222
|
def predefined_ranges
|
|
219
|
-
Time.zone ||=
|
|
223
|
+
Time.zone ||= "UTC"
|
|
220
224
|
{
|
|
221
225
|
date: predefined_date_ranges,
|
|
222
|
-
datetime: predefined_datetime_ranges
|
|
226
|
+
datetime: predefined_datetime_ranges
|
|
223
227
|
}
|
|
224
228
|
end
|
|
225
229
|
|
|
226
230
|
def predefined_date_ranges # rubocop:todo Metrics/AbcSize
|
|
227
231
|
{
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
Today: Time.zone.today..Time.zone.today,
|
|
233
|
+
Yesterday: [Time.zone.today - 1.day, Time.zone.today - 1.day],
|
|
234
|
+
"This Month": Time.zone.today.beginning_of_month...Time.zone.today,
|
|
235
|
+
"Last Month": Time.zone.today.prev_month.beginning_of_month...Time.zone.today.prev_month.end_of_month,
|
|
236
|
+
"This Year": Time.zone.today.beginning_of_year...Time.zone.today
|
|
233
237
|
}
|
|
234
238
|
end
|
|
235
239
|
|
|
236
240
|
def predefined_datetime_ranges # rubocop:todo Metrics/AbcSize
|
|
237
241
|
{
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
+
Today: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day,
|
|
243
|
+
Yesterday: [Time.zone.now.beginning_of_day - 1.day, Time.zone.now.end_of_day - 1.day],
|
|
244
|
+
"This Month": Time.zone.today.beginning_of_month.beginning_of_day...Time.zone.now.end_of_day,
|
|
245
|
+
"Last Month":
|
|
242
246
|
Time.zone.today.prev_month.beginning_of_month.beginning_of_day...Time.zone.today.prev_month.end_of_month.end_of_day,
|
|
243
|
-
|
|
247
|
+
"This Year": Time.zone.today.beginning_of_year.beginning_of_day...Time.zone.today.end_of_day
|
|
244
248
|
}
|
|
245
249
|
end
|
|
246
250
|
end
|