Class: Presenters::BatchSubmenuPresenter

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TextHelper
Defined in:
app/models/presenters/batch_submenu_presenter.rb

Overview

The Batch show page in the BatchesController has a side menu which displays a variety of options depending on properties of the batch. The BatchSubmenuPresenter encapsulates the logic which was previously in the view itself.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options


6
7
8
# File 'app/models/presenters/batch_submenu_presenter.rb', line 6

def options
  @options
end

Instance Method Details

#add_submenu_option(text, action_params) ⇒ Object


116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'app/models/presenters/batch_submenu_presenter.rb', line 116

def add_submenu_option(text, action_params)
  @options ||= Array.new

  # If it is a string, it will be an url
  unless action_params.is_a?(String)
    # If it is a symbol, it will be the action
    # If not, it will be a Hash with the new content (controller, action, ...)
    if (action_params.is_a?(Symbol))
      action_params = { action: action_params }
    end
    actionConfig = @defaults.dup
    action_params.each_pair do |key, value|
      actionConfig[key] = value
    end
    action_params = url_for(actionConfig)
  end
  @options += [{ label: text, url: action_params }]
end

#each_optionObject


135
136
137
138
139
140
# File 'app/models/presenters/batch_submenu_presenter.rb', line 135

def each_option
  build_submenu if @options.nil?
  @options.each do |option|
    yield option
  end
end