QR codes generation
This commit is contained in:
@@ -2,7 +2,7 @@ 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 ]
|
||||
before_action :set_contest, only: %i[ index edit new create update destroy import upload_csv convert_csv finalize_import export generate_qrcodes ]
|
||||
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 ]
|
||||
@@ -42,7 +42,7 @@ class ContestantsController < ApplicationController
|
||||
|
||||
if @contestant.update(contestant_params)
|
||||
update_contestant_categories
|
||||
redirect_to @contest, notice: t("contestants.edit.notice")
|
||||
redirect_to contest_contestants_path(@contest), notice: t("contestants.edit.notice")
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
end
|
||||
@@ -120,6 +120,12 @@ class ContestantsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def generate_qrcodes
|
||||
authorize @contest
|
||||
|
||||
@contestants = @contest.contestants.sort_by { |contestant| contestant.name }
|
||||
end
|
||||
|
||||
def get_public_completion
|
||||
skip_authorization
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
# email :string
|
||||
# name :string
|
||||
# projected_time :string
|
||||
# qrcode :string
|
||||
# time_seconds :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
@@ -27,6 +28,7 @@ class Contestant < ApplicationRecord
|
||||
has_and_belongs_to_many :categories
|
||||
|
||||
before_validation :initialize_time_seconds_if_empty
|
||||
before_commit :generate_qrcode, on: :create
|
||||
|
||||
validates :name, presence: true
|
||||
validates :time_seconds, presence: true
|
||||
@@ -48,4 +50,17 @@ class Contestant < ApplicationRecord
|
||||
self.time_seconds = 0
|
||||
end
|
||||
end
|
||||
|
||||
def generate_qrcode
|
||||
host = Rails.application.config.action_controller.default_url_options[:host]
|
||||
qrcode = RQRCode::QRCode.new("https://#{host}/public/p/#{self.generate_token_for(:token)}")
|
||||
self.qrcode = qrcode.as_svg(
|
||||
color: "000",
|
||||
shape_rendering: "crispEdges",
|
||||
module_size: 3,
|
||||
standalone: true,
|
||||
use_path: true,
|
||||
viewbox: true
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -33,7 +33,7 @@ class Offline < ApplicationRecord
|
||||
belongs_to :contestant, optional: true
|
||||
belongs_to :completion, optional: true
|
||||
|
||||
has_many_attached :images
|
||||
has_many_attached :images, dependent: :destroy
|
||||
|
||||
generates_token_for :token
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class Puzzle < ApplicationRecord
|
||||
belongs_to :contest
|
||||
|
||||
has_many :completions, dependent: :destroy
|
||||
has_one_attached :image
|
||||
has_one_attached :image, dependent: :destroy
|
||||
|
||||
validates :name, presence: true
|
||||
validates :pieces, presence: true
|
||||
|
||||
@@ -35,6 +35,10 @@ class ContestPolicy < ApplicationPolicy
|
||||
owner_or_admin
|
||||
end
|
||||
|
||||
def generate_qrcodes?
|
||||
owner_or_admin
|
||||
end
|
||||
|
||||
def settings_general_edit?
|
||||
edit?
|
||||
end
|
||||
|
||||
11
app/views/contestants/generate_qrcodes.html.slim
Normal file
11
app/views/contestants/generate_qrcodes.html.slim
Normal file
@@ -0,0 +1,11 @@
|
||||
.row.mb-4 style="height: calc(100vh - 280px)"
|
||||
.col.d-flex.flex-column style="height: 100%"
|
||||
.d-flex.flex-column style="overflow-y: auto"
|
||||
- for row in 0..((@contestants.length - 1) / 4)
|
||||
.mt-4.d-flex.flex-row
|
||||
- for col in 0..3
|
||||
- if row * 4 + col < @contestants.length
|
||||
.d-flex.flex-column.ms-5 style="align-items: center"
|
||||
= @contestants[row * 4 + col].name
|
||||
.mt-1 style="width: 200px; height: 200px;"
|
||||
= @contestants[row * 4 + col].qrcode.html_safe
|
||||
@@ -6,6 +6,8 @@
|
||||
| + #{t("helpers.buttons.add")}
|
||||
a.ms-2.btn.btn.btn-primary href=contest_import_path(@contest) style="margin-top: -3px"
|
||||
| #{t("helpers.buttons.import")}
|
||||
a.ms-2.btn.btn.btn-primary href=contest_generate_qrcodes_path(@contest) style="margin-top: -3px"
|
||||
| #{t("helpers.buttons.generate_qrcodes")}
|
||||
a.ms-2.btn.btn.btn-primary href="/contests/#{@contest.id}/export.csv" style="margin-top: -3px"
|
||||
| #{t("helpers.buttons.export")}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user