Module: Wallaby::IndexHelper
- Included in:
- ResourcesHelper
- Defined in:
- lib/helpers/wallaby/index_helper.rb
Overview
Helper methods for index page
Instance Method Summary collapse
-
#all_label ⇒ String
Just a label.
-
#export_link(model_class) ⇒ String
Export link for a given model_class.
-
#filter_label(filter_name, filters) ⇒ String
Label for a given name.
-
#filter_link(model_class, filter_name, filters) ⇒ String
Link for a given model class and filter name.
-
#paginate(model_class, collection, params) ⇒ Wallaby::ResourcePaginator
Wrap the collection with paginator.
-
#sort_link_builder ⇒ Sorting::LinkBuilder
Sort link builder.
Instance Method Details
#all_label ⇒ String
Just a label
15 16 17 |
# File 'lib/helpers/wallaby/index_helper.rb', line 15 def all_label t 'filters.all' end |
#export_link(model_class) ⇒ String
Export link for a given model_class
30 31 32 33 34 35 |
# File 'lib/helpers/wallaby/index_helper.rb', line 30 def export_link(model_class) url_params = index_params.except(:page, :per).merge(format: 'csv') index_link model_class, url_params: url_params do t 'links.export', ext: 'CSV' end end |
#filter_label(filter_name, filters) ⇒ String
Label for a given name
23 24 25 |
# File 'lib/helpers/wallaby/index_helper.rb', line 23 def filter_label(filter_name, filters) filters[filter_name].try(:[], :label) || filter_name.to_s.humanize end |
#filter_link(model_class, filter_name, filters) ⇒ String
Link for a given model class and filter name
42 43 44 45 46 47 48 49 50 |
# File 'lib/helpers/wallaby/index_helper.rb', line 42 def filter_link(model_class, filter_name, filters) is_all = filter_name == :all config = filters[filter_name] || {} label = is_all ? all_label : filter_label(filter_name, filters) url_params = if config[:default] then index_params.except(:filter) else index_params.merge(filter: filter_name) end index_link(model_class, url_params: url_params) { label } end |
#paginate(model_class, collection, params) ⇒ Wallaby::ResourcePaginator
Wrap the collection with paginator
9 10 11 |
# File 'lib/helpers/wallaby/index_helper.rb', line 9 def paginate(model_class, collection, params) Map.paginator_map(model_class).new model_class, collection, params end |
#sort_link_builder ⇒ Sorting::LinkBuilder
Sort link builder
54 55 56 57 |
# File 'lib/helpers/wallaby/index_helper.rb', line 54 def sort_link_builder @sort_link_builder ||= Sorting::LinkBuilder.new current_model_decorator, index_params, self end |