Skip to content

Commit

Permalink
Create new ordinal_label helper method to be used across files
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniBitZesty committed Aug 30, 2024
1 parent 471d525 commit f609d1a
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 27 deletions.
9 changes: 9 additions & 0 deletions app/helpers/form_answer_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,13 @@ def assessors_collection_for_bulk
def show_bulk_lieutenants_assignment?
policy(:lieutenant_assignment_collection).create?
end

def ordinal_label(index)
case index
when 0
"first"
when 1
"second"
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
module QaePdfForms::CustomQuestions::SupporterLists
include FormAnswerHelper
def render_supporters
entries = form_answer.support_letters.manual

Expand All @@ -9,40 +10,48 @@ def render_supporters

def render_supporters_list(entries)
entries.each_with_index do |entry, index|
entry_index = index == 0 ? "first" : "second"
ops = [
{ title: "name_of_the_person_who_wrote_the_#{entry_index}_letter_of_support".to_sym, value: ''},
{ ref: "C #{index + 1}.1", title: "name_of_the_person_who_wrote_the_#{ordinal_label(index)}_letter_of_support".to_sym, value: ''},
{ sub_field: "first_name".to_sym, value: entry.first_name },
{ sub_field: "last_name".to_sym, value: entry.last_name },
{ title: "relationship_to_nominee".to_sym, value: entry.relationship_to_nominee, hint: "For example, a beneficiary of the group, local resident or member of a partner charity." },
{ ref: "C #{index + 1}.2", title: "relationship_to_nominee".to_sym, value: entry.relationship_to_nominee, hint: "For example, a beneficiary of the group, local resident or member of a partner charity." },
]

render_supporter(entry, ops, entry_index)
render_supporter(entry, ops, index)
end
end

def render_supporter(entry, ops, entry_index)
form_pdf.move_down 5.mm
def render_supporter(entry, ops, index)
form_pdf.text "C #{index + 1}. The #{ordinal_label(index)} letter of support", style: :bold
form_pdf.move_down 2.5.mm

ops.each do |op|
form_pdf.text "#{format_label(op[:title])}: ", style: :bold if op[:title]
form_pdf.text "#{format_label(op[:sub_field])}: " if op[:sub_field]
form_pdf.text(op[:hint], style: :italic) if op[:hint]
form_pdf.text op[:value]
form_pdf.move_down 2.5.mm
if op[:ref]
form_pdf.text op[:ref], style: :bold
form_pdf.move_cursor_to form_pdf.cursor + 10.mm
form_pdf.indent(13.mm) { form_pdf.render_text format_label(op[:title]), style: :bold } if op[:title]
form_pdf.move_down 5.mm
form_pdf.text(op[:hint], style: :italic) if op[:hint]
else
form_pdf.indent 16.mm do
form_pdf.render_text format_label(op[:sub_field])
form_pdf.render_text op[:value]
end
end
form_pdf.move_down 5.mm
end

if entry.is_a?(SupportLetter)
render_support_letter(entry, entry_index)
render_support_letter(entry, index)
end
end

def format_label(text)
text.to_s.split('_').join(' ').capitalize
end

def render_support_letter(entry, entry_index)
form_pdf.text "Upload the #{entry_index} letter of support: ", style: :bold
def render_support_letter(entry, index)
form_pdf.text "C #{index + 1}.3. Upload the #{ordinal_label(index)} letter of support: ", style: :bold

if entry.support_letter_attachment.present?
form_pdf.base_link_sceleton(
Expand Down
14 changes: 12 additions & 2 deletions app/pdf_generators/qae_pdf_forms/general/question_pointer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,24 @@ def render_header_hint
end

def render_question_title_with_ref_or_not
if question.delegate_obj.ref.present? || question.delegate_obj.sub_ref.present?
if (question.delegate_obj.ref.present? || question.delegate_obj.sub_ref.present?) &&
!question.delegate_obj.is_a?(QaeFormBuilder::SupportersQuestion)
render_question_with_ref
else
render_question_without_ref
end
end

def render_context_and_answer_blocks
if question.key.to_s == "supporter_letters_list"
form_pdf.indent 11.mm do
render_question_context
render_question_help_note
render_question_hints

question_answer(question)
end
end
# for inline questions answer is rendered with the title
if RENDER_INLINE_KEYS.exclude?(question.key.to_s)
form_pdf.indent 25.mm do
Expand Down Expand Up @@ -382,7 +392,7 @@ def question_answer(question)
when QaeFormBuilder::ByYearsQuestion, QaeFormBuilder::OneOptionByYearsQuestion
render_years_table
when QaeFormBuilder::SupportersQuestion
render_supporters
render_supporters
when QaeFormBuilder::TextareaQuestion
title = q_visible? && humanized_answer.present? ? humanized_answer : ""

Expand Down
14 changes: 7 additions & 7 deletions app/views/form/support_letters/_form.html.slim
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
= f.simple_fields_for :support_letters do |ff|
- idx = ff.options[:child_index] + 1
- first_or_second = idx == 1 ? "first" : "second"
- child_index = ff.options[:child_index]
- idx = child_index + 1
li.borderless
.question-block
label[class="govuk-label"]
legend.govuk-label
= render "qae_form/question_ref", question: question, ref: "C #{idx}"
span[class="govuk-body govuk-!-font-size-36 govuk-!-font-weight-bold govuk-!-display-block"]
= "The #{first_or_second} letter of support"
= "The #{ordinal_label(child_index)} letter of support"

legend.govuk-label aria-label="C #{idx}.1: Name"
= render "qae_form/question_ref", question: question, ref: "C #{idx}.1"
span[class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block"]
= "Name of the person who wrote the #{first_or_second} letter of support"
= "Name of the person who wrote the #{ordinal_label(child_index)} letter of support"
= ff.input :first_name, label: "First name:", input_html: { class: "form-control medium" }
= ff.input :last_name, label: "Surname:", input_html: { class: "form-control medium" }

legend.govuk-label aria-label="C #{idx}.2: Relationship to Group"
= render "qae_form/question_ref", question: question, ref: "C #{idx}.2"
label for="form_answer_support_letters_attributes_#{ff.options[:child_index]}_relationship_to_nominee" class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block"
label for="form_answer_support_letters_attributes_#{child_index}_relationship_to_nominee" class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block"
= "Relationship to group"
span.question-context.question-debug.govuk-hint
' For example, a beneficiary of the group, local resident or member of a partner charity.
Expand All @@ -29,8 +29,8 @@

legend.govuk-label aria-label="C #{idx}.3: Upload Letter of Support"
= render "qae_form/question_ref", question: question, ref: "C #{idx}.3"
label for="form_answer_support_letters_attributes_#{ff.options[:child_index]}_support_letter_attachment" class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block"
= "Upload the #{first_or_second} letter of support"
label for="form_answer_support_letters_attributes_#{child_index}_support_letter_attachment" class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block"
= "Upload the #{ordinal_label(child_index)} letter of support"
span.question-context.question-debug.govuk-hint
' If you upload the wrong file, click the 'Remove' link next to the file name to delete it. The file upload button will reappear, allowing you to select the correct file.

Expand Down
7 changes: 3 additions & 4 deletions app/views/qae_form/_supporter_fields.html.slim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
- first_or_second = index == 0 ? "first" : "second"
- idx = index + 1
- persisted = supporter["support_letter_id"].present? || supporter["supporter_id"].present?
- create_url = users_form_answer_support_letters_url(@form_answer)
Expand All @@ -9,15 +8,15 @@ li.borderless[class=class_names("js-add-example", "js-support-letter-received" =
= render "qae_form/question_ref", question: question, ref: "C #{idx}"
label[class="govuk-label"]
span[class="govuk-body govuk-!-font-size-36 govuk-!-font-weight-bold govuk-!-display-block"]
= "The #{first_or_second} letter of support"
= "The #{ordinal_label(index)} letter of support"

input.js-support-entry-id type="hidden" name="form[#{question.key}][#{index}][support_letter_id]" value=supporter["support_letter_id"] *possible_read_only_ops(question.step.opts[:id])
.js-system-tag data-new-hidden-input-name="form[#{question.key}][#{index}][support_letter_id]"

legend.govuk-label aria-label="C #{index + 1}.1: Name"
= render "qae_form/question_ref", question: question, ref: "C #{idx}.1"
span class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block"
' Name of the person who wrote the #{first_or_second} letter of support
' Name of the person who wrote the #{ordinal_label(index)} letter of support
.govuk-form-group.question-block.question-required
label.govuk-label for="form[#{question.key}][#{index}][first_name]"
' First name:
Expand All @@ -43,7 +42,7 @@ li.borderless[class=class_names("js-add-example", "js-support-letter-received" =
= render "qae_form/question_ref", question: question, ref: "C #{idx}.3"
.govuk-form-group.question-block.question-required
label class="govuk-body govuk-!-font-size-24 govuk-!-font-weight-bold govuk-!-display-block" for="form[#{question.key}][#{index}][letter_of_support]"
' Upload the #{first_or_second} letter of support
' Upload the #{ordinal_label(index)} letter of support
span.question-context.question-debug.govuk-hint
' If you upload the wrong file, click the 'Remove' link next to the file name to delete it. The file upload button will reappear, allowing you to select the correct file.
span.govuk-error-message
Expand Down

0 comments on commit f609d1a

Please sign in to comment.