diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b2927f7..b06bd5c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -7,10 +7,11 @@ * Comment on the Github issue (or create one if one does not exist) and let us know that you're working on it. * Fork the project (if you have not already) or rebase your fork so that it is up to date with the current repository's **`development`** branch * Create a new branch in your fork. This will ensure that you are able to work at your own pace and continue to pull in any updates made to this project. - * Make your changes in the new branch. When you have finished your work, squash all the commits on the branch that you are working on: + * Make your changes in the new branch. When you have finished your work (e.g. 3 commits), squash all the commits on the branch that you are working on: ```bash - git squash -i + git rebase -i HEAD~3 # If you have added 3 commits ``` + Then, change `pick` to `squash` for the 2nd and 3rd commits (to squash them into the single first commit). * To make sure that your version of the **`development`** branch is still up to date with this project, switch to it and synchronise: ```bash git checkout development diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index 6031374..2e2dbc2 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -32,29 +32,30 @@ def create @plan = Plan.new authorize @plan + + # We set these ids to -1 on the page to trick ariatiseForm into allowing the autocomplete to be blank if + # the no org/funder checkboxes are checked off + org_id = (plan_params[:org_id] == '-1' ? '' : plan_params[:org_id]) + funder_id = (plan_params[:funder_id] == '-1' ? '' : plan_params[:funder_id]) - @plan.principal_investigator = current_user.surname.blank? ? nil : "#{current_user.firstname} #{current_user.surname}" - @plan.principal_investigator_email = current_user.email - - orcid = current_user.identifier_for(IdentifierScheme.find_by(name: 'orcid')) - @plan.principal_investigator_identifier = orcid.identifier unless orcid.nil? - - @plan.funder_name = plan_params[:funder_name] - - @plan.visibility = (plan_params['visibility'].blank? ? Rails.application.config.default_plan_visibility : - plan_params[:visibility]) - - # If a template hasn't been identified look for the available templates + # If the template_id is blank then we need to look up the available templates and return JSON if plan_params[:template_id].blank? - template_options(plan_params[:org_id], plan_params[:funder_id]) - - # Return the 'Select a template' section - respond_to do |format| - format.js {} - end - - # Otherwise create the plan + templates = template_options(org_id, funder_id) + render json: {"templates": templates.collect{|t| {id: t.id, title: t.title} }}.to_json + else + # Otherwise create the plan + @plan.principal_investigator = current_user.surname.blank? ? nil : "#{current_user.firstname} #{current_user.surname}" + @plan.principal_investigator_email = current_user.email + + orcid = current_user.identifier_for(IdentifierScheme.find_by(name: 'orcid')) + @plan.principal_investigator_identifier = orcid.identifier unless orcid.nil? + + @plan.funder_name = plan_params[:funder_name] + + @plan.visibility = (plan_params['visibility'].blank? ? Rails.application.config.default_plan_visibility : + plan_params[:visibility]) + @plan.template = Template.find(plan_params[:template_id]) if plan_params[:title].blank? @@ -68,9 +69,8 @@ @plan.assign_creator(current_user) # pre-select org's guidance - ggs = GuidanceGroup.where(org_id: plan_params[:org_id], - optional_subset: false, - published: true) + ggs = GuidanceGroup.where(org_id: org_id, optional_subset: false, published: true) + if !ggs.blank? then @plan.guidance_groups << ggs end default = Template.find_by(is_default: true) @@ -90,17 +90,14 @@ msg += " #{_('This plan is based on the')} #{@plan.template.org.name} template." end - flash[:notice] = msg - respond_to do |format| - format.js { render js: "window.location='#{plan_url(@plan)}?editing=true'" } + format.html { redirect_to plan_path(@plan), notice: msg } end else # Something went wrong so report the issue to the user - flash[:alert] = failed_create_error(@plan, 'Plan') respond_to do |format| - format.js {} + format.html { redirect_to new_plan_path, alert: failed_create_error(@plan, 'Plan') } end end end @@ -317,7 +314,7 @@ def set_test plan = Plan.find(params[:id]) authorize plan - plan.visibility = "#{plan_params[:visibility]}" + plan.visibility = (params[:is_test] === "1" ? :is_test : :privately_visible) if plan.save render json: {msg: (plan.is_test? ? _('Your project is now a test.') : _('Your project is no longer a test.') )} else @@ -327,7 +324,6 @@ private - def plan_params params.require(:plan).permit(:org_id, :org_name, :funder_id, :funder_name, :template_id, :title, :visibility, :grant_number, :description, :identifier, :principal_investigator, @@ -421,46 +417,42 @@ # Collect all of the templates available for the org+funder combination # -------------------------------------------------------------------------- def template_options(org_id, funder_id) - @templates = [] + templates = [] if org_id.present? || funder_id.present? if funder_id.blank? # Load the org's template(s) if org_id.present? org = Org.find(org_id) - @templates = Template.valid.where(published: true, org: org, customization_of: nil).to_a - @msg = _("We found multiple DMP templates corresponding to the research organisation.") if @templates.count > 1 + templates = Template.valid.where(published: true, org: org, customization_of: nil).to_a end else funder = Org.find(funder_id) # Load the funder's template(s) - @templates = Template.valid.where(published: true, org: funder).to_a + templates = Template.valid.where(published: true, org: funder).to_a if org_id.present? org = Org.find(org_id) # Swap out any organisational cusotmizations of a funder template - @templates.each do |tmplt| + templates.each do |tmplt| customization = Template.valid.find_by(published: true, org: org, customization_of: tmplt.dmptemplate_id) if customization.present? && tmplt.updated_at < customization.created_at - @templates.delete(tmplt) - @templates << customization + templates.delete(tmplt) + templates << customization end end end - - @msg = _("We found multiple DMP templates corresponding to the funder.") if @templates.count > 1 end end # If no templates were available use the generic templates - if @templates.empty? - @msg = _("Using the generic Data Management Plan") - @templates << Template.where(is_default: true, published: true).first + if templates.empty? + templates << Template.where(is_default: true, published: true).first end - @templates = @templates.sort{|x,y| x.title <=> y.title } if @templates.count > 1 + templates = (templates.count > 0 ? templates.sort{|x,y| x.title <=> y.title} : []) end end diff --git a/app/views/layouts/_es5_scripts.html.erb b/app/views/layouts/_es5_scripts.html.erb index bf3d268..350c240 100644 --- a/app/views/layouts/_es5_scripts.html.erb +++ b/app/views/layouts/_es5_scripts.html.erb @@ -5,8 +5,8 @@ <%= javascript_include_tag 'rails.js' %> <%= javascript_include_tag 'jquery-ui.min.js' %> <%= javascript_include_tag 'placeholder.min.js' %> - <%= javascript_include_tag 'jquery.tablesorter.min.js' %> - <%= javascript_include_tag 'jquery.tablesorter.widgets.min.js' %> + <%#= javascript_include_tag 'jquery.tablesorter.min.js' %> + <%#= javascript_include_tag 'jquery.tablesorter.widgets.min.js' %> <%= javascript_include_tag 'jquery.timeago.js' %> <%#= javascript_include_tag 'bootstrap.min.js' %> @@ -17,8 +17,8 @@ <%= javascript_include_tag 'utils_es5/tinymce.js' %> <%= javascript_include_tag 'utils_es5/validate.js' %> <%= javascript_include_tag 'utils_es5/ariatiseForm.js' %> - <%= javascript_include_tag 'utils_es5/filteriseTable.js' %> - <%= javascript_include_tag 'utils_es5/collateTable.js' %> + <%#= javascript_include_tag 'utils_es5/filteriseTable.js' %> + <%#= javascript_include_tag 'utils_es5/collateTable.js' %> @@ -34,7 +34,7 @@ <%= javascript_include_tag 'views/orgs/admin_edit.js' %> <%= javascript_include_tag 'views/orgs/shibboleth_ds.js' %> <%= javascript_include_tag 'views/plans/available_templates.js' %> - <%= javascript_include_tag 'views/plans/index.js' %> + <%= javascript_include_tag 'views/plans/index.js' %> <%= javascript_include_tag 'views/registrations/sign_in_sign_up.js' %> <%= javascript_include_tag 'views/shared/login_form.js' %> <%= javascript_include_tag 'views/shared/register_form.js' %> diff --git a/app/views/phases/_admin_add.html.erb b/app/views/phases/_admin_add.html.erb index 5d60ffd..39bff5a 100644 --- a/app/views/phases/_admin_add.html.erb +++ b/app/views/phases/_admin_add.html.erb @@ -1,4 +1,3 @@ -<%- model_class = Phase -%>

<%= _('Phase details') %>

<%= _('When you create a new phase for your template, a version will automatically be created. Once you complete the form below you will be provided with options to create sections and questions.') %>

<%= form_for :phase, { url: admin_create_phase_path, html: { class: 'form-horizontal' }} do |f| %> diff --git a/app/views/phases/admin_preview.html.erb b/app/views/phases/admin_preview.html.erb index 0e7466a..bb0fee7 100644 --- a/app/views/phases/admin_preview.html.erb +++ b/app/views/phases/admin_preview.html.erb @@ -1,5 +1,3 @@ -<%- model_class = Phase -%> -

diff --git a/app/views/plans/index.html.erb b/app/views/plans/index.html.erb index ee17cf7..390e03d 100644 --- a/app/views/plans/index.html.erb +++ b/app/views/plans/index.html.erb @@ -54,12 +54,16 @@ <%= display_role(plan.roles.find_by(user: current_user)) %> <% if plan.administerable_by?(current_user.id) then %> - <%= plan.administerable_by?(current_user.id) ? '' : 'disabled="true"' %> /> + <%= form_for plan, url: set_test_plan_url(plan), html: {method: :post, id: 'update-test-plan'} do |f| %> + <%= check_box_tag(:is_test, "1", (plan.visibility === 'is_test')) %> + <% end %> <% else %> <%= plan.visibility === 'is_test' ? _('Yes') : _('No') %> <% end %> - <%= raw display_visibility(plan.visibility) %> + + <%= plan.visibility === 'is_test' ? _('N/A') : raw(display_visibility(plan.visibility)) %> +