diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb
index 080f0d3..d7adfd5 100644
--- a/app/controllers/plans_controller.rb
+++ b/app/controllers/plans_controller.rb
@@ -1,6 +1,6 @@
+require 'pp'
class PlansController < ApplicationController
include ConditionalUserMailer
- require 'pp'
helper PaginableHelper
helper SettingsTemplateHelper
include FeedbacksHelper
@@ -160,10 +160,7 @@
readonly = !plan.editable_by?(current_user.id)
- guidance_groups_ids = plan.guidance_groups.collect(&:id)
-
- guidance_groups = GuidanceGroup.where(published: true, id: guidance_groups_ids)
-
+ guidance_groups = GuidanceGroup.where(published: true, id: plan.guidance_group_ids)
# Since the answers have been pre-fetched through plan (see Plan.load_for_phase)
# we create a hash whose keys are question id and value is the answer associated
answers = plan.answers.reduce({}){ |m, a| m[a.question_id] = a; m }
@@ -173,7 +170,8 @@
plan: plan, phase: phase, readonly: readonly,
question_guidance: plan.guidance_by_question_as_hash,
guidance_groups: guidance_groups,
- answers: answers })
+ answers: answers,
+ guidance_service: GuidanceService.new(plan) })
end
# PUT /plans/1
diff --git a/app/views/guidance_groups/_index_by_theme.html.erb b/app/views/guidance_groups/_index_by_theme.html.erb
index 3c39eff..8ba4226 100644
--- a/app/views/guidance_groups/_index_by_theme.html.erb
+++ b/app/views/guidance_groups/_index_by_theme.html.erb
@@ -11,22 +11,36 @@
<% guidance_groups_by_theme.each_pair do |guidance_group, theme_hash| %>
<% theme_hash.each_pair do |theme, guidances| %>
+<<<<<<< HEAD
"
+=======
+ id="<%= "#{guidances.object_id}" %>"
+>>>>>>> parent of ac3dbec2... Revert "lookup hash guidance groups by org. DMPRoadmap/roadmap#1409"
class="panel-collapse collapse"
role="tabpanel"
aria-labelledby="<%= "panel-heading-#{guidances.object_id}" %>">
@@ -39,4 +53,8 @@
<% end %>
<% end %>
+<<<<<<< HEAD
+=======
+
+>>>>>>> parent of ac3dbec2... Revert "lookup hash guidance groups by org. DMPRoadmap/roadmap#1409"
diff --git a/app/views/phases/_edit_plan_answers.html.erb b/app/views/phases/_edit_plan_answers.html.erb
index 41cc613..e01758b 100644
--- a/app/views/phases/_edit_plan_answers.html.erb
+++ b/app/views/phases/_edit_plan_answers.html.erb
@@ -72,7 +72,12 @@
- <%= render partial: '/phases/guidances_notes', locals: { plan: plan, template: phase.template, question: question, answer: answer, question_guidance: question_guidance, guidance_groups: guidance_groups, base_template_org: base_template_org } %>
+ <%= render partial: '/phases/guidances_notes', locals: {
+ plan: plan,
+ template: phase.template,
+ question: question,
+ answer: answer,
+ guidance_service: guidance_service } %>
<%= raw('
') if i != section.questions.length - 1 %>
diff --git a/app/views/phases/_guidances_notes.html.erb b/app/views/phases/_guidances_notes.html.erb
index 9ad6e2a..b080f71 100644
--- a/app/views/phases/_guidances_notes.html.erb
+++ b/app/views/phases/_guidances_notes.html.erb
@@ -1,7 +1,6 @@
-<%# locals: { plan, template, question, answer, question_guidance, guidance_groups } %>
-<% annotations = question.annotations.where(type: Annotation.types[:guidance]) %>
-<% guidance_set = question_guidance[question.id] || {} %>
-<% guidances_active = (annotations.present? || guidance_set.length > 0) %>
+<%# locals: { plan, template, question, answer, guidance_service } %>
+<% guidances_active = guidance_service.any? %>
+<% active_nav = nil %>
@@ -25,59 +24,45 @@
- <% if annotations.present? %>
-
-
-
-
- <% num_annotations = 0 %>
- <% i = 0 %>
- <% annotations.each do |annotation| %>
- <%= render partial: 'org_admin/annotations/show',
- locals: {
- template: template,
- example_answer: (annotation.example_answer? ? annotation : nil),
- guidance: (annotation.guidance? ? annotation : nil),
- for_plan: true
- } %>
- <% num_annotations += 1%>
- <% i += 1 %>
- <% end %>
-
-
-
- <% end %>
- <% guidance_accordion_id = 0 %>
- <% guidance_set.keys.each_with_index do |group, i| %>
- <% obj = guidance_groups.select{ |gg| gg.name == group }.first %>
- <% if obj.present? %>
- <% accordion_id = "#{question.id}-#{obj.id}" %>
-
+ <% guidance_service.orgs.each_with_index do |org, i| %>
+ <% if guidance_service.any?(org: org, question: question) %>
+
" role="tabpanel" class="tab-pane <%= active_nav == org.id ? 'active' : '' %>">
- <%= render partial: 'guidance_groups/show',
- locals: { group: guidance_set[group], question: question, guidance_accordion_id: "#{accordion_id}-#{i}" } %>
+ <% guidance_service.guidance_annotations(org: org, question: question).each do |annotation| %>
+ <%=
+ render partial: 'org_admin/annotations/show', locals: {
+ template: template,
+ example_answer: nil,
+ guidance: annotation,
+ for_plan: true }
+ %>
+ <% end %>
+ <% if guidance_service.guidance_annotations?(org: org, question: question) &&
+ guidance_service.guidance_groups_by_theme?(org: org, question: question) %>
+
+ <% end %>
+ <% if guidance_service.guidance_groups_by_theme?(org: org, question: question) %>
+ <%= render partial: 'guidance_groups/index_by_theme',
+ locals: { guidance_groups_by_theme: guidance_service.guidance_groups_by_theme(org: org, question: question) } %>
+ <% end %>
diff --git a/config/application.rb b/config/application.rb
index 7c2e2f1..e09c0ef 100644
--- a/config/application.rb
+++ b/config/application.rb
@@ -41,6 +41,7 @@
config.active_support.escape_html_entities_in_json = true
config.eager_load_paths << "app/models/scopes"
+ config.eager_load_paths << "app/services"
# Use SQL instead of Active Record's schema dumper when creating the database.
# This is necessary if your schema can't be completely dumped by the schema dumper,