diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 6c3e73e..27cca0d 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -110,6 +110,7 @@ @all_guidance_groups = @plan.get_guidance_group_options @selected_guidance_groups = @plan.guidance_groups.pluck(:id) + respond_to do |format| if @plan.save @@ -130,7 +131,24 @@ @plan = Plan.eager_load(params[:id]) authorize @plan @editing = (!params[:editing].nil? && @plan.administerable_by?(current_user.id)) + + # Get all Guidance Groups applicable for the plan and group them by org @all_guidance_groups = @plan.get_guidance_group_options + @all_ggs_grouped_by_org = @all_guidance_groups.sort.group_by(&:org) + + # Important ones come first on the page - we grab the user's org's GGs and "Organisation" org type GGs + @important_ggs = [] + @important_ggs << [current_user.org, @all_ggs_grouped_by_org.delete(current_user.org)] + @all_ggs_grouped_by_org.each do |org, ggs| + if org.organisation? + @important_ggs << [org,ggs] + @all_ggs_grouped_by_org.delete(org) + end + end + + # Sort the rest by org name for the accordion + @all_ggs_grouped_by_org = @all_ggs_grouped_by_org.sort_by {|org,gg| org.name} + @selected_guidance_groups = @plan.guidance_groups.pluck(:id) @based_on = @plan.base_template diff --git a/app/views/plans/_plan_details.html.erb b/app/views/plans/_plan_details.html.erb index 2817e20..2ed40f7 100644 --- a/app/views/plans/_plan_details.html.erb +++ b/app/views/plans/_plan_details.html.erb @@ -164,35 +164,70 @@ + <%= form_tag( update_guidance_choices_plan_path(@plan), method: :put) do %> +
+

Guidance Choices

+ + + <% @important_ggs.each do |org, groups| %> + + + <% end %> + <% end %> + + + <% end %> + +
+ <% if groups.size == 1 %> + <%= check_box_tag "guidance_group_ids[]", groups[0].id, @selected_guidance_groups.include?(groups[0].id) %> + <%= org.name %> + <% else %> + <%= org.name %> + <% groups.each do |group| %> +
+  <%= check_box_tag "guidance_group_ids[]", group.id, @selected_guidance_groups.include?(group.id) %> + <%= group.name %> +
+
-
- <%= form_tag( update_guidance_choices_plan_path(@plan), method: :put) do %> - - - <% all_guidance_groups.each do |group| %> - - - - <% end %> - - -
- <%= check_box_tag "guidance_group_ids[]", group.id, @selected_guidance_groups.include?(group.id) %> - <%= group.name %> -
- <%= submit_tag _('Save'), class: "btn btn-primary"%> +
+ + + <% @all_ggs_grouped_by_org.each do |org, groups| %> + + + <% end %> + <% end %> + + + <% end %> + +
+ <% if groups.size == 1 %> + <%= check_box_tag "guidance_group_ids[]", groups[0].id, @selected_guidance_groups.include?(groups[0].id) %> + <%= org.name %> + <% else %> + <%= org.name %> + <% groups.each do |group| %> +
+  <%= check_box_tag "guidance_group_ids[]", group.id, @selected_guidance_groups.include?(group.id) %> + <%= group.name %> +
+
<% end %>
-
+ + <%= submit_tag _('Save'), class: "btn btn-primary"%>