table_on_steroids 0.1.0.5 → 0.1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +88 -1
- data/app/controllers/concerns/table_on_steroids/table_concern.rb +21 -5
- data/app/views/table_on_steroids/_table_on_steroids.html.erb +3 -2
- data/app/views/table_on_steroids/_table_on_steroids_filters.html.erb +1 -1
- data/lib/table_on_steroids/version.rb +1 -1
- data/vendor/assets/images/csv.png +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d4edd10e8041898d2a51d6ce362e6317579c0e16f8862bff1fcbc82f1111ff2
|
4
|
+
data.tar.gz: c51917c51b558e9a4a158b8e5d3ed688064e945a44c689be91a3c759e23ee719
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f83e38d52722c6bcac3b3a9078a3a6bcc38f88200b50632348d207af53c6f15f48cd4e80abe2cab53cc0fd5eef17dcc7dfbca094bd88c465f85c0512006f845
|
7
|
+
data.tar.gz: 2666272c49fc25c18b35a175d61c83553d96f818229dfbfde48fac496b47b71c35bdce376a0a5d5c33cd654ded83b5d29fc9ff36d8744c89c63db82a503c61f9
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -22,7 +22,94 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
### Add assets
|
26
|
+
|
27
|
+
application.js
|
28
|
+
|
29
|
+
```
|
30
|
+
//= require table_on_steroids
|
31
|
+
```
|
32
|
+
|
33
|
+
application.scss
|
34
|
+
```
|
35
|
+
@import "table_on_steroids";
|
36
|
+
```
|
37
|
+
|
38
|
+
### In the controller
|
39
|
+
#### Add the concern
|
40
|
+
|
41
|
+
```
|
42
|
+
require 'table_on_steroids'
|
43
|
+
include TableOnSteroids::TableConcern
|
44
|
+
```
|
45
|
+
|
46
|
+
#### Define a global search (optional)*
|
47
|
+
```
|
48
|
+
def global_search
|
49
|
+
@global_search_lambda ||= nil #put whatever lambda you want here -> (objects, query) { objects.deep_search(query) }
|
50
|
+
end
|
51
|
+
```
|
52
|
+
|
53
|
+
#### Define your columns
|
54
|
+
|
55
|
+
The columns are defined by a hash:
|
56
|
+
Key: a key defining the column
|
57
|
+
|
58
|
+
options:
|
59
|
+
- *label*: column title
|
60
|
+
- *type*:
|
61
|
+
- *value_lambda*: how to get the value of this object. "context" is the view context. You can use it to call view methods (eg: `context.link_to` ... ; `context.render` ...)
|
62
|
+
- array : array lambdas for search and order
|
63
|
+
- filter_lambda
|
64
|
+
- order_lambda
|
65
|
+
- search_lambda
|
66
|
+
- activerecord : activerecord lambdas for search and order
|
67
|
+
- filter_lambda
|
68
|
+
- order_lambda
|
69
|
+
- search_lambda
|
70
|
+
|
71
|
+
|
72
|
+
```
|
73
|
+
def columns_on_steroid
|
74
|
+
@columns_on_steroid ||= {
|
75
|
+
'email' => {
|
76
|
+
label: "email",
|
77
|
+
type: 'order',
|
78
|
+
array: {
|
79
|
+
order_lambda: -> (objects) { objects.sort_by{ |o| o.user.email.downcase } }
|
80
|
+
},
|
81
|
+
activerecord: {
|
82
|
+
search_lambda: -> (objects, v) { objects.joins(:user).where('users.email ilike ?', ("%" + v + "%")) }
|
83
|
+
},
|
84
|
+
value_lambda: -> (object, context) { object.user.email }
|
85
|
+
}, ..
|
86
|
+
```
|
87
|
+
#### Use the columns to search and order
|
88
|
+
```
|
89
|
+
@objects = filter_and_order(@objects, columns_on_steroid, global_search)
|
90
|
+
```
|
91
|
+
#### Use the columns to create a csv
|
92
|
+
add *download_value_lambda* to your table columns
|
93
|
+
```
|
94
|
+
table_csv(@objects , columns_on_steroid_fulfillment)
|
95
|
+
```
|
96
|
+
|
97
|
+
### In the view
|
98
|
+
|
99
|
+
Render the table
|
100
|
+
|
101
|
+
```
|
102
|
+
= render partial: 'table_on_steroids/table_on_steroids', locals: { objects: @objects, columns: @columns_on_steroid}
|
103
|
+
|
104
|
+
```
|
105
|
+
|
106
|
+
_locals extra options:_
|
107
|
+
- title
|
108
|
+
- download_csv: the link of the download csv
|
109
|
+
- table_on_steroid_id
|
110
|
+
- omit_columns
|
111
|
+
|
112
|
+
|
26
113
|
|
27
114
|
## Development
|
28
115
|
|
@@ -27,6 +27,7 @@
|
|
27
27
|
#
|
28
28
|
#####
|
29
29
|
require 'kaminari'
|
30
|
+
require 'csv'
|
30
31
|
|
31
32
|
module TableOnSteroids
|
32
33
|
module TableConcern
|
@@ -35,8 +36,8 @@ module TableOnSteroids
|
|
35
36
|
included do
|
36
37
|
OBJECTS_PER_PAGE = 50
|
37
38
|
end
|
38
|
-
|
39
|
-
def filter_and_order(objects, columns_on_steroid, global_search=nil, include_counts=false )
|
39
|
+
|
40
|
+
def filter_and_order(objects, columns_on_steroid, global_search=nil, include_counts=false, all_pages=false )
|
40
41
|
# execute the global search if you have one
|
41
42
|
objects = global_search.call(objects,params[:search]) if global_search && params[:search].present?
|
42
43
|
|
@@ -69,7 +70,7 @@ module TableOnSteroids
|
|
69
70
|
end
|
70
71
|
|
71
72
|
#pagination
|
72
|
-
|
73
|
+
return (include_counts ? [objects, 1, objects.count] : objects) if all_pages
|
73
74
|
if(objects.is_a?(ActiveRecord::Base) || objects.is_a?(ActiveRecord::Relation))
|
74
75
|
objects = objects.page(params[:page]).per(OBJECTS_PER_PAGE)
|
75
76
|
total_pages = objects.total_pages
|
@@ -82,8 +83,23 @@ module TableOnSteroids
|
|
82
83
|
end
|
83
84
|
include_counts ? [objects, total_pages, total_count] : objects
|
84
85
|
end
|
85
|
-
|
86
|
-
|
86
|
+
|
87
|
+
def table_csv(objects, columns_on_steroid)
|
88
|
+
titles = []
|
89
|
+
csvs = CSV.generate do |csv|
|
90
|
+
columns_on_steroid.select{ |c,v| v[:download_value_lambda].present? }.each{ |c,v| ((v[:download_label].present?) ? titles.push(*v[:download_label]) : titles << v[:label]) }
|
91
|
+
csv << titles
|
92
|
+
objects.each do |o|
|
93
|
+
vals = []
|
94
|
+
columns_on_steroid.select{ |c,v| v[:download_value_lambda].present? }.each do |c,v|
|
95
|
+
vals.push(*v[:download_value_lambda].call(o))
|
96
|
+
end
|
97
|
+
csv << vals
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
|
87
103
|
def objects_where(objects, columns_on_steroid, t)
|
88
104
|
columns_on_steroid.select{
|
89
105
|
|c,v| v[t] && v[t][:search_lambda].present? }.each{
|
@@ -10,6 +10,7 @@
|
|
10
10
|
<% title ||= nil %>
|
11
11
|
<% subtext ||= nil %>
|
12
12
|
<% subtext_partial ||= nil %>
|
13
|
+
<% csv_image ||= nil %>
|
13
14
|
<% param_hash = CGI::parse(request.query_string) %>
|
14
15
|
<% expected_column_keys = columns.map{|col,col_values| col }+columns.map{|col,col_values|("search_" + col)}+columns.map{|col,col_values|("search_operator_" + col)} %>
|
15
16
|
<div class="table-on-steroids" id="<%= table_on_steroid_id %>">
|
@@ -54,8 +55,8 @@
|
|
54
55
|
</div>
|
55
56
|
<% if(download_csv) %>
|
56
57
|
<div class="float-right">
|
57
|
-
<a href="<%= (download_csv + "?filter=#{request.query_string.to_s}") %>" style="float:right">
|
58
|
-
<%= image_tag "csv.png", :height => "25", :style => "padding-top:5px;" %>
|
58
|
+
<a href="<%= (download_csv + "?filter=#{request.query_string.to_s}") %>" style="float:right" target="_blank">
|
59
|
+
<%= image_tag csv_image || "csv.png", :height => "25", :style => "padding-top:5px;" %>
|
59
60
|
</a>
|
60
61
|
</div>
|
61
62
|
<% end %>
|
@@ -3,7 +3,7 @@
|
|
3
3
|
<% columns_on_steroid.each_pair do | k , v | %>
|
4
4
|
<td class="column column-<%= k %> <%= 'd-none' unless selected_columns.include?(k) %> filter-cell-left <%= v[:css_class].join(' ') if(v[:css_class]) %> <%= table_on_steroid_id %>">
|
5
5
|
<% if v[:type] == 'filter' %>
|
6
|
-
<%= select_tag("filters[#{k}]", options_for_select(v[:select_values], params[:filters] && params[:filters][k]), multiple: v[:multiselect], class: '
|
6
|
+
<%= select_tag("filters[#{k}]", options_for_select(v[:select_values], params[:filters] && params[:filters][k]), multiple: v[:multiselect], class: 'form-control filter-control', form: "knowledge_base_filters#{table_on_steroid_id}", data: { "none-selected-text" => v[:label], style: 'table-on-steroids-selectpicker ', table_on_steroid_id: table_on_steroid_id}, table_on_steroid_id: table_on_steroid_id ) %>
|
7
7
|
<% elsif((v[:activerecord].present? && v[:activerecord][:search_lambda].present?) || (v[:array].present? && v[:array][:search_lambda].present?)) %>
|
8
8
|
<% operator_present = (v[:datatype].present? && ['date','integer'].include?(v[:datatype])) %>
|
9
9
|
<% if operator_present %>
|
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table_on_steroids
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marieke Gueye
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-05-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bootstrap-datepicker-rails
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/table_on_steroids.rb
|
127
127
|
- lib/table_on_steroids/version.rb
|
128
128
|
- table_on_steroids.gemspec
|
129
|
+
- vendor/assets/images/csv.png
|
129
130
|
- vendor/assets/javascripts/table_on_steroids.js
|
130
131
|
- vendor/assets/stylesheets/table_on_steroids.scss
|
131
132
|
homepage: http://www.github.com/mariekou
|