diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 8f2d4df..afaf084 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -51,7 +51,8 @@ # GET /dmptemplates/1 def admin_template - @template = Template.find(params[:id]) + @template = Template.includes(:org, phases: [sections: [questions: [:question_options, :question_format, + :suggested_answers]]]).find(params[:id]) # check to see if this is a funder template needing customized if @template.org_id != current_user.org_id # definitely need to deep_copy the given template @@ -72,7 +73,7 @@ end end end - customizations = Template.includes(phases: [sections: [questions: :suggested_answers ]]).where(org_id: current_user.org_id, customization_of: @template.dmptemplate_id).order(version: :desc) + customizations = Template.includes(:org, phases: [sections: [questions: :suggested_answers ]]).where(org_id: current_user.org_id, customization_of: @template.dmptemplate_id).order(version: :desc) if customizations.present? # existing customization to port over max_version = customizations.first @@ -145,6 +146,8 @@ @template = new_version end authorize @template + # once the correct template has been generated, we convert it to hash + @hash = @template.to_hash end diff --git a/app/views/templates/_show_phases_sections.html.erb b/app/views/templates/_show_phases_sections.html.erb index e802f08..1338717 100644 --- a/app/views/templates/_show_phases_sections.html.erb +++ b/app/views/templates/_show_phases_sections.html.erb @@ -11,10 +11,10 @@
|
- <%= section.title %> +<%= section[:data].title %> |
- <% if section.questions.any? %>
- <% questions = section.questions.order("number ASC") %>
+ <% if section[:questions].present? %>
- <% if @template.org.funder? || current_user.org.funder? then %>
+ <% if @hash[:template][:org].funder? || current_user.org.funder? %>
- <%end%>
+ <% end %>
- <% if !@template.phases.nil? then %>
- <% if @template.phases.count == 1 then %>
- <% @template.phases.each do |phase| %>
+ <% if @hash[:template][:phases].present? %>
+ <% if @hash[:template][:phases].length == 1 %>
+ <% @hash[:template][:phases].each do |phase_no, phase| %>
- <%= render partial: 'templates/show_phases_sections', locals: {phase: phase}%>
- <%end%>
- <%else%>
- <% @template.phases.order(:number).each do |phase| %>
+ <%= render partial: 'templates/show_phases_sections', locals: {phase: phase[:data], phase_hash: phase, template: @template} %>
+ <% end %>
+ <% else %>
+ <% (1..@hash[:template][:phases].length).each do |phase_no| %>
+ <% phase = @hash[:template][:phases][phase_no] %>
- <%= render partial: "templates/show_template", locals: {template: @template}%>
+ <%= render partial: "templates/show_template", locals: {template: @template, hash: @hash}%>
- <%= render partial: 'templates/show_phases_sections', locals: {phase: phase}%>
+ <%= render partial: 'templates/show_phases_sections', locals: {phase: phase[:data], phase_hash: phase, template: @template}%>
|
|---|