Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

53 lines
2.1 KiB

module LocationsHelper
def mobility_type_selection
mobility_types_to_display = Location.mobility_types.excluding("Property designed to accessible general standard", "Missing")
mobility_types_to_display.map { |key, value| OpenStruct.new(id: key, name: key.to_s.humanize, description: I18n.t("questions.descriptions.location.mobility_type.#{value}")) }
end
def another_location_selection
selection_options(%w[Yes No])
end
def type_of_units_selection
selection_options(Location.type_of_units)
end
def local_authorities_selection
null_option = [OpenStruct.new(id: "", name: "Select an option")]
null_option + Location.local_authorities.map { |code, name| OpenStruct.new(code:, name:) }
end
def selection_options(resource)
return [] if resource.blank?
resource.map { |key, _| OpenStruct.new(id: key, name: key.to_s.humanize) }
end
def display_location_attributes(location)
base_attributes = [
{ name: "Postcode", value: location.postcode },
{ name: "Local authority", value: location.location_admin_district },
{ name: "Location name", value: location.name, edit: true },
{ name: "Total number of units at this location", value: location.units },
{ name: "Common type of unit", value: location.type_of_unit },
{ name: "Mobility type", value: location.mobility_type },
{ name: "Code", value: location.location_code },
{ name: "Availability", value: location_availability(location) },
]
if FeatureToggle.location_toggle_enabled?
base_attributes.append({ name: "Status", value: location.status })
end
base_attributes
end
def location_availability(location)
availability = "Active from #{location.available_from.to_formatted_s(:govuk_date)}"
location.location_deactivation_periods.each do |deactivation|
availability << " to #{(deactivation.deactivation_date - 1.day).to_formatted_s(:govuk_date)}\nDeactivated on #{deactivation.deactivation_date.to_formatted_s(:govuk_date)}"
availability << "\nActive from #{deactivation.reactivation_date.to_formatted_s(:govuk_date)}" if deactivation.reactivation_date.present?
end
availability
end
end