Browse Source

CLDC-1688 Update logs page + banner

cldc-1688-deactivation-affected-logs
Sam Collard 2 years ago
parent
commit
4e083dd4a9
  1. 1
      app/controllers/lettings_logs_controller.rb
  2. 3
      app/controllers/schemes_controller.rb
  3. 8
      app/controllers/update_logs_controller.rb
  4. 12
      app/views/logs/index.html.erb
  5. 38
      app/views/logs/update_logs.html.erb
  6. 1
      config/routes.rb
  7. 13
      db/migrate/20221124171430_add_impacted_by_scheme_deactivation.rb
  8. 17
      db/schema.rb
  9. 30
      spec/features/lettings_log_spec.rb

1
app/controllers/lettings_logs_controller.rb

@ -13,6 +13,7 @@ class LettingsLogsController < LogsController
@pagy, @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
@logs_to_update = LettingsLog.where(created_by: current_user, impacted_by_scheme_deactivation: true).count
render "logs/index" render "logs/index"
end end
end end

3
app/controllers/schemes_controller.rb

@ -344,6 +344,7 @@ private
end end
def reset_location_and_scheme_for_logs! def reset_location_and_scheme_for_logs!
@scheme.lettings_logs.filter_by_before_startdate(params[:deactivation_date].to_time).update!(location: nil, scheme: nil) @scheme.lettings_logs.filter_by_before_startdate(params[:deactivation_date].to_time).update!(location: nil, scheme: nil, impacted_by_scheme_deactivation: true)
# TODO: E-mail users
end end
end end

8
app/controllers/update_logs_controller.rb

@ -0,0 +1,8 @@
class UpdateLogsController < ApplicationController
before_action :authenticate_user!
def show
@logs = LettingsLog.where(created_by: current_user, impacted_by_scheme_deactivation: true)
render "logs/update_logs"
end
end

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

@ -4,6 +4,18 @@
<% content_for :title, title %> <% content_for :title, title %>
<% if current_page?(controller: 'lettings_logs', action: 'index') %> <% if current_page?(controller: 'lettings_logs', action: 'index') %>
<% if @logs_to_update > 0 %>
<%= govuk_notification_banner(
title_text: "Important",
title_heading_level: 3,
title_id: "impacted-logs-banner",
) do |notification_banner| %>
<% notification_banner.heading(text: "A scheme has changed and it has affected #{@logs_to_update} #{@logs_to_update > 1 ? 'logs' : 'log'}") %>
<div class="govuk-notification-banner__heading">
<a class="govuk-notification-banner__link" href="./lettings-logs/update-logs">Update logs</a>
</div>
<% end %>
<% end %>
<%= render partial: "organisations/headings", locals: current_user.support? ? { main: "Lettings logs", sub: nil } : { main: "Lettings logs", sub: current_user.organisation.name } %> <%= render partial: "organisations/headings", locals: current_user.support? ? { main: "Lettings logs", sub: nil } : { main: "Lettings logs", sub: current_user.organisation.name } %>
<% elsif current_page?(controller: 'sales_logs', action: 'index') %> <% elsif current_page?(controller: 'sales_logs', action: 'index') %>
<%= render partial: "organisations/headings", locals: current_user.support? ? { main: "Sales logs", sub: nil } : { main: "Sales logs", sub: current_user.organisation.name } %> <%= render partial: "organisations/headings", locals: current_user.support? ? { main: "Sales logs", sub: nil } : { main: "Sales logs", sub: current_user.organisation.name } %>

38
app/views/logs/update_logs.html.erb

@ -0,0 +1,38 @@
<% content_for :title, "Update logs" %>
<div class="govuk-grid-row govuk-!-margin-bottom-8">
<h1 class="govuk-heading-xl">You need to update <%= @logs.count %> logs</h1>
<p class="govuk-body">
Some scheme details have changed, and now the following <%= @logs.count %> logs need updating.
</p>
<p class="govuk-body">
You'll have to answer a few questions for each log.
</p>
</div>
<div class="govuk-grid-row">
<%= govuk_table do |table|
table.head do |head|
head.row do |row|
row.cell(header: true, text: "Log ID")
row.cell(header: true, text: "Tenancy code")
row.cell(header: true, text: "Property reference")
row.cell(header: true, text: "Status")
row.cell # "Update now" column has no heading
end
end
table.body do |body|
@logs.each do |log|
body.row do |row|
row.cell(header: true, text: log.id)
row.cell(text: log.tenancycode)
row.cell(text: log.propcode)
row.cell { status_tag(log.status) }
row.cell(numeric: true) { govuk_link_to("Update now", "#") } # "numeric" to right-align
end
end
end
end %>
</div>

1
config/routes.rb

@ -111,6 +111,7 @@ Rails.application.routes.draw do
get "csv-download", to: "lettings_logs#download_csv" get "csv-download", to: "lettings_logs#download_csv"
post "email-csv", to: "lettings_logs#email_csv" post "email-csv", to: "lettings_logs#email_csv"
get "csv-confirmation", to: "lettings_logs#csv_confirmation" get "csv-confirmation", to: "lettings_logs#csv_confirmation"
get "update-logs", to: "update_logs#show"
end end
member do member do

13
db/migrate/20221124171430_add_impacted_by_scheme_deactivation.rb

@ -0,0 +1,13 @@
class AddImpactedBySchemeDeactivation < ActiveRecord::Migration[7.0]
def up
change_table :lettings_logs, bulk: true do |t|
t.column :impacted_by_scheme_deactivation, :boolean
end
end
def down
change_table :lettings_logs, bulk: true do |t|
t.remove :impacted_by_scheme_deactivation
end
end
end

17
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do ActiveRecord::Schema[7.0].define(version: 2022_11_24_171430) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -237,6 +237,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
t.integer "void_date_value_check" t.integer "void_date_value_check"
t.integer "housingneeds_type" t.integer "housingneeds_type"
t.integer "housingneeds_other" t.integer "housingneeds_other"
t.boolean "impacted_by_scheme_deactivation"
t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id" t.index ["created_by_id"], name: "index_lettings_logs_on_created_by_id"
t.index ["location_id"], name: "index_lettings_logs_on_location_id" t.index ["location_id"], name: "index_lettings_logs_on_location_id"
t.index ["managing_organisation_id"], name: "index_lettings_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_lettings_logs_on_managing_organisation_id"
@ -345,12 +346,10 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
t.integer "jointmore" t.integer "jointmore"
t.integer "jointpur" t.integer "jointpur"
t.integer "beds" t.integer "beds"
t.integer "companybuy"
t.integer "age1" t.integer "age1"
t.integer "age1_known" t.integer "age1_known"
t.integer "companybuy"
t.string "sex1" t.string "sex1"
t.integer "national"
t.string "othernational"
t.integer "ethnic" t.integer "ethnic"
t.integer "ethnic_group" t.integer "ethnic_group"
t.integer "buy1livein" t.integer "buy1livein"
@ -364,8 +363,10 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
t.integer "noint" t.integer "noint"
t.integer "buy2livein" t.integer "buy2livein"
t.integer "ecstat2" t.integer "ecstat2"
t.integer "privacynotice"
t.integer "ecstat1" t.integer "ecstat1"
t.integer "national"
t.string "othernational"
t.integer "privacynotice"
t.integer "wheel" t.integer "wheel"
t.integer "hholdcount" t.integer "hholdcount"
t.integer "age3" t.integer "age3"
@ -374,15 +375,15 @@ ActiveRecord::Schema[7.0].define(version: 2022_11_22_130928) do
t.integer "la_known" t.integer "la_known"
t.integer "income1" t.integer "income1"
t.integer "income1nk" t.integer "income1nk"
t.integer "details_known_2"
t.integer "details_known_3"
t.integer "details_known_4"
t.integer "age4" t.integer "age4"
t.integer "age4_known" t.integer "age4_known"
t.integer "age5" t.integer "age5"
t.integer "age5_known" t.integer "age5_known"
t.integer "age6" t.integer "age6"
t.integer "age6_known" t.integer "age6_known"
t.integer "details_known_2"
t.integer "details_known_3"
t.integer "details_known_4"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

30
spec/features/lettings_log_spec.rb

@ -134,4 +134,34 @@ RSpec.describe "Lettings Log Features" do
end end
end end
end end
context "when logs the user created have been affected by a scheme deactivation" do
let(:user) { create(:user, last_sign_in_at: Time.zone.now) }
let!(:my_impacted_logs) do
[
create(:lettings_log, created_by: user, impacted_by_scheme_deactivation: true),
create(:lettings_log, created_by: user, impacted_by_scheme_deactivation: true),
]
end
before do
# Non-impacted log
create(:lettings_log, created_by: user)
# Impacted log for a different user user
create(:lettings_log, impacted_by_scheme_deactivation: true)
visit("/lettings-logs")
fill_in("user[email]", with: user.email)
fill_in("user[password]", with: user.password)
click_button("Sign in")
end
it "displays a banner" do
expect(page).to have_content("A scheme has changed")
end
it "displays the count of affected logs" do
expect(page).to have_content("it has affected #{my_impacted_logs.count} logs")
end
end
end end

Loading…
Cancel
Save