Browse Source

enough changes to go to the new organisation

CLDC-1324-remove-not-started-status-no-rebase
JG 2 years ago
parent
commit
3392184660
  1. 53
      app/controllers/form_controller.rb
  2. 3
      app/controllers/lettings_logs_controller.rb
  3. 2
      app/controllers/sales_logs_controller.rb
  4. 2
      app/models/form.rb
  5. 4
      app/views/form/page.html.erb
  6. 7
      config/routes.rb

53
app/controllers/form_controller.rb

@ -60,8 +60,34 @@ class FormController < ApplicationController
end
end
def show_new_page
page_id = request.path.split("/")[-1].underscore
save_new_log page_id
if @log
restore_error_field_values
page_id = request.path.split("/")[-1].underscore
@page = @log.form.get_page(page_id)
@subsection = @log.form.subsection_for_page(@page)
if @page.routed_to?(@log, current_user)
render "form/page"
else
redirect_to lettings_log_path(@log)
end
else
render_not_found
end
end
private
def save_new_log(page_id)
if current_user.support?
@log.save! unless page_id.eql?("organisation") && @log.id.nil?
else
@log.save! unless page_id.eql?("needs_type") && @log.id.nil?
end
end
def restore_error_field_values
if session["errors"]
JSON(session["errors"]).each do |field, messages|
@ -105,22 +131,39 @@ private
end
end
def find_resource
@log = if params.key?("sales_log")
current_user.sales_logs.find_by(id: params[:id])
@log = if is_new_log_request? || new_log_referrer?
LettingsLog.new(owning_organisation: current_user.support? ? nil : current_user.organisation)
else
current_user.lettings_logs.find_by(id: params[:id])
params.key?("sales_log") ? current_user.sales_logs.find_by(id: params[:id]) : current_user.lettings_logs.find_by(id: params[:id])
end
end
def find_resource_by_named_id
@log = if params[:sales_log_id].present?
current_user.sales_logs.find_by(id: params[:sales_log_id])
if new_log_request?
SalesLog.new
else
current_user.sales_logs.find_by(id: params[:sales_log_id])
end
else
current_user.lettings_logs.find_by(id: params[:lettings_log_id])
if new_log_request?
LettingsLog.new
else
current_user.lettings_logs.find_by(id: params[:lettings_log_id])
end
end
end
def new_log_request?
request.path.split("/").include?("new")
end
def new_log_request_referrer?
request.referer.split("/").include?("new")
end
def is_referrer_check_answers?
referrer = request.headers["HTTP_REFERER"].presence || ""
referrer.present? && CGI.parse(referrer.split("?")[-1]).present? && CGI.parse(referrer.split("?")[-1])["referrer"][0] == "check_answers"

3
app/controllers/lettings_logs_controller.rb

@ -88,8 +88,9 @@ class LettingsLogsController < LogsController
def csv_confirmation; end
private
def new_log_request?
request.path.include?("new")
request.path.include?("new-log")
end
def permitted_log_params

2
app/controllers/sales_logs_controller.rb

@ -51,6 +51,6 @@ class SalesLogsController < LogsController
private
def new_log_request?
request.path.include?("new")
request.path.include?("new-log")
end
end

2
app/models/form.rb

@ -76,7 +76,7 @@ class Form
if nxt_page == :check_answers
"#{type}_log_#{subsection_for_page(page).id}_check_answers_path"
else
"#{type}_log_#{nxt_page}_path"
log.id ? "#{type}_log_#{nxt_page}_path" : "new_#{nxt_page}_#{type}_logs_path"
end
end

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

@ -4,8 +4,10 @@
<%= govuk_back_link(href: "javascript:history.back()") %>
<% end %>
<% path_url = @log.id ? form_lettings_log_path(@log) : new_form_lettings_logs_path %>
<div data-controller="govukfrontend"></div>
<%= form_with model: @log, url: form_lettings_log_path(@log), method: "post", local: true do |f| %>
<%= form_with model: @log, url: path_url, method: "post", local: true do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-<%= @page.questions[0].type == "interruption_screen" ? "full-from-desktop" : "two-thirds-from-desktop" %>">
<% remove_other_page_errors(@log, @page) %>

7
config/routes.rb

@ -28,6 +28,7 @@ Rails.application.routes.draw do
root to: "start#index"
get "/logs", to: redirect("/lettings-logs")
get "/logs/new/organisation", to: "form#show_new_page"
get "/accessibility-statement", to: "content#accessibility_statement"
get "/privacy-notice", to: "content#privacy_notice"
get "/data-sharing-agreement", to: "content#data_sharing_agreement"
@ -82,11 +83,17 @@ Rails.application.routes.draw do
collection do
get "create-new-log", to: "lettings_logs#create"
get "new-log", to: "lettings_logs#show"
post "new-form", to: "form#submit_form"
post "bulk-upload", to: "bulk_upload#bulk_upload"
get "bulk-upload", to: "bulk_upload#show"
get "csv-download", to: "lettings_logs#download_csv"
post "email-csv", to: "lettings_logs#email_csv"
get "csv-confirmation", to: "lettings_logs#csv_confirmation"
FormHandler.instance.forms.each do |_key, form|
form.pages.map do |page|
get "new/#{page.id.to_s.dasherize}", to: "form#show_new_page"
end
end
end
member do

Loading…
Cancel
Save