trk_datatables 0.2.2 → 0.2.3
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/Gemfile.lock +1 -1
- data/README.md +22 -9
- data/lib/trk_datatables/active_record.rb +3 -3
- data/lib/trk_datatables/neo4j.rb +15 -2
- data/lib/trk_datatables/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2dc7cec68c0ec6e71ac428ac6a966f3db8ddc102d63c226dc52f619f10a5d41d
|
|
4
|
+
data.tar.gz: 8ba50a886703bced435b29b696e35915215bfe018b6a5bd2a77c2b48568b0e4e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e1931363aa5fceb1393d961203b7c67d27e5dbe7ad8f4c45875e2c919ec1547257f0309ce68208f1cbfe58ad494168223c8958727cc5f875d15d702522aaf113
|
|
7
|
+
data.tar.gz: e15ac3cc6eab551c55010e10fa9f39d465a35266ed07d2e9817f39d72c978e20648e8fef43d8a23467cb515d7ab83e2b33908b46e9d8813c65a3c6659923da44
|
data/Gemfile.lock
CHANGED
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
|
-
|
|
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
|
|
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
|
|
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`
|
|
417
|
-
|
|
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
|
-
|
|
428
|
-
|
|
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
|
-
|
|
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
|
-
|
|
43
|
+
_filter_column_as_string(column_key_option, search_value)
|
|
44
44
|
end
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
def
|
|
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',
|
data/lib/trk_datatables/neo4j.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
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.
|
|
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-
|
|
11
|
+
date: 2020-09-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|