Browse Source

Generalise log type on logs index page

pull/863/head
Kat 3 years ago
parent
commit
f00006637a
  1. 26
      app/controllers/lettings_logs_controller.rb
  2. 2
      app/controllers/logs_controller.rb
  3. 6
      app/controllers/sales_logs_controller.rb
  4. 2
      app/helpers/navigation_items_helper.rb
  5. 14
      app/models/all_log.rb
  6. 3
      app/views/logs/_log_list.html.erb
  7. 8
      app/views/logs/_tasklist.html.erb
  8. 16
      app/views/logs/edit.html.erb
  9. 2
      app/views/logs/index.html.erb
  10. 4
      db/schema.rb
  11. 12
      db/views/logs_v01.sql

26
app/controllers/lettings_logs_controller.rb

@ -9,7 +9,7 @@ class LettingsLogsController < LogsController
respond_to do |format|
format.html do
@pagy, @lettings_logs = pagy(unpaginated_filtered_logs)
@pagy, @logs = pagy(unpaginated_filtered_logs)
@searched = search_term.presence
@total_count = all_logs.size
render "logs/index"
@ -26,11 +26,11 @@ class LettingsLogsController < LogsController
end
def update
if @lettings_log
if @lettings_log.update(api_log_params)
render json: @lettings_log, status: :ok
if @log
if @log.update(api_log_params)
render json: @log, status: :ok
else
render json: { errors: @lettings_log.errors.messages }, status: :unprocessable_entity
render json: { errors: @log.errors.messages }, status: :unprocessable_entity
end
else
render_not_found_json("Log", params[:id])
@ -42,8 +42,8 @@ class LettingsLogsController < LogsController
# We don't have a dedicated non-editable show view
format.html { render "logs/edit" }
format.json do
if @lettings_log
render json: @lettings_log, status: :ok
if @log
render json: @log, status: :ok
else
render_not_found_json("Log", params[:id])
end
@ -52,8 +52,8 @@ class LettingsLogsController < LogsController
end
def edit
@lettings_log = current_user.lettings_logs.find_by(id: params[:id])
if @lettings_log
@log = current_user.lettings_logs.find_by(id: params[:id])
if @log
render "logs/edit", locals: { current_user: }
else
render_not_found
@ -61,11 +61,11 @@ class LettingsLogsController < LogsController
end
def destroy
if @lettings_log
if @lettings_log.delete
if @log
if @log.delete
head :no_content
else
render json: { errors: @lettings_log.errors.messages }, status: :unprocessable_entity
render json: { errors: @log.errors.messages }, status: :unprocessable_entity
end
else
render_not_found_json("Log", params[:id])
@ -79,7 +79,7 @@ private
end
def find_resource
@lettings_log = LettingsLog.find_by(id: params[:id])
@log = LettingsLog.find_by(id: params[:id])
end
def post_create_redirect_url(log)

2
app/controllers/logs_controller.rb

@ -15,7 +15,7 @@ class LogsController < ApplicationController
respond_to do |format|
format.html do
@pagy, @lettings_logs = pagy(unpaginated_filtered_logs)
@pagy, @logs = pagy(unpaginated_filtered_logs)
@searched = search_term.presence
@total_count = all_logs.size
end

6
app/controllers/sales_logs_controller.rb

@ -5,13 +5,13 @@ class SalesLogsController < LogsController
def show
respond_to do |format|
format.html { "logs/edit" }
format.html { edit }
end
end
def edit
@sales_log = current_user.sales_logs.find_by(id: params[:id])
if @sales_log
@log = current_user.sales_logs.find_by(id: params[:id])
if @log
render "logs/edit", locals: { current_user: }
else
render_not_found

2
app/helpers/navigation_items_helper.rb

@ -6,7 +6,7 @@ module NavigationItemsHelper
[
NavigationItem.new("Organisations", organisations_path, organisations_current?(path)),
NavigationItem.new("Users", "/users", users_current?(path)),
NavigationItem.new("Logs", lettings_logs_path, logs_current?(path)),
NavigationItem.new("Logs", logs_path, logs_current?(path)),
NavigationItem.new("Schemes", "/schemes", supported_housing_schemes_current?(path)),
]
elsif current_user.data_coordinator? && current_user.organisation.holds_own_stock?

14
app/models/all_log.rb

@ -4,6 +4,10 @@ class AllLog < ApplicationRecord
STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
enum status: STATUS
belongs_to :owning_organisation, class_name: "Organisation", optional: true
belongs_to :managing_organisation, class_name: "Organisation", optional: true
belongs_to :created_by, class_name: "User", optional: true
def read_only?
true
end
@ -25,6 +29,14 @@ class AllLog < ApplicationRecord
end
def created_by
User.find(created_by_id)
User.find(created_by_id) if created_by_id.present?
end
def owning_organisation
Organisation.find(owning_organisation_id) if owning_organisation_id.present?
end
def managing_organisation
Organisation.find(managing_organisation_id) if managing_organisation_id.present?
end
end

3
app/views/logs/_log_list.html.erb

@ -2,7 +2,6 @@
<%= render(SearchResultCaptionComponent.new(searched:, count: pagy.count, item_label:, total_count:, item: "logs", path: request.path)) %>
<%= govuk_link_to "Download (CSV)", "#{request.path}.csv", type: "text/csv" %>
</h2>
<% lettings_logs.map do |log| %>
<% logs.map do |log| %>
<%= render(LogSummaryComponent.new(current_user:, log:)) %>
<% end %>

8
app/views/logs/_tasklist.html.erb

@ -1,5 +1,5 @@
<ol class="app-task-list govuk-!-margin-top-8">
<% @lettings_log.form.sections.map do |section| %>
<% @log.form.sections.map do |section| %>
<li>
<h2 class="app-task-list__section-heading">
<%= section.label %>
@ -9,11 +9,11 @@
<% end %>
<ul class="app-task-list__items">
<% section.subsections.map do |subsection| %>
<% if subsection.applicable_questions(@lettings_log).count > 0 || !subsection.enabled?(@lettings_log) %>
<% subsection_status = subsection.status(@lettings_log) %>
<% if subsection.applicable_questions(@log).count > 0 || !subsection.enabled?(@log) %>
<% subsection_status = subsection.status(@log) %>
<li class="app-task-list__item">
<span class="app-task-list__task-name" id="<%= subsection.id.dasherize %>">
<%= subsection_link(subsection, @lettings_log, current_user) %>
<%= subsection_link(subsection, @log, current_user) %>
</span>
<%= status_tag(subsection_status, "app-task-list__tag") %>
</li>

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

@ -1,4 +1,4 @@
<% content_for :title, "Log #{@lettings_log.id}" %>
<% content_for :title, "Log #{@log.id}" %>
<% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => "/logs",
content_for(:title) => "",
@ -10,10 +10,10 @@
<%= content_for(:title) %>
</h1>
<% if @lettings_log.status == "in_progress" %>
<p class="govuk-body govuk-!-margin-bottom-7"><%= get_subsections_count(@lettings_log, :completed) %> of <%= get_subsections_count(@lettings_log, :all) %> sections completed.</p>
<% if @log.status == "in_progress" %>
<p class="govuk-body govuk-!-margin-bottom-7"><%= get_subsections_count(@log, :completed) %> of <%= get_subsections_count(@log, :all) %> sections completed.</p>
<p class="govuk-body govuk-!-margin-bottom-2">
<% next_incomplete_section = get_next_incomplete_section(@lettings_log) %>
<% next_incomplete_section = get_next_incomplete_section(@log) %>
</p>
<p>
<% if next_incomplete_section.present? %>
@ -22,14 +22,14 @@
</a>
<% end %>
</p>
<% elsif @lettings_log.status == "not_started" %>
<% elsif @log.status == "not_started" %>
<p class="govuk-body">This log has not been started.</p>
<% elsif @lettings_log.status == "completed" %>
<% elsif @log.status == "completed" %>
<p class="govuk-body">
<%= status_tag(@lettings_log.status) %>
<%= status_tag(@log.status) %>
</p>
<p class="govuk-body">
You can <%= govuk_link_to "review and make changes to this log", "/logs/#{@lettings_log.id}/review" %> until 2nd June <%= @lettings_log.collection_start_year.present? ? @lettings_log.collection_start_year + 1 : "" %>.
You can <%= govuk_link_to "review and make changes to this log", "/logs/#{@log.id}/review" %> until 2nd June <%= @log.collection_start_year.present? ? @log.collection_start_year + 1 : "" %>.
</p>
<% end %>
<%= render "tasklist" %>

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

@ -18,7 +18,7 @@
<div class="app-filter-layout__content">
<%= render SearchComponent.new(current_user:, search_label: "Search by log ID, tenant code, property reference or postcode", value: @searched) %>
<%= govuk_section_break(visible: true, size: "m") %>
<%= render partial: "log_list", locals: { lettings_logs: @lettings_logs, title: "Logs", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<%= render partial: "log_list", locals: { logs: @logs, title: "Logs", pagy: @pagy, searched: @searched, item_label:, total_count: @total_count } %>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "logs" } %>
</div>
</div>

4
db/schema.rb

@ -420,6 +420,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_08_153924) do
lettings_logs.tenancycode,
lettings_logs.propcode,
lettings_logs.created_by_id,
lettings_logs.owning_organisation_id,
lettings_logs.managing_organisation_id,
'lettings'::text AS log_type
FROM lettings_logs
UNION
@ -429,6 +431,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_09_08_153924) do
NULL::character varying AS tenancycode,
NULL::character varying AS propcode,
sales_logs.created_by_id,
sales_logs.owning_organisation_id,
sales_logs.managing_organisation_id,
'sales'::text AS log_type
FROM sales_logs;
SQL

12
db/views/logs_v01.sql

@ -1,21 +1,25 @@
SELECT
id,
lettings_logs.id,
status,
created_at,
lettings_logs.created_at,
tenancycode,
propcode,
created_by_id,
owning_organisation_id,
managing_organisation_id,
'lettings' as log_type
FROM lettings_logs
UNION
SELECT
id,
sales_logs.id,
status,
created_at,
sales_logs.created_at,
null as tenancycode,
null as propcode,
created_by_id,
owning_organisation_id,
managing_organisation_id,
'sales' as log_type
FROM sales_logs

Loading…
Cancel
Save