@@ -7,12 +7,12 @@ class PhasesController < ApplicationController
77 # GET /plans/:plan_id/phases/:id/edit
88 def edit
99
10- @plan = Plan . eager_load2 ( params [ :plan_id ] )
10+ @plan = Plan . load_for_phase ( params [ :plan_id ] , params [ :id ] )
1111 # authorization done on plan so found in plan_policy
1212 authorize @plan
1313
1414 phase_id = params [ :id ] . to_i
15- @phase = @plan . template . phases . select { | p | p . id == phase_id } . first
15+ @phase = @plan . template . phases . first
1616 @readonly = !@plan . editable_by? ( current_user . id )
1717
1818 # Now we need to get all the themed guidance for the plan.
@@ -46,35 +46,35 @@ def edit
4646 end
4747 end
4848
49- # create hash from question id to theme to guidance array
50- # so when we arerendering a question we can grab the guidance out of this
51- #
52- # question_guidance = {
53- # question.id => {
54- # theme => [ {text: "......", org: "....."} ]
55- # }
56- # }
49+ questions = [ ]
50+ # Appends all the questions for a given phase into questions Array.
51+ @phase . sections . each do |section |
52+ section . questions . each do |question |
53+ questions . push ( question )
54+ end
55+ end
5756 @question_guidance = { }
58- @plan . questions . each do |question |
57+ # Puts in question_guidance (key/value) entries where key is the question id and value is a hash.
58+ # Each question id hash has (key/value) entries where key is a theme and value is an Array of {text, org} objects
59+ # Example hash
60+ # question_guidance = { question.id =>
61+ # { theme => [ {text: "......", org: "....."} ] }
62+ # }
63+ questions . each do |question |
5964 qg = { }
6065 question . themes . each do |t |
6166 title = t . title
6267 qg [ title ] = theme_guidance [ title ] if theme_guidance . has_key? ( title )
6368 end
64- if !@question_guidance . has_key? ( question . id )
65- @question_guidance [ question . id ] = Array . new
66- end
6769 @question_guidance [ question . id ] = qg
6870 end
6971
7072 if !user_signed_in? then
7173 respond_to do |format |
7274 format . html { redirect_to edit_user_registration_path }
73- end
74- end
75-
75+ end
7676 end
77-
77+ end
7878
7979 # GET /plans/PLANID/phases/PHASEID/status.json
8080 def status
0 commit comments