Browse Source

refactor: move scheme helper methods to helpers

pull/1455/head
natdeanlewissoftwire 3 years ago
parent
commit
11362f0c15
  1. 20
      app/helpers/question_view_helper.rb
  2. 18
      app/models/form/question.rb
  3. 22
      app/models/scheme.rb
  4. 6
      app/views/form/_select_question.html.erb

20
app/helpers/question_view_helper.rb

@ -13,6 +13,26 @@ module QuestionViewHelper
}
end
def answer_option_synonyms(resource)
return unless resource.instance_of?(Scheme)
resource.locations.map(&:postcode).join(",")
end
def answer_option_append(resource)
return unless resource.instance_of?(Scheme)
confirmed_locations_count = resource.locations.confirmed.size
unconfirmed_locations_count = resource.locations.unconfirmed.size
"#{confirmed_locations_count} completed #{'location'.pluralize(confirmed_locations_count)}, #{unconfirmed_locations_count} incomplete #{'location'.pluralize(unconfirmed_locations_count)}"
end
def answer_option_hint(resource)
return unless resource.instance_of?(Scheme)
[resource.primary_client_group, resource.secondary_client_group].filter(&:present?).join(", ")
end
private
def label_size(page_header, conditional, question)

18
app/models/form/question.rb

@ -226,24 +226,6 @@ class Form::Question
label
end
def answer_option_synonyms(resource)
return unless resource.respond_to?(:synonyms)
resource.synonyms
end
def answer_option_append(resource)
return unless resource.respond_to?(:appended_text)
resource.appended_text
end
def answer_option_hint(resource)
return unless resource.respond_to?(:hint)
resource.hint
end
def answer_selected?(log, answer)
return false unless type == "select"

22
app/models/scheme.rb

@ -161,18 +161,6 @@ class Scheme < ApplicationRecord
]
end
def synonyms
locations.map(&:postcode).join(",")
end
def appended_text
"#{confirmed_locations_count} completed #{'location'.pluralize(confirmed_locations_count)}, #{unconfirmed_locations_count} incomplete #{'location'.pluralize(unconfirmed_locations_count)}"
end
def hint
[primary_client_group, secondary_client_group].filter(&:present?).join(", ")
end
def care_acts_options_with_hints
hints = { "Yes – part registered as a care home": "A proportion of units are registered as being a care home." }
@ -254,14 +242,4 @@ class Scheme < ApplicationRecord
def deactivated?
status == :deactivated
end
private
def confirmed_locations_count
locations.confirmed.size
end
def unconfirmed_locations_count
locations.unconfirmed.size
end
end

6
app/views/form/_select_question.html.erb

@ -9,9 +9,9 @@
hint: { text: question.hint_text&.html_safe }) do %>
<% answers.each do |answer| %>
<option value="<%= answer.id %>"
data-synonyms="<%= question.answer_option_synonyms(answer.resource) %>"
data-append="<%= question.answer_option_append(answer.resource) %>"
data-hint="<%= question.answer_option_hint(answer.resource) %>"
data-synonyms="<%= answer_option_synonyms(answer.resource) %>"
data-append="<%= answer_option_append(answer.resource) %>"
data-hint="<%= answer_option_hint(answer.resource) %>"
<%= question.answer_selected?(@log, answer) ? "selected" : "" %>
<%= answer.id == "" ? "disabled" : "" %>><%= answer.name || answer.resource %></option>
<% end %>

Loading…
Cancel
Save