Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/forms/archived_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def show_pages
return redirect_to live_form_pages_path if current_form.is_live?
raise NotFoundError unless current_form.is_archived?

render :show_pages, locals: { form_document: current_archived_form, welsh_form_document: }
render :show_pages, locals: { form_document: current_archived_form, welsh_form_document:, multiple_branches_enabled: FeatureService.new(group: current_form.group).enabled?(:multiple_branches) }
end

private
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/forms/live_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def show_pages
return redirect_to archived_form_pages_path if current_form.is_archived?
raise NotFoundError unless current_form.is_live?

render :show_pages, locals: { form_document: current_live_form, welsh_form_document: }
render :show_pages, locals: { form_document: current_live_form, welsh_form_document:, multiple_branches_enabled: FeatureService.new(group: current_form.group).enabled?(:multiple_branches) }
end

private
Expand Down
5 changes: 3 additions & 2 deletions app/services/step_summary_card_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ def call(**args)
end
end

def initialize(step:, steps:, welsh_steps: nil)
def initialize(step:, steps:, welsh_steps: nil, multiple_branches_enabled: false)
@step = step
@steps = steps
@welsh_steps = welsh_steps
@multiple_branches_enabled = multiple_branches_enabled
end

def build_card
Expand All @@ -20,7 +21,7 @@ def build_card

def build_summary_list
{
rows: StepSummaryCardService.call(step: @step, steps: @steps).all_options_for_answer_type,
rows: StepSummaryCardService.call(step: @step, steps: @steps, multiple_branches_enabled: @multiple_branches_enabled).all_options_for_answer_type,
}
end

Expand Down
77 changes: 74 additions & 3 deletions app/services/step_summary_card_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ def call(**args)
end
end

def initialize(step:, steps:, read_only: true)
def initialize(step:, steps:, read_only: true, multiple_branches_enabled: false)
@read_only = read_only
@step = step
@steps = steps
@multiple_branches_enabled = multiple_branches_enabled
end

def all_options_for_answer_type
Expand Down Expand Up @@ -179,7 +180,19 @@ def address_input_type_to_string
end

def route_options
[{ key: { text: I18n.t("page_conditions.route") }, value: { text: route_value.html_safe } }]
if @multiple_branches_enabled
[{ key: { text: I18n.t("page_conditions.route2", count: number_of_routes) }, value: { text: route_value2 } }]
else
[{ key: { text: I18n.t("page_conditions.route") }, value: { text: route_value.html_safe } }]
end
end

def number_of_routes
if @step.routing_conditions.length == 1
1
else
answer_value_groups(@step.routing_conditions).length
end
end

def route_value
Expand All @@ -190,8 +203,47 @@ def route_value
end
end

def route_value2
if @step.routing_conditions.first.answer_value.present?
print_routes(@step.routing_conditions)
else
print_unconditional_route(@step.routing_conditions.first)
end
end

def print_unconditional_route(condition)
if condition.skip_to_end
I18n.t("page_conditions.unconditional_skip_to_end_of_form").html_safe
else
goto_question = @steps.find { |page| page.id == condition.goto_page_id }
goto_page_question_text = ActionController::Base.helpers.sanitize(goto_question.question_text)
goto_page_question_number = @steps.find_index(goto_question) + 1

I18n.t("page_conditions.unconditional_go_to_page", goto_page_question_number:, goto_page_question_text:).html_safe
end
end

def print_routes(conditions)
answer_value_groups = answer_value_groups(conditions)
answer_value_groups.map { |goto_page_id, condition_group|
if goto_page_id.nil?
caption = content_tag(:p, I18n.t("page_conditions.go_to_the_end"), class: "govuk-body-s")
else
goto_question = @steps.find { |page| page.id == condition_group.first.goto_page_id }
goto_page_question_text = ActionController::Base.helpers.sanitize(goto_question.question_text)
goto_page_question_number = @steps.find_index(goto_question) + 1

caption = content_tag(:p, I18n.t("page_conditions.go_to_page", goto_page_question_number:, goto_page_question_text:), class: "govuk-body-s")
end

answer_values = condition_group.map { |condition| "‘#{format_answer_value(condition.answer_value)}’" }
formatted_list = html_unordered_list2(answer_values)
safe_join([caption, formatted_list])
}.join.html_safe
end

def print_route(condition)
answer_value = ActionController::Base.helpers.sanitize(condition.answer_value)
answer_value = format_answer_value(condition.answer_value)

if condition.skip_to_end && condition.secondary_skip?
I18n.t("page_conditions.condition_compact_html_secondary_skip_to_end_of_form")
Expand All @@ -214,6 +266,11 @@ def print_route(condition)
end
end

def format_answer_value(answer_value)
answer_value = I18n.t("page_conditions.none_of_the_above") if answer_value == "none_of_the_above"
ActionController::Base.helpers.sanitize(answer_value)
end

def html_ordered_list(list_items)
content_tag(:ol, html_list_item(list_items), class: ["govuk-list", "govuk-list--number"])
end
Expand All @@ -222,7 +279,21 @@ def html_unordered_list(list_items)
content_tag(:ul, html_list_item(list_items), class: ["govuk-list", "govuk-list--bullet"])
end

def html_unordered_list2(list_items)
content_tag(:ul, html_list_item(list_items), class: ["govuk-list", "govuk-list--bullet govuk-!-static-margin-bottom-4"])
end

def html_list_item(item)
item.map { |i| content_tag(:li, i) }.join.html_safe
end

def answer_value_groups(conditions)
answer_order = @step.answer_settings.selection_options.map(&:value) || []

conditions.group_by(&:goto_page_id).map { |goto_page_id, condition_group|
goto_page_position = @steps.find_index { |page| page.id == goto_page_id } + 1 unless goto_page_id.nil?
sorted_condition_group = condition_group.in_order_of(:answer_value, answer_order, filter: false)
[goto_page_position, sorted_condition_group]
}.sort_by { |goto_page_position, _| goto_page_position || Float::INFINITY }
end
end
2 changes: 1 addition & 1 deletion app/views/forms/_made_live_form_pages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<%= StepSummaryCardPresenter.call(step:, steps: form_document.steps, welsh_steps: welsh_form_document.steps).build_untranslated_content[:text] %>
<% end %>
<% else %>
<%= govuk_summary_list(**StepSummaryCardPresenter.call(step:, steps: form_document.steps).build_summary_list)%>
<%= govuk_summary_list(**StepSummaryCardPresenter.call(step:, steps: form_document.steps, multiple_branches_enabled:).build_summary_list)%>
<% end %>
<% end %>
<% end %>
Expand Down
1 change: 1 addition & 0 deletions app/views/forms/archived/show_pages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
welsh_form_document:,
status: :archived,
show_form_path: archived_form_path(form_document.id),
multiple_branches_enabled:,
} %>
1 change: 1 addition & 0 deletions app/views/forms/live/show_pages.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
welsh_form_document:,
status: :live,
show_form_path: live_form_path(form_document.id),
multiple_branches_enabled:,
} %>
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1451,11 +1451,18 @@ en:
end_of_form: End of the form
exit_page: Add an exit page
exit_page_label: An ‘exit page’ to leave the form
go_to_page: 'Go to %{goto_page_question_number}, ‘%{goto_page_question_text}’ if the answer is:'
go_to_the_end: 'Go to the end of the form if the answer is:'
none_of_the_above: None of the above
route: Route
route2:
one: Route
other: Routes
secondary_skip_description: After %{check_page_question_text} go to %{goto_page_question_text}
skip_condition_route_page_text: "%{route_page_question_number}, “%{route_page_question_text}”"
unconditional_go_to_page: Go to %{goto_page_question_number}, ‘%{goto_page_question_text}’
unconditional_goto_page_text: Go to %{goto_page_question_number}, ‘%{goto_page_question_text}’
unconditional_skip_to_end_of_form: Go to the end of the form
unconditional_skip_to_end_text: Go to the end of the form
page_route_card:
any_other_answer: Route for any other answer
Expand Down
3 changes: 2 additions & 1 deletion spec/services/step_summary_card_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
let(:steps) do
[step, *build_list(:form_document_step, 5)]
end
let(:presenter) { described_class.call(step:, steps:) }
let(:multiple_branches_enabled) { false }
let(:presenter) { described_class.call(step:, steps:, multiple_branches_enabled:) }

describe "#build_card" do
before do
Expand Down
Loading