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
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
end
else
@ -167,7 +167,7 @@ private
def question_missing_response?(responses_for_page, question)
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
params[@log.model_name.param_key][question.id].exclude?(option)
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) } || []
end
def reset_not_routed_questions(log)
def reset_not_routed_questions(log, current_user = nil)
enabled_questions = enabled_page_questions(log)
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
attr_accessor :current_user, :log
def initialize(id, hsh, page)
super
@ -10,7 +9,7 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
@answer_options = answer_options
end
def answer_options
def answer_options(log = nil, current_user = nil)
opts = { "" => "Select an option" }
return opts unless ActiveRecord::Base.connected?
@ -33,19 +32,13 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
end
def displayed_answer_options(log, user)
@current_user = user
@log = log
answer_options
answer_options(log, user)
end
def label_from_value(value, log = nil, user = nil)
@log = log
@current_user = user
return unless value
answer_options[value]
answer_options(log, user)[value]
end
def derived?
@ -53,8 +46,7 @@ class Form::Lettings::Questions::ManagingOrganisation < ::Form::Question
end
def hidden_in_check_answers?(log, user = nil)
@current_user = user
@current_user.nil? || !@page.routed_to?(log, user)
user.nil? || !@page.routed_to?(log, user)
end
def enabled

2
app/models/form/question.rb

@ -107,7 +107,7 @@ class Form::Question
end
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)
end
end

4
app/models/log.rb

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

Loading…
Cancel
Save