effective_datatables 4.18.0 → 4.19.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +21 -0
- data/app/assets/javascripts/effective_datatables/filters.js.coffee +88 -0
- data/app/controllers/effective/datatables_controller.rb +2 -2
- data/app/models/effective/datatable_dsl_tool.rb +9 -13
- 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: 1f5e3d8ed9d497dea48da82cc800596e4b43500d7b85030d1fced300f846218d
|
4
|
+
data.tar.gz: c9b2b959192a337aa876830f1c4c9d7b5d6b8f58f89b1ca0812be995ab050e45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c045b22d3482ef816c21f157c7cf2fc113f6434a8f0f01a7467f3cff494b1d3dda4dbce680166dc5298c8bb5723f4b3b49ec22679a48c06db792d0752435f67
|
7
|
+
data.tar.gz: 250528bb18da5a76ba3d9c1d567d56bea5e58e8093f24bb23e55c8b6821e8f58c24c60a714e245bf5312d5de069c3aaef90d061eec161facefb72765b57c65fd
|
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)
|
@@ -15,7 +15,7 @@ module Effective
|
|
15
15
|
EffectiveDatatables.authorize!(self, :index, @datatable.collection_class)
|
16
16
|
|
17
17
|
render json: @datatable.to_json
|
18
|
-
rescue => e
|
18
|
+
rescue Exception => e
|
19
19
|
EffectiveDatatables.authorized?(self, :index, @datatable.try(:collection_class))
|
20
20
|
render json: error_json(e)
|
21
21
|
|
@@ -84,7 +84,7 @@ module Effective
|
|
84
84
|
render status: :ok, body: :ok
|
85
85
|
rescue Effective::AccessDenied => e
|
86
86
|
render(status: :unauthorized, body: 'Access Denied')
|
87
|
-
rescue => e
|
87
|
+
rescue Exception => e
|
88
88
|
render(status: :error, body: 'Unexpected Error')
|
89
89
|
end
|
90
90
|
|
@@ -24,20 +24,16 @@ module Effective
|
|
24
24
|
raise "#{method} block must be declared outside the datatable do ... end block"
|
25
25
|
end
|
26
26
|
|
27
|
-
if datatable.respond_to?(method)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
view.send(method, *args, **kwargs) { yield }
|
36
|
-
else
|
37
|
-
view.send(method, *args, **kwargs)
|
38
|
-
end
|
27
|
+
subject = datatable if datatable.respond_to?(method)
|
28
|
+
subject ||= view if view.respond_to?(method)
|
29
|
+
subject ||= Tenant.helpers if defined?(Tenant) && Tenant.helpers.respond_to?(method)
|
30
|
+
|
31
|
+
return super unless subject
|
32
|
+
|
33
|
+
if block_given?
|
34
|
+
subject.send(method, *args, **kwargs) { yield }
|
39
35
|
else
|
40
|
-
|
36
|
+
subject.send(method, *args, **kwargs)
|
41
37
|
end
|
42
38
|
end
|
43
39
|
|
@@ -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.1
|
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-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|