Skip to content

Commit

Permalink
new layout for voting poster, enlarge QR code
Browse files Browse the repository at this point in the history
  • Loading branch information
thoherr committed Oct 21, 2024
1 parent ffdbdf9 commit 0671c14
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
57 changes: 38 additions & 19 deletions app/services/voting_poster_creation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,47 @@ class VotingPosterCreation < ApplicationService
def initialize(exhibit)
@exhibit = exhibit
@url = new_vote_url(@exhibit)
@stroke_bounds = false
end

def call
{ pdf: voting_poster, filename: filename }
end

def filename
type = @exhibit.is_collab? ? 'COLLAB' : 'MOC';
type = @exhibit.is_collab? ? 'COLLAB' : 'MOC'
"#{type}-voting-#{@exhibit.id}-#{@exhibit.platform_position}.pdf"
end

private

def voting_poster
throw "Exhibit #{@exhibit.to_s} is not votable" if not @exhibit.votable?
pdf = Prawn::Document.new(margin: 7, page_size: 'A6', page_layout: :landscape, print_scaling: :none)
throw "Exhibit #{@exhibit.to_s} is not votable" unless @exhibit.votable?

pdf = Prawn::Document.new(margin: 7, page_size: 'A6', page_layout: :portrait, print_scaling: :none)

width = pdf.bounds.width
height = pdf.bounds.height
name_top = height - 40
name_height = 75
instructions_top = name_top - name_height
instructions_height = 60
qr_top = instructions_top - instructions_height
qr_height = 220

logo_url = @exhibit.attendance.event.logo_url
unless logo_url.blank?
pdf.image URI.parse(logo_url).open,
position: :center, vposition: :top, width: width * 0.9, height: height * 0.2
position: :center, vposition: :top, width: width * 0.9
else
pdf.text @exhibit.event_title, align: :center, style: :bold, size: 14
end
pdf.text @exhibit.event_title, align: :center, style: :bold, size: 12

pdf.float do
pdf.image StringIO.new(qr_png.to_datastream.to_s), position: :right, vposition: :bottom, scale: 1.20
pdf.bounding_box([0, qr_top], width: width, height: qr_height) do
pdf.stroke_bounds if @stroke_bounds
pdf.image StringIO.new(qr_png.to_datastream.to_s), position: :center, fit: [width, qr_height]
end
end

pdf.float do
Expand All @@ -45,42 +59,47 @@ def voting_poster
end

pdf.float do
pdf.bounding_box([0, 110], width: 275, height: 70) do
pdf.bounding_box([0, instructions_top], width: width, height: instructions_height) do
pdf.stroke_bounds if @stroke_bounds
current_locale = I18n.locale
I18n.locale = :de
pdf.text I18n.t('voting_poster_intro'), align: :right
pdf.text I18n.t('voting_poster_instruction'), align: :right
pdf.move_down 5.mm
I18n.locale = :en
pdf.text I18n.t('voting_poster_intro'), align: :right
pdf.text I18n.t('voting_poster_instruction'), align: :right
[:de, :en].each do |locale|
I18n.locale = locale
pdf.move_down 1.mm
pdf.text I18n.t('voting_poster_intro'), align: :center, style: :bold
pdf.text I18n.t('voting_poster_instruction'), align: :center
end
I18n.locale = current_locale
end
end

pdf.float do
pdf.bounding_box([0, name_top], width: width, height: name_height) do
pdf.stroke_bounds if @stroke_bounds
end
pdf.text_box "#{@exhibit.name}" +
"#{'<br/><font size=\'12\'> (' + @exhibit.installation.name + ')</font>' if @exhibit.installation}" +
"#{'<br/><font size=\'10\'> (Gemeinschaftsprojekt / Collab)</font>' if @exhibit.is_collab?}",
inline_format: true,
at: [0, 210],
at: [0, name_top],
width: width,
height: 80,
height: name_height,
overflow: :shrink_to_fit,
style: :bold, size: 24,
align: :center, valign: :center
end

pdf.float do
pdf.bounding_box([0, 40], width: 275, height: 40) do
pdf.text @exhibit.platform_position, style: :bold, size: 24, valign: :bottom
pdf.bounding_box([0, 20], width: width * 0.6, height: 20) do
pdf.stroke_bounds if @stroke_bounds
pdf.text @exhibit.platform_position, style: :bold, size: 18, valign: :bottom
end
end

pdf.render
end

def qr_png
RQRCode::QRCode.new(@url).as_png
RQRCode::QRCode.new(@url).as_png(size: 100)
end

end
4 changes: 2 additions & 2 deletions config/locales/application.de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ de:
no_file_added: "Keine Datei angegeben"
only_csv_files_allowed: "Nur CSV-Dateien können importiert werden"
vote_for: "Ich möchte abstimmen für das MOC"
voting_poster_intro: "Wähle dieses Modell als einen Deiner Favoriten"
voting_poster_instruction: "Zur Stimmabgabe den QR Code scannen"
voting_poster_intro: "Gefällt Dir das Modell?"
voting_poster_instruction: "Dann scanne den Code und gibt Deine Stimme ab!"
exhibit_voting_results_for: "Ergebnisse der MOC-Wahl für"
no_votes: "Keine abgegebenen Stimmen"
number_of_votes: "Es wurden %{size} Stimmen abgegeben"
Expand Down
4 changes: 2 additions & 2 deletions config/locales/application.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,8 @@ en:
no_file_added: "No file added"
only_csv_files_allowed: "Only CSV files allowed"
vote_for: "I'd like to vote for MOC"
voting_poster_intro: "Vote for this model as one of your favorites"
voting_poster_instruction: "To vote scan the QR code"
voting_poster_intro: "You like the model?"
voting_poster_instruction: "Then scan the code and cast your vote!"
exhibit_voting_results_for: "Results of the MOC voting for"
no_votes: "No votes"
number_of_votes: "We got %{size} votes"
Expand Down

0 comments on commit 0671c14

Please sign in to comment.