From 96826b06bccb2f2fcc3a16dbf122eecc84825e99 Mon Sep 17 00:00:00 2001 From: Lukas Behrendt Date: Tue, 13 Dec 2016 01:42:53 +0100 Subject: [PATCH] Fix overview table formatting --- lib/pdf_generation/applications_pdf.rb | 40 ++++++++++++---------- spec/controllers/events_controller_spec.rb | 2 +- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/lib/pdf_generation/applications_pdf.rb b/lib/pdf_generation/applications_pdf.rb index 16717933..5ebc38f0 100644 --- a/lib/pdf_generation/applications_pdf.rb +++ b/lib/pdf_generation/applications_pdf.rb @@ -31,11 +31,13 @@ def create_overview end unless @event.application_letters.empty? table overview_table_data, - header: true, width: 500, position: :center, row_colors: ["F9F9F9", "FFFFFF"] do + header: 2, position: :center, row_colors: ["F9F9F9", "FFFFFF"] do cells.borders = [] - row(0).borders = [:bottom] + row(1).borders = [:bottom] + row(1).font_style = :bold row(0).font_style = :bold - row(0).valign = :bottom + row(0).padding = [5, 0, 5, 5] #minimize padding between first two rows + row(1).padding = [0, 5, 5, 5] end end end @@ -53,18 +55,19 @@ def description_table_data end def overview_table_data - data = [[Profile.human_attribute_name(:name), - Profile.human_attribute_name(:gender), - Profile.human_attribute_name(:age), - t("events.applicants_overview.participations") + "\n" + - t("events.applicants_overview.accepted_rejected"), - ApplicationLetter.human_attribute_name(:status)]] + #line breaks lead to weird table formatting, so we create 2 header rows to fit all the text + data = [["", "", "", t("events.applicants_overview.participations"), ""]] + data += [[Profile.human_attribute_name(:name), + Profile.human_attribute_name(:gender), + Profile.human_attribute_name(:age), + t("events.applicants_overview.accepted_rejected"), + ApplicationLetter.human_attribute_name(:status)]] data += @event.application_letters.map { |a| [a.user.profile.name, a.user.profile.gender, a.user.profile.age, "#{a.user.accepted_applications_count(@event)} / #{a.user.rejected_applications_count(@event)}", - a.status]} + t("application_status.#{a.status}")]} end def create_application_page(application_letter, index) @@ -88,24 +91,23 @@ def create_application_page_content(application_letter) cells.padding = 3 column(0).font_style = :bold column(0).align = :right - column(0).width = 180 end - pad_top(10) { text "#{ApplicationLetter.human_attribute_name(:motivation)}", inline_format: true} + pad_top(20) { text "#{ApplicationLetter.human_attribute_name(:motivation)}", inline_format: true} pad_top(5) { text application_letter.motivation } end def applicants_detail_data(application_letter) - data = [[Profile.human_attribute_name(:gender)+":", application_letter.user.profile.gender], - [Profile.human_attribute_name(:age)+":", application_letter.user.profile.age], - [Profile.human_attribute_name(:address)+":", application_letter.user.profile.address], - [User.human_attribute_name(:accepted_application_count)+":", application_letter.user.accepted_applications_count(application_letter.event)], - [User.human_attribute_name(:rejected_application_count)+":", application_letter.user.rejected_applications_count(application_letter.event)], - [Profile.human_attribute_name(:status)+":", t("application_status.#{application_letter.status}")]] + [[Profile.human_attribute_name(:gender)+":", application_letter.user.profile.gender], + [Profile.human_attribute_name(:age)+":", application_letter.user.profile.age], + [Profile.human_attribute_name(:address)+":", application_letter.user.profile.address], + [User.human_attribute_name(:accepted_application_count)+":", application_letter.user.accepted_applications_count(@event)], + [User.human_attribute_name(:rejected_application_count)+":", application_letter.user.rejected_applications_count(@event)], + [Profile.human_attribute_name(:status)+":", t("application_status.#{application_letter.status}")]] end def create_main_header(application_letter) text t("application_letters.application_page.title", name: application_letter.user.profile.name), size: 20 - text t("application_letters.application_page.for", event: application_letter.event.name), size: 14 + text t("application_letters.application_page.for", event: @event.name), size: 14 stroke_horizontal_rule end diff --git a/spec/controllers/events_controller_spec.rb b/spec/controllers/events_controller_spec.rb index 7c876589..4c97c137 100644 --- a/spec/controllers/events_controller_spec.rb +++ b/spec/controllers/events_controller_spec.rb @@ -265,7 +265,7 @@ a.user.profile.gender, a.user.accepted_applications_count(@event).to_s, a.user.rejected_applications_count(@event).to_s, - a.status) + I18n.t("application_status.#{a.status}")) end end end