diff --git a/app/controllers/answers_controller.rb b/app/controllers/answers_controller.rb index e66bd66..d8f09ca 100644 --- a/app/controllers/answers_controller.rb +++ b/app/controllers/answers_controller.rb @@ -51,7 +51,7 @@ }, "plan" => { "id" => @plan.id, - "progress" => render_to_string(:partial => 'plans/progress', locals: { plan: @plan }, formats: [:html]) + "progress" => render_to_string(:partial => 'plans/progress', locals: { plan: @plan, current_phase: @section.phase }, formats: [:html]) } }.to_json end # End update diff --git a/app/models/phase.rb b/app/models/phase.rb index 5c2323f..857c3c3 100644 --- a/app/models/phase.rb +++ b/app/models/phase.rb @@ -106,4 +106,23 @@ return phase_copy end + # Returns the number of answered question for the phase. It is assumed that the plan_id passed + # has this phase instance. + def num_answered_questions(plan_id) + n = 0 + self.sections.each do |s| + n+= s.num_answered_questions(plan_id) + end + return n + end + + # Returns the number of questions for a phase. Note, this method becomes useful + # for when sections and their questions are eager loaded so that avoids SQL queries. + def num_questions + n = 0 + self.sections.each do |s| + n+= s.questions.size() + end + return n + end end diff --git a/app/views/phases/_edit_plan_answers.html.erb b/app/views/phases/_edit_plan_answers.html.erb index d87522f..d4b142e 100644 --- a/app/views/phases/_edit_plan_answers.html.erb +++ b/app/views/phases/_edit_plan_answers.html.erb @@ -14,7 +14,7 @@