3 changed files with 33 additions and 11 deletions
@ -1,21 +1,43 @@ |
|||||||
module TasklistHelper |
module TasklistHelper |
||||||
|
STATUSES = { |
||||||
|
:not_started => "Not started", |
||||||
|
:cannot_start_yet => "Cannot start yet", |
||||||
|
:completed => "Completed", |
||||||
|
:in_progress => "In progress" |
||||||
|
} |
||||||
|
|
||||||
|
STYLES = { |
||||||
|
:not_started => "govuk-tag--grey", |
||||||
|
:cannot_start_yet => "govuk-tag--grey", |
||||||
|
:completed => "", |
||||||
|
:in_progress => "govuk-tag--blue" |
||||||
|
} |
||||||
|
|
||||||
def get_subsection_status(subsection_name, case_log) |
def get_subsection_status(subsection_name, case_log) |
||||||
@form = Form.new(2021, 2022) |
@form = Form.new(2021, 2022) |
||||||
questions = @form.questions_for_subsection(subsection_name).keys |
questions = @form.questions_for_subsection(subsection_name).keys |
||||||
|
|
||||||
if subsection_name == "declaration" |
if subsection_name == "declaration" |
||||||
return all_questions_completed(case_log) ? "Not started" : "Cannot start yet" |
return all_questions_completed(case_log) ? :not_started : :cannot_start_yet |
||||||
end |
end |
||||||
if questions.all? {|question| case_log[question].blank?} |
if questions.all? {|question| case_log[question].blank?} |
||||||
return "Not started" |
return :not_started |
||||||
end |
end |
||||||
if questions.all? {|question| case_log[question].present?} |
if questions.all? {|question| case_log[question].present?} |
||||||
return "Completed" |
return :completed |
||||||
end |
end |
||||||
"In progress" |
:in_progress |
||||||
end |
end |
||||||
|
|
||||||
def all_questions_completed(case_log) |
def all_questions_completed(case_log) |
||||||
case_log.attributes.all? { |_question, answer| answer.present?} |
case_log.attributes.all? { |_question, answer| answer.present?} |
||||||
end |
end |
||||||
|
|
||||||
|
def get_status_style(status_label) |
||||||
|
STYLES[status_label] |
||||||
|
end |
||||||
|
|
||||||
|
def get_status_label(status) |
||||||
|
STATUSES[status] |
||||||
|
end |
||||||
end |
end |
||||||
|
Loading…
Reference in new issue