Class: GovukPublishingComponents::Presenters::PageWithStepByStepNavigation

Inherits:
Object
  • Object
show all
Defined in:
lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb

Overview

Only used by the step by step component

Constant Summary collapse

MAX_SECTION_LENGTH =
RelatedNavigationHelper::MAX_SECTION_LENGTH

Instance Method Summary collapse

Constructor Details

#initialize(content_store_response, current_path, query_parameters = {}) ⇒ PageWithStepByStepNavigation

Returns a new instance of PageWithStepByStepNavigation.



8
9
10
11
12
# 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

Instance Method Details

#active_step_by_stepObject



106
107
108
109
110
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 106

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?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 102

def active_step_by_step?
  active_step_nav_content_id.present? && active_step_by_step.present?
end

#also_part_of_step_navObject



70
71
72
73
74
# 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(ga4_tracking) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 85

def header(ga4_tracking)
  if show_header?
    {
      title: current_step_nav.title,
      path: current_step_nav.base_path,
      tracking_id: current_step_nav.content_id,
      ga4_tracking:,
    }
  else
    {}
  end
end

#primary_step_by_steps?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 98

def primary_step_by_steps?
  step_navs_combined_list.any?
end


56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 56

def related_links
  step_by_step_navs = if active_step_by_step?
                        [active_step_by_step]
                      elsif step_navs.any?
                        step_navs
                      elsif show_related_links_for_secondary_step_by_steps?
                        secondary_step_by_steps
                      else
                        []
                      end

  format_related_links(step_by_step_navs)
end


20
21
22
23
24
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 20

def related_to_step_navs
  @related_to_step_navs ||= parsed_related_to_step_navs.map do |step_nav|
    StepByStepModel.new(step_nav)
  end
end

#secondary_step_by_stepObject



116
117
118
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 116

def secondary_step_by_step
  secondary_step_by_steps.first
end

#secondary_step_by_step?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 112

def secondary_step_by_step?
  secondary_step_by_steps.any?
end

#secondary_step_by_stepsObject



26
27
28
29
30
# 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?Boolean

Returns:

  • (Boolean)


52
53
54
# 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?Boolean

Returns:

  • (Boolean)


36
37
38
# 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

Returns:

  • (Boolean)


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 40

def show_related_links?
  if active_step_by_step?
    true
  elsif step_navs.any?
    true
  elsif show_related_links_for_secondary_step_by_steps?
    true
  else
    false
  end
end

Returns:

  • (Boolean)


124
125
126
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 124

def show_related_links_for_secondary_step_by_steps?
  !primary_step_by_steps? && secondary_step_by_step?
end

#show_secondary_step_by_step?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 120

def show_secondary_step_by_step?
  !primary_step_by_steps? && secondary_step_by_step? && secondary_step_by_steps.count == 1
end

#show_sidebar?Boolean

Returns:

  • (Boolean)


32
33
34
# 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


76
77
78
79
80
81
82
83
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 76

def sidebar
  if show_sidebar?
    @sidebar ||= current_step_nav.content.tap do |sb|
      configure_for_sidebar(sb)
      sb.merge!(small: true, heading_level: 3, tracking_id: current_step_nav.content_id, ga4_tracking: @query_parameters[:ga4_tracking])
    end
  end
end

#step_navsObject



14
15
16
17
18
# 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