Offer to download QR codes in a ZIP archive
All checks were successful
CI / scan_ruby (push) Successful in 17s
CI / scan_js (push) Successful in 14s
CI / lint (push) Successful in 14s
CI / test (push) Successful in 36s

This commit is contained in:
sto
2026-03-08 10:09:55 +01:00
parent c787e913fa
commit 589e46c1fd
8 changed files with 32 additions and 1 deletions

View File

@@ -1,8 +1,10 @@
require "zip"
class ContestantsController < ApplicationController
include CompletionsConcern
include ContestantsConcern
before_action :set_contest, only: %i[ index edit new create update destroy import upload_csv convert_csv finalize_import export generate_qrcodes generate_qrcodes_pdf ]
before_action :set_contest, only: %i[ index edit new create update destroy import upload_csv convert_csv finalize_import export generate_qrcodes generate_qrcodes_pdf generate_qrcodes_archive ]
before_action :set_contestant, only: %i[ destroy edit update]
before_action :set_completions, only: %i[edit update ]
skip_before_action :require_authentication, only: %i[ get_public_completion post_public_completion public_completion_updated ]
@@ -140,6 +142,24 @@ class ContestantsController < ApplicationController
end
end
def generate_qrcodes_archive
authorize @contest
generate_contestants_qrcodes(@contest)
@contestants = @contest.contestants.sort_by { |contestant| contestant.name }
stringio = Zip::OutputStream.write_buffer do |zio|
@contestants.each do |contestant|
zio.put_next_entry("#{@contest.friendly_id}_#{contestant.name}.svg")
zio.write contestant.qrcode
end
end
binary_data = stringio.string
send_data binary_data, filename: "#{@contest.friendly_id}_qrcodes.zip", disposition: "attachment"
end
def get_public_completion
skip_authorization

View File

@@ -119,6 +119,10 @@ class ContestPolicy < ApplicationPolicy
owner_or_admin
end
def generate_qrcodes_archive?
owner_or_admin
end
def upload_csv?
owner_or_admin
end

View File

@@ -7,6 +7,8 @@
a.mt-3.mb-3.btn.btn-primary href="#{contest_generate_qrcodes_pdf_path(@contest)}" target="_blank" style="margin-top: -3px"
= t("helpers.buttons.open_raw")
a.mt-3.mb-3.ms-3.btn.btn-primary href="#{contest_generate_qrcodes_archive_path(@contest)}" target="_blank" style="margin-top: -3px"
= t("helpers.buttons.download_qrcodes_archive")
.col.d-flex.flex-column style="height: calc(100% - 200px)"
.d-flex.flex-column style="overflow-y: auto;"