trk_datatables 0.2.2 → 0.2.3

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
  SHA256:
3
- metadata.gz: 3ccb77ab8bb5b29b22c346044bdb06171bed27a50721873cd1d5ec619c8ef1f1
4
- data.tar.gz: 0d747920ac2dd280c0274dd46af82c59afd7c55151910e598d97d64ac2447a6d
3
+ metadata.gz: 2dc7cec68c0ec6e71ac428ac6a966f3db8ddc102d63c226dc52f619f10a5d41d
4
+ data.tar.gz: 8ba50a886703bced435b29b696e35915215bfe018b6a5bd2a77c2b48568b0e4e
5
5
  SHA512:
6
- metadata.gz: a2ce8344fdb8912d0116b5c21695b62cc83292f91a2987917ac78b3ff30c45793be8634b46354d9bb50e5181fa30469d4dcfddf4ed8de64deaba938eaaac29d4
7
- data.tar.gz: a4e65f172f9916df7b79fcfc9d084975564623f915dacbfef017521dd8c7a66a5b54a885fab14362b049a6f43b9f30caa1f7e2e4d13e4b16aaed0e145a40dc86
6
+ metadata.gz: e1931363aa5fceb1393d961203b7c67d27e5dbe7ad8f4c45875e2c919ec1547257f0309ce68208f1cbfe58ad494168223c8958727cc5f875d15d702522aaf113
7
+ data.tar.gz: e15ac3cc6eab551c55010e10fa9f39d465a35266ed07d2e9817f39d72c978e20648e8fef43d8a23467cb515d7ab83e2b33908b46e9d8813c65a3c6659923da44
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trk_datatables (0.2.2)
4
+ trk_datatables (0.2.3)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -62,9 +62,10 @@ import 'bootstrap'
62
62
 
63
63
  // our stuff
64
64
  import 'stylesheet/application'
65
- import 'turbolinks.load'
66
65
 
67
- # app/javascript/turbolinks.load.js
66
+ // attach jQuery so it is available for javascript included with asset pipeline
67
+ window.$ = window.jQuery = jQuery;
68
+
68
69
  const trkDatatables = require('trk_datatables')
69
70
 
70
71
  document.addEventListener('turbolinks:load', () => {
@@ -88,7 +89,11 @@ environment.plugins.append('Provide', new webpack.ProvidePlugin({
88
89
  module.exports = environment
89
90
 
90
91
  # app/views/layouts/application.html.erb
92
+ <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
93
+ <%# we need stylesheet for production server, locally it could work without stylesheet_pack_tag even in production mode %>
91
94
  <%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
95
+ <%# we use jQuery from wepbacker so asset pipeline should be included later %>
96
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
92
97
  ```
93
98
 
94
99
  Than add a gem and sample PostsDatatable
@@ -408,13 +413,17 @@ generated based on other columns):
408
413
  posts_count FROM "users" LEFT OUTER JOIN "posts" ON "posts"."user_id" =
409
414
  "users"."id" GROUP BY users.id`
410
415
 
411
- Since in SQL you can not use aggregate functions in WHERE (we can repeat
416
+ Since in SQL you can not use aggregate functions in WHERE (we should repeat
412
417
  calculation and subqueries), currently TrkDatatables does not support using
413
418
  aggregate functions since it requires implementation of `HAVING` (unless you
414
- disable search and order `'users.posts_count': { search: false, order: false }`).
419
+ disable search and order for those fields with aggregate functions
420
+ `'users.posts_count': { search: false, order: false }`).
415
421
  You can use concatenation aggregate function: in postgres `STRING_AGG`, in mysql
416
- `GROUP_CONCAT` since we search in real columns and show concatenation (we do not
417
- search concatenation like we need to search new field `post_count`).
422
+ `GROUP_CONCAT` so in this case we search on real columns. For example let's we
423
+ have `Post.select(%(posts.*, GROUP_CONCAT(comments.body) AS
424
+ comments_body)).left_outer_joins(:comments) .group('posts.id')` and that we have
425
+ a row `postName, comment1, comment2` than when we searh for `comment2` we will
426
+ get a row `postName, comment2`.
418
427
 
419
428
  Simple calculations and subqueries works fine, just you have to use public
420
429
  method to define calculation (that method is also used in filtering). Name of
@@ -424,8 +433,12 @@ name you should use one of:
424
433
  `:date_calculated_in_db`, `:datetime_calculated_in_db` or
425
434
  `:boolean_calculated_in_db`.
426
435
 
427
- Before we give an example there is an issue in calling `all.count` if you are
428
- using subquery so we need to patch ActiveRecord
436
+ There is an issue in calling `all.count` when you are using subquery, or
437
+ selecting two columns `User.select(:id, :email).count`, or using star in string
438
+ `User.select('users.*').count` (although `User.select(Arel.star).count` works),
439
+ using AS `User.select('users.id AS i').count` (here arel does not help, still
440
+ raise exception `User.select(User.arel_table[:email].as('imejl')).count`).
441
+ We need to patch ActiveRecord to define `returns_count_sum`:
429
442
  ```
430
443
  # config/initializers/active_record_group_count.rb
431
444
  # When you are using subquery or joins/group_by than all.count does not work
@@ -774,8 +787,8 @@ release a new version, update the version number and then publish with
774
787
 
775
788
  ```
776
789
  vi lib/trk_datatables/version.rb
777
- git commit -am'...'
778
790
  bundle
791
+ git commit -am'...'
779
792
  bundle exec rake release
780
793
  ```
781
794
 
@@ -5,7 +5,7 @@ module TrkDatatables
5
5
  def filter_by_search_all(filtered)
6
6
  conditions = @dt_params.search_all.split(' ').map do |search_string|
7
7
  @column_key_options.searchable_and_global_search.map do |column_key_option|
8
- filter_column_as_string column_key_option, search_string
8
+ _filter_column_as_string column_key_option, search_string
9
9
  end.reduce(:or) # any searchable column is 'or'-ed
10
10
  end.reduce(:and) # 'and' for each search_string
11
11
 
@@ -40,11 +40,11 @@ module TrkDatatables
40
40
  from, to = search_value.split BETWEEN_SEPARATOR
41
41
  filter_column_as_between(column_key_option, from, to)
42
42
  else
43
- filter_column_as_string(column_key_option, search_value)
43
+ _filter_column_as_string(column_key_option, search_value)
44
44
  end
45
45
  end
46
46
 
47
- def filter_column_as_string(column_key_option, search_value)
47
+ def _filter_column_as_string(column_key_option, search_value)
48
48
  search_value.split(' ').map do |search_string|
49
49
  casted_column = ::Arel::Nodes::NamedFunction.new(
50
50
  'CAST',
@@ -1,7 +1,14 @@
1
1
  module TrkDatatables
2
2
  class Neo4j < Base
3
3
  def filter_by_search_all(filtered)
4
- filtered
4
+ return filtered unless @dt_params.search_all.present?
5
+
6
+ # https://neo4jrb.readthedocs.io/en/stable/QueryClauseMethods.html?highlight=where#where
7
+ sql = @column_key_options.searchable_and_global_search.map do |column_key_option|
8
+ "#{column_key_option[:column_key]} =~ ?"
9
+ end.join(' or ')
10
+
11
+ filtered.where sql, ".*#{@dt_params.search_all}.*"
5
12
  end
6
13
 
7
14
  def filter_by_columns(all)
@@ -15,7 +22,13 @@ module TrkDatatables
15
22
  end
16
23
 
17
24
  def order_items(filtered)
18
- filtered
25
+ order_by = dt_orders_or_default_index_and_direction.each_with_object([]) do |(index, direction), queries|
26
+ column_key_option = @column_key_options[index]
27
+ next if column_key_option[:column_options][ColumnKeyOptions::ORDER_OPTION] == false
28
+
29
+ queries << "#{column_key_option[:column_key]} #{direction}"
30
+ end
31
+ filtered.order(order_by.join(', '))
19
32
  end
20
33
  end
21
34
  end
@@ -1,3 +1,3 @@
1
1
  module TrkDatatables
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.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.2
4
+ version: 0.2.3
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-09-03 00:00:00.000000000 Z
11
+ date: 2020-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport