Browse Source

wip

fix-remove-attr-accessors-from-questions-in-cldc-1723
Sam Seed 2 years ago
parent
commit
4565e4382e
  1. 4
      app/controllers/form_controller.rb
  2. 2
      app/models/form.rb
  3. 16
      app/models/form/lettings/questions/managing_organisation.rb
  4. 2
      app/models/form/question.rb
  5. 4
      app/models/log.rb

4
app/controllers/form_controller.rb

@ -96,7 +96,7 @@ private
next unless question_params next unless question_params
if %w[checkbox validation_override].include?(question.type) if %w[checkbox validation_override].include?(question.type)
question.answer_options.keys.reject { |x| x.match(/divider/) }.each do |option| question.answer_options(@log, current_user).keys.reject { |x| x.match(/divider/) }.each do |option|
result[option] = question_params.include?(option) ? 1 : 0 result[option] = question_params.include?(option) ? 1 : 0
end end
else else
@ -167,7 +167,7 @@ private
def question_missing_response?(responses_for_page, question) def question_missing_response?(responses_for_page, question)
if %w[checkbox validation_override].include?(question.type) if %w[checkbox validation_override].include?(question.type)
answered = question.answer_options.keys.reject { |x| x.match(/divider/) }.map do |option| answered = question.answer_options(@log, current_user).keys.reject { |x| x.match(/divider/) }.map do |option|
session["fields"][option] = @log[option] = params[@log.model_name.param_key][question.id].include?(option) ? 1 : 0 session["fields"][option] = @log[option] = params[@log.model_name.param_key][question.id].include?(option) ? 1 : 0
params[@log.model_name.param_key][question.id].exclude?(option) params[@log.model_name.param_key][question.id].exclude?(option)
end end

2
app/models/form.rb

@ -159,7 +159,7 @@ class Form
questions.reject { |q| q.page.routed_to?(log, current_user) || q.derived? || callback_questions.include?(q.id) } || [] questions.reject { |q| q.page.routed_to?(log, current_user) || q.derived? || callback_questions.include?(q.id) } || []
end end
def reset_not_routed_questions(log) def reset_not_routed_questions(log, current_user = nil)
enabled_questions = enabled_page_questions(log) enabled_questions = enabled_page_questions(log)
enabled_question_ids = enabled_questions.map(&:id) enabled_question_ids = enabled_questions.map(&:id)

16
app/models/form/lettings/questions/managing_organisation.rb

@ -1,5 +1,4 @@
class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
attr_accessor :current_user, :log
def initialize(id, hsh, page) def initialize(id, hsh, page)
super super
@ -10,7 +9,7 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
@answer_options = answer_options @answer_options = answer_options
end end
def answer_options def answer_options(log = nil, current_user = nil)
opts = { "" => "Select an option" } opts = { "" => "Select an option" }
return opts unless ActiveRecord::Base.connected? return opts unless ActiveRecord::Base.connected?
@ -33,19 +32,13 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
end end
def displayed_answer_options(log, user) def displayed_answer_options(log, user)
@current_user = user answer_options(log, user)
@log = log
answer_options
end end
def label_from_value(value, log = nil, user = nil) def label_from_value(value, log = nil, user = nil)
@log = log
@current_user = user
return unless value return unless value
answer_options[value] answer_options(log, user)[value]
end end
def derived? def derived?
@ -53,8 +46,7 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
end end
def hidden_in_check_answers?(log, user = nil) def hidden_in_check_answers?(log, user = nil)
@current_user = user user.nil? || !@page.routed_to?(log, user)
@current_user.nil? || !@page.routed_to?(log, user)
end end
def enabled def enabled

2
app/models/form/question.rb

@ -107,7 +107,7 @@ class Form::Question
end end
def displayed_answer_options(log, _current_user = nil) def displayed_answer_options(log, _current_user = nil)
answer_options.select do |_key, val| answer_options().select do |_key, val|
!val.is_a?(Hash) || !val["depends_on"] || form.depends_on_met(val["depends_on"], log) !val.is_a?(Hash) || !val["depends_on"] || form.depends_on_met(val["depends_on"], log)
end end
end end

4
app/models/log.rb

@ -73,10 +73,10 @@ private
subsection_statuses.all? { |status| not_started_statuses.include?(status) } subsection_statuses.all? { |status| not_started_statuses.include?(status) }
end end
def reset_invalidated_dependent_fields! def reset_invalidated_dependent_fields!(user = nil)
return unless form return unless form
form.reset_not_routed_questions(self) form.reset_not_routed_questions(self, user)
reset_created_by! reset_created_by!
end end

Loading…
Cancel
Save