From e97bffb54f249850f8013f1416574310ca063731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Meny?= Date: Thu, 28 Jul 2022 14:58:46 +0100 Subject: [PATCH] Add the bottom guidance partial (#788) --- app/models/form/question.rb | 14 ++++++++++++++ app/models/form/setup/questions/scheme_id.rb | 2 ++ app/views/form/_checkbox_question.html.erb | 4 +++- app/views/form/_date_question.html.erb | 4 +++- app/views/form/_numeric_output_question.html.erb | 4 +++- app/views/form/_numeric_question.html.erb | 4 +++- app/views/form/_radio_question.html.erb | 4 +++- app/views/form/_select_question.html.erb | 4 +++- app/views/form/_text_question.html.erb | 4 +++- app/views/form/_textarea_question.html.erb | 4 +++- app/views/form/guidance/_scheme_selection.html.erb | 5 +++++ 11 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 app/views/form/guidance/_scheme_selection.html.erb diff --git a/app/models/form/question.rb b/app/models/form/question.rb index eb437b456..c21477bc9 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -5,6 +5,11 @@ class Form::Question :inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value, :guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived + module GuidancePosition + TOP = 1 + BOTTOM = 2 + end + def initialize(id, hsh, page) @id = id @page = page @@ -12,6 +17,7 @@ class Form::Question @check_answer_label = hsh["check_answer_label"] @header = hsh["header"] @guidance_partial = hsh["guidance_partial"] + @guidance_position = GuidancePosition::TOP @hint_text = hsh["hint_text"] @type = hsh["type"] @min = hsh["min"] @@ -238,6 +244,14 @@ class Form::Question case_log[id].to_s == answer.id.to_s end + def top_guidance? + @guidance_partial && @guidance_position == GuidancePosition::TOP + end + + def bottom_guidance? + @guidance_partial && @guidance_position == GuidancePosition::BOTTOM + end + private def selected_answer_option_is_derived?(case_log) diff --git a/app/models/form/setup/questions/scheme_id.rb b/app/models/form/setup/questions/scheme_id.rb index 27a9a6664..3c4985de1 100644 --- a/app/models/form/setup/questions/scheme_id.rb +++ b/app/models/form/setup/questions/scheme_id.rb @@ -7,6 +7,8 @@ class Form::Setup::Questions::SchemeId < ::Form::Question @type = "select" @answer_options = answer_options @derived = true unless FeatureToggle.supported_housing_schemes_enabled? + @guidance_position = GuidancePosition::BOTTOM + @guidance_partial = "scheme_selection" end def answer_options diff --git a/app/views/form/_checkbox_question.html.erb b/app/views/form/_checkbox_question.html.erb index eb6cd8d40..41bd3cc6d 100644 --- a/app/views/form/_checkbox_question.html.erb +++ b/app/views/form/_checkbox_question.html.erb @@ -1,4 +1,4 @@ -<%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %> <%= f.govuk_check_boxes_fieldset question.id.to_sym, caption: caption(caption_text, page_header, conditional), @@ -20,3 +20,5 @@ <% end %> <% end %> <% end %> + +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %> diff --git a/app/views/form/_date_question.html.erb b/app/views/form/_date_question.html.erb index 753ea5ba1..53abb5878 100644 --- a/app/views/form/_date_question.html.erb +++ b/app/views/form/_date_question.html.erb @@ -1,4 +1,4 @@ -<%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %> <%= f.govuk_date_field question.id.to_sym, caption: caption(caption_text, page_header, conditional), @@ -6,3 +6,5 @@ hint: { text: question.hint_text&.html_safe || "For example, 1 9 2022." }, width: 20, **stimulus_html_attributes(question) %> + +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %> diff --git a/app/views/form/_numeric_output_question.html.erb b/app/views/form/_numeric_output_question.html.erb index fdcfa4148..7f3f73719 100644 --- a/app/views/form/_numeric_output_question.html.erb +++ b/app/views/form/_numeric_output_question.html.erb @@ -1,4 +1,4 @@ -<%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %>
+ +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %> diff --git a/app/views/form/_numeric_question.html.erb b/app/views/form/_numeric_question.html.erb index 1d3d49646..d40067194 100644 --- a/app/views/form/_numeric_question.html.erb +++ b/app/views/form/_numeric_question.html.erb @@ -1,4 +1,4 @@ -<%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %> <%= f.govuk_number_field question.id.to_sym, caption: caption(caption_text, page_header, conditional), @@ -10,3 +10,5 @@ prefix_text: question.prefix.to_s, suffix_text: question.suffix_label(@case_log), **stimulus_html_attributes(question) %> + +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %> diff --git a/app/views/form/_radio_question.html.erb b/app/views/form/_radio_question.html.erb index a6cd165f9..d7bcc0381 100644 --- a/app/views/form/_radio_question.html.erb +++ b/app/views/form/_radio_question.html.erb @@ -1,4 +1,4 @@ -<%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %> <%= f.govuk_radio_buttons_fieldset question.id.to_sym, caption: caption(caption_text, page_header, conditional), @@ -34,3 +34,5 @@ <% end %> <% end %> <% end %> + +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %> diff --git a/app/views/form/_select_question.html.erb b/app/views/form/_select_question.html.erb index ef63153d7..ff4dd5f2e 100644 --- a/app/views/form/_select_question.html.erb +++ b/app/views/form/_select_question.html.erb @@ -1,4 +1,4 @@ -<%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %> <% selected = @case_log.public_send(question.id) || "" %> <% answers = question.displayed_answer_options(@case_log).map { |key, value| OpenStruct.new(id: key, name: value.respond_to?(:service_name) ? value.service_name : nil, resource: value) } %> @@ -16,3 +16,5 @@ <%= answer.id == "" ? "disabled" : "" %>><%= answer.name || answer.resource %> <% end %> <% end %> + +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %> diff --git a/app/views/form/_text_question.html.erb b/app/views/form/_text_question.html.erb index 4b11bea36..74e7e9b26 100644 --- a/app/views/form/_text_question.html.erb +++ b/app/views/form/_text_question.html.erb @@ -1,4 +1,4 @@ -<%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %> <%= f.govuk_text_field question.id.to_sym, caption: caption(caption_text, page_header, conditional), @@ -6,3 +6,5 @@ hint: { text: question.hint_text&.html_safe }, width: question.width || nil, **stimulus_html_attributes(question) %> + +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %> diff --git a/app/views/form/_textarea_question.html.erb b/app/views/form/_textarea_question.html.erb index e87cb558b..a9768e4d0 100644 --- a/app/views/form/_textarea_question.html.erb +++ b/app/views/form/_textarea_question.html.erb @@ -1,4 +1,4 @@ -<%= render partial: "form/guidance/#{question.guidance_partial}" if question.guidance_partial %> +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %> <%= f.govuk_text_area question.id.to_sym, caption: caption(caption_text, page_header, conditional), @@ -6,3 +6,5 @@ hint: { text: question.hint_text&.html_safe }, width: question.width || nil, **stimulus_html_attributes(question) %> + +<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %> diff --git a/app/views/form/guidance/_scheme_selection.html.erb b/app/views/form/guidance/_scheme_selection.html.erb new file mode 100644 index 000000000..c48644077 --- /dev/null +++ b/app/views/form/guidance/_scheme_selection.html.erb @@ -0,0 +1,5 @@ +<% if current_user.data_provider? %> +

If you can’t find the supported housing service you’re looking for or not sure which to choose, contact a data coordinator at <%= current_user.organisation.name %>.

+<% elsif current_user.data_coordinator? %> +

or <%= govuk_link_to "create a new supported housing service", new_scheme_path %>

+<% end %>