Browse Source

Update flow to allow non persisted logs

CLDC-1324-remove-not-started
Jack S 2 years ago
parent
commit
2cac3442d1
  1. 14
      app/controllers/form_controller.rb
  2. 12
      app/controllers/lettings_logs_controller.rb
  3. 6
      app/controllers/sales_logs_controller.rb
  4. 49
      app/helpers/form_page_helper.rb
  5. 44
      app/helpers/log_actions_helper.rb
  6. 6
      app/helpers/tasklist_helper.rb
  7. 2
      app/models/form.rb
  8. 7
      app/services/feature_toggle.rb
  9. 18
      app/views/form/check_answers.html.erb
  10. 11
      app/views/form/page.html.erb
  11. 4
      app/views/logs/index.html.erb
  12. 4
      app/views/organisations/logs.html.erb

14
app/controllers/form_controller.rb

@ -107,7 +107,11 @@ private
def find_resource
@log = if params.key?("sales_log")
current_user.sales_logs.visible.find_by(id: params[:id])
if params[:id] == "new" && FeatureToggle.not_started_status_removed?
current_user.sales_logs.new
else
current_user.sales_logs.visible.find_by(id: params[:id])
end
else
current_user.lettings_logs.visible.find_by(id: params[:id])
end
@ -115,7 +119,13 @@ private
def find_resource_by_named_id
@log = if params[:sales_log_id].present?
current_user.sales_logs.visible.find_by(id: params[:sales_log_id])
if params[:sales_log_id] == "new" && FeatureToggle.not_started_status_removed?
current_user.sales_logs.new
else
current_user.sales_logs.visible.find_by(id: params[:sales_log_id])
end
elsif params[:lettings_log_id] == "new" && FeatureToggle.not_started_status_removed?
current_user.lettings_logs.new
else
current_user.lettings_logs.visible.find_by(id: params[:lettings_log_id])
end

12
app/controllers/lettings_logs_controller.rb

@ -58,7 +58,11 @@ class LettingsLogsController < LogsController
end
def edit
@log = current_user.lettings_logs.find(params[:id])
@log = if params[:id] == "new" && FeatureToggle.not_started_status_removed?
current_user.lettings_logs.new
else
current_user.lettings_logs.find(params[:id])
end
if @log.unresolved
redirect_to(send(@log.form.unresolved_log_path, @log))
@ -139,7 +143,11 @@ private
end
def find_resource
@log = LettingsLog.visible.find_by(id: params[:id])
@log = if params[:id] == "new" && FeatureToggle.not_started_status_removed?
LettingsLog.new
else
LettingsLog.visible.find_by(id: params[:id])
end
end
def post_create_redirect_url(log)

6
app/controllers/sales_logs_controller.rb

@ -34,7 +34,11 @@ class SalesLogsController < LogsController
end
def edit
@log = current_user.sales_logs.visible.find(params[:id])
@log = if params[:id] == "new" && FeatureToggle.not_started_status_removed?
current_user.sales_logs.new
else
current_user.sales_logs.visible.find(params[:id])
end
render "logs/edit", locals: { current_user: }
end

49
app/helpers/form_page_helper.rb

@ -1,5 +1,52 @@
module FormPageHelper
def action_href(log, page_id, referrer = "check_answers")
send("#{log.model_name.param_key}_#{page_id}_path", log, referrer:)
if FeatureToggle.not_started_status_removed?
if log.is_a? SalesLog
send("#{log.model_name.param_key}_#{page_id}_path", sales_log_id: (log.id || "new"), referrer:)
else
send("#{log.model_name.param_key}_#{page_id}_path", lettings_log_id: (log.id || "new"), referrer:)
end
else
send("#{log.model_name.param_key}_#{page_id}_path", log, referrer:)
end
end
def page_back_link(log:, page:, user:, referrer:)
if FeatureToggle.not_started_status_removed?
govuk_back_link(href: send(*log.form.previous_page_redirect_path(page, log, user, referrer)))
else
govuk_back_link(href: send(*log.form.previous_page_redirect_path(page, log, current_user, referrer)))
end
end
def page_cancel_link(page:, log:)
if FeatureToggle.not_started_status_removed?
if log.sales?
govuk_link_to "Cancel", send(log.form.cancel_path(page, log), sales_log_id: log.id || "new")
else
govuk_link_to "Cancel", send(log.form.cancel_path(page, log), lettings_log_id: log.id || "new")
end
else
govuk_link_to "Cancel", send(log.form.cancel_path(page, log), log)
end
end
def page_skip_link(page:, log:, user:)
link = (page.skip_href(log) || (
if FeatureToggle.not_started_status_removed?
if log.sales?
send(log.form.next_page_redirect_path(page, log, user), sales_log_id: log.id || "new")
else
send(log.form.next_page_redirect_path(page, log, user), lettings_log_id: log.id || "new")
end
else
send(log.form.next_page_redirect_path(page, log, user), log)
end
))
govuk_link_to(
page.skip_text || "Skip for now",
link,
)
end
end

44
app/helpers/log_actions_helper.rb

@ -12,6 +12,50 @@ module LogActionsHelper
end
end
def create_lettings_log_button
if FeatureToggle.not_started_status_removed?
govuk_button_link_to "Create a new lettings log", lettings_log_path(id: "new"), class: "govuk-!-margin-right-6"
else
govuk_button_to "Create a new lettings log", lettings_logs_path, class: "govuk-!-margin-right-6"
end
end
def create_lettings_log_for_org_button(org)
# This doesn't work because it's a get request and can't old params like that
if FeatureToggle.not_started_status_removed?
govuk_button_link_to(
"Create a new lettings log for this organisation",
lettings_log_path(id: "new", lettings_log: { owning_organisation_id: org.id }),
)
else
govuk_button_to(
"Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: org.id }, method: :post)
)
end
end
def create_sales_log_button
if FeatureToggle.not_started_status_removed?
govuk_button_link_to "Create a new sales log", sales_log_path(id: "new"), class: "govuk-!-margin-right-6"
else
govuk_button_to "Create a new sales log", sales_logs_path, class: "govuk-!-margin-right-6"
end
end
def create_sales_log_for_org_button(org)
if FeatureToggle.not_started_status_removed?
govuk_button_link_to(
"Create a new sales log for this organisation",
sales_logs_path(id: "new", sales_log: { owning_organisation_id: org.id }),
)
else
govuk_button_to(
"Create a new sales log for this organisation",
sales_logs_path(sales_log: { owning_organisation_id: org.id }, method: :post),
)
end
end
private
def back_button_for(log)

6
app/helpers/tasklist_helper.rb

@ -50,6 +50,10 @@ private
"#{log.class.name.underscore}_#{next_question_page(subsection, log, current_user)}_path"
end
send(path, log)
if log.is_a? SalesLog
send(path, sales_log_id: log.id || "new")
else
send(path, lettings_log_id: log.id || "new")
end
end
end

2
app/models/form.rb

@ -106,7 +106,7 @@ class Form
if referrer == "check_answers"
"#{type}_log_#{subsection_for_page(page).id}_check_answers_path"
elsif previous_page_id == :tasklist
"#{type}_log_path"
["#{type}_log_path", { id: (log.id || "new") }]
else
"#{type}_log_#{previous_page_id}_path"
end

7
app/services/feature_toggle.rb

@ -45,4 +45,11 @@ class FeatureToggle
def self.merge_organisations_enabled?
!Rails.env.production?
end
def self.not_started_status_removed?
return false if Rails.env.production?
return false if Rails.env.test?
true
end
end

18
app/views/form/check_answers.html.erb

@ -30,11 +30,19 @@
} %>
<% end %>
<%= form_with model: @log, method: "get" do |f| %>
<%= f.govuk_submit "Save and return to log" do %>
<% next_incomplete_section_redirect_path = @log.form.next_incomplete_section_redirect_path(subsection, @log) %>
<% if @log.status == "in_progress" && next_incomplete_section_redirect_path != "error" %>
<%= govuk_button_link_to "Save and go to next incomplete section", send(next_incomplete_section_path(@log, next_incomplete_section_redirect_path), @log), secondary: true %>
<% if @log.id.nil? %>
<% if @log.lettings? %>
<%= govuk_button_link_to "Return to log", sales_log_path(id: "new"), class: "govuk-!-margin-right-6" %>
<% else %>
<%= govuk_button_link_to "Return to log", lettings_log_path(id: "new"), class: "govuk-!-margin-right-6" %>
<% end %>
<% else %>
<%= form_with model: @log, method: "get" do |f| %>
<%= f.govuk_submit "Save and return to log" do %>
<% next_incomplete_section_redirect_path = @log.form.next_incomplete_section_redirect_path(subsection, @log) %>
<% if @log.status == "in_progress" && next_incomplete_section_redirect_path != "error" %>
<%= govuk_button_link_to "Save and go to next incomplete section", send(next_incomplete_section_path(@log, next_incomplete_section_redirect_path), @log), secondary: true %>
<% end %>
<% end %>
<% end %>
<% end %>

11
app/views/form/page.html.erb

@ -1,7 +1,7 @@
<% content_for :title, @page.header.presence || @page.questions.first.header.html_safe %>
<% content_for :before_content do %>
<%= govuk_back_link(href: send(@log.form.previous_page_redirect_path(@page, @log, current_user, params[:referrer]), @log)) %>
<%= page_back_link(log: @log, page: @page, user: current_user, referrer: params[:referrer]) %>
<% end %>
<div data-controller="govukfrontend"></div>
@ -65,13 +65,10 @@
<div class="govuk-button-group">
<% if !@page.interruption_screen? && if request.query_parameters["referrer"] != "check_answers" %>
<%= f.govuk_submit "Save and continue" %>
<%= govuk_link_to(
(@page.skip_text || "Skip for now"),
(@page.skip_href(@log) || send(@log.form.next_page_redirect_path(@page, @log, current_user), @log)),
) %>
<% else %>
<%= page_skip_link(page: @page, log: @log, user: current_user) %>
<% else %>
<%= f.govuk_submit "Save changes" %>
<%= govuk_link_to "Cancel", send(@log.form.cancel_path(@page, @log), @log) %>
<%= page_cancel_link(log: @log, page: @page) %>
<% end %>
<% end %>
</div>

4
app/views/logs/index.html.erb

@ -48,11 +48,11 @@
<% unless @bulk_upload %>
<div class="govuk-button-group app-filter-toggle govuk-!-margin-bottom-6">
<% if current_page?(controller: 'lettings_logs', action: 'index') %>
<%= govuk_button_to "Create a new lettings log", lettings_logs_path, class: "govuk-!-margin-right-6" %>
<%= create_lettings_log_button %>
<% end %>
<% if current_page?(controller: 'sales_logs', action: 'index') %>
<%= govuk_button_to "Create a new sales log", sales_logs_path, class: "govuk-!-margin-right-6" %>
<%= create_sales_log_button %>
<% end %>
<% if FeatureToggle.bulk_upload_lettings_logs? && log_type_for_controller(controller) == "lettings" %>

4
app/views/organisations/logs.html.erb

@ -15,10 +15,10 @@
<div class="app-filter-layout" data-controller="filter-layout">
<div class="govuk-button-group app-filter-toggle">
<% if current_page?(controller: 'organisations', action: 'lettings_logs') %>
<%= govuk_button_to "Create a new lettings log for this organisation", lettings_logs_path(lettings_log: { owning_organisation_id: @organisation.id }, method: :post) %>
<%= create_lettings_log_for_org_button(@organisation) %>
<% end %>
<% if current_page?(controller: 'organisations', action: 'sales_logs') %>
<%= govuk_button_to "Create a new sales log for this organisation", sales_logs_path(sales_log: { owning_organisation_id: @organisation.id }, method: :post) %>
<%= create_sales_log_for_org_button(@organisation) %>
<% end %>
</div>

Loading…
Cancel
Save