easy_data_tables 0.3.0 → 0.3.1
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/Gemfile.lock +1 -1
- data/README.md +26 -10
- data/app/models/easy_data_tables/column.rb +24 -10
- data/lib/easy_data_tables/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: 9834be732ee7e650cfdb78dd7fa98b56f27c47d52c337fd651e1395e74ed7bf2
|
4
|
+
data.tar.gz: 7fc26a6bc4c9bc6a207f966bb66f0693ca2a87347a16c17af304e80c4b72e9c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 804d0b118271e64ae2716bdbfaebdf79ab984153c6640888fc47baa1623211913727f631b31248a0530fa196e6c8342aa5a8f6d109dd9a22c9435665239a872c
|
7
|
+
data.tar.gz: 7ec14bdf6fc87f3f2ca391d16ac87ab9830f5cb95ab3ce3f8ca460d59d9ea391a5a8d79618896df7621036b58390f6803bedc8de0aa2487f7dd1654890615690
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,7 @@ Or install it yourself as:
|
|
26
26
|
|
27
27
|
You will have a method available once you install this gem: `easy_data_table(columns, rows, grouping)` in order to expose it, you need to add `helper EasyDataTables::Engine.helpers` to your app's ApplicationController. You can call this helper method in any view and it will output a table with the data you provide.
|
28
28
|
|
29
|
+
### Style
|
29
30
|
In order to access the style of the application add:
|
30
31
|
`@import "easy_data_tables/application";`
|
31
32
|
|
@@ -40,24 +41,29 @@ Columns are an array of hashes. There are three types of columns: 'normal', 'cus
|
|
40
41
|
Normal column hashes accept the following keys:
|
41
42
|
|
42
43
|
- **label**: string, default: '' => will inform the label of the column on the table
|
43
|
-
- **type**: string, default: 'Integer', options: 'Integer', 'Currency', 'Percentage' => will inform the formating of the column
|
44
|
+
- **type**: string, default: 'Integer', options: 'Integer', 'Currency', 'Percentage', 'Date' => will inform the formating of the column
|
44
45
|
- **default**: any, default: 0 => Will inform the default when a value is not found
|
45
46
|
- **collection**: ActiveRecord::Relation, **required** => The data of the column (e.g. User.where(active: true)- -
|
46
47
|
- **agregate_function**: Array of symbols OR symbol, **required** => aggregate function to run (e.g. [:average, :expense] OR :count)
|
47
48
|
- **column_type**: string => will inform the type of column to use
|
49
|
+
- **date_format**: symbol, default: :default => Will inform the formating of the date
|
50
|
+
|
51
|
+
Custom column hashes accept the following keys:
|
48
52
|
|
49
|
-
Custom column hashes accept the following keys:
|
50
53
|
- **label**: string, default: '' => will inform the label of the column on the table
|
51
54
|
- **values**: Hash, keys must coincide with the rows of the table, values are the content that will appear in each cell
|
52
55
|
- **column_type**: string => must be '**custom**'
|
53
56
|
|
57
|
+
NB: A rendered template can be used here for each column (for example to have a form per column)
|
58
|
+
|
54
59
|
Cobmbined column hashes accept the following keys:
|
55
60
|
|
56
61
|
- **label**: string, default: '' => will inform the label of the column on the table
|
57
|
-
- **type**: string, default: 'Integer', options: 'Integer', 'Currency', 'Percentage' => will inform the formating of the column
|
62
|
+
- **type**: string, default: 'Integer', options: 'Integer', 'Currency', 'Percentage', 'Date' => will inform the formating of the column
|
58
63
|
- **columns**: Array, **required** => Will inform the columns to combine (e.g. ['expenditure', 'user_count'])
|
59
64
|
- **method**: string, options: 'rate', 'substract', **required** => how to combine the columns to produce the data cell value
|
60
65
|
- **column_type**: string, **must be set to 'combined'** => will inform the type of column to use
|
66
|
+
- **date_format**: symbol, default: :default => Will inform the formating of the date
|
61
67
|
|
62
68
|
### Rows
|
63
69
|
|
@@ -97,6 +103,11 @@ easy_data_table(
|
|
97
103
|
columns: ['active_user_count', 'user_count'],
|
98
104
|
method: 'rate',
|
99
105
|
label: 'active_user_rate'
|
106
|
+
},
|
107
|
+
{
|
108
|
+
column_type: 'custom',
|
109
|
+
values: {"Premium" => '30 eur', 'Freemium' => '0 eur', 'Premium++' => '60 eur'}
|
110
|
+
label: 'monthly_cost'
|
100
111
|
}
|
101
112
|
],
|
102
113
|
User.all.pluck(:status).uniq,
|
@@ -106,11 +117,11 @@ easy_data_table(
|
|
106
117
|
```
|
107
118
|
will generate a table that looks like this:
|
108
119
|
|
109
|
-
| | User count | Active user count | Active user expense | Active User Rate |
|
110
|
-
|
111
|
-
| Premium | 10 | 8 | 90 $ | 80 % |
|
112
|
-
| Freemium | 5 | 3 | 0 $ | 60 % |
|
113
|
-
| Premium ++ | 3 | 1 | 150 $ | 33.33 % |
|
120
|
+
| | User count | Active user count | Active user expense | Active User Rate | Monthly Cost |
|
121
|
+
|------------|------------|-------------------|---------------------|------------------|---------------|
|
122
|
+
| Premium | 10 | 8 | 90 $ | 80 % | 30 eur |
|
123
|
+
| Freemium | 5 | 3 | 0 $ | 60 % | 0 eur |
|
124
|
+
| Premium ++ | 3 | 1 | 150 $ | 33.33 % | 60 eur |
|
114
125
|
|
115
126
|
The table has the classes : "table" and "datatable"
|
116
127
|
|
@@ -128,6 +139,8 @@ en:
|
|
128
139
|
active_user_expense_title: Sum of the expenses for the active users of each status
|
129
140
|
active_user_rate: Active User Rate
|
130
141
|
active_user_rate_title: % of active users over total users per status
|
142
|
+
monthly_cost: Monthly Cost
|
143
|
+
monthly_cost_title: Monthly Cost
|
131
144
|
download_links:
|
132
145
|
download_formated_csv: Download Formated CSV
|
133
146
|
download_unformated_csv: Download Unformated CSV
|
@@ -163,5 +176,8 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
163
176
|
### v 0.2.0
|
164
177
|
- added possibility of downloading the table as a csv (both formated and unformated)
|
165
178
|
|
166
|
-
### v 0.
|
167
|
-
- added possibility of creating custom
|
179
|
+
### v 0.3.0
|
180
|
+
- added possibility of creating custom columns
|
181
|
+
|
182
|
+
### v 0.3.1
|
183
|
+
- added possibility of formating date columns
|
@@ -13,26 +13,40 @@ module EasyDataTables
|
|
13
13
|
@collection = args[:collection]
|
14
14
|
@grouping = args[:grouping]
|
15
15
|
@agregate_function = args[:agregate_function]
|
16
|
+
@date_format = args[:date_format] || :default
|
16
17
|
@values = construct_values
|
17
18
|
end
|
18
19
|
|
19
20
|
def formated_data_at(row)
|
20
|
-
|
21
|
-
when 'Integer'
|
22
|
-
helpers.number_with_delimiter(data_at(row))
|
23
|
-
when 'Percentage'
|
24
|
-
helpers.number_to_percentage(data_at(row), precision: 2)
|
25
|
-
when 'Currency'
|
26
|
-
helpers.number_to_currency(data_at(row))
|
27
|
-
else
|
28
|
-
data_at(row)
|
29
|
-
end
|
21
|
+
send(@type.downcase, row)
|
30
22
|
end
|
31
23
|
|
32
24
|
def data_at(row)
|
33
25
|
@values[row]
|
34
26
|
end
|
35
27
|
|
28
|
+
protected
|
29
|
+
|
30
|
+
def integer(row)
|
31
|
+
helpers.number_with_delimiter(data_at(row))
|
32
|
+
end
|
33
|
+
|
34
|
+
def percentage(row)
|
35
|
+
helpers.number_to_percentage(data_at(row), precision: 2)
|
36
|
+
end
|
37
|
+
|
38
|
+
def currency(row)
|
39
|
+
helpers.number_to_currency(data_at(row))
|
40
|
+
end
|
41
|
+
|
42
|
+
def date(row)
|
43
|
+
begin
|
44
|
+
I18n.l(data_at(row), format: @date_format)
|
45
|
+
rescue I18n::ArgumentError
|
46
|
+
data_at(row)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
36
50
|
private
|
37
51
|
|
38
52
|
def construct_values
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_data_tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Curell
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Create fast tables based on the models of your db
|
14
14
|
email:
|