Class: HasHelpers::Resource::ListPresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/has_helpers/resource/list_presenter.rb

Overview

HasHelpers::Resource::ListPresenter is used to represent overview information for a resource record. The presenter is meant to display tabular data. Each list presenter has rows (RowPresenters) and each row has cells (CellPresenters).

Instance Attribute Summary collapse

Attributes inherited from BasePresenter

#errors, #wrapped_object

Instance Method Summary collapse

Methods inherited from BasePresenter

#==, #error_on, #initialize, wrap, wrap_with_options

Methods included from Attributes

included

Constructor Details

This class inherits a constructor from HasHelpers::BasePresenter

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class HasHelpers::BasePresenter

Instance Attribute Details

#actionsObject



90
91
92
93
94
95
96
97
98
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 90

def actions
  (@actions || []).map do |action_or_attrs|
    if action_or_attrs.is_a?(Hash)
      ::HasHelpers::Resource::ActionPresenter.new(action_or_attrs)
    else
      action_or_attrs
    end
  end
end

#captionObject

Returns the value of attribute caption.



9
10
11
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 9

def caption
  @caption
end

#caption_optionsObject

Returns the value of attribute caption_options.



9
10
11
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 9

def caption_options
  @caption_options
end

#caption_templateObject

Returns the value of attribute caption_template.



9
10
11
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 9

def caption_template
  @caption_template
end

#current_user=(value) ⇒ Object (writeonly)

Sets the attribute current_user

Parameters:

  • value

    the value to set the attribute current_user to.



7
8
9
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 7

def current_user=(value)
  @current_user = value
end

#header_optionsObject



104
105
106
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 104

def header_options
  @header_options || {}
end

#headersObject

Returns the value of attribute headers.



9
10
11
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 9

def headers
  @headers
end

#iconsObject



108
109
110
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 108

def icons
  @icons || []
end

#is_dropdownObject

Returns the value of attribute is_dropdown.



9
10
11
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 9

def is_dropdown
  @is_dropdown
end

#is_sublistObject

Returns the value of attribute is_sublist.



9
10
11
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 9

def is_sublist
  @is_sublist
end

#itemsObject

E.g., :rows => [ HasHelpers::Resource::RowPresenter.new(:items => [=> "Hello", => "World"]), HasHelpers::Resource::RowPresenter.new(:items => [=> "Adios"]) ] This manner of setting Row presenters explicitly offers the most flexibility and control.



30
31
32
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 30

def items
  @items
end

#rowsObject

Returns the assigned values of @rows or items converted to rows.



70
71
72
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 70

def rows
  @rows_memoized ||= @rows || items_to_rows # rubocop:disable Naming/MemoizedInstanceVariableName
end

#serviceObject

Returns the value of attribute service.



9
10
11
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 9

def service
  @service
end

#skinObject

Returns the value of attribute skin.



9
10
11
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 9

def skin
  @skin
end

#subcaptionObject

Returns the value of attribute subcaption.



9
10
11
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 9

def subcaption
  @subcaption
end

#tagsObject

Returns presenter instances for all the options passed to :tags



75
76
77
78
79
80
81
82
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 75

def tags
  @tags_memoized ||= (@tags || []).map do |tag_options| # rubocop:disable Naming/MemoizedInstanceVariableName
    case tag_options
    when ::HasHelpers::Resource::TagPresenter then tag_options
    else ::HasHelpers::Resource::TagPresenter.new(tag_options)
    end
  end
end

Instance Method Details

#has_rows_to_toggleObject

Some lists may have data which should not be display in the initial (closed) state, but which should be accessible when a user toggles to an open state.



86
87
88
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 86

def has_rows_to_toggle
  rows.present? && rows.any?(&:toggle)
end

#header_details_templateObject



100
101
102
# File 'app/presenters/has_helpers/resource/list_presenter.rb', line 100

def header_details_template
  header_options[:template]
end