trk_datatables 0.2.5 → 0.2.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df8bfddf3658f2462c4aedc466514453d6b28745b80fa54a76e92321004090b2
4
- data.tar.gz: 43af45648ffbbb57db38547ee2487cb11be6abb660be9eb7a8a405c485e1f293
3
+ metadata.gz: 40eeba5483cf896ad0df528f5b329a0bdfd7b2a7d78ab18df295f1b30737ba8f
4
+ data.tar.gz: 7e9c1cd8f4c9fcf942dd5639b7f406e85ccb6c0c037e2dd6a3a7b42ece5d641b
5
5
  SHA512:
6
- metadata.gz: 8e3173a1237202c8949f77594922d98f4dbf98e869f74660f708d0c81b3c3869c9a1e48e351ffba5c694826c27df60e5394c5513338e6be356d0efda58eee857
7
- data.tar.gz: 10da1a1ebcd9a4d725ee16b6876df0eae18ea4feaa36f3c8a2128637bdf48ed2042ba9ffcb410626ad2beba60c20a07d5e6d76ddccef109c490259d4098ee596
6
+ metadata.gz: b29ccb1148bb7b4782b4cf5d466330d241bbc90c5554129b4d243833d5585a2fad599fbf6e518e62a08db487e32adcdf0ebd65232592f9d01fe048a4898f0310
7
+ data.tar.gz: 3b3f65377b9bc66f33874abcbe231fc6e5ace020b82526fb8edbab5b697085bcf1f3bd48c2bc8f7d42873770a6c61e2096716a3bf95343dad20aa9c2947ee0dd
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trk_datatables (0.2.5)
4
+ trk_datatables (0.2.6)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -18,7 +18,7 @@ you can get something like
18
18
 
19
19
  ![trk-datatables](test/trk_datatables_with_daterangepicker.png "TRK Datatables")
20
20
 
21
- Currenlty it supports:
21
+ Currently supports:
22
22
  * ActiveRecord
23
23
  * Neo4j
24
24
 
@@ -284,47 +284,32 @@ class PostsDatatable < TrkDatatables::ActiveRecord
284
284
  end
285
285
  ```
286
286
 
287
- To enable shortcuts for selecting ranges, you can override predefined ranges and
288
- enable for all `date` and `datetime` column
289
-
290
- ```
291
- # app/datatables/base_trk_datatable.rb
292
- class BaseTrkDatable < TrkDatatables::ActiveRecord
293
- def predefined_ranges
294
- # defaults are defined in https://github.com/trkin/trk_datatables/blob/master/lib/trk_datatables/base.rb
295
- default_predefined_ranges
296
- end
297
- end
298
- ```
299
- or you can enable for all `date` and `datetime columns` for specific datatable
300
- by defining `predefined_ranges` on that datatable. You can disable for specific columns also
287
+ By default, predefined ranges are enabled. You can find source for
288
+ `predefined_date_ranges` and `predefined_datetime_ranges` in
289
+ [base.rb](https://github.com/trkin/trk_datatables/blob/master/lib/trk_datatables/base.rb)
290
+ You can overwrite them in BaseTrkDatable or your trk datatable class.
291
+ You can disable or enable for specific columns like in this example:
301
292
  ```
302
293
  class PostsDatatable < TrkDatatables::ActiveRecord
303
- def predefined_ranges
294
+ def predefined_datetime_ranges
304
295
  {
305
296
  'Today': Time.zone.now.beginning_of_day..Time.zone.now.end_of_day,
306
297
  'Yesterday': [Time.zone.now.beginning_of_day - 1.day, Time.zone.now.end_of_day - 1.day],
307
298
  'This Month': Time.zone.today.beginning_of_month...Time.zone.now.end_of_day,
308
299
  'Last Month': Time.zone.today.prev_month.beginning_of_month...Time.zone.today.prev_month.end_of_month.end_of_day,
309
300
  'This Year': Time.zone.today.beginning_of_year...Time.zone.today.end_of_day,
310
- }
301
+ }.transform_values do |range|
302
+ # datepicker expects format 2020-11-29 11:59:59
303
+ range.first.strftime('%F %T')..range.last.strftime('%F %T')
304
+ end
311
305
  end
312
306
 
313
307
  def columns
314
308
  {
315
- 'posts.created_at': {}, # this column will have predefined_ranges
316
- 'posts.published_on': { predefined_ranges: false }
317
- end
318
- end
319
- ```
320
- or you can define for specific column
321
- ```
322
- # app/datatables/posts_datatable.rb
323
- class PostsDatatable < TrkDatatables::ActiveRecord
324
- def columns
325
- {
326
- 'posts.created_at': { predefined_ranges: { 'Today': Time.zone.now.beginning_of_day...Time.zone.now.end_of_day } },
327
- }
309
+ 'posts.created_at': {}, # this column will have predefined_datetime_ranges
310
+ 'posts.published_on': { predefined_ranges: false },
311
+ 'posts.updated_at': { predefined_ranges: { 'Today': Time.zone.now.beginning_of_day...Time.zone.now.end_of_day } },
312
+ }
328
313
  end
329
314
  end
330
315
  ```
@@ -602,6 +587,15 @@ Usefull when you want to provide a form for a user to search on specific column
602
587
  <% end %>
603
588
  ```
604
589
 
590
+ For global search you can use `[search][value]` for example
591
+
592
+ ```
593
+ <%= form_tag url: posts_path, method: :get do |f| %>
594
+ <%= f.text_field '[search][value]', 'my@email.com' %>
595
+ <%= f.submit 'Search' %>
596
+ <% end %>
597
+ ```
598
+
605
599
  If you need, you can fetch params with this helper
606
600
 
607
601
  ```
@@ -219,18 +219,34 @@ module TrkDatatables
219
219
  end
220
220
 
221
221
  def predefined_ranges
222
- {}
222
+ Time.zone ||= 'UTC'
223
+ {
224
+ date: predefined_date_ranges,
225
+ datetime: predefined_datetime_ranges,
226
+ }
223
227
  end
224
228
 
225
- def default_predefined_ranges
226
- Time.zone ||= 'UTC'
229
+ def predefined_date_ranges
230
+ {
231
+ 'Today': Time.zone.today..Time.zone.today,
232
+ 'Yesterday': [Time.zone.today - 1.day, Time.zone.today - 1.day],
233
+ 'This Month': Time.zone.today.beginning_of_month...Time.zone.today,
234
+ 'Last Month': Time.zone.today.prev_month.beginning_of_month...Time.zone.today.prev_month.end_of_month,
235
+ 'This Year': Time.zone.today.beginning_of_year...Time.zone.today,
236
+ }
237
+ end
238
+
239
+ def predefined_datetime_ranges
227
240
  {
228
241
  'Today': Time.zone.now.beginning_of_day..Time.zone.now.end_of_day,
229
242
  'Yesterday': [Time.zone.now.beginning_of_day - 1.day, Time.zone.now.end_of_day - 1.day],
230
- 'This Month': Time.zone.today.beginning_of_month...Time.zone.now.end_of_day,
231
- 'Last Month': Time.zone.today.prev_month.beginning_of_month...Time.zone.today.prev_month.end_of_month.end_of_day,
232
- 'This Year': Time.zone.today.beginning_of_year...Time.zone.today.end_of_day,
233
- }
243
+ 'This Month': Time.zone.today.beginning_of_month.beginning_of_day...Time.zone.now.end_of_day,
244
+ 'Last Month': Time.zone.today.prev_month.beginning_of_month.beginning_of_day...Time.zone.today.prev_month.end_of_month.end_of_day,
245
+ 'This Year': Time.zone.today.beginning_of_year.beginning_of_day...Time.zone.today.end_of_day,
246
+ }.transform_values do |range|
247
+ # datepicker expects format 2020-11-29 11:59:59
248
+ range.first.strftime('%F %T')..range.last.strftime('%F %T')
249
+ end
234
250
  end
235
251
  end
236
252
  end
@@ -22,11 +22,15 @@ module TrkDatatables
22
22
  end
23
23
 
24
24
  # Get the form field name for column. This is class method so you do not
25
- # need datatable instance.
25
+ # need datatable instance. It returns something like
26
+ # 'column[3][search][value]`. For global search you can use
27
+ # '[search][value]`
26
28
  #
27
29
  # @example
28
30
  # form_tag url: posts_path, method: :get do |f|
29
31
  # f.text_field PostsDatatable.form_field_name('users.email'), 'my@email.com'
32
+ # # it is the same as
33
+ # f.text_field 'columns[3][search][value]', 'my@email.com'
30
34
  def form_field_name(column_key)
31
35
  datatable = new OpenStruct.new(params: {})
32
36
  column_index = datatable.index_by_column_key column_key
@@ -244,11 +244,11 @@ module TrkDatatables
244
244
  if %i[date datetime].include? column_type_in_db
245
245
  res['data-datatable-range'] = column_type_in_db == :datetime ? :datetime : true
246
246
  if column_options[PREDEFINED_RANGES].present? ||
247
- (@predefined_ranges.present? && column_options[PREDEFINED_RANGES] != false)
247
+ (@predefined_ranges.try(:[], column_type_in_db).present? && column_options[PREDEFINED_RANGES] != false)
248
248
  res['data-datatable-predefined-ranges'] = if column_options[PREDEFINED_RANGES].is_a? Hash
249
249
  column_options[PREDEFINED_RANGES]
250
250
  else
251
- @predefined_ranges
251
+ @predefined_ranges[column_type_in_db]
252
252
  end
253
253
  res['data-datatable-predefined-ranges'].transform_values! do |range|
254
254
  [range.first.to_s, range.last.to_s]
@@ -128,6 +128,25 @@ module TrkDatatables
128
128
  end
129
129
 
130
130
  def table_tag_client
131
+ # Should we allow generating datatable only in view
132
+ # <%= ClientDatatable.new(self).render_html do %>
133
+ # <thead>
134
+ # <tr>
135
+ # so we do not need datatable and search route
136
+ # than we just need <table> tag, but it uses datatable to determine page
137
+ # length and order (which in turn it determines from params or
138
+ # preferences)
139
+ # _content_tag(
140
+ # :table,
141
+ # class: "table table-bordered table-striped #{@html_options[:class]}",
142
+ # 'data-datatable': true,
143
+ # 'data-datatable-ajax-url': @search_link,
144
+ # 'data-datatable-page-length': @datatable.dt_per_page_or_default,
145
+ # 'data-datatable-order': @datatable.dt_orders_or_default_index_and_direction.to_json,
146
+ # # for initial page load we do not have ability to show recordsTotal
147
+ # # https://github.com/trkin/trk_datatables_js/issues/1
148
+ # 'data-datatable-total-length': @datatable.filtered_items_count,
149
+ # ) do
131
150
  ''
132
151
  end
133
152
  end
@@ -1,3 +1,3 @@
1
1
  module TrkDatatables
2
- VERSION = '0.2.5'.freeze
2
+ VERSION = '0.2.6'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trk_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dusan Orlovic
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-20 00:00:00.000000000 Z
11
+ date: 2020-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  - !ruby/object:Gem::Version
207
207
  version: '0'
208
208
  requirements: []
209
- rubygems_version: 3.0.3
209
+ rubygems_version: 3.0.8
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: Gem that simplify using datatables with Ruby on Rails and Sinatra.