trk_datatables 0.1.21 → 0.1.22

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: 77300955004aaab10aa5709dc4879d106c68eabe398b64d404dc12486b270e29
4
- data.tar.gz: 64145170a26243653b16114c10e2915ca41043174b9a7f6f7be78b40affdf6bd
3
+ metadata.gz: 68552088303bb4189ce3e56623313eacf5e0b3d9f4af72ab75209c9caa2d92fc
4
+ data.tar.gz: a0af9029d761be77f52c4fdac363fd8c193eca9329d8ec6e2436cbcffbcb8d0a
5
5
  SHA512:
6
- metadata.gz: 84a24f2a2541ce046bcfab7549f5d4b9e70b5b8bfb63dc7c88b368207bb15d5be7ca5792652fcacc7891e99997b9babc277e62037b7e22cc84ac0f6cedf4a51c
7
- data.tar.gz: 375b132fc647e77513821691f25336613349ee7e96bfe5dbfd07f437622d23af8d7eaee8323a979d61d1543cb83e060738d5641b77720248ba900b0544fae628
6
+ metadata.gz: c20174324e50a8de14ceb878e2051ccdad5f4eca4e9585b8955c59db8e1249be636deb009ba922db481635613b155760dcf0f972fbb536126933352da5cd987f
7
+ data.tar.gz: edb6ea4d2f16b0e84b30d91ab35d202894cca49c917a5a2efbc81b32c5a5888ab57f55b0cdaa342695d118c78fe1a05e7d33553e67317d13ffea5a7dce121088
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trk_datatables (0.1.21)
4
+ trk_datatables (0.1.22)
5
5
  activesupport
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -1,12 +1,23 @@
1
1
  # Trk Datatables
2
2
 
3
- This is a source for [trk_datatables gem](https://rubygems.org/gems/trk_datatables) that you
4
- can use with [trk_datatables npm package](https://www.npmjs.com/package/trk_datatables) for easier usage of [Datatables plug-in for jQuery library](https://datatables.net)
3
+ This is a source for [trk_datatables gem](https://rubygems.org/gems/trk_datatables) that is
4
+ used with [trk_datatables npm package](https://www.npmjs.com/package/trk_datatables) to render tables.
5
5
 
6
- After [configuration](https://github.com/trkin/trk_datatables#configuration) you can use
7
- one line commands (like `@datatable.render_html`) to generate first page in html
8
- (so non-js crawlers can see it), global search, filtering and sorting, adding
9
- map and other complex listing based on GET params.
6
+ Instead of using Rails scaffold generator you can use advanced [Datatables plug-in for jQuery library](https://datatables.net).
7
+
8
+ After [few lines of code](https://github.com/trkin/trk_datatables#installation) you can use
9
+ one line commands `@datatable.render_html` to generate index page that supports:
10
+ global search, filtering and sorting, first page is prerendered (so non-js
11
+ crawlers can see it), adding map and other interesting features.
12
+
13
+ So instead of basic Rails scaffold with a lot of html code
14
+
15
+ ![rails scaffold](test/scaffold.png "Rails default scaffold")
16
+
17
+ You can get something like
18
+
19
+
20
+ ![trk-datatables](test/trk_datatables_with_daterangepicker.png "TRK Datatables")
10
21
 
11
22
  ## Table of Contents
12
23
  <!--ts-->
@@ -36,18 +47,75 @@ map and other complex listing based on GET params.
36
47
 
37
48
  ## Installation
38
49
 
39
- Add this line to your application's Gemfile:
50
+ Let's first add Boostrap js package and https://www.npmjs.com/package/trk_datatables
51
+ ```
52
+ yarn add trk_datatables bootstrap jquery popper.js
40
53
 
41
- ```ruby
42
- # Gemfile
43
- gem 'trk_datatables'
54
+ # app/javascript/packs/application.js
55
+ // node_modules
56
+ import 'bootstrap'
57
+
58
+ // our stuff
59
+ import 'stylesheet/application'
60
+ import 'turbolinks.load'
61
+
62
+ # app/javascript/turbolinks.load.js
63
+ const trkDatatables = require('trk_datatables')
64
+
65
+ document.addEventListener('turbolinks:load', () => {
66
+ // this will initialise all data-datatables elements
67
+ trkDatatables.initialise()
68
+ })
69
+
70
+ # app/views/layouts/application.html.erb
71
+ /* here we include other packages so postcss-import plugin will load css file from style attribute from package.json */
72
+ @import 'bootstrap'
73
+
74
+ # config/webpack/environment.js
75
+ const { environment } = require('@rails/webpacker')
76
+ const webpack = require('webpack');
77
+ environment.plugins.append('Provide', new webpack.ProvidePlugin({
78
+ $: 'jquery',
79
+ jQuery: 'jquery',
80
+ Popper: ['popper.js', 'default']
81
+ }));
82
+
83
+ module.exports = environment
84
+
85
+ # app/views/layouts/application.html.erb
86
+ <%= stylesheet_pack_tag 'application', 'data-turbolinks-track': 'reload' %>
44
87
  ```
45
88
 
46
- You need to create a class that inherits from `TrkDatatables::ActiveRecord` (you
47
- can use Rails generator)
89
+ To add a gem follow those instructions
48
90
 
49
91
  ```
50
- rails g trk_datatables user
92
+ # Gemfile
93
+ gem 'trk_datatables'
94
+
95
+ # in console
96
+ bundle
97
+ rails g trk_datatables post
98
+ vi app/datatables/posts_datatable.rb
99
+
100
+ # config/routes.rb
101
+ resources :posts do
102
+ collection do
103
+ post :search
104
+ end
105
+ end
106
+
107
+ # app/controllers/posts_controller.rb
108
+ def index
109
+ @datatable = PostsDatatable.new view_context
110
+ end
111
+
112
+ def search
113
+ render json: PostsDatatable.new(view_context)
114
+ end
115
+
116
+ # app/views/posts/index.html.erb
117
+ <h1>Posts</h1>
118
+ <%= @datatable.render_html search_posts_path(format: :json) %>
51
119
  ```
52
120
 
53
121
  ## Usage example in Ruby on Rails
@@ -19,10 +19,13 @@ module TrkDatatables
19
19
  PREDEFINED_RANGES = :predefined_ranges
20
20
  HIDE_OPTION = :hide
21
21
  CLASS_NAME = :class_name
22
+ COLUMN_TYPE_IN_DB = :column_type_in_db
22
23
  # this will load date picker
23
24
  # SEARCH_OPTION_DATE_VALUE = :date
24
25
  # SEARCH_OPTION_DATETIME_VALUE = :datetime
25
- COLUMN_OPTIONS = [SEARCH_OPTION, ORDER_OPTION, TITLE_OPTION, SELECT_OPTIONS, PREDEFINED_RANGES, HIDE_OPTION, CLASS_NAME].freeze
26
+ COLUMN_OPTIONS = [SEARCH_OPTION, ORDER_OPTION, TITLE_OPTION, SELECT_OPTIONS,
27
+ PREDEFINED_RANGES, HIDE_OPTION, CLASS_NAME,
28
+ COLUMN_TYPE_IN_DB].freeze
26
29
 
27
30
  # for columns that as calculated in db query
28
31
  STRING_CALCULATED_IN_DB = :string_calculcated_in_db
@@ -93,7 +96,7 @@ module TrkDatatables
93
96
  else
94
97
  table_class = _determine_table_class table_name, column_options[CLASS_NAME]
95
98
 
96
- column_type_in_db = _determine_db_type_for_column(table_class, column_name) unless column_options[SEARCH_OPTION] == false && column_options[ORDER_OPTION] == false
99
+ column_type_in_db = column_options[COLUMN_TYPE_IN_DB] || _determine_db_type_for_column(table_class, column_name) unless column_options[SEARCH_OPTION] == false && column_options[ORDER_OPTION] == false
97
100
  end
98
101
  arr << {
99
102
  column_key: column_key.to_sym,
@@ -1,3 +1,3 @@
1
1
  module TrkDatatables
2
- VERSION = '0.1.21'.freeze
2
+ VERSION = '0.1.22'.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.1.21
4
+ version: 0.1.22
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-01-31 00:00:00.000000000 Z
11
+ date: 2020-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport