effective_datatables 4.18.0 → 4.19.0
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/README.md +21 -0
- data/app/assets/javascripts/effective_datatables/filters.js.coffee +88 -0
- data/app/views/effective/datatables/_filter_date_range.html.haml +37 -9
- data/app/views/effective/datatables/_filters.html.haml +1 -1
- data/lib/effective_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: d9a3cae1554f2bcf9b6d73f51972eb1f8bc00c38a30d160c7f8910bf6e339a99
|
4
|
+
data.tar.gz: 72193d4f4895fa60a933c6be50d2d5d6a9d32d5d09a7f60558b130c2042eee1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 321d799d2a21d4e3d19523ef8ae24d8ae62649bd1656afcc90223b26a77409d00dd8bd80a8f15bd40eb07476ea2b1f4a3eb7500f0f44a4a6b0b98553c873ba1d
|
7
|
+
data.tar.gz: f35dc8eeabe695ded08c56d80d1f09cfb18ac1e9925cf55d43870ac121d357543e085e9fdeb14020f92a52f6419de45712a0a663cb4429029ee3edcd9f29e9b4
|
data/README.md
CHANGED
@@ -1131,6 +1131,27 @@ Above we have `resources :things` for the 7 crud actions. And we add two more me
|
|
1131
1131
|
|
1132
1132
|
Your datatable should now have New, Show, Edit, Approve and Reject buttons. Click them for inline functionality.
|
1133
1133
|
|
1134
|
+
## Adding an Ajax member action
|
1135
|
+
|
1136
|
+
To render a member action with an inline datatable:
|
1137
|
+
|
1138
|
+
- Create a "cool_things.html" template and a "_cool_things.html" partial file. Need both.
|
1139
|
+
|
1140
|
+
- The links must be inside an `actions_col` or a `col(:thing, col_class: 'col-actions')` for the javascript to work.
|
1141
|
+
|
1142
|
+
- The action itself just needs to be `data-remote=true`. Try `link_to('Show Cool Things', thing_cool_things_path(thing), 'data-remote': true)`
|
1143
|
+
|
1144
|
+
Make sure the route and permissions are working:
|
1145
|
+
|
1146
|
+
```
|
1147
|
+
resources :things do
|
1148
|
+
get :cool_things, on: :member
|
1149
|
+
```
|
1150
|
+
|
1151
|
+
and `can?(:cool_things, Thing)`
|
1152
|
+
|
1153
|
+
Good luck.
|
1154
|
+
|
1134
1155
|
## Troubleshooting Inline
|
1135
1156
|
|
1136
1157
|
If things aren't working, try the following:
|
@@ -5,3 +5,91 @@ $(document).on 'click', 'a[data-apply-effective-datatables-filters]', (event) ->
|
|
5
5
|
$table = $('#' + $form.attr('aria-controls'))
|
6
6
|
$table.DataTable().draw()
|
7
7
|
|
8
|
+
# Date Filters
|
9
|
+
# This uses moment.js. Sorry.
|
10
|
+
selectMonth = ($filter, date) ->
|
11
|
+
prevDate = date.clone().subtract('1', 'month').startOf('month')
|
12
|
+
startDate = date.clone().startOf('month')
|
13
|
+
endDate = date.clone().endOf('month')
|
14
|
+
nextDate = date.clone().add('1', 'month').startOf('month')
|
15
|
+
|
16
|
+
# Update Previous Button
|
17
|
+
$filter.find('[data-effective-datatables-filter-prev-month]').data('effective-datatables-filter-prev-month', prevDate.format('YYYY-MM-DD'))
|
18
|
+
$filter.find('[data-effective-datatables-filter-prev-month]').find('span.prev-month').text(prevDate.format('MMM'))
|
19
|
+
|
20
|
+
# Update Start and End Dates
|
21
|
+
$filter.find('.start-date').text(startDate.format('YYYY-MM-DD'))
|
22
|
+
$filter.find('.end-date').text(endDate.format('YYYY-MM-DD'))
|
23
|
+
|
24
|
+
# Update Next Button
|
25
|
+
$filter.find('[data-effective-datatables-filter-next-month]').data('effective-datatables-filter-next-month', nextDate.format('YYYY-MM-DD'))
|
26
|
+
$filter.find('[data-effective-datatables-filter-next-month]').find('span.next-month').text(nextDate.format('MMM'))
|
27
|
+
|
28
|
+
# Update hidden inputs
|
29
|
+
$filter.find("input[id='filters_start_date']").data('DateTimePicker').date(startDate.format('YYYY-MM-DD'))
|
30
|
+
$filter.find("input[id='filters_end_date']").data('DateTimePicker').date(endDate.format('YYYY-MM-DD'))
|
31
|
+
|
32
|
+
$table = $('#' + $filter.closest('.effective-datatables-filters').attr('aria-controls'))
|
33
|
+
$table.DataTable().draw()
|
34
|
+
|
35
|
+
$(document).on 'click', 'a[data-effective-datatables-filter-next-month]', (event) ->
|
36
|
+
event.preventDefault()
|
37
|
+
|
38
|
+
$obj = $(event.currentTarget)
|
39
|
+
$filter = $obj.closest('.effective-datatables-filter')
|
40
|
+
date = moment($obj.data('effective-datatables-filter-next-month'))
|
41
|
+
|
42
|
+
selectMonth($filter, date)
|
43
|
+
|
44
|
+
$(document).on 'click', 'a[data-effective-datatables-filter-prev-month]', (event) ->
|
45
|
+
event.preventDefault()
|
46
|
+
|
47
|
+
$obj = $(event.currentTarget)
|
48
|
+
$filter = $obj.closest('.effective-datatables-filter')
|
49
|
+
date = moment($obj.data('effective-datatables-filter-prev-month'))
|
50
|
+
|
51
|
+
selectMonth($filter, date)
|
52
|
+
|
53
|
+
## Years
|
54
|
+
selectYear = ($filter, date) ->
|
55
|
+
prevDate = date.clone().subtract('1', 'year').startOf('year')
|
56
|
+
startDate = date.clone().startOf('year')
|
57
|
+
endDate = date.clone().endOf('year')
|
58
|
+
nextDate = date.clone().add('1', 'year').startOf('year')
|
59
|
+
|
60
|
+
# Update Previous Button
|
61
|
+
$filter.find('[data-effective-datatables-filter-prev-year]').data('effective-datatables-filter-prev-year', prevDate.format('YYYY-MM-DD'))
|
62
|
+
$filter.find('[data-effective-datatables-filter-prev-year]').find('span.prev-year').text(prevDate.format('YYYY'))
|
63
|
+
|
64
|
+
# Update Start and End Dates
|
65
|
+
$filter.find('.start-date').text(startDate.format('YYYY-MM-DD'))
|
66
|
+
$filter.find('.end-date').text(endDate.format('YYYY-MM-DD'))
|
67
|
+
|
68
|
+
# Update Next Button
|
69
|
+
$filter.find('[data-effective-datatables-filter-next-year]').data('effective-datatables-filter-next-year', nextDate.format('YYYY-MM-DD'))
|
70
|
+
$filter.find('[data-effective-datatables-filter-next-year]').find('span.next-year').text(nextDate.format('YYYY'))
|
71
|
+
|
72
|
+
# Update hidden inputs
|
73
|
+
$filter.find("input[id='filters_start_date']").data('DateTimePicker').date(startDate.format('YYYY-MM-DD'))
|
74
|
+
$filter.find("input[id='filters_end_date']").data('DateTimePicker').date(endDate.format('YYYY-MM-DD'))
|
75
|
+
|
76
|
+
$table = $('#' + $filter.closest('.effective-datatables-filters').attr('aria-controls'))
|
77
|
+
$table.DataTable().draw()
|
78
|
+
|
79
|
+
$(document).on 'click', 'a[data-effective-datatables-filter-next-year]', (event) ->
|
80
|
+
event.preventDefault()
|
81
|
+
|
82
|
+
$obj = $(event.currentTarget)
|
83
|
+
$filter = $obj.closest('.effective-datatables-filter')
|
84
|
+
date = moment($obj.data('effective-datatables-filter-next-year'))
|
85
|
+
|
86
|
+
selectYear($filter, date)
|
87
|
+
|
88
|
+
$(document).on 'click', 'a[data-effective-datatables-filter-prev-year]', (event) ->
|
89
|
+
event.preventDefault()
|
90
|
+
|
91
|
+
$obj = $(event.currentTarget)
|
92
|
+
$filter = $obj.closest('.effective-datatables-filter')
|
93
|
+
date = moment($obj.data('effective-datatables-filter-prev-year'))
|
94
|
+
|
95
|
+
selectYear($filter, date)
|
@@ -31,17 +31,45 @@
|
|
31
31
|
= f.static_field :year do
|
32
32
|
#{now.beginning_of_year.strftime('%F')} to #{now.strftime('%F')} (today)
|
33
33
|
|
34
|
+
= f.show_if :date_range, :year do
|
35
|
+
= f.static_field :year, wrapper: { class: 'effective-datatables-filter' } do
|
36
|
+
- date = f.object.start_date.beginning_of_year
|
37
|
+
|
38
|
+
= link_to '#', 'data-effective-datatables-filter-prev-year': date.advance(years: -1).strftime('%F') do
|
39
|
+
= icon('arrow-left-circle')
|
40
|
+
%span.prev-year= date.advance(years: -1).strftime('%Y')
|
41
|
+
|
42
|
+
%span.start-date= f.object.start_date.strftime('%F')
|
43
|
+
to
|
44
|
+
%span.end-date= f.object.end_date.strftime('%F')
|
45
|
+
|
46
|
+
= link_to '#', 'data-effective-datatables-filter-next-year': date.advance(years: 1).strftime('%F') do
|
47
|
+
= icon('arrow-right-circle')
|
48
|
+
%span.next-year= date.advance(years: 1).strftime('%Y')
|
49
|
+
|
50
|
+
%div{style: 'display: none;'}
|
51
|
+
= f.date_field :start_date, name: name, autocomplete: 'off', feedback: false
|
52
|
+
= f.date_field :end_date, name: name, autocomplete: 'off', feedback: false
|
53
|
+
|
34
54
|
= f.show_if :date_range, :month do
|
35
|
-
= f.static_field :month do
|
36
|
-
|
37
|
-
#{start_date.beginning_of_month.strftime('%F')} to #{start_date.end_of_month.strftime('%F')}
|
38
|
-
= link_to((icon('arrow-right-circle') + ' ' + next_month.strftime('%b %Y')).html_safe, next_month_path.sub(path, request.path))
|
55
|
+
= f.static_field :month, wrapper: { class: 'effective-datatables-filter' } do
|
56
|
+
- date = f.object.start_date.beginning_of_month
|
39
57
|
|
40
|
-
=
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
=
|
58
|
+
= link_to '#', 'data-effective-datatables-filter-prev-month': date.advance(months: -1).strftime('%F') do
|
59
|
+
= icon('arrow-left-circle')
|
60
|
+
%span.prev-month= date.advance(months: -1).strftime('%b')
|
61
|
+
|
62
|
+
%span.start-date= f.object.start_date.strftime('%F')
|
63
|
+
to
|
64
|
+
%span.end-date= f.object.end_date.strftime('%F')
|
65
|
+
|
66
|
+
= link_to '#', 'data-effective-datatables-filter-next-month': date.advance(months: 1).strftime('%F') do
|
67
|
+
= icon('arrow-right-circle')
|
68
|
+
%span.next-month= date.advance(months: 1).strftime('%b')
|
69
|
+
|
70
|
+
%div{style: 'display: none;'}
|
71
|
+
= f.date_field :start_date, name: name, autocomplete: 'off', feedback: false
|
72
|
+
= f.date_field :end_date, name: name, autocomplete: 'off', feedback: false
|
45
73
|
|
46
74
|
= f.show_if :date_range, :custom do
|
47
75
|
.row
|
@@ -1,6 +1,6 @@
|
|
1
1
|
.effective-datatables-filters{'aria-controls': datatable.to_param}
|
2
2
|
|
3
|
-
= effective_form_with(model: datatable.filters_form, scope: :filters, url: (datatable._form[:url] || '#'), method: datatable._form[:verb], id: nil) do |form|
|
3
|
+
= effective_form_with(model: datatable.filters_form, scope: :filters, url: (datatable._form[:url] || '#'), method: datatable._form[:verb], id: nil, authenticity_token: datatable._filters_form_required?) do |form|
|
4
4
|
.form-row.align-items-center
|
5
5
|
- if datatable._scopes.present?
|
6
6
|
= datatable_scope_tag(form, datatable)
|
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.
|
4
|
+
version: 4.19.0
|
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: 2023-
|
11
|
+
date: 2023-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|