diff --git a/app/components/check_answers_summary_list_card_component.html.erb b/app/components/check_answers_summary_list_card_component.html.erb index 73e9335c8..f299674b2 100644 --- a/app/components/check_answers_summary_list_card_component.html.erb +++ b/app/components/check_answers_summary_list_card_component.html.erb @@ -16,18 +16,18 @@ <% row.key { question.check_answer_label.to_s.presence || question.header.to_s } %> <% row.value do %> <%= get_answer_label(question) %> - <% extra_value = question.get_extra_check_answer_value(lettings_log) %> + <% extra_value = question.get_extra_check_answer_value(log) %> <% if extra_value %> <%= extra_value %> <% end %>
- <% question.get_inferred_answers(lettings_log).each do |inferred_answer| %> + <% question.get_inferred_answers(log).each do |inferred_answer| %> <%= inferred_answer %> <% end %> <% end %> <% row.action( - text: question.action_text(lettings_log), - href: question.action_href(lettings_log, question.page.id), + text: question.action_text(log), + href: question.action_href(log, question.page.id), visually_hidden_text: question.check_answer_label.to_s.downcase, ) %> <% end %> diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb index bc7d8cdb9..de7fe9685 100644 --- a/app/components/check_answers_summary_list_card_component.rb +++ b/app/components/check_answers_summary_list_card_component.rb @@ -1,18 +1,18 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base - attr_reader :questions, :lettings_log, :user + attr_reader :questions, :log, :user - def initialize(questions:, lettings_log:, user:) + def initialize(questions:, log:, user:) @questions = questions - @lettings_log = lettings_log + @log = log @user = user super end def applicable_questions - questions.reject { |q| q.hidden_in_check_answers?(lettings_log, user) } + questions.reject { |q| q.hidden_in_check_answers?(log, user) } end def get_answer_label(question) - question.answer_label(lettings_log).presence || "You didn’t answer this question".html_safe + question.answer_label(log).presence || "You didn’t answer this question".html_safe end end diff --git a/app/controllers/lettings_logs_controller.rb b/app/controllers/lettings_logs_controller.rb index 10b64d830..0fa90a9d6 100644 --- a/app/controllers/lettings_logs_controller.rb +++ b/app/controllers/lettings_logs_controller.rb @@ -12,6 +12,7 @@ class LettingsLogsController < LogsController @pagy, @lettings_logs = pagy(unpaginated_filtered_logs) @searched = search_term.presence @total_count = all_logs.size + render "logs/index" end format.csv do @@ -39,7 +40,7 @@ class LettingsLogsController < LogsController def show respond_to do |format| # We don't have a dedicated non-editable show view - format.html { edit } + format.html { render "logs/edit" } format.json do if @lettings_log render json: @lettings_log, status: :ok @@ -53,7 +54,7 @@ class LettingsLogsController < LogsController def edit @lettings_log = current_user.lettings_logs.find_by(id: params[:id]) if @lettings_log - render :edit, locals: { current_user: } + render "logs/edit", locals: { current_user: } else render_not_found end diff --git a/app/controllers/logs_controller.rb b/app/controllers/logs_controller.rb index ea140426f..3a6bc4af7 100644 --- a/app/controllers/logs_controller.rb +++ b/app/controllers/logs_controller.rb @@ -10,7 +10,7 @@ class LogsController < ApplicationController def index set_session_filters - all_logs = current_user.lettings_logs + current_user.sales_logs + all_logs = AllLog.where(id: (current_user.lettings_logs + current_user.sales_logs).pluck(:id)) unpaginated_filtered_logs = filtered_logs(filtered_collection(all_logs, search_term)) respond_to do |format| diff --git a/app/controllers/modules/logs_filter.rb b/app/controllers/modules/logs_filter.rb index ef33ac372..83e0de9ea 100644 --- a/app/controllers/modules/logs_filter.rb +++ b/app/controllers/modules/logs_filter.rb @@ -9,7 +9,7 @@ module Modules::LogsFilter logs = logs.public_send("filter_by_#{category}", values, current_user) end end - logs = logs.sort_by(&:created_at) + logs = logs.order(created_at: :desc) current_user.support? ? logs.all.includes(:owning_organisation, :managing_organisation) : logs end diff --git a/app/controllers/sales_logs_controller.rb b/app/controllers/sales_logs_controller.rb index 3d13b3b4b..588602d7f 100644 --- a/app/controllers/sales_logs_controller.rb +++ b/app/controllers/sales_logs_controller.rb @@ -5,14 +5,14 @@ class SalesLogsController < LogsController def show respond_to do |format| - format.html { edit } + format.html { "logs/edit" } end end def edit @sales_log = current_user.sales_logs.find_by(id: params[:id]) if @sales_log - render :edit, locals: { current_user: } + render "logs/edit", locals: { current_user: } else render_not_found end diff --git a/app/models/all_log.rb b/app/models/all_log.rb new file mode 100644 index 000000000..e3638b608 --- /dev/null +++ b/app/models/all_log.rb @@ -0,0 +1,30 @@ +class AllLog < ApplicationRecord + self.table_name = :logs + + STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze + enum status: STATUS + + def read_only? + true + end + + def tenancycode? + log_type == "lettings" + end + + def needstype? + log_type == "lettings" + end + + def startdate? + false + end + + def is_general_needs? + log_type == "lettings" + end + + def created_by + User.find(created_by_id) + end +end diff --git a/app/models/lettings_log.rb b/app/models/lettings_log.rb index a1639a42e..1973ad015 100644 --- a/app/models/lettings_log.rb +++ b/app/models/lettings_log.rb @@ -67,11 +67,9 @@ class LettingsLog < Log OPTIONAL_FIELDS = %w[first_time_property_let_as_social_housing tenancycode propcode].freeze RENT_TYPE_MAPPING_LABELS = { 1 => "Social Rent", 2 => "Affordable Rent", 3 => "Intermediate Rent" }.freeze HAS_BENEFITS_OPTIONS = [1, 6, 8, 7].freeze - STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze NUM_OF_WEEKS_FROM_PERIOD = { 2 => 26, 3 => 13, 4 => 12, 5 => 50, 6 => 49, 7 => 48, 8 => 47, 9 => 46, 1 => 52 }.freeze SUFFIX_FROM_PERIOD = { 2 => "every 2 weeks", 3 => "every 4 weeks", 4 => "every month" }.freeze RETIREMENT_AGES = { "M" => 67, "F" => 60, "X" => 67 }.freeze - enum status: STATUS def form FormHandler.instance.get_form(form_name) || FormHandler.instance.forms.first.second diff --git a/app/models/log.rb b/app/models/log.rb index 57d2935ad..de0b2a601 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -5,6 +5,9 @@ class Log < ApplicationRecord belongs_to :managing_organisation, class_name: "Organisation", optional: true belongs_to :created_by, class_name: "User", optional: true + STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze + enum status: STATUS + scope :combined, -> { ActiveRecord::Base.connection.execute("SELECT * FROM logs") } def collection_start_year diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index 5a616007e..edd2b4edd 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -10,9 +10,6 @@ class SalesLog < Log scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } - STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze - enum status: STATUS - OPTIONAL_FIELDS = [].freeze def startdate diff --git a/app/views/lettings_logs/_log_filters.erb b/app/views/logs/_log_filters.erb similarity index 100% rename from app/views/lettings_logs/_log_filters.erb rename to app/views/logs/_log_filters.erb diff --git a/app/views/lettings_logs/_log_list.html.erb b/app/views/logs/_log_list.html.erb similarity index 100% rename from app/views/lettings_logs/_log_list.html.erb rename to app/views/logs/_log_list.html.erb diff --git a/app/views/lettings_logs/_tasklist.html.erb b/app/views/logs/_tasklist.html.erb similarity index 100% rename from app/views/lettings_logs/_tasklist.html.erb rename to app/views/logs/_tasklist.html.erb diff --git a/app/views/lettings_logs/bulk_upload.html.erb b/app/views/logs/bulk_upload.html.erb similarity index 100% rename from app/views/lettings_logs/bulk_upload.html.erb rename to app/views/logs/bulk_upload.html.erb diff --git a/app/views/lettings_logs/edit.html.erb b/app/views/logs/edit.html.erb similarity index 100% rename from app/views/lettings_logs/edit.html.erb rename to app/views/logs/edit.html.erb diff --git a/app/views/lettings_logs/index.html.erb b/app/views/logs/index.html.erb similarity index 100% rename from app/views/lettings_logs/index.html.erb rename to app/views/logs/index.html.erb diff --git a/app/views/sales_logs/_tasklist.html.erb b/app/views/sales_logs/_tasklist.html.erb deleted file mode 100644 index e635d8241..000000000 --- a/app/views/sales_logs/_tasklist.html.erb +++ /dev/null @@ -1,25 +0,0 @@ -
    - <% @sales_log.form.sections.map do |section| %> -
  1. -

    - <%= section.label %> -

    - <% if section.description %> -

    <%= section.description.html_safe %>

    - <% end %> - -
  2. - <% end %> -
diff --git a/app/views/sales_logs/edit.html.erb b/app/views/sales_logs/edit.html.erb deleted file mode 100644 index e444dd0e8..000000000 --- a/app/views/sales_logs/edit.html.erb +++ /dev/null @@ -1,37 +0,0 @@ -<% content_for :title, "Log #{@sales_log.id}" %> -<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: { - "Logs" => "/logs", - content_for(:title) => "", -}) %> - -
-
-

- <%= content_for(:title) %> -

- - <% if @sales_log.status == "in_progress" %> -

<%= get_subsections_count(@sales_log, :completed) %> of <%= get_subsections_count(@sales_log, :all) %> sections completed.

-

- <% next_incomplete_section = get_next_incomplete_section(@sales_log) %> -

-

- <% if next_incomplete_section.present? %> - - Skip to next incomplete section: <%= next_incomplete_section.label %> - - <% end %> -

- <% elsif @sales_log.status == "not_started" %> -

This log has not been started.

- <% elsif @sales_log.status == "completed" %> -

- <%= status_tag(@sales_log.status) %> -

-

- You can <%= govuk_link_to "review and make changes to this log", "/logs/#{@sales_log.id}/review" %> until 2nd June <%= @sales_log.collection_start_year.present? ? @sales_log.collection_start_year + 1 : "" %>. -

- <% end %> - <%= render "tasklist" %> -
-
diff --git a/config/routes.rb b/config/routes.rb index 6f87c1f2c..f27273caa 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -74,7 +74,8 @@ Rails.application.routes.draw do end get "logs", to: "logs#index" - resources :lettings_logs, path: "/logs" do + + resources :lettings_logs, path: "/lettings-logs" do collection do post "bulk-upload", to: "bulk_upload#bulk_upload" get "bulk-upload", to: "bulk_upload#show" diff --git a/db/schema.rb b/db/schema.rb index a4c9209d5..f1f1f7c8b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -417,12 +417,18 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_08_153924) do SELECT lettings_logs.id, lettings_logs.status, lettings_logs.created_at, + lettings_logs.tenancycode, + lettings_logs.propcode, + lettings_logs.created_by_id, 'lettings'::text AS log_type FROM lettings_logs UNION SELECT sales_logs.id, sales_logs.status, sales_logs.created_at, + NULL::character varying AS tenancycode, + NULL::character varying AS propcode, + sales_logs.created_by_id, 'sales'::text AS log_type FROM sales_logs; SQL diff --git a/db/views/logs_v01.sql b/db/views/logs_v01.sql index 095c5b3e6..8d2470334 100644 --- a/db/views/logs_v01.sql +++ b/db/views/logs_v01.sql @@ -2,6 +2,9 @@ SELECT id, status, created_at, + tenancycode, + propcode, + created_by_id, 'lettings' as log_type FROM lettings_logs @@ -11,5 +14,8 @@ SELECT id, status, created_at, + null as tenancycode, + null as propcode, + created_by_id, 'sales' as log_type FROM sales_logs diff --git a/spec/requests/lettings_logs_controller_spec.rb b/spec/requests/lettings_logs_controller_spec.rb index e70cace51..5a44b0735 100644 --- a/spec/requests/lettings_logs_controller_spec.rb +++ b/spec/requests/lettings_logs_controller_spec.rb @@ -50,7 +50,7 @@ RSpec.describe LettingsLogsController, type: :request do before do Timecop.freeze(Time.utc(2022, 2, 8)) - post "/logs", headers:, params: params.to_json + post "/lettings-logs", headers:, params: params.to_json end after do @@ -132,7 +132,7 @@ RSpec.describe LettingsLogsController, type: :request do before do RequestHelper.stub_http_requests sign_in user - post "/logs", headers: + post "/lettings-logs", headers: end it "tracks who created the record" do @@ -826,7 +826,7 @@ RSpec.describe LettingsLogsController, type: :request do let(:id) { lettings_log.id } before do - patch "/logs/#{id}", headers:, params: params.to_json + patch "/lettings-logs/#{id}", headers:, params: params.to_json end it "returns http success" do @@ -884,7 +884,7 @@ RSpec.describe LettingsLogsController, type: :request do let(:id) { lettings_log.id } before do - put "/logs/#{id}", headers:, params: params.to_json + put "/lettings-logs/#{id}", headers:, params: params.to_json end it "returns http success" do @@ -924,7 +924,7 @@ RSpec.describe LettingsLogsController, type: :request do context "when deleting a lettings log" do before do - delete "/logs/#{id}", headers: + delete "/lettings-logs/#{id}", headers: end it "returns http success" do @@ -958,7 +958,7 @@ RSpec.describe LettingsLogsController, type: :request do before do allow(LettingsLog).to receive(:find_by).and_return(lettings_log) allow(lettings_log).to receive(:delete).and_return(false) - delete "/logs/#{id}", headers: + delete "/lettings-logs/#{id}", headers: end it "returns an unprocessable entity 422" do