Browse Source

feat: use dynamic pages for age

CLDC-1528-person-1-relationship-to-buyer-1
natdeanlewissoftwire 2 years ago
parent
commit
8b1989a232
  1. 19
      app/models/form/sales/pages/person1_age.rb
  2. 19
      app/models/form/sales/pages/person1_age_joint_purchase.rb
  3. 19
      app/models/form/sales/pages/person2_age.rb
  4. 19
      app/models/form/sales/pages/person2_age_joint_purchase.rb
  5. 19
      app/models/form/sales/pages/person3_age.rb
  6. 19
      app/models/form/sales/pages/person3_age_joint_purchase.rb
  7. 19
      app/models/form/sales/pages/person4_age.rb
  8. 19
      app/models/form/sales/pages/person4_age_joint_purchase.rb
  9. 41
      app/models/form/sales/pages/person_age.rb
  10. 21
      app/models/form/sales/questions/person1_age.rb
  11. 49
      app/models/form/sales/questions/person1_age_known.rb
  12. 21
      app/models/form/sales/questions/person2_age.rb
  13. 49
      app/models/form/sales/questions/person2_age_known.rb
  14. 21
      app/models/form/sales/questions/person3_age.rb
  15. 49
      app/models/form/sales/questions/person3_age_known.rb
  16. 21
      app/models/form/sales/questions/person4_age.rb
  17. 49
      app/models/form/sales/questions/person4_age_known.rb
  18. 32
      app/models/form/sales/questions/person_age.rb
  19. 48
      app/models/form/sales/questions/person_age_known.rb
  20. 16
      app/models/form/sales/subsections/household_characteristics.rb

19
app/models/form/sales/pages/person1_age.rb

@ -1,19 +0,0 @@
class Form::Sales::Pages::Person1Age < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_1_age"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_1" => 1, "jointpur" => 2 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person1AgeKnown.new("age2_known", nil, self),
Form::Sales::Questions::Person1Age.new("age2", nil, self),
]
end
end

19
app/models/form/sales/pages/person1_age_joint_purchase.rb

@ -1,19 +0,0 @@
class Form::Sales::Pages::Person1AgeJointPurchase < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_1_age_joint_purchase"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_1" => 1, "jointpur" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person1AgeKnown.new("age3_known", nil, self),
Form::Sales::Questions::Person1Age.new("age3", nil, self),
]
end
end

19
app/models/form/sales/pages/person2_age.rb

@ -1,19 +0,0 @@
class Form::Sales::Pages::Person2Age < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_2_age"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_2" => 1, "jointpur" => 2 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person2AgeKnown.new("age3_known", nil, self),
Form::Sales::Questions::Person2Age.new("age3", nil, self),
]
end
end

19
app/models/form/sales/pages/person2_age_joint_purchase.rb

@ -1,19 +0,0 @@
class Form::Sales::Pages::Person2AgeJointPurchase < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_2_age_joint_purchase"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_2" => 1, "jointpur" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person2AgeKnown.new("age4_known", nil, self),
Form::Sales::Questions::Person2Age.new("age4", nil, self),
]
end
end

19
app/models/form/sales/pages/person3_age.rb

@ -1,19 +0,0 @@
class Form::Sales::Pages::Person3Age < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_3_age"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_3" => 1, "jointpur" => 2 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person3AgeKnown.new("age4_known", nil, self),
Form::Sales::Questions::Person3Age.new("age4", nil, self),
]
end
end

19
app/models/form/sales/pages/person3_age_joint_purchase.rb

@ -1,19 +0,0 @@
class Form::Sales::Pages::Person3AgeJointPurchase < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_3_age_joint_purchase"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_3" => 1, "jointpur" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person3AgeKnown.new("age5_known", nil, self),
Form::Sales::Questions::Person3Age.new("age5", nil, self),
]
end
end

19
app/models/form/sales/pages/person4_age.rb

@ -1,19 +0,0 @@
class Form::Sales::Pages::Person4Age < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_4_age"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_4" => 1, "jointpur" => 2 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person4AgeKnown.new("age5_known", nil, self),
Form::Sales::Questions::Person4Age.new("age5", nil, self),
]
end
end

19
app/models/form/sales/pages/person4_age_joint_purchase.rb

@ -1,19 +0,0 @@
class Form::Sales::Pages::Person4AgeJointPurchase < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "person_4_age_joint_purchase"
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_4" => 1, "jointpur" => 1 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::Person4AgeKnown.new("age6_known", nil, self),
Form::Sales::Questions::Person4Age.new("age6", nil, self),
]
end
end

41
app/models/form/sales/pages/person_age.rb

@ -0,0 +1,41 @@
class Form::Sales::Pages::PersonAge < ::Form::Page
def initialize(id, hsh, subsection)
super
@header = ""
@description = ""
@subsection = subsection
@depends_on = [
{ "details_known_#{person_display_number}" => 1, "jointpur" => joint_purchase? ? 1 : 2 },
]
end
def questions
@questions ||= [
Form::Sales::Questions::PersonAgeKnown.new("age#{person_database_number}_known", nil, self),
Form::Sales::Questions::PersonAge.new("age#{person_database_number}", nil, self),
]
end
def person_database_number
PERSON_INDEX[id]
end
def person_display_number
joint_purchase? ? PERSON_INDEX[id] - 2 : PERSON_INDEX[id] - 1
end
def joint_purchase?
id.include?("_joint_purchase")
end
PERSON_INDEX = {
"person_1_age" => 2,
"person_2_age" => 3,
"person_3_age" => 4,
"person_4_age" => 5,
"person_1_age_joint_purchase" => 3,
"person_2_age_joint_purchase" => 4,
"person_3_age_joint_purchase" => 5,
"person_4_age_joint_purchase" => 6,
}.freeze
end

21
app/models/form/sales/questions/person1_age.rb

@ -1,21 +0,0 @@
class Form::Sales::Questions::Person1Age < ::Form::Question
def initialize(id, hsh, page)
super
@check_answer_label = "Person 1’s age"
@header = "Age"
@type = "numeric"
@page = page
@width = 3
@inferred_check_answers_value = if id == "age2"
{ "condition" => { "age2_known" => 1 }, "value" => "Not known" }
else
{ "condition" => { "age3_known" => 1 }, "value" => "Not known" }
end
@hidden_in_check_answers = if id == "age2"
{ "depends_on" => [{ "jointpur" => 1 }] }
else
{ "depends_on" => [{ "jointpur" => 2 }] }
end
@check_answers_card_number = id == "age2" ? 2 : 3
end
end

49
app/models/form/sales/questions/person1_age_known.rb

@ -1,49 +0,0 @@
class Form::Sales::Questions::Person1AgeKnown < ::Form::Question
def initialize(id, hsh, page)
super
@check_answer_label = "Person 1’s age known?"
@header = "Do you know person 1’s age?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
@conditional_for = if id == "age2_known"
{
"age2" => [0],
}
else
{
"age3" => [0],
}
end
@hidden_in_check_answers = if id == "age2_known"
{
"depends_on" => [
{
"age2_known" => 0,
},
{
"age2_known" => 1,
},
],
}
else
{
"depends_on" => [
{
"age3_known" => 0,
},
{
"age3_known" => 1,
},
],
}
end
@check_answers_card_number = id == "age2_known" ? 2 : 3
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
end

21
app/models/form/sales/questions/person2_age.rb

@ -1,21 +0,0 @@
class Form::Sales::Questions::Person2Age < ::Form::Question
def initialize(id, hsh, page)
super
@check_answer_label = "Person 2’s age"
@header = "Age"
@type = "numeric"
@page = page
@width = 3
@inferred_check_answers_value = if id == "age3"
{ "condition" => { "age3_known" => 1 }, "value" => "Not known" }
else
{ "condition" => { "age4_known" => 1 }, "value" => "Not known" }
end
@hidden_in_check_answers = if id == "age3"
{ "depends_on" => [{ "jointpur" => 1 }] }
else
{ "depends_on" => [{ "jointpur" => 2 }] }
end
@check_answers_card_number = id == "age3" ? 3 : 4
end
end

49
app/models/form/sales/questions/person2_age_known.rb

@ -1,49 +0,0 @@
class Form::Sales::Questions::Person2AgeKnown < ::Form::Question
def initialize(id, hsh, page)
super
@check_answer_label = "Person 2’s age known?"
@header = "Do you know person 2’s age?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
@conditional_for = if id == "age3_known"
{
"age3" => [0],
}
else
{
"age4" => [0],
}
end
@hidden_in_check_answers = if id == "age3_known"
{
"depends_on" => [
{
"age3_known" => 0,
},
{
"age3_known" => 1,
},
],
}
else
{
"depends_on" => [
{
"age4_known" => 0,
},
{
"age4_known" => 1,
},
],
}
end
@check_answers_card_number = id == "age3_known" ? 3 : 4
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
end

21
app/models/form/sales/questions/person3_age.rb

@ -1,21 +0,0 @@
class Form::Sales::Questions::Person3Age < ::Form::Question
def initialize(id, hsh, page)
super
@check_answer_label = "Person 3’s age"
@header = "Age"
@type = "numeric"
@page = page
@width = 3
@inferred_check_answers_value = if id == "age4"
{ "condition" => { "age4_known" => 1 }, "value" => "Not known" }
else
{ "condition" => { "age5_known" => 1 }, "value" => "Not known" }
end
@hidden_in_check_answers = if id == "age4"
{ "depends_on" => [{ "jointpur" => 1 }] }
else
{ "depends_on" => [{ "jointpur" => 2 }] }
end
@check_answers_card_number = id == "age4" ? 4 : 5
end
end

49
app/models/form/sales/questions/person3_age_known.rb

@ -1,49 +0,0 @@
class Form::Sales::Questions::Person3AgeKnown < ::Form::Question
def initialize(id, hsh, page)
super
@check_answer_label = "Person 3’s age known?"
@header = "Do you know person 3’s age?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
@conditional_for = if id == "age4_known"
{
"age4" => [0],
}
else
{
"age5" => [0],
}
end
@hidden_in_check_answers = if id == "age4_known"
{
"depends_on" => [
{
"age4_known" => 0,
},
{
"age4_known" => 1,
},
],
}
else
{
"depends_on" => [
{
"age5_known" => 0,
},
{
"age5_known" => 1,
},
],
}
end
@check_answers_card_number = id == "age4_known" ? 4 : 5
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
end

21
app/models/form/sales/questions/person4_age.rb

@ -1,21 +0,0 @@
class Form::Sales::Questions::Person4Age < ::Form::Question
def initialize(id, hsh, page)
super
@check_answer_label = "Person 4’s age"
@header = "Age"
@type = "numeric"
@page = page
@width = 3
@inferred_check_answers_value = if id == "age5"
{ "condition" => { "age5_known" => 1 }, "value" => "Not known" }
else
{ "condition" => { "age6_known" => 1 }, "value" => "Not known" }
end
@hidden_in_check_answers = if id == "age5"
{ "depends_on" => [{ "jointpur" => 1 }] }
else
{ "depends_on" => [{ "jointpur" => 2 }] }
end
@check_answers_card_number = id == "age5" ? 5 : 6
end
end

49
app/models/form/sales/questions/person4_age_known.rb

@ -1,49 +0,0 @@
class Form::Sales::Questions::Person4AgeKnown < ::Form::Question
def initialize(id, hsh, page)
super
@check_answer_label = "Person 4’s age known?"
@header = "Do you know person 4’s age?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
@conditional_for = if id == "age5_known"
{
"age5" => [0],
}
else
{
"age6" => [0],
}
end
@hidden_in_check_answers = if id == "age5_known"
{
"depends_on" => [
{
"age5_known" => 0,
},
{
"age5_known" => 1,
},
],
}
else
{
"depends_on" => [
{
"age6_known" => 0,
},
{
"age6_known" => 1,
},
],
}
end
@check_answers_card_number = id == "age5_known" ? 5 : 6
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
end

32
app/models/form/sales/questions/person_age.rb

@ -0,0 +1,32 @@
class Form::Sales::Questions::PersonAge < ::Form::Question
def initialize(id, hsh, page)
super
@check_answer_label = "Person #{person_display_number}’s age"
@header = "Age"
@type = "numeric"
@page = page
@width = 3
@inferred_check_answers_value = { "condition" => { "age#{PERSON_INDEX[id]}_known" => 1 }, "value" => "Not known" }
@check_answers_card_number = person_database_number
end
def person_database_number
PERSON_INDEX[id]
end
PERSON_INDEX = {
"age2" => 2,
"age3" => 3,
"age4" => 4,
"age5" => 5,
"age6" => 6,
}.freeze
def person_display_number
joint_purchase? ? PERSON_INDEX[id] - 2 : PERSON_INDEX[id] - 1
end
def joint_purchase?
page.id.include?("_joint_purchase")
end
end

48
app/models/form/sales/questions/person_age_known.rb

@ -0,0 +1,48 @@
class Form::Sales::Questions::PersonAgeKnown < ::Form::Question
def initialize(id, hsh, page)
super
@check_answer_label = "Person #{person_display_number}’s age known?"
@header = "Do you know person #{person_display_number}’s age?"
@type = "radio"
@answer_options = ANSWER_OPTIONS
@page = page
@hint_text = ""
@conditional_for = { "age#{PERSON_INDEX[id]}" => [0] }
@hidden_in_check_answers = {
"depends_on" => [
{
"age#{PERSON_INDEX[id]}_known" => 0,
},
{
"age#{PERSON_INDEX[id]}_known" => 1,
},
],
}
@check_answers_card_number = PERSON_INDEX[id]
end
ANSWER_OPTIONS = {
"0" => { "value" => "Yes" },
"1" => { "value" => "No" },
}.freeze
def person_database_number
PERSON_INDEX[id]
end
PERSON_INDEX = {
"age2_known" => 2,
"age3_known" => 3,
"age4_known" => 4,
"age5_known" => 5,
"age6_known" => 6,
}.freeze
def person_display_number
joint_purchase? ? PERSON_INDEX[id] - 2 : PERSON_INDEX[id] - 1
end
def joint_purchase?
page.id.include?("_joint_purchase")
end
end

16
app/models/form/sales/subsections/household_characteristics.rb

@ -33,22 +33,22 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
Form::Sales::Pages::Person1KnownJointPurchase.new(nil, nil, self), Form::Sales::Pages::Person1KnownJointPurchase.new(nil, nil, self),
Form::Sales::Pages::Person1RelationshipToBuyer1.new(nil, nil, self), Form::Sales::Pages::Person1RelationshipToBuyer1.new(nil, nil, self),
Form::Sales::Pages::Person1RelationshipToBuyer1JointPurchase.new(nil, nil, self), Form::Sales::Pages::Person1RelationshipToBuyer1JointPurchase.new(nil, nil, self),
Form::Sales::Pages::Person1Age.new(nil, nil, self), Form::Sales::Pages::PersonAge.new("person_1_age", nil, self),
Form::Sales::Pages::Person1AgeJointPurchase.new(nil, nil, self), Form::Sales::Pages::PersonAge.new("person_1_age_joint_purchase", nil, self),
Form::Sales::Pages::Person1GenderIdentity.new(nil, nil, self), Form::Sales::Pages::Person1GenderIdentity.new(nil, nil, self),
Form::Sales::Pages::Person1GenderIdentityJointPurchase.new(nil, nil, self), Form::Sales::Pages::Person1GenderIdentityJointPurchase.new(nil, nil, self),
Form::Sales::Pages::Person2Known.new(nil, nil, self), Form::Sales::Pages::Person2Known.new(nil, nil, self),
Form::Sales::Pages::Person2KnownJointPurchase.new(nil, nil, self), Form::Sales::Pages::Person2KnownJointPurchase.new(nil, nil, self),
Form::Sales::Pages::Person2Age.new(nil, nil, self), Form::Sales::Pages::PersonAge.new("person_2_age", nil, self),
Form::Sales::Pages::Person2AgeJointPurchase.new(nil, nil, self), Form::Sales::Pages::PersonAge.new("person_2_age_joint_purchase", nil, self),
Form::Sales::Pages::Person3Known.new(nil, nil, self), Form::Sales::Pages::Person3Known.new(nil, nil, self),
Form::Sales::Pages::Person3KnownJointPurchase.new(nil, nil, self), Form::Sales::Pages::Person3KnownJointPurchase.new(nil, nil, self),
Form::Sales::Pages::Person3Age.new(nil, nil, self), Form::Sales::Pages::PersonAge.new("person_3_age", nil, self),
Form::Sales::Pages::Person3AgeJointPurchase.new(nil, nil, self), Form::Sales::Pages::PersonAge.new("person_3_age_joint_purchase", nil, self),
Form::Sales::Pages::Person4Known.new(nil, nil, self), Form::Sales::Pages::Person4Known.new(nil, nil, self),
Form::Sales::Pages::Person4KnownJointPurchase.new(nil, nil, self), Form::Sales::Pages::Person4KnownJointPurchase.new(nil, nil, self),
Form::Sales::Pages::Person4Age.new(nil, nil, self), Form::Sales::Pages::PersonAge.new("person_4_age", nil, self),
Form::Sales::Pages::Person4AgeJointPurchase.new(nil, nil, self), Form::Sales::Pages::PersonAge.new("person_4_age_joint_purchase", nil, self),
] ]
end end
end end

Loading…
Cancel
Save