effective_datatables 2.5.0 → 2.5.1
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
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cc8bee1f23053d54e283c7300a106c2357014c4
|
4
|
+
data.tar.gz: e433bbad08218dc5e13c2ffc58449dbec5a7cefa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d360f64c24af9e92337d89c86b3670e3b6d2b7ec1bd1fb1bd66b6ef358da4cb23de97492edc487cdcd5628a6d02369e127b4b4b95e3d6c4a2a45f9623b740935
|
7
|
+
data.tar.gz: 692685e7a4543fbf591754fd615f1b2b4ccad5bbf55e39806c099b1c2e8ce27b4a3f1e5c1266ef688744b52128446abc1dad907b78954f1b7ee4a65f5bbc8035
|
data/README.md
CHANGED
@@ -555,6 +555,12 @@ def collection
|
|
555
555
|
end
|
556
556
|
```
|
557
557
|
|
558
|
+
As well, you need to change the controller where you define the datatable to be aware of the scope params.
|
559
|
+
|
560
|
+
```ruby
|
561
|
+
@datatable = Effective::Datatables::Posts.new(params[:scopes])
|
562
|
+
```
|
563
|
+
|
558
564
|
So initially, the `:start_date` will have the value of `Time.zone.now-3.months` and when submitted by the form, the value will be set there.
|
559
565
|
|
560
566
|
The form value will come back as a string, so you may need to `Time.zone.parse` that value.
|
@@ -5,8 +5,9 @@ module Effective
|
|
5
5
|
# This will respond to both a GET and a POST
|
6
6
|
def show
|
7
7
|
attributes = (params[:attributes].presence || {}).merge(referer: request.referer)
|
8
|
+
scopes = (params[:scopes].presence || {})
|
8
9
|
|
9
|
-
@datatable = find_datatable(params[:id]).try(:new, attributes)
|
10
|
+
@datatable = find_datatable(params[:id]).try(:new, attributes.merge(scopes))
|
10
11
|
@datatable.view = view_context if !@datatable.nil?
|
11
12
|
|
12
13
|
EffectiveDatatables.authorized?(self, :index, @datatable.try(:collection_class) || @datatable.try(:class))
|
@@ -5,7 +5,7 @@ module Effective
|
|
5
5
|
# These two options control the render behaviour of a datatable
|
6
6
|
attr_accessor :table_html_class, :simple
|
7
7
|
|
8
|
-
delegate :render, :controller, :link_to, :mail_to, :number_to_currency, :to => :@view
|
8
|
+
delegate :render, :controller, :link_to, :mail_to, :number_to_currency, :number_to_percentage, :to => :@view
|
9
9
|
|
10
10
|
include Effective::EffectiveDatatable::Dsl
|
11
11
|
extend Effective::EffectiveDatatable::Dsl::ClassMethods
|
@@ -23,8 +23,8 @@ module Effective
|
|
23
23
|
end
|
24
24
|
|
25
25
|
initialize_datatable # This creates @table_columns based on the DSL datatable do .. end block
|
26
|
+
initialize_scopes # This normalizes scopes, and copies scope default values to attributes
|
26
27
|
initialize_options # This normalizes all the options
|
27
|
-
initialize_scopes # This normalizes scopes, and copies scopes to attributes
|
28
28
|
|
29
29
|
unless active_record_collection? || array_collection?
|
30
30
|
raise "Unsupported collection type. Should be ActiveRecord class, ActiveRecord relation, or an Array of Arrays [[1, 'something'], [2, 'something else']]"
|
@@ -119,22 +119,6 @@ module Effective
|
|
119
119
|
@view = view_context
|
120
120
|
@view.formats = [:html]
|
121
121
|
|
122
|
-
# Set any scopes
|
123
|
-
if @view.params[:scopes].kind_of?(Hash)
|
124
|
-
@view.params[:scopes].each do |name, value|
|
125
|
-
next unless scopes.key?(name)
|
126
|
-
|
127
|
-
if scopes[name][:fallback] || scopes[name][:presence]
|
128
|
-
value = value.presence || scopes[name][:default]
|
129
|
-
end
|
130
|
-
|
131
|
-
self.attributes[name] = value
|
132
|
-
|
133
|
-
self.scopes[name][:filter][:input_html] ||= HashWithIndifferentAccess.new
|
134
|
-
self.scopes[name][:filter][:input_html][:value] = value
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
122
|
# 'Just work' with attributes
|
139
123
|
@view.class.send(:attr_accessor, :attributes)
|
140
124
|
@view.attributes = self.attributes
|
@@ -19,23 +19,28 @@ module Effective
|
|
19
19
|
protected
|
20
20
|
|
21
21
|
# The scope DSL is
|
22
|
-
# scope :start_date, default_value, options {}
|
22
|
+
# scope :start_date, default_value, options: {}
|
23
|
+
#
|
24
|
+
# The value might already be assigned, but if not, we have to assign the default to attributes
|
23
25
|
|
24
26
|
# A scope comes to us like {:start_date => {default: Time.zone.now, filter: {as: :select, collection: ... input_html :}}}
|
25
27
|
# We want to make sure an input_html: { value: default } exists
|
26
28
|
def initialize_scope_options(scopes)
|
27
29
|
(scopes || []).each do |name, options|
|
30
|
+
value = attributes.key?(name) ? attributes[name] : options[:default]
|
31
|
+
|
28
32
|
options[:filter] ||= HashWithIndifferentAccess.new()
|
29
33
|
options[:filter][:input_html] ||= HashWithIndifferentAccess.new()
|
30
|
-
options[:filter][:input_html][:value] =
|
31
|
-
end
|
34
|
+
options[:filter][:input_html][:value] = value
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
36
|
+
if attributes.key?(name) == false
|
37
|
+
self.attributes[name] = options[:default]
|
38
|
+
end
|
37
39
|
|
38
|
-
|
40
|
+
if (options[:fallback] || options[:presence]) && attributes[name].blank? && attributes[name] != false
|
41
|
+
self.attributes[name] = options[:default]
|
42
|
+
end
|
43
|
+
end
|
39
44
|
end
|
40
45
|
|
41
46
|
def initialize_column_options(cols)
|
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: 2.5.
|
4
|
+
version: 2.5.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: 2016-06-
|
11
|
+
date: 2016-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|