Browse Source

enough changes to go to the new log page

CLDC-1324-remove-not-started-status-no-rebase
JG 2 years ago
parent
commit
3b6df70fc9
  1. 9
      app/controllers/lettings_logs_controller.rb
  2. 3
      app/controllers/logs_controller.rb
  3. 4
      app/helpers/tasklist_helper.rb
  4. 2
      app/views/logs/edit.html.erb
  5. 2
      app/views/logs/index.html.erb
  6. 2
      config/routes.rb

9
app/controllers/lettings_logs_controller.rb

@ -49,7 +49,11 @@ class LettingsLogsController < LogsController
end end
def edit def edit
@log = current_user.lettings_logs.find_by(id: params[:id]) @log = if new_log_request?
LettingsLog.new
else
current_user.lettings_logs.find_by(id: params[:id])
end
if @log if @log
render "logs/edit", locals: { current_user: } render "logs/edit", locals: { current_user: }
else else
@ -84,6 +88,9 @@ class LettingsLogsController < LogsController
def csv_confirmation; end def csv_confirmation; end
private private
def new_log_request?
request.path.include?("new")
end
def permitted_log_params def permitted_log_params
params.require(:lettings_log).permit(LettingsLog.editable_fields) params.require(:lettings_log).permit(LettingsLog.editable_fields)

3
app/controllers/logs_controller.rb

@ -15,8 +15,7 @@ private
respond_to do |format| respond_to do |format|
format.html do format.html do
log.save! redirect_to new_log_lettings_logs_path
redirect_to post_create_redirect_url(log)
end end
format.json do format.json do
if log.save if log.save

4
app/helpers/tasklist_helper.rb

@ -17,7 +17,11 @@ module TasklistHelper
else else
"#{log.class.name.underscore}_#{next_question_page(subsection, log, current_user)}_path" "#{log.class.name.underscore}_#{next_question_page(subsection, log, current_user)}_path"
end end
if log.id
send(path, log) send(path, log)
else
"/logs/new/#{next_question_page(subsection, log, current_user)}"
end
end end
def next_question_page(subsection, log, current_user) def next_question_page(subsection, log, current_user)

2
app/views/logs/edit.html.erb

@ -1,4 +1,4 @@
<% content_for :title, "Log #{@log.id}" %> <% content_for :title, "Log #{@log.id ? @log.id : "new"}" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => @log.lettings? ? lettings_logs_path : sales_logs_path, "Logs" => @log.lettings? ? lettings_logs_path : sales_logs_path,
content_for(:title) => "", content_for(:title) => "",

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

@ -8,7 +8,7 @@
<div class="app-filter-layout" data-controller="filter-layout"> <div class="app-filter-layout" data-controller="filter-layout">
<div class="govuk-button-group app-filter-toggle"> <div class="govuk-button-group app-filter-toggle">
<% if current_page?(:controller => 'lettings_logs', :action => 'index') %> <% if current_page?(:controller => 'lettings_logs', :action => 'index') %>
<%= govuk_button_to "Create a new lettings log", lettings_logs_path %> <%= govuk_button_to "Create a new lettings log", create_new_log_lettings_logs_path, method: :get %>
<% end %> <% end %>
<% if FeatureToggle.sales_log_enabled? && current_page?(:controller => 'sales_logs', :action => 'index') %> <% if FeatureToggle.sales_log_enabled? && current_page?(:controller => 'sales_logs', :action => 'index') %>
<%= govuk_button_to "Create a new sales log", sales_logs_path %> <%= govuk_button_to "Create a new sales log", sales_logs_path %>

2
config/routes.rb

@ -80,6 +80,8 @@ Rails.application.routes.draw do
resources :lettings_logs, path: "/lettings-logs" do resources :lettings_logs, path: "/lettings-logs" do
collection do collection do
get "create-new-log", to: "lettings_logs#create"
get "new-log", to: "lettings_logs#show"
post "bulk-upload", to: "bulk_upload#bulk_upload" post "bulk-upload", to: "bulk_upload#bulk_upload"
get "bulk-upload", to: "bulk_upload#show" get "bulk-upload", to: "bulk_upload#show"
get "csv-download", to: "lettings_logs#download_csv" get "csv-download", to: "lettings_logs#download_csv"

Loading…
Cancel
Save