effective_datatables 3.0.8 → 3.0.9
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 +8 -0
- data/app/assets/stylesheets/effective_datatables/_overrides.scss +1 -2
- data/app/helpers/effective_datatables_private_helper.rb +1 -0
- data/app/models/effective/datatable_column.rb +4 -0
- data/app/models/effective/datatable_column_tool.rb +2 -2
- data/app/models/effective/datatable_value_tool.rb +2 -2
- data/app/models/effective/effective_datatable/compute.rb +17 -16
- data/app/models/effective/effective_datatable/format.rb +4 -3
- data/config/effective_datatables.rb +3 -0
- data/lib/effective_datatables.rb +1 -0
- data/lib/effective_datatables/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58e4a1ee916c1766e2d3d2be61ffe2607d92c0d4
|
4
|
+
data.tar.gz: b796116f649e7ca0711d7436f50b587d12c47576
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bcd2435e64b3576f7568f126791a77e6c5da1de4a26244b8f290ce4f9d03f43037d23075b7f932e21a3c288a8049c4a0fd9b3b4ec314f1c0498f37edd7f4734
|
7
|
+
data.tar.gz: 5286e5530da18eaea928e8fae7311be484778b6be2694e1d0855c69c61cda7ba74efaa4b62e3fd79e8c7f44d2dbdf50d1b5bd6278ba202052403b3526dc6b518
|
data/README.md
CHANGED
@@ -593,6 +593,14 @@ aggregate :average_as_percentage do |values, column|
|
|
593
593
|
end
|
594
594
|
```
|
595
595
|
|
596
|
+
You can also override an individual columns aggregate calculation as follows:
|
597
|
+
|
598
|
+
```ruby
|
599
|
+
col :created_at, label: 'Created' do |post|
|
600
|
+
time_ago_in_words(post.created_at)
|
601
|
+
end.aggregate { |values, column| distance_of_time_in_words(values.min, values.max) }
|
602
|
+
```
|
603
|
+
|
596
604
|
In the above example, `values` is an Array containing all row's values for one column at a time.
|
597
605
|
|
598
606
|
## filters
|
@@ -147,7 +147,7 @@ table.dataTable.dtr-inline.collapsed > tbody > tr:not(.child) > th:first-child {
|
|
147
147
|
}
|
148
148
|
|
149
149
|
// Column specific adjustments
|
150
|
-
table.dataTable
|
150
|
+
table.dataTable {
|
151
151
|
td.col-price { text-align: right; }
|
152
152
|
td.col-right { text-align: right; }
|
153
153
|
|
@@ -162,5 +162,4 @@ table.dataTable tbody {
|
|
162
162
|
td {
|
163
163
|
p { margin-bottom: 0px; }
|
164
164
|
}
|
165
|
-
|
166
165
|
}
|
@@ -69,6 +69,7 @@ module EffectiveDatatablesPrivateHelper
|
|
69
69
|
wrapper_html: wrapper_html,
|
70
70
|
input_group: false,
|
71
71
|
input_html: input_html,
|
72
|
+
date_linked: false,
|
72
73
|
input_js: { useStrict: true, keepInvalid: true }
|
73
74
|
# Keep invalid format like "2015-11" so we can still search by year, month or day
|
74
75
|
when :select, :boolean
|
@@ -40,7 +40,7 @@ module Effective
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def order_column(collection, direction, column, sql_column)
|
43
|
-
Rails.logger.info "COLUMN TOOL: order_column #{column.to_s} #{direction} #{sql_column}"
|
43
|
+
Rails.logger.info "COLUMN TOOL: order_column #{column.to_s} #{direction} #{sql_column}" if EffectiveDatatables.debug
|
44
44
|
|
45
45
|
if column[:sql_as_column]
|
46
46
|
collection.order("#{sql_column} #{datatable.resource.sql_direction(direction)}")
|
@@ -73,7 +73,7 @@ module Effective
|
|
73
73
|
end
|
74
74
|
|
75
75
|
def search_column(collection, value, column, sql_column)
|
76
|
-
Rails.logger.info "COLUMN TOOL: search_column #{column.to_s} #{value} #{sql_column}"
|
76
|
+
Rails.logger.info "COLUMN TOOL: search_column #{column.to_s} #{value} #{sql_column}" if EffectiveDatatables.debug
|
77
77
|
|
78
78
|
Effective::Resource.new(collection)
|
79
79
|
.search(column[:name], value, as: column[:as], fuzzy: column[:search][:fuzzy], sql_column: sql_column)
|
@@ -37,7 +37,7 @@ module Effective
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def order_column(collection, direction, column, index)
|
40
|
-
Rails.logger.info "VALUE TOOL: order_column :#{column.to_s} :#{direction} #{index}"
|
40
|
+
Rails.logger.info "VALUE TOOL: order_column :#{column.to_s} :#{direction} #{index}" if EffectiveDatatables.debug
|
41
41
|
|
42
42
|
if direction == :asc
|
43
43
|
collection.sort! do |x, y|
|
@@ -69,7 +69,7 @@ module Effective
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def search_column(collection, value, column, index)
|
72
|
-
Rails.logger.info "VALUE TOOL: search_column #{column.to_s} #{value} #{index}"
|
72
|
+
Rails.logger.info "VALUE TOOL: search_column #{column.to_s} #{value} #{index}" if EffectiveDatatables.debug
|
73
73
|
|
74
74
|
fuzzy = column[:search][:fuzzy]
|
75
75
|
term = Effective::Attribute.new(column[:as]).parse(value, name: column[:name])
|
@@ -81,6 +81,8 @@ module Effective
|
|
81
81
|
cols = collection.transpose
|
82
82
|
|
83
83
|
_aggregates.map do |_, aggregate|
|
84
|
+
aggregate[:labeled] = false
|
85
|
+
|
84
86
|
columns.map do |name, opts|
|
85
87
|
next if state[:visible][name] == false && datatables_ajax_request?
|
86
88
|
|
@@ -88,44 +90,43 @@ module Effective
|
|
88
90
|
|
89
91
|
if state[:visible][name] == false
|
90
92
|
BLANK
|
93
|
+
elsif [:bulk_actions, :actions].include?(opts[:as])
|
94
|
+
BLANK
|
95
|
+
elsif values.length == 0
|
96
|
+
BLANK
|
97
|
+
elsif opts[:aggregate]
|
98
|
+
dsl_tool.instance_exec(values, columns[name], &opts[:aggregate])
|
91
99
|
elsif aggregate[:compute]
|
92
100
|
dsl_tool.instance_exec(values, columns[name], &aggregate[:compute])
|
93
101
|
else
|
94
102
|
format_column(aggregate_column(values, opts, aggregate), opts)
|
95
|
-
end
|
103
|
+
end || BLANK
|
96
104
|
end.compact
|
97
105
|
end
|
98
106
|
end
|
99
107
|
|
100
108
|
def aggregate_column(values, column, aggregate)
|
101
|
-
labeled = false
|
102
109
|
length = values.length
|
103
110
|
values = values.reject { |value| value.nil? }
|
104
111
|
|
105
|
-
if [:bulk_actions, :actions].include?(column[:as]) || length == 0
|
106
|
-
return BLANK
|
107
|
-
end
|
108
|
-
|
109
112
|
case aggregate[:name]
|
110
113
|
when :total
|
111
|
-
if
|
114
|
+
if [:percentage].include?(column[:as])
|
115
|
+
BLANK
|
116
|
+
elsif values.all? { |value| value.kind_of?(Numeric) }
|
112
117
|
values.sum
|
113
118
|
elsif values.all? { |value| value == true || value == false }
|
114
|
-
"#{values.count { |val| val == true }}
|
115
|
-
elsif
|
116
|
-
labeled = aggregate[:label]
|
117
|
-
elsif values.any? { |value| value.kind_of?(String) == false }
|
118
|
-
"#{values.flatten.count} total"
|
119
|
+
"#{values.count { |val| val == true }} • #{values.count { |val| val == false}}"
|
120
|
+
elsif aggregate[:labeled] == false
|
121
|
+
aggregate[:labeled] = aggregate[:label]
|
119
122
|
end
|
120
123
|
when :average
|
121
124
|
if values.all? { |value| value.kind_of?(Numeric) }
|
122
125
|
values.sum / [length, 1].max
|
123
126
|
elsif values.all? { |value| value == true || value == false }
|
124
127
|
values.count { |val| val == true } >= (length / 2) ? true : false
|
125
|
-
elsif
|
126
|
-
labeled = aggregate[:label]
|
127
|
-
elsif values.any? { |value| value.kind_of?(String) == false }
|
128
|
-
'-'
|
128
|
+
elsif aggregate[:labeled] == false
|
129
|
+
aggregate[:labeled] = aggregate[:label]
|
129
130
|
end
|
130
131
|
else
|
131
132
|
raise 'not implemented'
|
@@ -54,12 +54,15 @@ module Effective
|
|
54
54
|
def format_column(value, column)
|
55
55
|
return if value.nil?
|
56
56
|
|
57
|
+
unless column[:as] == :email
|
58
|
+
return value if value.kind_of?(String)
|
59
|
+
end
|
60
|
+
|
57
61
|
case column[:as]
|
58
62
|
when :boolean
|
59
63
|
case value
|
60
64
|
when true ; 'Yes'
|
61
65
|
when false ; 'No'
|
62
|
-
when String ; value
|
63
66
|
end
|
64
67
|
when :currency
|
65
68
|
view.number_to_currency(value)
|
@@ -85,13 +88,11 @@ module Effective
|
|
85
88
|
case value
|
86
89
|
when Integer ; "#{value}%"
|
87
90
|
when Numeric ; view.number_to_percentage(value * 100, precision: 2)
|
88
|
-
when String ; value
|
89
91
|
end
|
90
92
|
when :price
|
91
93
|
case value
|
92
94
|
when Integer ; view.number_to_currency(value / 100.0) # an Integer representing the number of cents
|
93
95
|
when Numeric ; view.number_to_currency(value)
|
94
|
-
when String ; value
|
95
96
|
end
|
96
97
|
else
|
97
98
|
value.to_s
|
data/lib/effective_datatables.rb
CHANGED
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: 3.0.
|
4
|
+
version: 3.0.9
|
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: 2017-
|
11
|
+
date: 2017-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|