diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 9284b64..ae97316 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -72,8 +72,9 @@ if @plan.save @plan.assign_creator(current_user) - # pre-select org's guidance - ggs = GuidanceGroup.where(org_id: org_id, optional_subset: false, published: true) + # pre-select org's guidance and the default org's guidance + ids = (Org.managing_orgs << org_id).flatten.uniq + ggs = GuidanceGroup.where(org_id: ids, optional_subset: false, published: true) if !ggs.blank? then @plan.guidance_groups << ggs end @@ -108,35 +109,6 @@ end end end - - ## Using GET request to display all gudiance groups - def select_guidances_list - @plan = Plan.find(params[:id]) - authorize @plan - @all_guidance_groups = @plan.get_guidance_group_options - @selected_guidance_groups = @plan.guidance_groups - - render json: { - "plan" => { - "id" => @plan.id, - "html" => render_to_string(partial: 'plans/all_guidances', - locals: { guidance_groups: @all_guidance_groups, - selected_guidance_groups: @selected_guidance_groups }, - formats: [:html]) - } - }.to_json - end - - ## Using PUT request to update the plan with the guidance group selections - def update_guidances_list - @plan = Plan.find(params[:id]) - authorize @plan - - guidance_group_ids = params[:guidance_group_ids].blank? ? [] : params[:guidance_group_ids].map(&:to_i) - save_guidance_selections(guidance_group_ids) - @plan.save! - redirect_to(request.env["HTTP_REFERER"] || plan_path(@plan), notice: success_message(_('plan'), _('saved')) ) - end # GET /plans/show def show @@ -154,17 +126,16 @@ # 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)] + + @important_ggs << [current_user.org, @all_ggs_grouped_by_org[current_user.org]] if @all_ggs_grouped_by_org.include?(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 # If this is one of the already selected guidance groups its important! if !(ggs & @selected_guidance_groups).empty? @important_ggs << [org,ggs] unless @important_ggs.include?([org,ggs]) - @all_ggs_grouped_by_org.delete(org) end end @@ -186,7 +157,7 @@ attrs = plan_params # Save the guidance group selections - guidance_group_ids = params[:guidance_group_ids].blank? ? [] : params[:guidance_group_ids].map(&:to_i) + guidance_group_ids = params[:guidance_group_ids].blank? ? [] : params[:guidance_group_ids].map(&:to_i).uniq save_guidance_selections(guidance_group_ids) respond_to do |format| diff --git a/app/views/phases/_guidances_notes.html.erb b/app/views/phases/_guidances_notes.html.erb index 11d175e..7209d46 100644 --- a/app/views/phases/_guidances_notes.html.erb +++ b/app/views/phases/_guidances_notes.html.erb @@ -46,10 +46,10 @@ <% end %>
-
-
- <% if annotations.present? %> -
+ <% if annotations.present? %> +
+
+
<% num_annotations = 0 %> <% i = 0 %> @@ -65,20 +65,24 @@ <% 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}" %> -
+
+
+ <% 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}" %> +
+
+
<%= render partial: 'guidance_groups/show', locals: { group: guidance_set[group], question: question, guidance_accordion_id: "#{accordion_id}-#{i}" } %>
- <% end %> - <% end %> -
-
+
+
+ <% end %> + <% end %>
diff --git a/app/views/plans/_all_guidances.html.erb b/app/views/plans/_all_guidances.html.erb deleted file mode 100644 index 5130b63..0000000 --- a/app/views/plans/_all_guidances.html.erb +++ /dev/null @@ -1,36 +0,0 @@ - \ No newline at end of file diff --git a/app/views/plans/_edit_details.html.erb b/app/views/plans/_edit_details.html.erb index a489166..02e60a5 100644 --- a/app/views/plans/_edit_details.html.erb +++ b/app/views/plans/_edit_details.html.erb @@ -155,17 +155,37 @@ current_selections: @selected_guidance_groups} %> - <%#= _('See guidance from additional organisations') %> - - -

<%= _('Find guidance from additional organisations below') %>

- <%= link_to 'see the full list', select_guidances_list_plan_path(@plan), 'data-toggle' => 'modal', 'data-target' => '#modal-full-guidances', class: 'modal-guidances-window' %> - + <%= link_to 'See the full list', '#', 'data-toggle' => 'modal', 'data-target' => '#modal-full-guidances', class: 'modal-guidances-window' %> + +
+ <%= f.button(_('Submit'), class: "btn btn-default", type: "submit") %>
+ + + <% end %> - \ No newline at end of file + diff --git a/app/views/plans/_guidance_choices.html.erb b/app/views/plans/_guidance_choices.html.erb index eed6e73..6763f49 100644 --- a/app/views/plans/_guidance_choices.html.erb +++ b/app/views/plans/_guidance_choices.html.erb @@ -8,7 +8,6 @@ <% elsif groups %>
  • - diff --git a/config/branding_example.yml b/config/branding_example.yml index 2f82040..dfd82d3 100644 --- a/config/branding_example.yml +++ b/config/branding_example.yml @@ -4,7 +4,7 @@ # Warning: The abbreviation here should match the org.abbreviation value registered in your database! organisation: name: 'Curation Center' - abbreviation: 'CC' + abbreviation: 'CC' # This value is used to identify the default guidance that get auto-selected when a new plan is created url: 'https://github.com/DMPRoadmap/roadmap/wiki' copywrite_name: 'Curation Centre (CC)' email: 'tester@cc_curation_centre.org' diff --git a/config/routes.rb b/config/routes.rb index 6e9684d..cf050bd 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -208,8 +208,6 @@ post 'set_test', constraints: {format: [:json]} get 'request_feedback' get 'overview' - get 'select_guidances_list' - put 'update_guidances_list' end collection do diff --git a/lib/assets/javascripts/application.js b/lib/assets/javascripts/application.js index f5e2ac2..9671418 100644 --- a/lib/assets/javascripts/application.js +++ b/lib/assets/javascripts/application.js @@ -31,7 +31,6 @@ import './views/plans/index'; import './views/plans/new'; import './views/plans/share'; -import './views/plans/all_guidances'; import './views/roles/edit'; import './views/sections/edit'; import './views/sections/index'; diff --git a/lib/assets/javascripts/constants.js b/lib/assets/javascripts/constants.js index 15fc67e..82109c3 100644 --- a/lib/assets/javascripts/constants.js +++ b/lib/assets/javascripts/constants.js @@ -5,6 +5,8 @@ // top of the screen in the lower navigation row next to the Org Logo export const MAX_NUMBER_ORG_URLS = 3; +export const MAX_NUMBER_GUIDANCE_SELECTIONS = 6; + export const VALIDATION_MESSAGE_DEFAULT = 'Please enter a valid value.'; export const VALIDATION_MESSAGE_EMAIL = 'You must enter a valid email address.'; export const VALIDATION_MESSAGE_URL = 'You must enter a valid URL (e.g. https://organisation.org).'; diff --git a/lib/assets/javascripts/views/plans/all_guidances.js b/lib/assets/javascripts/views/plans/all_guidances.js deleted file mode 100644 index 76425a9..0000000 --- a/lib/assets/javascripts/views/plans/all_guidances.js +++ /dev/null @@ -1,23 +0,0 @@ -$(() => { - const success = (data) => { - // Render the html in the modal-permissions modal - $('#modal-full-guidances').html(data.plan.html); - }; - - const error = () => { - // There was an ajax error so just route the user to the sign-in modal - // and let them sign in as a Non-Partner Institution - $('a[data-target="#modal-full-guidances"]').tab('show'); - }; - // Loading the list of guidance groups options when user clicks the 'see the full list' link - $('.modal-guidances-window').on('click', (e) => { - const target = $(e.target); - $('#modal-full-guidances').html(''); - $.ajax({ - method: 'GET', - url: target.attr('href'), - }).done((data) => { - success(data); - }, error); - }); -}); diff --git a/lib/assets/javascripts/views/plans/edit_details.js b/lib/assets/javascripts/views/plans/edit_details.js index 468098e..f63eb51 100644 --- a/lib/assets/javascripts/views/plans/edit_details.js +++ b/lib/assets/javascripts/views/plans/edit_details.js @@ -1,5 +1,6 @@ import { Tinymce } from '../../utils/tinymce'; import ariatiseForm from '../../utils/ariatiseForm'; +import { MAX_NUMBER_GUIDANCE_SELECTIONS } from '../../constants'; $(() => { Tinymce.init(); @@ -20,4 +21,31 @@ showHideDataContact($(e.currentTarget)); }); showHideDataContact($('#show_data_contact')); + + // Keep the modal window's guidance selections in line with selections on the main page + const syncGuidance = () => { + const choices = $('#priority-guidance-orgs, #other-guidance-orgs').find('input[type="checkbox"]:checked') + .map((i, el) => $(el).val()).get() + .filter((v, i, a) => a.indexOf(v) === i); + + $('#priority-guidance-orgs, #other-guidance-orgs').find('input[type="checkbox"]').each((i, el) => { + const target = $(el); + if (choices.indexOf(target.val()) >= 0) { + target.attr('checked'); + } else { + target.removeAttr('checked'); + + // Disable the checkbox if it is unchecked and the user has already selected the max + if (choices.length >= MAX_NUMBER_GUIDANCE_SELECTIONS) { + target.attr('disabled', 'disabled'); + } else { + target.removeAttr('disabled'); + } + } + }); + }; + + $('#other-guidance-orgs').find('input[type="checkbox"]').click(syncGuidance); + $('#priority-guidance-orgs').find('input[type="checkbox"]').click(syncGuidance); }); + diff --git a/test/functional/plans_controller_test.rb b/test/functional/plans_controller_test.rb index dd1fe3a..c5f137e 100644 --- a/test/functional/plans_controller_test.rb +++ b/test/functional/plans_controller_test.rb @@ -77,36 +77,6 @@ # GET /plan/:id (plan_path) # ---------------------------------------------------------- - test "select_guidances_list for a plan" do - # Should redirect user to the root path if they are not logged in! - get select_guidances_list_plan_path(@plan) - assert_unauthorized_redirect_to_root_path - - sign_in @user - # GET /plan/:id (plan_path) - get select_guidances_list_plan_path(@plan) - assert_response :success - assert assigns(:plan) - assert_not assigns(:editing) - assert assigns(:all_guidance_groups) - end - - # PUT /plan/:id (plan_path) - # ---------------------------------------------------------- - test "update_guidances_list for a plan" do - ids = [GuidanceGroup.first.id, GuidanceGroup.last.id] - # Should redirect user to the root path if they are not logged in! - put update_guidances_list_plan_path(@plan), { "HTTP_REFERER": plan_path(@plan) } - assert_unauthorized_redirect_to_root_path - - sign_in @user - # GET /plan/:id (plan_path) - put update_guidances_list_plan_path(@plan), {plan: {id: @plan.id}, guidance_group_ids: ids} - assert_response :redirect - end - - # GET /plan/:id (plan_path) - # ---------------------------------------------------------- test 'show the plan page' do # Should redirect user to the root path if they are not logged in! get plan_path(@plan)