Offer to download QR codes in a ZIP archive
This commit is contained in:
1
Gemfile
1
Gemfile
@@ -47,6 +47,7 @@ gem "friendly_id", "~> 5.5.0"
|
||||
gem "csv"
|
||||
gem "damerau-levenshtein"
|
||||
gem "rqrcode", "~> 3.0"
|
||||
gem "rubyzip"
|
||||
|
||||
group :development, :test do
|
||||
# See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
|
||||
|
||||
@@ -473,6 +473,7 @@ DEPENDENCIES
|
||||
rqrcode (~> 3.0)
|
||||
rspec-rails
|
||||
rubocop-rails-omakase
|
||||
rubyzip
|
||||
selenium-webdriver
|
||||
slim
|
||||
so_many_devices
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;"
|
||||
|
||||
@@ -282,6 +282,7 @@ en:
|
||||
create: "Create"
|
||||
details: Open
|
||||
delete: "Delete"
|
||||
download_qrcodes_archive: "Download in a ZIP archive"
|
||||
edit: "Edit"
|
||||
end: Click here to submit your completion
|
||||
export: Export
|
||||
|
||||
@@ -253,6 +253,7 @@ fr:
|
||||
create: "Créer"
|
||||
delete: "Supprimer"
|
||||
details: Détails
|
||||
download_qrcodes_archive: "Télécharger dans une archive ZIP"
|
||||
edit: "Modifier"
|
||||
end: Clique ici pour valider ta complétion du puzzle
|
||||
export: Exporter
|
||||
|
||||
@@ -37,6 +37,7 @@ Rails.application.routes.draw do
|
||||
get "export", to: "contestants#export"
|
||||
get "generate_qrcodes", to: "contestants#generate_qrcodes"
|
||||
get "generate_qrcodes_pdf", to: "contestants#generate_qrcodes_pdf"
|
||||
get "generate_qrcodes_archive", to: "contestants#generate_qrcodes_archive"
|
||||
end
|
||||
resources :passwords, param: :token
|
||||
resource :session
|
||||
|
||||
Reference in New Issue
Block a user