smart_table 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +171 -0
- data/LICENSE.txt +21 -0
- data/README.md +132 -0
- data/app/assets/javascripts/smart_table.js +137 -0
- data/app/assets/stylesheets/smart_table.scss +85 -0
- data/app/controllers/concerns/smart_table/smart_table_concern.rb +58 -0
- data/app/helpers/smart_table/smart_table_helper.rb +211 -0
- data/app/views/kaminari/smart_table/_first_page.html.erb +12 -0
- data/app/views/kaminari/smart_table/_gap.html.erb +8 -0
- data/app/views/kaminari/smart_table/_last_page.html.erb +12 -0
- data/app/views/kaminari/smart_table/_next_page.html.erb +12 -0
- data/app/views/kaminari/smart_table/_page.html.erb +10 -0
- data/app/views/kaminari/smart_table/_paginator.html.erb +25 -0
- data/app/views/kaminari/smart_table/_prev_page.html.erb +12 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/config/locales/smart_table.en.yml +25 -0
- data/config/locales/smart_table.pt.yml +25 -0
- data/lib/generators/init_generator.rb +16 -0
- data/lib/generators/templates/smart_table_initializer.rb +6 -0
- data/lib/smart_table/config.rb +15 -0
- data/lib/smart_table/engine.rb +21 -0
- data/lib/smart_table/version.rb +3 -0
- data/lib/smart_table.rb +28 -0
- data/smart_table-0.0.1.gem +0 -0
- data/smart_table.gemspec +33 -0
- data/spec/dummy_app/Rakefile +6 -0
- data/spec/dummy_app/app/assets/config/manifest.js +3 -0
- data/spec/dummy_app/app/assets/javascripts/application.js +15 -0
- data/spec/dummy_app/app/assets/javascripts/cable.js +13 -0
- data/spec/dummy_app/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy_app/app/channels/application_cable/channel.rb +4 -0
- data/spec/dummy_app/app/channels/application_cable/connection.rb +4 -0
- data/spec/dummy_app/app/controllers/application_controller.rb +2 -0
- data/spec/dummy_app/app/helpers/application_helper.rb +2 -0
- data/spec/dummy_app/app/jobs/application_job.rb +2 -0
- data/spec/dummy_app/app/mailers/application_mailer.rb +4 -0
- data/spec/dummy_app/app/models/application_record.rb +3 -0
- data/spec/dummy_app/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy_app/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy_app/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy_app/bin/bundle +3 -0
- data/spec/dummy_app/bin/rails +4 -0
- data/spec/dummy_app/bin/rake +4 -0
- data/spec/dummy_app/bin/setup +36 -0
- data/spec/dummy_app/bin/update +31 -0
- data/spec/dummy_app/bin/yarn +11 -0
- data/spec/dummy_app/config/application.rb +17 -0
- data/spec/dummy_app/config/boot.rb +5 -0
- data/spec/dummy_app/config/cable.yml +10 -0
- data/spec/dummy_app/config/database.yml +25 -0
- data/spec/dummy_app/config/environment.rb +5 -0
- data/spec/dummy_app/config/environments/development.rb +61 -0
- data/spec/dummy_app/config/environments/production.rb +94 -0
- data/spec/dummy_app/config/environments/test.rb +46 -0
- data/spec/dummy_app/config/initializers/application_controller_renderer.rb +8 -0
- data/spec/dummy_app/config/initializers/assets.rb +14 -0
- data/spec/dummy_app/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy_app/config/initializers/content_security_policy.rb +25 -0
- data/spec/dummy_app/config/initializers/cookies_serializer.rb +5 -0
- data/spec/dummy_app/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy_app/config/initializers/inflections.rb +16 -0
- data/spec/dummy_app/config/initializers/mime_types.rb +4 -0
- data/spec/dummy_app/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy_app/config/locales/en.yml +33 -0
- data/spec/dummy_app/config/puma.rb +34 -0
- data/spec/dummy_app/config/routes.rb +3 -0
- data/spec/dummy_app/config/spring.rb +6 -0
- data/spec/dummy_app/config/storage.yml +34 -0
- data/spec/dummy_app/config.ru +5 -0
- data/spec/dummy_app/db/test.sqlite3 +0 -0
- data/spec/dummy_app/log/test.log +0 -0
- data/spec/dummy_app/package.json +5 -0
- data/spec/dummy_app/public/404.html +67 -0
- data/spec/dummy_app/public/422.html +67 -0
- data/spec/dummy_app/public/500.html +66 -0
- data/spec/dummy_app/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy_app/public/apple-touch-icon.png +0 -0
- data/spec/dummy_app/public/favicon.ico +0 -0
- data/spec/rails_helper.rb +13 -0
- data/spec/smart_table/app/controllers/concerns/smart_table_concern_spec.rb +104 -0
- data/spec/smart_table/app/helpers/smart_table_helper_spec.rb +48 -0
- data/spec/smart_table/lib/config_spec.rb +18 -0
- data/spec/smart_table/lib/engine_spec.rb +12 -0
- data/spec/smart_table_spec.rb +26 -0
- data/spec/spec_helper.rb +20 -0
- metadata +263 -0
@@ -0,0 +1,211 @@
|
|
1
|
+
module SmartTable
|
2
|
+
module SmartTableHelper
|
3
|
+
|
4
|
+
# include Kaminari helpers, like paginate
|
5
|
+
include Kaminari::Helpers::HelperMethods
|
6
|
+
|
7
|
+
# Renders pagination controls (centered, usually below the table). Usage:
|
8
|
+
#
|
9
|
+
# <%= smart_table_paginate @records, @total_records_count, Record.model_name.human %>
|
10
|
+
#
|
11
|
+
# This method requires the loaded records for the current page and the total
|
12
|
+
# record count (sum of all pages). It also requires the listed record's human
|
13
|
+
# name, so it can generate a human sentence for the number of records shown.
|
14
|
+
#
|
15
|
+
# When the user clicks on one of the page size's links, a new request to the
|
16
|
+
# index action is made, including a page number parameter available through
|
17
|
+
# smart_table_params.limit and smart_table_params.offset.
|
18
|
+
#
|
19
|
+
# These values can be passed to ActiveRecord directly, e.g.:
|
20
|
+
#
|
21
|
+
# @records = Record.
|
22
|
+
# limit(smart_table_params.limit).
|
23
|
+
# offset(smart_table_params.offset)
|
24
|
+
|
25
|
+
def smart_table_paginate(records, total_records_count, record_model_name)
|
26
|
+
raise 'smart_table_params must be called on the controller, before using smart_table_paginate helper' unless get_cached_smart_table_params
|
27
|
+
|
28
|
+
paginatable_array = Kaminari.
|
29
|
+
paginate_array(records, total_count: total_records_count).
|
30
|
+
page(get_cached_smart_table_params.page_number).
|
31
|
+
per(get_cached_smart_table_params.page_size)
|
32
|
+
|
33
|
+
html_elements = []
|
34
|
+
|
35
|
+
# call to Kaminari view helper
|
36
|
+
html_elements << paginate(paginatable_array, param_name: PAGE_PARAM, theme: "smart_table")
|
37
|
+
|
38
|
+
html_elements << content_tag(:div, class: 'text-center') do
|
39
|
+
# call to Kaminari view helper
|
40
|
+
page_entries_info(paginatable_array, entry_name: record_model_name.downcase)
|
41
|
+
end
|
42
|
+
|
43
|
+
html_elements.join.html_safe
|
44
|
+
end
|
45
|
+
|
46
|
+
SORT_ORDERS = ["asc", "desc"]
|
47
|
+
|
48
|
+
# Renders table header with sortable feature. Usage:
|
49
|
+
#
|
50
|
+
# <th><%= smart_table_sortable("Header Text", :attribute_name) %></th>
|
51
|
+
#
|
52
|
+
# This will generate a link that will make a new request to your index page,
|
53
|
+
# including a sort parameter that will be available through smart_table_params.sort.
|
54
|
+
# You can simply pass this parameter to ActiveRecord:
|
55
|
+
#
|
56
|
+
# @records = Record.order(smart_table_params.sort)
|
57
|
+
|
58
|
+
def smart_table_sortable(text, attribute)
|
59
|
+
raise 'smart_table_params must be called on the controller, before using smart_table_sortable helper' unless get_cached_smart_table_params
|
60
|
+
|
61
|
+
current_sort_state = get_cached_smart_table_params.sort
|
62
|
+
attribute = attribute.to_s
|
63
|
+
|
64
|
+
current_sort_attribute, current_sort_order = if current_sort_state.present?
|
65
|
+
current_sort_state.downcase.split
|
66
|
+
else
|
67
|
+
nil
|
68
|
+
end
|
69
|
+
|
70
|
+
next_sort_order = if current_sort_attribute == attribute
|
71
|
+
SORT_ORDERS[(SORT_ORDERS.index(current_sort_order) + 1) % SORT_ORDERS.size]
|
72
|
+
else
|
73
|
+
SORT_ORDERS.first
|
74
|
+
end
|
75
|
+
|
76
|
+
link_url = current_request_url_with_merged_query_params(SORT_PARAM => "#{attribute} #{next_sort_order}")
|
77
|
+
link_to link_url do
|
78
|
+
text.html_safe + ' ' + (
|
79
|
+
if current_sort_attribute == attribute && current_sort_order == 'asc'
|
80
|
+
"<span class='fa fa-sort-down'></span>".html_safe
|
81
|
+
elsif current_sort_attribute == attribute && current_sort_order == 'desc'
|
82
|
+
"<span class='fa fa-sort-up'></span>".html_safe
|
83
|
+
else
|
84
|
+
"<span class='fa fa-sort'></span>".html_safe
|
85
|
+
end
|
86
|
+
)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# Renders table page size selector (centered, usually below the table). Usage:
|
91
|
+
#
|
92
|
+
# <%= smart_table_page_size_selector @total_records_count, Record.model_name.human %>
|
93
|
+
#
|
94
|
+
# This method requires the total number of records, so it can prune the list
|
95
|
+
# of available page size to only the ones that make sense for a certain
|
96
|
+
# number of records. It also requires the listed record's human name, so
|
97
|
+
# it can generate a human sentence for the number of records shown.
|
98
|
+
#
|
99
|
+
# When the user clicks on one of the page size's links, a new request to the
|
100
|
+
# index action is made, including a page size parameter available through
|
101
|
+
# smart_table_params.limit and smart_table_params.offset.
|
102
|
+
#
|
103
|
+
# These values can be passed to ActiveRecord directly, e.g.:
|
104
|
+
#
|
105
|
+
# @records = Record.
|
106
|
+
# limit(smart_table_params.limit).
|
107
|
+
# offset(smart_table_params.offset)
|
108
|
+
|
109
|
+
|
110
|
+
def smart_table_page_size_selector(total_records_count, record_model_name)
|
111
|
+
raise 'smart_table_params must be called on the controller, before using smart_table_page_size_selector helper' unless get_cached_smart_table_params
|
112
|
+
|
113
|
+
page_sizes = PAGE_SIZES.dup
|
114
|
+
page_sizes << get_cached_smart_table_params.page_size.to_i if get_cached_smart_table_params.page_size
|
115
|
+
page_sizes.sort!
|
116
|
+
|
117
|
+
if page_sizes.last >= total_records_count || get_cached_smart_table_params.page_size.nil?
|
118
|
+
page_sizes.reject! {|size| size > total_records_count}
|
119
|
+
page_sizes << SHOW_ALL
|
120
|
+
end
|
121
|
+
|
122
|
+
content_tag(:div, class: 'text-center') do
|
123
|
+
(
|
124
|
+
record_model_name.pluralize + ' ' +
|
125
|
+
I18n.t('smart_table.per_page') + ': ' +
|
126
|
+
page_sizes.map do |page_size|
|
127
|
+
if page_size == get_cached_smart_table_params.page_size
|
128
|
+
page_size.to_s
|
129
|
+
else
|
130
|
+
human_page_size = (page_size == SHOW_ALL ? I18n.t('smart_table.show_all') : page_size.to_s)
|
131
|
+
link_to human_page_size, current_request_url_with_merged_query_params(PAGE_SIZE_PARAM => page_size)
|
132
|
+
end
|
133
|
+
end.join(' ')
|
134
|
+
).html_safe
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
# Renders search field (right-aligned, usually above the table). Usage:
|
139
|
+
#
|
140
|
+
# <div>
|
141
|
+
# <%= smart_table_search %>
|
142
|
+
# </div>
|
143
|
+
#
|
144
|
+
# <table class='table'>
|
145
|
+
# <thead>
|
146
|
+
# ...
|
147
|
+
#
|
148
|
+
# When the user types something on the search field and focuses out (or
|
149
|
+
# presses ENTER), a new request is made to the index action, including a
|
150
|
+
# search parameter available through smart_table_params.search.
|
151
|
+
#
|
152
|
+
# You are responsible for using the search parameter to build a query in your
|
153
|
+
# own way e.g.:
|
154
|
+
#
|
155
|
+
# @records = Record.
|
156
|
+
# where(
|
157
|
+
# 'column1 LIKE ? OR column2 LIKE ?',
|
158
|
+
# *Array.new(2, "%#{ActiveRecord::Base.sanitize_sql_like(smart_table_params.search)}%")
|
159
|
+
# )
|
160
|
+
|
161
|
+
def smart_table_search
|
162
|
+
raise 'smart_table_params must be called on the controller, before using smart_table_search helper' unless get_cached_smart_table_params
|
163
|
+
|
164
|
+
text_field_tag(
|
165
|
+
SEARCH_PARAM,
|
166
|
+
get_cached_smart_table_params.search,
|
167
|
+
type: 'search', placeholder: I18n.t('smart_table.search'), class: 'smart_table_search', id: 'smart_table_search'
|
168
|
+
)
|
169
|
+
end
|
170
|
+
|
171
|
+
# Creates section for extra table filters. Usage:
|
172
|
+
#
|
173
|
+
# <%= smart_table_extra_filters do %>
|
174
|
+
# <%= check_box_tag 'somekey', 'value', params['somekey'] %>
|
175
|
+
# <%= select_tag "credit_card", options_for_select({"VISA" => 'visa', "MasterCard" => 'master_card'}, params['credit_card']) %>
|
176
|
+
# <%= text_field_tag "somefield", params['somefield'] %>
|
177
|
+
# <%= radio_button_tag("category", "", !params["category"].present?) %>
|
178
|
+
# <%= radio_button_tag("category", "rails", params["category"] == 'rails') %>
|
179
|
+
# <%= radio_button_tag("category", "java", params["category"] == 'java') %>
|
180
|
+
# <% end %>
|
181
|
+
#
|
182
|
+
# Everytime the user changes any of the fields inside this section, the page
|
183
|
+
# will be refreshed and the field value will be included to the request params.
|
184
|
+
#
|
185
|
+
# You are responsible for using the parameters by yourself when loading the
|
186
|
+
# records.
|
187
|
+
|
188
|
+
def smart_table_extra_filters(&block)
|
189
|
+
raise 'smart_table_params must be called on the controller, before using smart_table_extra_filters helper' unless get_cached_smart_table_params
|
190
|
+
|
191
|
+
content = capture(&block)
|
192
|
+
content_tag(:div,
|
193
|
+
content,
|
194
|
+
id: 'smart_table_extra_filters',
|
195
|
+
class: 'smart_table_extra_filters'
|
196
|
+
)
|
197
|
+
end
|
198
|
+
|
199
|
+
private
|
200
|
+
|
201
|
+
# generates url merging parameters to the current url
|
202
|
+
def current_request_url_with_merged_query_params(params)
|
203
|
+
request_url = URI::parse(request.url)
|
204
|
+
link_query_params = URI::decode_www_form(request_url.query || '').to_h.merge(params.stringify_keys)
|
205
|
+
link_url = request_url.dup
|
206
|
+
link_url.query = URI::encode_www_form(link_query_params)
|
207
|
+
link_url.to_s
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%# Link to the "First" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the first page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
|
10
|
+
<% unless current_page.first? %>
|
11
|
+
<%= link_to t('views.pagination.first').html_safe, url, class: 'first', :remote => remote %>
|
12
|
+
<% end %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%# Non-link tag that stands for skipped pages...
|
2
|
+
- available local variables
|
3
|
+
current_page: a page object for the currently displayed page
|
4
|
+
total_pages: total number of pages
|
5
|
+
per_page: number of items to fetch per page
|
6
|
+
remote: data-remote
|
7
|
+
-%>
|
8
|
+
<span class="page gap"><%= t('views.pagination.truncate').html_safe %></span>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%# Link to the "Last" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the last page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
|
10
|
+
<% unless current_page.last? %>
|
11
|
+
<%= link_to t('views.pagination.last').html_safe, url, class: 'last', :remote => remote %>
|
12
|
+
<% end %>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%# Link to the "Next" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the next page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
|
10
|
+
<% unless current_page.last? %>
|
11
|
+
<%= link_to t('views.pagination.next').html_safe, url, class: 'next', :rel => 'next', :remote => remote %>
|
12
|
+
<% end %>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%# Link showing page number
|
2
|
+
- available local variables
|
3
|
+
page: a page object for "this" page
|
4
|
+
url: url to this page
|
5
|
+
current_page: a page object for the currently displayed page
|
6
|
+
total_pages: total number of pages
|
7
|
+
per_page: number of items to fetch per page
|
8
|
+
remote: data-remote
|
9
|
+
-%>
|
10
|
+
<%= link_to page, url, {:remote => remote, class: "page#{ ' current' if page.current? }", :rel => page.next? ? 'next' : page.prev? ? 'prev' : nil} %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%# The container tag
|
2
|
+
- available local variables
|
3
|
+
current_page: a page object for the currently displayed page
|
4
|
+
total_pages: total number of pages
|
5
|
+
per_page: number of items to fetch per page
|
6
|
+
remote: data-remote
|
7
|
+
paginator: the paginator that renders the pagination tags inside
|
8
|
+
-%>
|
9
|
+
<%= paginator.render do -%>
|
10
|
+
<div class="text-center">
|
11
|
+
<ul class="pagination">
|
12
|
+
<%= first_page_tag unless current_page.first? || total_pages <= 2 %>
|
13
|
+
<%= prev_page_tag unless current_page.first? %>
|
14
|
+
<% each_page do |page| -%>
|
15
|
+
<% if page.left_outer? || page.right_outer? || page.inside_window? -%>
|
16
|
+
<%= page_tag page %>
|
17
|
+
<% elsif !page.was_truncated? -%>
|
18
|
+
<%= gap_tag %>
|
19
|
+
<% end -%>
|
20
|
+
<% end -%>
|
21
|
+
<%= next_page_tag unless current_page.last? %>
|
22
|
+
<%= last_page_tag unless current_page.last? || total_pages <= 2 %>
|
23
|
+
</ul>
|
24
|
+
</div>
|
25
|
+
<% end -%>
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<%# Link to the "Previous" page
|
2
|
+
- available local variables
|
3
|
+
url: url to the previous page
|
4
|
+
current_page: a page object for the currently displayed page
|
5
|
+
total_pages: total number of pages
|
6
|
+
per_page: number of items to fetch per page
|
7
|
+
remote: data-remote
|
8
|
+
-%>
|
9
|
+
|
10
|
+
<% unless current_page.first? %>
|
11
|
+
<%= link_to t('views.pagination.previous').html_safe, url, class: 'prev', rel: 'prev', :remote => remote %>
|
12
|
+
<% end %>
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "solvis_auth"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
en:
|
2
|
+
views:
|
3
|
+
# Kaminari translations
|
4
|
+
pagination:
|
5
|
+
first: "« First"
|
6
|
+
last: "Last »"
|
7
|
+
previous: "‹ Prev"
|
8
|
+
next: "Next ›"
|
9
|
+
truncate: "…"
|
10
|
+
helpers:
|
11
|
+
# Kaminari translations
|
12
|
+
page_entries_info:
|
13
|
+
one_page:
|
14
|
+
display_entries:
|
15
|
+
zero: "No %{entry_name} found"
|
16
|
+
one: "Displaying <b>1</b> %{entry_name}"
|
17
|
+
other: "Displaying <b>all %{count}</b> %{entry_name}"
|
18
|
+
more_pages:
|
19
|
+
display_entries: "Displaying %{entry_name} <b>%{first} - %{last}</b> of <b>%{total}</b> in total"
|
20
|
+
|
21
|
+
# smart_table gem's specific translations
|
22
|
+
smart_table:
|
23
|
+
per_page: "per page"
|
24
|
+
show_all: "All"
|
25
|
+
search: "Search"
|
@@ -0,0 +1,25 @@
|
|
1
|
+
pt:
|
2
|
+
views:
|
3
|
+
# Kaminari translations
|
4
|
+
pagination:
|
5
|
+
first: "« Primeira"
|
6
|
+
last: "Última »"
|
7
|
+
previous: "‹ Anterior"
|
8
|
+
next: "Próxima ›"
|
9
|
+
truncate: "…"
|
10
|
+
helpers:
|
11
|
+
# Kaminari translations
|
12
|
+
page_entries_info:
|
13
|
+
one_page:
|
14
|
+
display_entries:
|
15
|
+
zero: "Sem %{entry_name} para exibir"
|
16
|
+
one: "Mostrando <b>1</b> %{entry_name}"
|
17
|
+
other: "Mostrando <b>todos %{count}</b> %{entry_name}"
|
18
|
+
more_pages:
|
19
|
+
display_entries: "Mostrando %{entry_name} <b>%{first} - %{last}</b> de <b>%{total}</b> no total"
|
20
|
+
|
21
|
+
# smart_table gem's specific translations
|
22
|
+
smart_table:
|
23
|
+
per_page: "por página"
|
24
|
+
show_all: "Tudo"
|
25
|
+
search: "Buscar"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
# Generates gem initializer
|
4
|
+
#
|
5
|
+
# rails g smart_table:init
|
6
|
+
#
|
7
|
+
|
8
|
+
module SmartTable
|
9
|
+
class InitGenerator < Rails::Generators::Base
|
10
|
+
source_root File.expand_path('../templates', __FILE__)
|
11
|
+
|
12
|
+
def copy_initializer
|
13
|
+
copy_file 'smart_table_initializer.rb', 'config/initializers/smart_table.rb'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module SmartTable
|
2
|
+
class Config
|
3
|
+
DEFAULT_CONFIGS = {
|
4
|
+
|
5
|
+
}
|
6
|
+
|
7
|
+
DEFAULT_CONFIGS.each do |config_name, default_value|
|
8
|
+
# defines accessors for each configuration on Config class
|
9
|
+
self.cattr_accessor config_name, instance_accessor: false
|
10
|
+
# initializes default value
|
11
|
+
self.send(config_name.to_s + '=', default_value)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
|
2
|
+
module SmartTable
|
3
|
+
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
|
6
|
+
# This makes models, controllers and routes defined on this gem to be all
|
7
|
+
# scoped under SmartTable::
|
8
|
+
# Ref: http://edgeguides.rubyonrails.org/engines.html
|
9
|
+
isolate_namespace SmartTable
|
10
|
+
|
11
|
+
# This automatically includes smart_table methods on all controllers
|
12
|
+
initializer 'smart_table.action_controller' do |app|
|
13
|
+
ActiveSupport.on_load :action_controller do
|
14
|
+
include SmartTable::SmartTableConcern
|
15
|
+
helper SmartTable::SmartTableHelper
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/lib/smart_table.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rails'
|
2
|
+
require 'kaminari'
|
3
|
+
|
4
|
+
require 'smart_table/engine' if defined?(Rails::Engine)
|
5
|
+
|
6
|
+
require 'smart_table/version'
|
7
|
+
require 'smart_table/config'
|
8
|
+
require 'generators/init_generator'
|
9
|
+
|
10
|
+
|
11
|
+
module SmartTable
|
12
|
+
|
13
|
+
# Method called on the gem initializer
|
14
|
+
def self.setup
|
15
|
+
if block_given?
|
16
|
+
yield Config
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Constants
|
21
|
+
SORT_PARAM = :st_sort
|
22
|
+
PAGE_PARAM = :st_page
|
23
|
+
PAGE_SIZE_PARAM = :st_page_size
|
24
|
+
SEARCH_PARAM = :st_search
|
25
|
+
SHOW_ALL = 'show_all'
|
26
|
+
PAGE_SIZES = [10,50,200]
|
27
|
+
|
28
|
+
end
|
Binary file
|
data/smart_table.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'smart_table/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "smart_table"
|
9
|
+
spec.version = SmartTable::VERSION
|
10
|
+
spec.authors = ["Henrique Gubert"]
|
11
|
+
spec.email = ["guberthenrique@hotmail.com"]
|
12
|
+
|
13
|
+
spec.summary = %q{Implements tables with pagination and search for Rails,
|
14
|
+
with server-side content loading.}
|
15
|
+
spec.description = %q{}
|
16
|
+
|
17
|
+
spec.files = Dir[File.dirname(__FILE__) + '/**/*'].reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
# this gem should be used in a rails app
|
23
|
+
spec.add_runtime_dependency 'rails', '<5.3.0', '>4.2.0'
|
24
|
+
spec.add_runtime_dependency 'kaminari', '~> 0'
|
25
|
+
spec.add_runtime_dependency 'font-awesome-rails', '~> 0'
|
26
|
+
|
27
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
28
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
29
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
30
|
+
spec.add_development_dependency 'rspec-rails', '~> 3.7'
|
31
|
+
spec.add_development_dependency 'sqlite3', '~> 0'
|
32
|
+
spec.add_development_dependency "byebug", '~> 9'
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into application.js, which will include all the files
|
2
|
+
// listed below.
|
3
|
+
//
|
4
|
+
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
|
5
|
+
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
|
6
|
+
//
|
7
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
8
|
+
// compiled file. JavaScript code in this file should be added after the last require_* statement.
|
9
|
+
//
|
10
|
+
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
|
11
|
+
// about supported directives.
|
12
|
+
//
|
13
|
+
//= require rails-ujs
|
14
|
+
//= require activestorage
|
15
|
+
//= require_tree .
|
@@ -0,0 +1,13 @@
|
|
1
|
+
// Action Cable provides the framework to deal with WebSockets in Rails.
|
2
|
+
// You can generate new channels where WebSocket features live using the `rails generate channel` command.
|
3
|
+
//
|
4
|
+
//= require action_cable
|
5
|
+
//= require_self
|
6
|
+
//= require_tree ./channels
|
7
|
+
|
8
|
+
(function() {
|
9
|
+
this.App || (this.App = {});
|
10
|
+
|
11
|
+
App.cable = ActionCable.createConsumer();
|
12
|
+
|
13
|
+
}).call(this);
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
|
10
|
+
* files in this directory. Styles in this file should be added after the last require_* statement.
|
11
|
+
* It is generally better to create a new file per style scope.
|
12
|
+
*
|
13
|
+
*= require_tree .
|
14
|
+
*= require_self
|
15
|
+
*/
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>DummyApp</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
<%= csp_meta_tag %>
|
7
|
+
|
8
|
+
<%= stylesheet_link_tag 'application', media: 'all' %>
|
9
|
+
<%= javascript_include_tag 'application' %>
|
10
|
+
</head>
|
11
|
+
|
12
|
+
<body>
|
13
|
+
<%= yield %>
|
14
|
+
</body>
|
15
|
+
</html>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= yield %>
|