listings 0.1.6 → 0.1.7
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.
- data/README.md +10 -3
- data/app/controllers/listings/listings_controller.rb +6 -0
- data/app/views/listings/_filters.html.haml +2 -0
- data/app/views/listings/_side_filters.html.haml +2 -0
- data/app/views/listings/_top_filters.html.haml +1 -0
- data/app/views/listings/twitter-bootstrap-2/_side_filter.html.haml +8 -0
- data/app/views/listings/twitter-bootstrap-2/_top_filter.html.haml +10 -0
- data/app/views/listings/twitter-bootstrap-3/_side_filter.html.haml +7 -0
- data/app/views/listings/twitter-bootstrap-3/_side_filters.html.haml +1 -8
- data/app/views/listings/twitter-bootstrap-3/_top_filter.html.haml +10 -0
- data/lib/listings/base.rb +1 -1
- data/lib/listings/configuration_methods.rb +2 -2
- data/lib/listings/custom_filter_descriptor.rb +3 -1
- data/lib/listings/custom_filter_view.rb +24 -4
- data/lib/listings/filter_view.rb +23 -3
- data/lib/listings/version.rb +1 -1
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/listings/filtered_posts_listing.rb +11 -0
- data/spec/dummy/app/views/listings/_date.html.haml +4 -0
- metadata +11 -5
- data/app/views/listings/twitter-bootstrap-2/_side_filters.html.haml +0 -11
- data/app/views/listings/twitter-bootstrap-2/_top_filters.html.haml +0 -11
- data/app/views/listings/twitter-bootstrap-3/_top_filters.html.haml +0 -11
data/README.md
CHANGED
@@ -249,13 +249,20 @@ Also `render:` option can be used to suppress the rendering of the filter, but a
|
|
249
249
|
filter :id, render: false
|
250
250
|
```
|
251
251
|
|
252
|
+
Or `render:` can be user to indicate the partial to be used for rendering that filter. Hence allowing custom UI for certain filter among the default UI. See [Templates](#templates) for information regarding where the partial will be looked.
|
253
|
+
|
254
|
+
```ruby
|
255
|
+
filter :update_at, render: 'date'
|
256
|
+
```
|
257
|
+
|
258
|
+
|
252
259
|
Filters are rendered by default by the side of the listing. With `layout` method you can change this and render them on the top.
|
253
260
|
|
254
261
|
```ruby
|
255
262
|
layout filters: :top
|
256
263
|
```
|
257
264
|
|
258
|
-
Custom filters allows definition of custom meaning to a key. This filters are not rendered.
|
265
|
+
Custom filters allows definition of custom meaning to a key. This filters are not rendered by default. Use `render:` option to indicate the partial to be used for rendering.
|
259
266
|
|
260
267
|
```ruby
|
261
268
|
custom_filter :order_lte do |items, value|
|
@@ -408,10 +415,10 @@ There are a number of templates involved in rendering the listing. These templat
|
|
408
415
|
|
409
416
|
For example if a listing named `tracks` is rendered with `twitter-bootstrap-3` theme the templates are looked up in the following locations/order:
|
410
417
|
|
411
|
-
* `<app>/views/listings/twitter-bootstrap-3/<partial>`
|
412
|
-
* `<gem>/views/listings/twitter-bootstrap-3/<partial>`
|
413
418
|
* `<app>/views/listings/tracks/<partial>`
|
414
419
|
* `<gem>/views/listings/tracks/<partial>`
|
420
|
+
* `<app>/views/listings/twitter-bootstrap-3/<partial>`
|
421
|
+
* `<gem>/views/listings/twitter-bootstrap-3/<partial>`
|
415
422
|
* `<app>/views/listings/<partial>`
|
416
423
|
* `<gem>/views/listings/<partial>`
|
417
424
|
|
@@ -5,11 +5,15 @@ module Listings
|
|
5
5
|
def full
|
6
6
|
@listing = prepare_listing params, view_context
|
7
7
|
render 'listings/full'
|
8
|
+
ensure
|
9
|
+
Kaminari::Helpers::Tag.paginate_with_listings(nil)
|
8
10
|
end
|
9
11
|
|
10
12
|
def content
|
11
13
|
@listing = prepare_listing params, view_context
|
12
14
|
render 'listings/content'
|
15
|
+
ensure
|
16
|
+
Kaminari::Helpers::Tag.paginate_with_listings(nil)
|
13
17
|
end
|
14
18
|
|
15
19
|
def export
|
@@ -22,6 +26,8 @@ module Listings
|
|
22
26
|
render 'listings/export'
|
23
27
|
end
|
24
28
|
end
|
29
|
+
ensure
|
30
|
+
Kaminari::Helpers::Tag.paginate_with_listings(nil)
|
25
31
|
end
|
26
32
|
|
27
33
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
= listings_partial_render 'filters', listing
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%li.dropdown.pull-right
|
2
|
+
%a.dropdown-toggle(data-toggle="dropdown" href="#")
|
3
|
+
= filter.human_name
|
4
|
+
%b.caret
|
5
|
+
%ul.dropdown-menu
|
6
|
+
- filter.values.each do |value|
|
7
|
+
%li.filter
|
8
|
+
%a{:href => '#', :'data-key' => filter.key, :'data-value' => value}
|
9
|
+
= filter.value_for(value)
|
10
|
+
%i.icon-remove
|
@@ -1,9 +1,2 @@
|
|
1
1
|
.filters.list-group
|
2
|
-
|
3
|
-
%a.list-group-item.disabled(href="#")
|
4
|
-
= "Filter by #{filter_view.human_name}"
|
5
|
-
- filter_view.values.each do |value|
|
6
|
-
%a.list-group-item.filter{:href => '#', :'data-key' => filter_view.key, :'data-value' => value}
|
7
|
-
= filter_view.value_for(value)
|
8
|
-
%span.icon-remove
|
9
|
-
×
|
2
|
+
= listings_partial_render 'filters', listing
|
@@ -0,0 +1,10 @@
|
|
1
|
+
%li.dropdown
|
2
|
+
%a.dropdown-toggle(data-toggle="dropdown" href="#")
|
3
|
+
= filter.human_name
|
4
|
+
%span.caret
|
5
|
+
%ul.dropdown-menu
|
6
|
+
- filter.values.each do |value|
|
7
|
+
%li.filter
|
8
|
+
%a{:href => '#', :'data-key' => filter.key, :'data-value' => value}
|
9
|
+
= filter.value_for(value)
|
10
|
+
%i.icon-remove
|
data/lib/listings/base.rb
CHANGED
@@ -164,8 +164,8 @@ module Listings
|
|
164
164
|
filters << FilterDescriptor.new(path, props, proc)
|
165
165
|
end
|
166
166
|
|
167
|
-
def custom_filter(key, &proc)
|
168
|
-
filters << CustomFilterDescriptor.new(key, proc)
|
167
|
+
def custom_filter(key, props = {}, &proc)
|
168
|
+
filters << CustomFilterDescriptor.new(key, props, proc)
|
169
169
|
end
|
170
170
|
|
171
171
|
def layout(props = {})
|
@@ -8,12 +8,12 @@ module Listings
|
|
8
8
|
@descriptor = descriptor
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
|
11
|
+
def prepare_values
|
12
|
+
# custom filters do not perform lookup
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
16
|
-
|
15
|
+
def key
|
16
|
+
@descriptor.key
|
17
17
|
end
|
18
18
|
|
19
19
|
def apply_filter(value)
|
@@ -21,5 +21,25 @@ module Listings
|
|
21
21
|
listing.instance_exec items, value, &@descriptor.proc
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
def render?
|
26
|
+
if render_option.is_a?(String)
|
27
|
+
true
|
28
|
+
else
|
29
|
+
render_option
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def partial_name
|
34
|
+
if render_option.is_a?(String)
|
35
|
+
render_option
|
36
|
+
else
|
37
|
+
raise "custom filters can only be rendered when a partial is specified"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def render_option
|
42
|
+
@descriptor.props.fetch(:render, false)
|
43
|
+
end
|
24
44
|
end
|
25
45
|
end
|
data/lib/listings/filter_view.rb
CHANGED
@@ -4,6 +4,10 @@ module Listings
|
|
4
4
|
super
|
5
5
|
end
|
6
6
|
|
7
|
+
def prepare_values
|
8
|
+
values
|
9
|
+
end
|
10
|
+
|
7
11
|
def values
|
8
12
|
@values ||= listing.data_source.values_for_filter(field)
|
9
13
|
end
|
@@ -16,12 +20,28 @@ module Listings
|
|
16
20
|
end
|
17
21
|
end
|
18
22
|
|
23
|
+
def apply_filter(value)
|
24
|
+
listing.data_source.filter(field, value)
|
25
|
+
end
|
26
|
+
|
19
27
|
def render?
|
20
|
-
|
28
|
+
if render_option.is_a?(String)
|
29
|
+
true
|
30
|
+
else
|
31
|
+
render_option
|
32
|
+
end
|
21
33
|
end
|
22
34
|
|
23
|
-
def
|
24
|
-
|
35
|
+
def partial_name
|
36
|
+
if render_option.is_a?(String)
|
37
|
+
render_option
|
38
|
+
else
|
39
|
+
"#{listing.layout_options[:filters]}_filter"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def render_option
|
44
|
+
@field_description.props.fetch(:render, true)
|
25
45
|
end
|
26
46
|
end
|
27
47
|
end
|
data/lib/listings/version.rb
CHANGED
@@ -22,3 +22,18 @@
|
|
22
22
|
// console.log(el);
|
23
23
|
// });
|
24
24
|
// });
|
25
|
+
|
26
|
+
$(function(){
|
27
|
+
|
28
|
+
$('.listing').on('change', '#date-filter', function(){
|
29
|
+
var listings = $(this).closest('.listing')
|
30
|
+
var filter = $(this);
|
31
|
+
|
32
|
+
if (filter.val() == '') {
|
33
|
+
listings.trigger("listings:filter:key:clear", filter.data('filter-key'))
|
34
|
+
} else {
|
35
|
+
listings.trigger("listings:filter:key:set", [filter.data('filter-key'), filter.val()])
|
36
|
+
}
|
37
|
+
});
|
38
|
+
});
|
39
|
+
|
@@ -13,11 +13,22 @@ class FilteredPostsListing < Listings::Base
|
|
13
13
|
filter :author
|
14
14
|
filter :category
|
15
15
|
|
16
|
+
custom_filter :updated, render: 'date' do |items, value|
|
17
|
+
begin
|
18
|
+
d = Date.parse(value)
|
19
|
+
items.where(updated_at: d.beginning_of_day..d.end_of_day)
|
20
|
+
rescue
|
21
|
+
items
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
16
25
|
|
17
26
|
column :id
|
18
27
|
column :title, searchable: true
|
19
28
|
column :author
|
20
29
|
column :category
|
30
|
+
column :updated_at
|
31
|
+
|
21
32
|
column do |post|
|
22
33
|
link_to 'Editar', edit_post_path(post)
|
23
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: listings
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -187,19 +187,23 @@ files:
|
|
187
187
|
- app/controllers/listings/listings_controller.rb
|
188
188
|
- app/helpers/listings/application_helper.rb
|
189
189
|
- app/views/layouts/listings/application.html.erb
|
190
|
+
- app/views/listings/_filters.html.haml
|
190
191
|
- app/views/listings/_listing.html.haml
|
192
|
+
- app/views/listings/_side_filters.html.haml
|
191
193
|
- app/views/listings/_table_content.html.haml
|
194
|
+
- app/views/listings/_top_filters.html.haml
|
192
195
|
- app/views/listings/content.js.erb
|
193
196
|
- app/views/listings/export.xls.erb
|
194
197
|
- app/views/listings/full.js.erb
|
195
198
|
- app/views/listings/twitter-bootstrap-2/_header.html.haml
|
196
|
-
- app/views/listings/twitter-bootstrap-2/
|
199
|
+
- app/views/listings/twitter-bootstrap-2/_side_filter.html.haml
|
197
200
|
- app/views/listings/twitter-bootstrap-2/_table_full.html.haml
|
198
|
-
- app/views/listings/twitter-bootstrap-2/
|
201
|
+
- app/views/listings/twitter-bootstrap-2/_top_filter.html.haml
|
199
202
|
- app/views/listings/twitter-bootstrap-3/_header.html.haml
|
203
|
+
- app/views/listings/twitter-bootstrap-3/_side_filter.html.haml
|
200
204
|
- app/views/listings/twitter-bootstrap-3/_side_filters.html.haml
|
201
205
|
- app/views/listings/twitter-bootstrap-3/_table_full.html.haml
|
202
|
-
- app/views/listings/twitter-bootstrap-3/
|
206
|
+
- app/views/listings/twitter-bootstrap-3/_top_filter.html.haml
|
203
207
|
- config/locales/listings.yml
|
204
208
|
- config/routes.rb
|
205
209
|
- lib/listings/action_view_extensions.rb
|
@@ -251,6 +255,7 @@ files:
|
|
251
255
|
- spec/dummy/app/models/post.rb
|
252
256
|
- spec/dummy/app/models/track.rb
|
253
257
|
- spec/dummy/app/views/layouts/application.html.erb
|
258
|
+
- spec/dummy/app/views/listings/_date.html.haml
|
254
259
|
- spec/dummy/app/views/posts/filtered.html.haml
|
255
260
|
- spec/dummy/app/views/posts/index.html.haml
|
256
261
|
- spec/dummy/app/views/shared/_post_partial.html.haml
|
@@ -348,6 +353,7 @@ test_files:
|
|
348
353
|
- spec/dummy/app/models/post.rb
|
349
354
|
- spec/dummy/app/models/track.rb
|
350
355
|
- spec/dummy/app/views/layouts/application.html.erb
|
356
|
+
- spec/dummy/app/views/listings/_date.html.haml
|
351
357
|
- spec/dummy/app/views/posts/filtered.html.haml
|
352
358
|
- spec/dummy/app/views/posts/index.html.haml
|
353
359
|
- spec/dummy/app/views/shared/_post_partial.html.haml
|
@@ -1,11 +0,0 @@
|
|
1
|
-
.filters
|
2
|
-
- listing.filters_to_render.reverse.each do |filter_view|
|
3
|
-
%ul.nav.nav-list.well
|
4
|
-
%li.nav-header
|
5
|
-
= "Filter by #{filter_view.human_name}"
|
6
|
-
- filter_view.values.each do |value|
|
7
|
-
%li.filter
|
8
|
-
%a{:href => '#', :'data-key' => filter_view.key, :'data-value' => value}
|
9
|
-
= filter_view.value_for(value)
|
10
|
-
%i.icon-remove
|
11
|
-
|
@@ -1,11 +0,0 @@
|
|
1
|
-
- listing.filters_to_render.each do |filter_view|
|
2
|
-
%li.dropdown.pull-right
|
3
|
-
%a.dropdown-toggle(data-toggle="dropdown" href="#")
|
4
|
-
= filter_view.human_name
|
5
|
-
%b.caret
|
6
|
-
%ul.dropdown-menu
|
7
|
-
- filter_view.values.each do |value|
|
8
|
-
%li.filter
|
9
|
-
%a{:href => '#', :'data-key' => filter_view.key, :'data-value' => value}
|
10
|
-
= filter_view.value_for(value)
|
11
|
-
%i.icon-remove
|
@@ -1,11 +0,0 @@
|
|
1
|
-
- listing.filters_to_render.each do |filter_view|
|
2
|
-
%li.dropdown
|
3
|
-
%a.dropdown-toggle(data-toggle="dropdown" href="#")
|
4
|
-
= filter_view.human_name
|
5
|
-
%span.caret
|
6
|
-
%ul.dropdown-menu
|
7
|
-
- filter_view.values.each do |value|
|
8
|
-
%li.filter
|
9
|
-
%a{:href => '#', :'data-key' => filter_view.key, :'data-value' => value}
|
10
|
-
= filter_view.value_for(value)
|
11
|
-
%i.icon-remove
|