Module: Wallaby::IndexHelper

Included in:
ResourcesHelper
Defined in:
lib/helpers/wallaby/index_helper.rb

Overview

Helper methods for index page

Instance Method Summary collapse

Instance Method Details

#all_labelString

Just a label

Returns:

  • (String)


15
16
17
# File 'lib/helpers/wallaby/index_helper.rb', line 15

def all_label
  t 'filters.all'
end

Export link for a given model_class

Parameters:

  • model_class (Class)

Returns:

  • (String)

    HTML anchor link



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

Parameters:

  • filter_name (String, Symbol)
  • filters (Hash)

Returns:

  • (String)


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

Link for a given model class and filter name

Parameters:

  • model_class (Class)
  • filter_name (String, Symbol)
  • filters (Hash)

Returns:

  • (String)

    HTML anchor link



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

Parameters:

  • model_class (Class)
  • collection (#map)
  • params (ActionController::Parameters)

Returns:



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



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