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)
  • url_params (Hash, ActionController::Parameters) (defaults to: {})

Returns:

  • (String)

    HTML anchor link



31
32
33
34
35
36
37
# File 'lib/helpers/wallaby/index_helper.rb', line 31

def export_link(model_class, url_params: {})
  url_params =
    index_params.except(:page, :per).merge(format: 'csv').merge(url_params)
  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) (defaults to: {})
  • url_params (Hash, ActionController::Parameters) (defaults to: {})

Returns:

  • (String)

    HTML anchor link



45
46
47
48
49
50
51
52
53
54
# File 'lib/helpers/wallaby/index_helper.rb', line 45

def filter_link(model_class, filter_name, filters: {}, url_params: {})
  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).merge(url_params)
    else index_params.merge(filter: filter_name).merge(url_params)
    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



58
59
60
61
# File 'lib/helpers/wallaby/index_helper.rb', line 58

def sort_link_builder
  @sort_link_builder ||=
    Sorting::LinkBuilder.new current_model_decorator, index_params, self
end