Browse Source

wip

fix-remove-attr-accessors-from-questions-in-cldc-1723
Phil Lee 2 years ago committed by Sam Seed
parent
commit
0fa8337e9f
  1. 2
      app/components/check_answers_summary_list_card_component.html.erb
  2. 2
      app/components/check_answers_summary_list_card_component.rb
  3. 2
      app/helpers/check_answers_helper.rb
  4. 8
      app/models/form/lettings/questions/managing_organisation.rb
  5. 2
      app/models/form/lettings/questions/stock_owner.rb
  6. 6
      app/models/form/question.rb

2
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 %>
<span class="govuk-!-margin-right-4"><%= get_answer_label(question) %></span>
<span class="govuk-!-margin-right-4"><%= get_answer_label(question, user) %></span>
<% extra_value = question.get_extra_check_answer_value(log) %>
<% if extra_value %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= extra_value %></span>

2
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 || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
question.answer_label(log, user).presence || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
end
def check_answers_card_title(question)

2
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 || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
question.answer_label(lettings_log, current_user).presence || "<span class=\"app-!-colour-muted\">You didn’t answer this question</span>".html_safe
end
end

8
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]

2
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]

6
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

Loading…
Cancel
Save