Module: Wallaby::IndexHelper
- Included in:
- ResourcesHelper
- Defined in:
- lib/helpers/wallaby/index_helper.rb
Overview
Helper methods for index action
Instance Method Summary collapse
-
#all_label ⇒ String
Just a label.
-
#export_link(model_class, url_params: {}, html_options: {}) ⇒ String
Export link for the given model_class.
-
#filter_label(filter_name, filters) ⇒ String
Filter label for the given field name.
-
#filter_link(model_class, filter_name, filters: {}, url_params: {}, html_options: {}) ⇒ String
Link for a given model class and filter name.
-
#filter_name_by(filter_name, filters) ⇒ String
Filter name.
-
#json_fields_of(decorated_collection, fields_from_params = params[:fields]) ⇒ Array<String>
If ‘:fields` parameter is given, only display fields that is in `index_field_names` Otherwise, `index_field_names`.
- #sort_link_builder(sorting_strategy = wallaby_controller.sorting_strategy) ⇒ Sorting::LinkBuilder
Instance Method Details
#all_label ⇒ String
Just a label
8 9 10 |
# File 'lib/helpers/wallaby/index_helper.rb', line 8 def all_label wt 'filters.all' end |
#export_link(model_class, url_params: {}, html_options: {}) ⇒ String
Returns Export link for the given model_class.
63 64 65 66 67 68 69 70 71 |
# File 'lib/helpers/wallaby/index_helper.rb', line 63 def export_link(model_class, url_params: {}, html_options: {}) index_link( model_class, url_params: url_params.merge(format: 'csv', page: nil, per: nil, with_query: true), html_options: ) do wt 'links.export', ext: 'CSV' end end |
#filter_label(filter_name, filters) ⇒ String
Returns filter label for the given field name.
29 30 31 32 |
# File 'lib/helpers/wallaby/index_helper.rb', line 29 def filter_label(filter_name, filters) # TODO: use locale for filter_name label filters[filter_name].try(:[], :label) || filter_name.to_s.humanize end |
#filter_link(model_class, filter_name, filters: {}, url_params: {}, html_options: {}) ⇒ String
Link for a given model class and filter name
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/helpers/wallaby/index_helper.rb', line 48 def filter_link(model_class, filter_name, filters: {}, url_params: {}, html_options: {}) is_all = filter_name == :all config = filters[filter_name] || {} label = is_all ? all_label : filter_label(filter_name, filters) url_params[:filter] = config[:default] ? nil : filter_name index_link( model_class, url_params: url_params.merge(with_query: true), html_options: ) { label } end |
#filter_name_by(filter_name, filters) ⇒ String
Returns filter name.
38 39 40 |
# File 'lib/helpers/wallaby/index_helper.rb', line 38 def filter_name_by(filter_name, filters) FilterUtils.filter_name_by filter_name, filters end |
#json_fields_of(decorated_collection, fields_from_params = params[:fields]) ⇒ Array<String>
If ‘:fields` parameter is given, only display fields that is in `index_field_names` Otherwise, `index_field_names`
17 18 19 20 21 22 23 24 |
# File 'lib/helpers/wallaby/index_helper.rb', line 17 def json_fields_of(decorated_collection, fields_from_params = params[:fields]) return [] if decorated_collection.blank? decorated = decorated_collection.first index_field_names = decorated.index_field_names.map(&:to_s) fields = (fields_from_params.presence || index_field_names).split(/\s*,\s*/).flatten fields & index_field_names end |
#sort_link_builder(sorting_strategy = wallaby_controller.sorting_strategy) ⇒ Sorting::LinkBuilder
75 76 77 78 79 80 |
# File 'lib/helpers/wallaby/index_helper.rb', line 75 def sort_link_builder(sorting_strategy = wallaby_controller.sorting_strategy) @sort_link_builder ||= Sorting::LinkBuilder.new( current_model_decorator, params.slice(:sort).permit!, self, sorting_strategy ) end |