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

2
app/controllers/logs_controller.rb

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

6
app/controllers/sales_logs_controller.rb

@ -5,13 +5,13 @@ class SalesLogsController < LogsController
def show def show
respond_to do |format| respond_to do |format|
format.html { "logs/edit" } format.html { edit }
end end
end end
def edit def edit
@sales_log = current_user.sales_logs.find_by(id: params[:id]) @log = current_user.sales_logs.find_by(id: params[:id])
if @sales_log if @log
render "logs/edit", locals: { current_user: } render "logs/edit", locals: { current_user: }
else else
render_not_found 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("Organisations", organisations_path, organisations_current?(path)),
NavigationItem.new("Users", "/users", users_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)), NavigationItem.new("Schemes", "/schemes", supported_housing_schemes_current?(path)),
] ]
elsif current_user.data_coordinator? && current_user.organisation.holds_own_stock? 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 STATUS = { "not_started" => 0, "in_progress" => 1, "completed" => 2 }.freeze
enum status: STATUS 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? def read_only?
true true
end end
@ -25,6 +29,14 @@ class AllLog < ApplicationRecord
end end
def created_by 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
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)) %> <%= 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" %> <%= govuk_link_to "Download (CSV)", "#{request.path}.csv", type: "text/csv" %>
</h2> </h2>
<% logs.map do |log| %>
<% lettings_logs.map do |log| %>
<%= render(LogSummaryComponent.new(current_user:, log:)) %> <%= render(LogSummaryComponent.new(current_user:, log:)) %>
<% end %> <% end %>

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

@ -1,5 +1,5 @@
<ol class="app-task-list govuk-!-margin-top-8"> <ol class="app-task-list govuk-!-margin-top-8">
<% @lettings_log.form.sections.map do |section| %> <% @log.form.sections.map do |section| %>
<li> <li>
<h2 class="app-task-list__section-heading"> <h2 class="app-task-list__section-heading">
<%= section.label %> <%= section.label %>
@ -9,11 +9,11 @@
<% end %> <% end %>
<ul class="app-task-list__items"> <ul class="app-task-list__items">
<% section.subsections.map do |subsection| %> <% section.subsections.map do |subsection| %>
<% if subsection.applicable_questions(@lettings_log).count > 0 || !subsection.enabled?(@lettings_log) %> <% if subsection.applicable_questions(@log).count > 0 || !subsection.enabled?(@log) %>
<% subsection_status = subsection.status(@lettings_log) %> <% subsection_status = subsection.status(@log) %>
<li class="app-task-list__item"> <li class="app-task-list__item">
<span class="app-task-list__task-name" id="<%= subsection.id.dasherize %>"> <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> </span>
<%= status_tag(subsection_status, "app-task-list__tag") %> <%= status_tag(subsection_status, "app-task-list__tag") %>
</li> </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: { <% content_for :breadcrumbs, govuk_breadcrumbs(breadcrumbs: {
"Logs" => "/logs", "Logs" => "/logs",
content_for(:title) => "", content_for(:title) => "",
@ -10,10 +10,10 @@
<%= content_for(:title) %> <%= content_for(:title) %>
</h1> </h1>
<% if @lettings_log.status == "in_progress" %> <% if @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> <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"> <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>
<p> <p>
<% if next_incomplete_section.present? %> <% if next_incomplete_section.present? %>
@ -22,14 +22,14 @@
</a> </a>
<% end %> <% end %>
</p> </p>
<% elsif @lettings_log.status == "not_started" %> <% elsif @log.status == "not_started" %>
<p class="govuk-body">This log has not been started.</p> <p class="govuk-body">This log has not been started.</p>
<% elsif @lettings_log.status == "completed" %> <% elsif @log.status == "completed" %>
<p class="govuk-body"> <p class="govuk-body">
<%= status_tag(@lettings_log.status) %> <%= status_tag(@log.status) %>
</p> </p>
<p class="govuk-body"> <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> </p>
<% end %> <% end %>
<%= render "tasklist" %> <%= render "tasklist" %>

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

@ -18,7 +18,7 @@
<div class="app-filter-layout__content"> <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) %> <%= 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") %> <%= 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" } %> <%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "logs" } %>
</div> </div>
</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.tenancycode,
lettings_logs.propcode, lettings_logs.propcode,
lettings_logs.created_by_id, lettings_logs.created_by_id,
lettings_logs.owning_organisation_id,
lettings_logs.managing_organisation_id,
'lettings'::text AS log_type 'lettings'::text AS log_type
FROM lettings_logs FROM lettings_logs
UNION 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 tenancycode,
NULL::character varying AS propcode, NULL::character varying AS propcode,
sales_logs.created_by_id, sales_logs.created_by_id,
sales_logs.owning_organisation_id,
sales_logs.managing_organisation_id,
'sales'::text AS log_type 'sales'::text AS log_type
FROM sales_logs; FROM sales_logs;
SQL SQL

12
db/views/logs_v01.sql

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

Loading…
Cancel
Save