Browse Source

spiked extra values for location la

pull/780/head
JG 3 years ago
parent
commit
46117e05bd
  1. 8
      app/models/case_log.rb
  2. 18
      app/models/form/question.rb
  3. 1
      app/models/form/setup/questions/location_id.rb
  4. 7
      app/views/form/_check_answers_summary_list.html.erb
  5. 3
      db/seeds.rb

8
app/models/case_log.rb

@ -110,6 +110,14 @@ class CaseLog < ApplicationRecord
end end
end end
def location_admin_district
if location
location.location_admin_district
else
super
end
end
def postcode_full def postcode_full
if location if location
location.postcode location.postcode

18
app/models/form/question.rb

@ -3,7 +3,8 @@ class Form::Question
:type, :min, :max, :step, :width, :fields_to_add, :result_field, :type, :min, :max, :step, :width, :fields_to_add, :result_field,
:conditional_for, :readonly, :answer_options, :page, :check_answer_label, :conditional_for, :readonly, :answer_options, :page, :check_answer_label,
:inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value, :inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value,
:guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived :guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived,
:extra_check_answer_value
def initialize(id, hsh, page) def initialize(id, hsh, page)
@id = id @id = id
@ -24,6 +25,7 @@ class Form::Question
@answer_options = hsh["answer_options"] @answer_options = hsh["answer_options"]
@conditional_for = hsh["conditional_for"] @conditional_for = hsh["conditional_for"]
@inferred_answers = hsh["inferred_answers"] @inferred_answers = hsh["inferred_answers"]
@extra_check_answer_value = hsh["extra_check_answer_value"]
@inferred_check_answers_value = hsh["inferred_check_answers_value"] @inferred_check_answers_value = hsh["inferred_check_answers_value"]
@hidden_in_check_answers = hsh["hidden_in_check_answers"] @hidden_in_check_answers = hsh["hidden_in_check_answers"]
@derived = hsh["derived"] @derived = hsh["derived"]
@ -51,16 +53,22 @@ class Form::Question
def get_inferred_answers(case_log) def get_inferred_answers(case_log)
return [] unless inferred_answers return [] unless inferred_answers
enabled_inferred_answers(inferred_answers, case_log).keys.map do |x| enabled_inferred_answers(inferred_answers, case_log).keys.map do |answer|
question = form.get_question(x, case_log) question = form.get_question(answer, case_log)
if question.present? if question.present?
question.label_from_value(case_log[x]) question.label_from_value(case_log[answer])
else else
Array(x.to_s.split(".")).inject(case_log) { |o, a| o.present? ? o.public_send(*a) : "" } Array(answer.to_s.split(".")).inject(case_log) { |log, method| log.present? ? log.public_send(*method) : "" }
end end
end end
end end
def get_extra_check_answer_value(case_log)
return nil unless extra_check_answer_value
case_log.public_send(extra_check_answer_value)
end
def read_only? def read_only?
!!readonly !!readonly
end end

1
app/models/form/setup/questions/location_id.rb

@ -5,6 +5,7 @@ class Form::Setup::Questions::LocationId < ::Form::Question
@header = "Which location is this log for?" @header = "Which location is this log for?"
@hint_text = "" @hint_text = ""
@type = "radio" @type = "radio"
@extra_check_answer_value = "location_admin_district"
@answer_options = answer_options @answer_options = answer_options
@inferred_answers = { @inferred_answers = {
"location.name": { "location.name": {

7
app/views/form/_check_answers_summary_list.html.erb

@ -3,7 +3,12 @@
<% summary_list.row do |row| %> <% summary_list.row do |row| %>
<% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %> <% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %>
<% row.value do %> <% row.value do %>
<%= get_answer_label(question, @case_log) %><br> <%= get_answer_label(question, @case_log) %>
<% extra_value = question.get_extra_check_answer_value(@case_log) %>
<% if extra_value %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= extra_value %></span>
<% end %>
<br>
<% question.get_inferred_answers(@case_log).each do |inferred_answer| %> <% question.get_inferred_answers(@case_log).each do |inferred_answer| %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span> <span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span>
<% end %> <% end %>

3
db/seeds.rb

@ -28,6 +28,7 @@ unless Rails.env.test?
if Rails.env.development? && User.count.zero? if Rails.env.development? && User.count.zero?
User.create!( User.create!(
name: "Provider",
email: "provider@example.com", email: "provider@example.com",
password: "password", password: "password",
organisation: org, organisation: org,
@ -36,6 +37,7 @@ unless Rails.env.test?
) )
User.create!( User.create!(
name: "Coordinator",
email: "coordinator@example.com", email: "coordinator@example.com",
password: "password", password: "password",
organisation: org, organisation: org,
@ -44,6 +46,7 @@ unless Rails.env.test?
) )
User.create!( User.create!(
name: "Support",
email: "support@example.com", email: "support@example.com",
password: "password", password: "password",
organisation: org, organisation: org,

Loading…
Cancel
Save