From 0fa8337e9fc07498d6c7c183b89fc37727ff4e84 Mon Sep 17 00:00:00 2001 From: Phil Lee Date: Fri, 16 Dec 2022 16:51:57 +0000 Subject: [PATCH] wip --- .../check_answers_summary_list_card_component.html.erb | 2 +- .../check_answers_summary_list_card_component.rb | 2 +- app/helpers/check_answers_helper.rb | 2 +- .../form/lettings/questions/managing_organisation.rb | 8 +++++++- app/models/form/lettings/questions/stock_owner.rb | 2 +- app/models/form/question.rb | 6 +++--- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/components/check_answers_summary_list_card_component.html.erb b/app/components/check_answers_summary_list_card_component.html.erb index 0005ed790..bc220ea75 100644 --- a/app/components/check_answers_summary_list_card_component.html.erb +++ b/app/components/check_answers_summary_list_card_component.html.erb @@ -11,7 +11,7 @@ <% summary_list.row do |row| %> <% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %> <% row.value do %> - <%= get_answer_label(question) %> + <%= get_answer_label(question, user) %> <% extra_value = question.get_extra_check_answer_value(log) %> <% if extra_value %> <%= extra_value %> diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb index 246173f48..113303ba0 100644 --- a/app/components/check_answers_summary_list_card_component.rb +++ b/app/components/check_answers_summary_list_card_component.rb @@ -13,7 +13,7 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base end def get_answer_label(question) - question.answer_label(log).presence || "You didn’t answer this question".html_safe + question.answer_label(log, user).presence || "You didn’t answer this question".html_safe end def check_answers_card_title(question) diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 709bbacd6..66a833859 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -43,6 +43,6 @@ private end def get_answer_label(question, lettings_log) - question.answer_label(lettings_log).presence || "You didn’t answer this question".html_safe + question.answer_label(lettings_log, current_user).presence || "You didn’t answer this question".html_safe end end diff --git a/app/models/form/lettings/questions/managing_organisation.rb b/app/models/form/lettings/questions/managing_organisation.rb index a2c14398d..95dd5d09f 100644 --- a/app/models/form/lettings/questions/managing_organisation.rb +++ b/app/models/form/lettings/questions/managing_organisation.rb @@ -10,8 +10,10 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question @answer_options = answer_options end + # def answer_options(log, current_user) def answer_options opts = { "" => "Select an option" } + return opts unless ActiveRecord::Base.connected? return opts unless current_user return opts unless log @@ -38,7 +40,11 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question answer_options end - def label_from_value(value) + def label_from_value(value, log = nil, user = nil) + # def label_from_value(log = nil, user = nil) + @current_user = user + @log = log + return unless value answer_options[value] diff --git a/app/models/form/lettings/questions/stock_owner.rb b/app/models/form/lettings/questions/stock_owner.rb index de82258a6..29aba5963 100644 --- a/app/models/form/lettings/questions/stock_owner.rb +++ b/app/models/form/lettings/questions/stock_owner.rb @@ -28,7 +28,7 @@ class Form::Lettings::Questions::StockOwner < ::Form::Question answer_options end - def label_from_value(value) + def label_from_value(value, log = nil, user = nil) return unless value answer_options[value] diff --git a/app/models/form/question.rb b/app/models/form/question.rb index ebc7b1fc6..979e8d19d 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -46,11 +46,11 @@ class Form::Question delegate :subsection, to: :page delegate :form, to: :subsection - def answer_label(log) + def answer_label(log, user = nil) return checkbox_answer_label(log) if type == "checkbox" return log[id]&.to_formatted_s(:govuk_date).to_s if type == "date" - answer = label_from_value(log[id]) if log[id].present? + answer = label_from_value(log[id], log, user) if log[id].present? answer_label = [prefix, format_value(answer), suffix_label(log)].join("") if answer inferred_answer_value(log) || answer_label @@ -151,7 +151,7 @@ class Form::Question end end - def label_from_value(value) + def label_from_value(value, user = nil) return unless value label = case type