Sha256: d147b278ca02fb99bfc3dede1346faf56be327036d1ab149d294e8c071e42f58

Contents?: true

Size: 1.51 KB

Versions: 33

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module EffectiveResourcesWizardHelper

  def render_wizard_sidebar(resource, numbers: true, path: nil, horizontal: false, &block)
    if path.present?
      raise('expected path to be a string with /build/ in it ') unless path.to_s.include?('/build/')
      path = path.split('/build/').first + '/build/'
    end

    klasses = ['wizard-sidebar', 'list-group', ('list-group-horizontal' if horizontal)].compact.join(' ')

    sidebar = content_tag(:div, class: klasses) do
      resource.sidebar_steps.map.with_index do |nav_step, index|
        render_wizard_sidebar_item(resource, nav_step: nav_step, index: (index + 1 if numbers), path: (path + nav_step.to_s if path))
      end.join.html_safe
    end

    return sidebar unless block_given?

    content_tag(:div, class: 'row') do
      content_tag(:div, class: 'col-lg-3') { sidebar } +
      content_tag(:div, class: 'col-lg-9') { yield }
    end
  end

  def render_wizard_sidebar_item(resource, nav_step:, path: nil, index: nil)
    # From Controller
    current = (nav_step == step)
    title = resource_wizard_step_title(resource, nav_step)

    # From Model
    disabled = !resource.can_visit_step?(nav_step)

    label = [index, title].compact.join('. ')
    klass = ['list-group-item', 'list-group-item-action', ('active' if current), ('disabled' if disabled && !current)].compact.join(' ')

    if (current || disabled)
      content_tag(:a, label, class: klass)
    else
      link_to(label, path || wizard_path(nav_step), class: klass)
    end
  end

end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
effective_resources-2.7.8 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.7.7 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.7.6 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.7.5 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.7.4 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.7.3 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.7.2 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.7.1 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.7.0 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.6.2 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.6.1 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.6.0 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.5.4 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.5.3 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.5.2 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.5.1 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.5.0 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.4.7 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.4.6 app/helpers/effective_resources_wizard_helper.rb
effective_resources-2.4.5 app/helpers/effective_resources_wizard_helper.rb