Browse Source

feat: add merge_date to org and display merged status

pull/1787/head
natdeanlewissoftwire 3 years ago
parent
commit
5bb2366a5e
  1. 14
      app/helpers/organisation_helper.rb
  2. 2
      app/helpers/tag_helper.rb
  3. 23
      app/models/organisation.rb
  4. 4
      app/views/organisations/_organisation_list.html.erb
  5. 2
      app/views/organisations/show.html.erb
  6. 3
      db/schema.rb

14
app/helpers/organisation_helper.rb

@ -8,4 +8,18 @@ module OrganisationHelper
current_organisation.name current_organisation.name
end end
end end
def display_organisation_attributes(organisation)
[
{ name: "Name", value: organisation.name, editable: true },
{ name: "Organisation ID", value: "ORG#{organisation.id}", editable: false },
{ name: "Address", value: organisation.address_string, editable: true },
{ name: "Telephone number", value: organisation.phone, editable: true },
{ name: "Type of provider", value: organisation.display_provider_type, editable: false },
{ name: "Registration number", value: organisation.housing_registration_no || "", editable: false },
{ name: "Rent periods", value: organisation.rent_period_labels, editable: false, format: :bullet },
{ name: "Owns housing stock", value: organisation.holds_own_stock ? "Yes" : "No", editable: false },
{ name: "Status", value: status_tag(organisation.status), editable: false },
]
end
end end

2
app/helpers/tag_helper.rb

@ -13,6 +13,7 @@ module TagHelper
reactivating_soon: "Reactivating soon", reactivating_soon: "Reactivating soon",
deactivated: "Deactivated", deactivated: "Deactivated",
deleted: "Deleted", deleted: "Deleted",
merged: "Merged",
}.freeze }.freeze
COLOUR = { COLOUR = {
@ -27,6 +28,7 @@ module TagHelper
reactivating_soon: "blue", reactivating_soon: "blue",
deactivated: "grey", deactivated: "grey",
deleted: "red", deleted: "red",
merged: "green",
}.freeze }.freeze
def status_tag(status, classes = []) def status_tag(status, classes = [])

23
app/models/organisation.rb

@ -102,19 +102,6 @@ class Organisation < ApplicationRecord
DISPLAY_PROVIDER_TYPE[provider_type.to_sym] DISPLAY_PROVIDER_TYPE[provider_type.to_sym]
end end
def display_organisation_attributes
[
{ name: "Name", value: name, editable: true },
{ name: "Organisation ID", value: "ORG#{id}", editable: false },
{ name: "Address", value: address_string, editable: true },
{ name: "Telephone number", value: phone, editable: true },
{ name: "Type of provider", value: display_provider_type, editable: false },
{ name: "Registration number", value: housing_registration_no || "", editable: false },
{ name: "Rent periods", value: rent_period_labels, editable: false, format: :bullet },
{ name: "Owns housing stock", value: holds_own_stock ? "Yes" : "No", editable: false },
]
end
def has_managing_agents? def has_managing_agents?
managing_agents.count.positive? managing_agents.count.positive?
end end
@ -122,4 +109,14 @@ class Organisation < ApplicationRecord
def has_stock_owners? def has_stock_owners?
stock_owners.count.positive? stock_owners.count.positive?
end end
def status
@status ||= status_at(Time.zone.now)
end
def status_at(date)
return :merged if merge_date.present? && merge_date < date
:active
end
end end

4
app/views/organisations/_organisation_list.html.erb

@ -14,6 +14,9 @@
<% row.cell(header: true, text: "Type", html_attributes: { <% row.cell(header: true, text: "Type", html_attributes: {
scope: "col", scope: "col",
}) %> }) %>
<% row.cell(header: true, text: "Status", html_attributes: {
scope: "col",
}) %>
<% end %> <% end %>
<% end %> <% end %>
<% @organisations.each do |organisation| %> <% @organisations.each do |organisation| %>
@ -26,6 +29,7 @@
<% end %> <% end %>
<% row.cell(text: organisation.housing_registration_no) %> <% row.cell(text: organisation.housing_registration_no) %>
<% row.cell(text: organisation.display_provider_type) %> <% row.cell(text: organisation.display_provider_type) %>
<% row.cell(text: status_tag(organisation.status)) %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

2
app/views/organisations/show.html.erb

@ -14,7 +14,7 @@
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop"> <div class="govuk-grid-column-two-thirds-from-desktop">
<%= govuk_summary_list do |summary_list| %> <%= govuk_summary_list do |summary_list| %>
<% @organisation.display_organisation_attributes.each do |attr| %> <% display_organisation_attributes(@organisation).each do |attr| %>
<% if can_edit_org?(current_user) && attr[:editable] %> <% if can_edit_org?(current_user) && attr[:editable] %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>
<% row.key { attr[:name] } %> <% row.key { attr[:name] } %>

3
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: 2023_07_10_101532) do ActiveRecord::Schema[7.0].define(version: 2023_07_18_151955) 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"
@ -432,6 +432,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_07_10_101532) do
t.integer "unspecified_units" t.integer "unspecified_units"
t.string "old_org_id" t.string "old_org_id"
t.string "old_visible_id" t.string "old_visible_id"
t.datetime "merge_date"
t.index ["old_visible_id"], name: "index_organisations_on_old_visible_id", unique: true t.index ["old_visible_id"], name: "index_organisations_on_old_visible_id", unique: true
end end

Loading…
Cancel
Save