module Wallaby::IndexHelper

Helper methods for index action

Public Instance Methods

all_label() click to toggle source

Just a label @return [String]

# File lib/helpers/wallaby/index_helper.rb, line 8
def all_label
  wt 'filters.all'
end
filter_label(filter_name, filters) click to toggle source

@param filter_name [String, Symbol] @param filters [Hash] @return [String] filter label for the given field name

# 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_name_by(filter_name, filters) click to toggle source

@param filter_name [String, Symbol] @param filters [Hash] @return [String] filter name @see Wallaby::FilterUtils.filter_name_by

# 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]) click to toggle source

If `:fields` parameter is given, only display fields that is in `index_field_names` Otherwise, `index_field_names` @param decorated_collection [Array<Wallaby::ResourceDecorator>] @param fields_from_params [Array<String>] @return [Array<String>] a list of field names for json builder

# 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