diff --git a/app/controllers/phases_controller.rb b/app/controllers/phases_controller.rb index e3980fd..d20b7ea 100644 --- a/app/controllers/phases_controller.rb +++ b/app/controllers/phases_controller.rb @@ -4,8 +4,8 @@ after_action :verify_authorized - # GET /plans/:plan_id/phases/:id/edit - def edit + # GET /plans/:plan_id/phases/:id/edit + def edit @plan = Plan.eager_load2(params[:plan_id]) # authorization done on plan so found in plan_policy @@ -69,12 +69,12 @@ if !user_signed_in? then respond_to do |format| - format.html { redirect_to edit_user_registration_path } - end - end - + format.html { redirect_to edit_user_registration_path } + end end + end + # GET /plans/PLANID/phases/PHASEID/status.json def status diff --git a/app/controllers/plans_controller.rb b/app/controllers/plans_controller.rb index e4bce3a..06373d9 100644 --- a/app/controllers/plans_controller.rb +++ b/app/controllers/plans_controller.rb @@ -174,7 +174,12 @@ @plan = Plan.find(params[:id]) authorize @plan @visibility = @plan.visibility.present? ? @plan.visibility.to_s : Rails.application.config.default_plan_visibility - @allow_visibility = (@plan.num_answered_questions >= 1 && !@plan.is_test?) + + min_percentage = Rails.application.config.default_plan_percentage_answered + nanswers = @plan.num_answered_questions() + nquestions = @plan.num_questions() + value=(nanswers.to_f/nquestions*100).round(2) + @allow_visibility = (value >= min_percentage && !@plan.is_test?) end @@ -290,13 +295,9 @@ respond_to do |format| if @plan.save @plan.assign_creator(current_user) - flash[:notice] = success_message(_('plan'), _('copied')) - format.js { render js: "window.location='#{plan_url(@plan)}?editing=true'" } - # format.html { redirect_to @plan, notice: _('Plan was successfully duplicated.') } - # format.json { head :no_content } + format.html { redirect_to @plan, notice: success_message(_('plan'), _('copied')) } else - flash[:alert] = failed_create_error(@plan, 'Plan') - format.js {} + format.html { redirect_to plans_path, alert: failed_create_error(@plan, 'Plan') } end end end @@ -454,7 +455,6 @@ if templates.empty? templates << Template.where(is_default: true, published: true).first end - templates = (templates.count > 0 ? templates.sort{|x,y| x.title <=> y.title} : []) end diff --git a/app/models/exported_plan.rb b/app/models/exported_plan.rb index c14979f..bc42e4b 100644 --- a/app/models/exported_plan.rb +++ b/app/models/exported_plan.rb @@ -158,7 +158,9 @@ end sections.each do |section| - output += "\n#{section.title}\n" + if question_headings + output += "\n#{section.title}\n" + end section.questions.each do |question| answer = self.plan.answer(question.id, false) #skip if question un-answered diff --git a/app/views/plans/_download_form.html.erb b/app/views/plans/_download_form.html.erb index 03449f9..b6965e8 100644 --- a/app/views/plans/_download_form.html.erb +++ b/app/views/plans/_download_form.html.erb @@ -1,5 +1,5 @@ -<%= form_tag( export_plan_path(@plan), method: :get) do |f| %> -
<%= _('Public or organisational visibility is intended for finished plans. You must answer at least one question to enable these options.') %>
+<%= _('Public and organisational visibility are intended for finished plans. You must answer at least %{percentage}%% of the questions to enable these options. Test plans are private by default and not included in usage information.') % {percentage: Rails.application.config.default_plan_percentage_answered.round} %>
<%= form_for @plan, html: {method: :put, id: "set_visibility"} do |f| %>