effective_datatables 4.8.14 → 4.8.15

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: 065a97713aa78f1febed39ab02736af303742cc15a691fa556f60225035bdc91
4
- data.tar.gz: dcfe7909bd5e6a30a16ca700bdaf01721ca95590a58b36ee20c5f17f446faa36
3
+ metadata.gz: 21c974538c4d1f563649f55c956ee568196acb3db15e7555c4aad0d0c2da9a2b
4
+ data.tar.gz: '0159f6dd253f33578b0d897268ce302cc0302af5ff6b7f097f905b75bb1100fa'
5
5
  SHA512:
6
- metadata.gz: ea4bd624315535fd4eca9ae8abef4176c10fc7033e0dc45cf2d6fa56a439dad5adbf81a5249d727b02c0e4a0f6d799710779fd69b8d80aaab779c2b3dadb716c
7
- data.tar.gz: 075defd26c55ed28f71dc6a8becd9efb71c2edf51799c56568b8fbfc612689e95b0cf3bdfe7b7447eb858261b11a1878366792074ba254cef7b2c0e0cb6eaecb
6
+ metadata.gz: 92fb13082dcbed02030a1238830f6e3341825fb80cba2636306244405ff0fbbfd4bd2e05dead6bf61cc63de7ea59f544dd566e007bb91ecdc8a9e6b9d8d3df25
7
+ data.tar.gz: 821d5f2cb5707cc5001dac816fd6f85d4e6a39d48dae724b236975f1b647cbb0cbad3ac48c41701dcc91cf6510da1854ad316620796c9f5c10fecc9417babb98
data/README.md CHANGED
@@ -8,7 +8,7 @@ Does the right thing with searching sql columns as well as computed values from
8
8
 
9
9
  Displays links to associated edit/show/destroy actions based on `current_user` authorized actions.
10
10
 
11
- Other features include aggregate (total/average) footer rows, bulk actions, show/hide columns, responsive collapsing columns and Google charts.
11
+ Other features include aggregate (total/average) footer rows, bulk actions, show/hide columns, responsive collapsing columns, google charts, and inline crud.
12
12
 
13
13
  This gem includes the jQuery DataTables assets.
14
14
 
@@ -54,7 +54,8 @@ Please check out [Effective Datatables 3.x](https://github.com/code-and-effect/e
54
54
  * [bulk_action](#bulk_action_divider)
55
55
  * [bulk_download](#bulk_download)
56
56
  * [bulk_action_content](#bulk_action_content)
57
- * [charts](#charts)
57
+ * [Charts](#charts)
58
+ * [Inline](#inline)
58
59
  * [Extras](#extras)
59
60
  * [Advanced Search and Sort](#advanced-search-and-sort)
60
61
  * [Addtional Functionality](#additional-functionality)
@@ -453,7 +454,7 @@ The `datatable do ... end` block configures a table of data.
453
454
 
454
455
  Initialize the datatable in your controller or view, `@datatable = PostsDatatable.new(self)`, and render it in your view `<%= render_datatable(@datatable) %>`
455
456
 
456
- ### col
457
+ ## col
457
458
 
458
459
  This is the main DSL method that you will interact with.
459
460
 
@@ -526,7 +527,7 @@ You can also use the joined syntax, `col 'user.email'` to create a column for ju
526
527
 
527
528
  This feature is only working with `belongs_to` and you need to add the `.joins(:user)` to the collection do ... end block yourself.
528
529
 
529
- ### val
530
+ ## val
530
531
 
531
532
  Shorthand for value, this command also creates a column on the datatable.
532
533
 
@@ -548,7 +549,7 @@ This is implemented as a full Array search/sort and is much slower for large dat
548
549
 
549
550
  The `.format do ... end` block can then be used to apply custom formatting.
550
551
 
551
- ### bulk_actions_col
552
+ ## bulk_actions_col
552
553
 
553
554
  Creates a column of checkboxes for use with the `bulk_actions` section.
554
555
 
@@ -558,7 +559,7 @@ Use these checkboxes to select all / none / one or more rows for the `bulk_actio
558
559
 
559
560
  You can only have one `bulk_actions_col` per datatable.
560
561
 
561
- ### actions_col
562
+ ## actions_col
562
563
 
563
564
  When working with an ActiveRecord based collection, this column will consider the `current_user`'s authorization, and generate links to edit, show and destroy actions for any collection class.
564
565
 
@@ -596,7 +597,7 @@ Any `data-remote` actions will be hijacked and performed as inline ajax by datat
596
597
 
597
598
  If you'd like to opt-out of this behavior, use `actions_col(inline: false)` or add `data-inline: false` to your action link.
598
599
 
599
- ### length
600
+ ## length
600
601
 
601
602
  Sets the default number of rows per page. Valid lengths are `5`, `10`, `25`, `50`, `100`, `250`, `500`, `:all`
602
603
 
@@ -606,7 +607,7 @@ When not specified, effective_datatables uses the default as per the `config/ini
606
607
  length 100
607
608
  ```
608
609
 
609
- ### order
610
+ ## order
610
611
 
611
612
  Sets the default order of table rows. The first argument is the column, the second the direction.
612
613
 
@@ -618,7 +619,7 @@ When not specified, effective_datatables will sort by the first defined column.
618
619
  order :created_at, :asc|:desc
619
620
  ```
620
621
 
621
- ### reorder
622
+ ## reorder
622
623
 
623
624
  Enables drag-and-drop row re-ordering.
624
625
 
@@ -636,7 +637,7 @@ reorder :position
636
637
 
637
638
  Using `reorder` will sort the collection by this field and disable all other column sorting.
638
639
 
639
- ### aggregate
640
+ ## aggregate
640
641
 
641
642
  The `aggregate` command inserts a row in the table's `tfoot`.
642
643
 
@@ -681,7 +682,7 @@ The form is submitted by an AJAX POST action, or, in some advanced circumstances
681
682
 
682
683
  Initialize the datatable in your controller or view, `@datatable = PostsDatatable.new(self)`, and render its filters anywhere with `<%= render_datatable_filters(@datatable) %>`.
683
684
 
684
- ### scope
685
+ ## scope
685
686
 
686
687
  All defined scopes are rendered as a single radio button form field. Works great with the [effective_form_inputs](https://github.com/code-and-effect/effective_form_inputs) gem.
687
688
 
@@ -705,7 +706,7 @@ class Post < ApplicationRecord | ActiveRecord::Base
705
706
  end
706
707
  ```
707
708
 
708
- ### filter
709
+ ## filter
709
710
 
710
711
  Each filter has a name and a default/fallback value. If the form is submitted blank, the default values are used.
711
712
 
@@ -758,7 +759,7 @@ Creates a single dropdown menu with a link to each action, download or content.
758
759
 
759
760
  Along with this section, you must put a `bulk_actions_col` somewhere in your `datatable do ... end` section.
760
761
 
761
- ### bulk_action
762
+ ## bulk_action
762
763
 
763
764
  Creates a link that becomes clickable when one or more checkbox/rows are selected as per the `bulk_actions_col` column.
764
765
 
@@ -814,11 +815,11 @@ def approve!
814
815
  end
815
816
  ```
816
817
 
817
- ### bulk_action_divider
818
+ ## bulk_action_divider
818
819
 
819
820
  Inserts a menu divider `<li class='divider' role='separator'></li>`
820
821
 
821
- ### bulk_download
822
+ ## bulk_download
822
823
 
823
824
  So it turns out there are some http issues with using an AJAX action to download a file.
824
825
 
@@ -859,7 +860,7 @@ def bulk_export_report
859
860
  end
860
861
  ```
861
862
 
862
- ### bulk_action_content
863
+ ## bulk_action_content
863
864
 
864
865
  Blindly inserts content into the dropdown.
865
866
 
@@ -873,7 +874,7 @@ end
873
874
 
874
875
  Don't actually use this.
875
876
 
876
- ## charts
877
+ # Charts
877
878
 
878
879
  Create a [Google Chart](https://developers.google.com/chart/interactive/docs/quick_start) based on your searched collection, filters and attributes.
879
880
 
@@ -930,11 +931,169 @@ All options passed to `chart` are used to initialize the chart javascript.
930
931
 
931
932
  By default, the only package that is loaded is `corechart`, see the `config/initializers/effective_datatables.rb` file to add more packages.
932
933
 
933
- ## Extras
934
+ # Inline
935
+
936
+ Any datatable can be used as an inline datatable, to create, update and destroy resources without leaving the current page.
937
+
938
+ If your datatable is already working with `actions_col` and being rendered from an `Effective::CrudController` controller, all you need to do is change your view from `render_datatable(@datatable)` to `render_datatable(@datatable, inline: true)`.
939
+
940
+ Click here for a [Inline Live Demo](https://effective-datatables-demo.herokuapp.com/things) and here for an [Inline Code Example](https://github.com/code-and-effect/effective_datatables_demo)
941
+ (only the `thing` data model and `things_datatable` are being used inline)
942
+
943
+ To use effective_datatables as an inline CRUD builder, you will be relying heavily on [effective_resources](https://github.com/code-and-effect/effective_resources) which is a dependency of this gem. I would also recommend you install [effective_developer](https://github.com/code-and-effect/effective_developer) to get access to some scaffolds and generators. It's not required but I'm gonna use them in this example.
944
+
945
+ Here is how I build rails models for inline datatable CRUD operations:
946
+
947
+ 1. Create a new model file `app/models/thing.rb`:
948
+
949
+ ```ruby
950
+ class Thing < ApplicationRecord
951
+ belongs_to :user
952
+
953
+ effective_resource do
954
+ title :string
955
+ description :text
956
+ timestamps
957
+ end
958
+
959
+ scope :deep, -> { includes(:user) }
960
+ scope :sorted, -> { order(:title) }
961
+
962
+ def to_s
963
+ title
964
+ end
965
+ end
966
+ ```
967
+
968
+ The `effective_resource do` block comes from the [effective_resources](https://github.com/code-and-effect/effective_resources) gem and is used to build any permitted_params.
969
+
970
+ 2. Generate a migration. Run `rails generate effective:migration things` to create a migration based off the model file then `rails db:migrate`.
971
+
972
+ 3. Scaffold the rest. Run `rails generate effective:scaffold_controller things` which will create:
973
+
974
+ - A controller `app/controllers/things_controller.rb`:
975
+
976
+ ```ruby
977
+ class ThingsController < ApplicationController
978
+ include Effective::CrudController
979
+ end
980
+ ```
981
+
982
+ The Effective::CrudController comes from [effective_resources](https://github.com/code-and-effect/effective_resources) gem and handles the standard 7 CRUD actions and member and collection actions. It is opinionated code that follows rails conventions. It considers the `routes.rb` and `ability.rb` or other authorization, to find all available actions.
983
+
984
+ - A datatable `app/datatables/things_datatable.rb`:
985
+
986
+ ```ruby
987
+ class ThingsDatatable < Effective::Datatable
988
+ datatable do
989
+ col :title
990
+ col :description
991
+ actions_col
992
+ end
993
+
994
+ collection do
995
+ Thing.deep.all
996
+ end
997
+ end
998
+ ```
999
+
1000
+ This is an ordinary datatable. As long as it's an ActiveRecord collection, inline crud will work.
1001
+
1002
+ - A view partial `app/views/things/_thing.html.haml`:
1003
+
1004
+ ```ruby
1005
+ %table.table
1006
+ %tbody
1007
+ %tr
1008
+ %th Title
1009
+ %td= thing.title
1010
+ %tr
1011
+ %th Description
1012
+ %td= thing.description
1013
+ ```
1014
+
1015
+ This file is what rails uses when you call `render(thing)` and what datatables uses for the inline `show` action. It's important that its called `_thing.html`.
1016
+
1017
+ - A form partial `app/views/things/_form.html.haml`:
1018
+
1019
+ ```ruby
1020
+ = effective_form_with(model: thing) do |f|
1021
+ = f.text_field :title
1022
+ = f.text_area :description
1023
+ = f.submit
1024
+ ```
1025
+
1026
+ The `effective_form_with` comes from [effective_bootstrap](https://github.com/code-and-effect/effective_bootstrap) gem and is a drop-in replacement for the newer `form_with` syntax. It's really good, you should use it, but an ordinary `form_with` will work here just fine.
1027
+
1028
+ This `_form.html` is an effective gems convention. This file must exist for your resource.
1029
+
1030
+ - A resources entry in `config/routes.rb`:
1031
+
1032
+ ```ruby
1033
+ Rails.application.routes.draw do
1034
+ resources :things do
1035
+ post :approve, on: :member
1036
+ post :reject, on: :member
1037
+ end
1038
+ end
1039
+ ```
1040
+
1041
+ Above we have `resources :things` for the 7 crud actions. And we add two more member actions, which datatables will call `approve!` or `reject!` on thing.
1042
+
1043
+
1044
+ 4. Render in the view. Create an `app/views/things/index.html.haml` and call `render_datatable(@datatable, inline: true)` or `render_inline_datatable(@datatable).
1045
+
1046
+ ```ruby
1047
+ = render_datatable(@datatable, inline: true)
1048
+ ```
1049
+
1050
+ Your datatable should now have New, Show, Edit, Approve and Reject buttons. Click them for inline functionality.
1051
+
1052
+ ## Troubleshooting Inline
1053
+
1054
+ If things aren't working, try the following:
1055
+
1056
+ - Double check your javascripts:
1057
+
1058
+ ```ruby
1059
+ //= require jquery3
1060
+ //= require popper
1061
+ //= require bootstrap
1062
+ //= require effective_bootstrap
1063
+ //= require effective_datatables
1064
+ //= require jquery_ujs
1065
+ ```
1066
+
1067
+ The inline functionality requires one of sprockets jquery_ujs, sprockets rails_ujs or webpack @rails/ujs libraries.
1068
+
1069
+ - Double check your stylesheets:
1070
+
1071
+ ```ruby
1072
+ @import 'bootstrap';
1073
+ @import 'effective_bootstrap';
1074
+ @import 'effective_datatables';
1075
+ ```
1076
+
1077
+ - Make sure your datatable is not being rendered inside a `<form>...</form>` tag. It will display a javascript console error and won't work.
1078
+
1079
+ - Double check your `resources :things` are in `routes.rb` in the same namespace as the controller, and that you have authorization for those actions in `ability.rb` or whatever your `config/initializers/effective_datatables.rb` `config.authorization_method` returns.
1080
+
1081
+ ## A note on how it works
1082
+
1083
+ We use good old `rails_ujs` for all inline actions.
1084
+
1085
+ When inline, any of the actions_col actions, as well as the New button, will be changed into `data-remote: true` actions.
1086
+
1087
+ The [inline_crud javascript](https://github.com/code-and-effect/effective_datatables/blob/master/app/assets/javascripts/effective_datatables/inline_crud.js.coffee) handles fetching the form, or view partial and expanding/collapsing the appropriate row of the datatable.
1088
+
1089
+ When an inline action is clicked, effective_datatables will make an AJAX request to the server, which could be received by an `Effective::CrudController` that will handle the `.js` format, and respond_with the appropriate [rails_ujs .js.erb views](https://github.com/code-and-effect/effective_resources/tree/master/app/views/application).
1090
+
1091
+
1092
+ # Extras
934
1093
 
935
1094
  The following commands don't quite fit into the DSL, but are present nonetheless.
936
1095
 
937
- ### simple
1096
+ ## simple
938
1097
 
939
1098
  To render a simple table, without pagination, sorting, filtering, export buttons, per page, and default visibility:
940
1099
 
@@ -942,7 +1101,7 @@ To render a simple table, without pagination, sorting, filtering, export buttons
942
1101
  <%= render_datatable(@datatable, simple: true) %>
943
1102
  ```
944
1103
 
945
- ### index
1104
+ ## index
946
1105
 
947
1106
  If you just want to render a datatable and nothing else, there is a quick way to skip creating a view:
948
1107
 
@@ -956,13 +1115,13 @@ end
956
1115
 
957
1116
  will render `views/effective/datatables/index` with the assigned datatable.
958
1117
 
959
- ## Advanced Search and Sort
1118
+ # Advanced Search and Sort
960
1119
 
961
1120
  The built-in search and ordering can be overridden on a per-column basis.
962
1121
 
963
1122
  The only gotcha here is that you must be aware of the type of collection.
964
1123
 
965
- ### With ActiveRecord collection
1124
+ ## With ActiveRecord collection
966
1125
 
967
1126
  In the case of a `col` and an ActiveRecord collection:
968
1127
 
@@ -994,7 +1153,7 @@ If `column[:sql_column].blank?` then this `col` has fallen back to being a `val`
994
1153
 
995
1154
  Try adding `col :post_category, sql_column: 'post_categories.title'`
996
1155
 
997
- ### With Array collection
1156
+ ## With Array collection
998
1157
 
999
1158
  And in the case of a `col` with an Array collection, or any `val`:
1000
1159
 
@@ -1033,7 +1192,7 @@ end
1033
1192
 
1034
1193
  The search and sort for each column will be merged together to form the final results.
1035
1194
 
1036
- ### Default search collection
1195
+ ## Default search collection
1037
1196
 
1038
1197
  When using a `col :comments` type belongs_to or has_many column, a search collection for that class will be loaded.
1039
1198
 
@@ -200,6 +200,7 @@ initializeDataTables = (target) ->
200
200
 
201
201
  table.addClass('initialized')
202
202
  table.children('thead').trigger('effective-bootstrap:initialize')
203
+ table.children('thead').find('input[autofocus]').first().focus()
203
204
  true
204
205
 
205
206
  destroyDataTables = ->
@@ -1,8 +1,9 @@
1
1
  .btn-group.buttons-bulk-actions
2
2
  %button.btn.btn-link.btn-sm.dropdown-toggle{'type': 'button', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false, 'disabled': 'disabled'}
3
- Bulk Actions
3
+ = t('effective_datatables.bulk_actions')
4
4
  .dropdown-menu
5
5
  - if datatable._bulk_actions.present?
6
6
  = datatable._bulk_actions.join.html_safe
7
7
  - else
8
- %a.dropdown-item{href: '#'} No bulk actions
8
+ %a.dropdown-item{href: '#'}
9
+ = t('effective_datatables.no_bulk_actions')
@@ -7,6 +7,7 @@ en:
7
7
  new: New
8
8
  actions: Actions
9
9
  bulk_actions: Bulk Actions
10
+ no_bulk_actions: No bulk actions
10
11
  applying: Applying...
11
12
  boolean_true: 'Yes'
12
13
  boolean_false: 'No'
@@ -7,6 +7,7 @@ es:
7
7
  new: Nuevo
8
8
  actions: Acciones
9
9
  bulk_actions: Acciones en masa
10
+ no_bulk_actions: Sin acciones en masa
10
11
  applying: Filtrando...
11
12
  boolean_true: 'Sí'
12
13
  boolean_false: 'No'
@@ -7,6 +7,7 @@ nl:
7
7
  new: Nieuwe
8
8
  actions: Acties
9
9
  bulk_actions: Bulkacties
10
+ no_bulk_actions: Geen bulkacties
10
11
  applying: Toepassen...
11
12
  boolean_true: 'Ja'
12
13
  boolean_false: 'Nee'
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.8.14'.freeze
2
+ VERSION = '4.8.15'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_datatables
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.14
4
+ version: 4.8.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-15 00:00:00.000000000 Z
11
+ date: 2021-01-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails