Class: GovukPublishingComponents::Presenters::PageWithStepByStepNavigation
- Inherits:
-
Object
- Object
- GovukPublishingComponents::Presenters::PageWithStepByStepNavigation
- 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
- #active_step_by_step ⇒ Object
- #active_step_by_step? ⇒ Boolean
- #also_part_of_step_nav ⇒ Object
- #header(disable_ga4) ⇒ Object
-
#initialize(content_store_response, current_path, query_parameters = {}) ⇒ PageWithStepByStepNavigation
constructor
A new instance of PageWithStepByStepNavigation.
- #primary_step_by_steps? ⇒ Boolean
- #related_links ⇒ Object
- #related_to_step_navs ⇒ Object
- #secondary_step_by_step ⇒ Object
- #secondary_step_by_step? ⇒ Boolean
- #secondary_step_by_steps ⇒ Object
- #show_also_part_of_step_nav? ⇒ Boolean
- #show_header? ⇒ Boolean
- #show_related_links? ⇒ Boolean
- #show_related_links_for_secondary_step_by_steps? ⇒ Boolean
- #show_secondary_step_by_step? ⇒ Boolean
- #show_sidebar? ⇒ Boolean
- #sidebar ⇒ Object
- #step_navs ⇒ Object
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_step ⇒ Object
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
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_nav ⇒ Object
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 } (step_by_step_navs) end |
#header(disable_ga4) ⇒ 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(disable_ga4) if show_header? { title: current_step_nav.title, path: current_step_nav.base_path, tracking_id: current_step_nav.content_id, disable_ga4:, } else {} end end |
#primary_step_by_steps? ⇒ 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 |
#related_links ⇒ Object
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 step_by_step_navs = if active_step_by_step? [active_step_by_step] elsif step_navs.any? step_navs elsif secondary_step_by_steps else [] end (step_by_step_navs) end |
#related_to_step_navs ⇒ Object
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 ||= .map do |step_nav| StepByStepModel.new(step_nav) end end |
#secondary_step_by_step ⇒ Object
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
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_steps ⇒ Object
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
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
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 |
#show_related_links? ⇒ 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 if active_step_by_step? true elsif step_navs.any? true elsif true else false end end |
#show_related_links_for_secondary_step_by_steps? ⇒ Boolean
124 125 126 |
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 124 def !primary_step_by_steps? && secondary_step_by_step? end |
#show_secondary_step_by_step? ⇒ 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
32 33 34 |
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 32 def show_header? && current_step_nav.steps.present? end |
#sidebar ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/govuk_publishing_components/presenters/page_with_step_by_step_navigation.rb', line 76 def if @sidebar ||= current_step_nav.content.tap do |sb| (sb) sb.merge!(small: true, heading_level: 3, tracking_id: current_step_nav.content_id, disable_ga4: @query_parameters[:disable_ga4]) end end end |
#step_navs ⇒ Object
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 |