Browse Source

Refactor formhandler

pull/1283/head
Jack S 3 years ago
parent
commit
69bc5b8363
  1. 42
      app/models/form_handler.rb

42
app/models/form_handler.rb

@ -3,6 +3,19 @@ class FormHandler
include CollectionTimeHelper include CollectionTimeHelper
attr_reader :forms attr_reader :forms
SALES_SECTIONS = [
Form::Sales::Sections::PropertyInformation,
Form::Sales::Sections::Household,
Form::Sales::Sections::Finances,
Form::Sales::Sections::SaleInformation,
].freeze
LETTINGS_SECTIONS = [
Form::Lettings::Sections::TenancyAndProperty,
Form::Lettings::Sections::Household,
Form::Lettings::Sections::RentAndCharges,
].freeze
def initialize def initialize
@forms = get_all_forms @forms = get_all_forms
end end
@ -20,18 +33,11 @@ class FormHandler
end end
def sales_forms def sales_forms
sales_sections = [ {
Form::Sales::Sections::PropertyInformation, "current_sales" => Form.new(nil, current_collection_start_year, SALES_SECTIONS, "sales"),
Form::Sales::Sections::Household, "previous_sales" => Form.new(nil, current_collection_start_year - 1, SALES_SECTIONS, "sales"),
Form::Sales::Sections::Finances, "next_sales" => Form.new(nil, current_collection_start_year + 1, SALES_SECTIONS, "sales"),
Form::Sales::Sections::SaleInformation, }
]
current_form = Form.new(nil, current_collection_start_year, sales_sections, "sales")
previous_form = Form.new(nil, current_collection_start_year - 1, sales_sections, "sales")
next_form = Form.new(nil, current_collection_start_year + 1, sales_sections, "sales")
{ "current_sales" => current_form,
"previous_sales" => previous_form,
"next_sales" => next_form }
end end
def lettings_forms def lettings_forms
@ -45,17 +51,11 @@ class FormHandler
end end
end end
lettings_sections = [
Form::Lettings::Sections::TenancyAndProperty,
Form::Lettings::Sections::Household,
Form::Lettings::Sections::RentAndCharges,
]
if forms["previous_lettings"].blank? && current_collection_start_year >= 2022 if forms["previous_lettings"].blank? && current_collection_start_year >= 2022
forms["previous_lettings"] = Form.new(nil, current_collection_start_year - 1, lettings_sections, "lettings") forms["previous_lettings"] = Form.new(nil, current_collection_start_year - 1, LETTINGS_SECTIONS, "lettings")
end end
forms["current_lettings"] = Form.new(nil, current_collection_start_year, lettings_sections, "lettings") if forms["current_lettings"].blank? forms["current_lettings"] = Form.new(nil, current_collection_start_year, LETTINGS_SECTIONS, "lettings") if forms["current_lettings"].blank?
forms["next_lettings"] = Form.new(nil, current_collection_start_year + 1, lettings_sections, "lettings") if forms["next_lettings"].blank? forms["next_lettings"] = Form.new(nil, current_collection_start_year + 1, LETTINGS_SECTIONS, "lettings") if forms["next_lettings"].blank?
forms forms
end end

Loading…
Cancel
Save