class GovukPublishingComponents::Presenters::PageWithStepByStepNavigation

@private Only used by the step by step component

Constants

MAX_SECTION_LENGTH

Attributes

content_item[R]
current_path[R]

Public Class Methods

new(content_store_response, current_path, query_parameters = {}) click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 8
def initialize(content_store_response, current_path, query_parameters = {})
  @content_item = content_store_response.to_h.deep_symbolize_keys
  @current_path = current_path
  @query_parameters = query_parameters
end

Public Instance Methods

active_step_by_step() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 105
def active_step_by_step
  step_navs_list = step_navs_combined_list
  @active_step_navs ||= step_navs_list.select { |step_nav| step_nav.content_id == active_step_nav_content_id }
  @active_step_navs.first
end
active_step_by_step?() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 101
def active_step_by_step?
  active_step_nav_content_id.present? && active_step_by_step.present?
end
also_part_of_step_nav() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 70
def also_part_of_step_nav
  step_navs_list = step_navs_combined_list
  step_by_step_navs = step_navs_list.delete_if { |step_nav| step_nav.content_id == active_step_by_step.content_id }
  format_related_links(step_by_step_navs)
end
header() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 85
def header
  if show_header?
    {
      title: current_step_nav.title,
      path: current_step_nav.base_path,
      tracking_id: current_step_nav.content_id,
    }
  else
    {}
  end
end
primary_step_by_steps?() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 97
def primary_step_by_steps?
  step_navs_combined_list.any?
end
secondary_step_by_step() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 115
def secondary_step_by_step
  secondary_step_by_steps.first
end
secondary_step_by_step?() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 111
def secondary_step_by_step?
  secondary_step_by_steps.any?
end
secondary_step_by_steps() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 26
def secondary_step_by_steps
  @secondary_step_by_steps ||= parsed_secondary_to_step_navs.map do |step_nav|
    StepByStepModel.new(step_nav)
  end
end
show_also_part_of_step_nav?() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 52
def show_also_part_of_step_nav?
  active_step_by_step? && also_part_of_step_nav.any? && step_navs_combined_list.count < MAX_SECTION_LENGTH
end
show_header?() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 36
def show_header?
  step_navs.count == 1 || active_step_by_step? || show_secondary_step_by_step?
end
show_secondary_step_by_step?() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 119
def show_secondary_step_by_step?
  !primary_step_by_steps? && secondary_step_by_step? && secondary_step_by_steps.count == 1
end
show_sidebar?() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 32
def show_sidebar?
  show_header? && current_step_nav.steps.present?
end
sidebar() click to toggle source
step_navs() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 14
def step_navs
  @step_navs ||= parsed_step_navs.map do |step_nav|
    StepByStepModel.new(step_nav)
  end
end

Private Instance Methods

active_step_nav_content_id() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 141
def active_step_nav_content_id
  @active_step_nav_content_id ||= @query_parameters["step-by-step-nav"].present? ? @query_parameters["step-by-step-nav"] : nil
end
configure_for_sidebar(step_nav_content) click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 168
def configure_for_sidebar(step_nav_content)
  step_nav_content[:steps].each_with_index do |step, step_index|
    step[:contents].each do |content|
      next unless content[:contents]

      content[:contents].each do |link|
        next unless link[:href] == current_path

        link[:active] = true
        step_nav_content[:show_step] = step_index + 1
        step_nav_content[:highlight_step] = step_index + 1
      end
    end
  end
  step_nav_content
end
current_step_nav() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 131
def current_step_nav
  if active_step_by_step?
    active_step_by_step
  elsif primary_step_by_steps?
    step_navs.first
  elsif show_secondary_step_by_step?
    secondary_step_by_step
  end
end
parsed_secondary_to_step_navs() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 164
def parsed_secondary_to_step_navs
  content_item.dig(:links, :secondary_to_step_navs).to_a
end
parsed_step_navs() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 156
def parsed_step_navs
  content_item.dig(:links, :part_of_step_navs).to_a
end
step_navs_combined_list() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 149
def step_navs_combined_list
  step_nav_list = []
  step_nav_list += step_navs if step_navs.any?
  step_nav_list += related_to_step_navs if related_to_step_navs.any?
  step_nav_list
end
steps() click to toggle source
# File lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb, line 145
def steps
  @steps ||= step_nav[:steps]
end