@@ -122,12 +122,16 @@ class ContestantsController < ApplicationController
|
|||||||
def generate_qrcodes
|
def generate_qrcodes
|
||||||
authorize @contest
|
authorize @contest
|
||||||
|
|
||||||
|
generate_contestants_qrcodes(@contest)
|
||||||
|
|
||||||
@contestants = @contest.contestants.sort_by { |contestant| contestant.name }
|
@contestants = @contest.contestants.sort_by { |contestant| contestant.name }
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_qrcodes_pdf
|
def generate_qrcodes_pdf
|
||||||
authorize @contest
|
authorize @contest
|
||||||
|
|
||||||
|
generate_contestants_qrcodes(@contest)
|
||||||
|
|
||||||
@contestants = @contest.contestants.sort_by { |contestant| contestant.name }
|
@contestants = @contest.contestants.sort_by { |contestant| contestant.name }
|
||||||
@nonav = true
|
@nonav = true
|
||||||
|
|
||||||
@@ -139,7 +143,7 @@ class ContestantsController < ApplicationController
|
|||||||
def get_public_completion
|
def get_public_completion
|
||||||
skip_authorization
|
skip_authorization
|
||||||
|
|
||||||
@contestant = Contestant.find_by_token_for(:token, params[:token])
|
@contestant = Contestant.find(params[:contestant_id])
|
||||||
if !@contestant
|
if !@contestant
|
||||||
not_found and return
|
not_found and return
|
||||||
end
|
end
|
||||||
@@ -156,7 +160,7 @@ class ContestantsController < ApplicationController
|
|||||||
def post_public_completion
|
def post_public_completion
|
||||||
skip_authorization
|
skip_authorization
|
||||||
|
|
||||||
@contestant = Contestant.find_by_token_for(:token, params[:token])
|
@contestant = Contestant.find(params[:contestant_id])
|
||||||
if !@contestant
|
if !@contestant
|
||||||
not_found and return
|
not_found and return
|
||||||
end
|
end
|
||||||
@@ -186,7 +190,7 @@ class ContestantsController < ApplicationController
|
|||||||
def public_completion_updated
|
def public_completion_updated
|
||||||
skip_authorization
|
skip_authorization
|
||||||
|
|
||||||
@contestant = Contestant.find_by_token_for(:token, params[:token])
|
@contestant = Contestant.find(params[:contestant_id])
|
||||||
if !@contestant
|
if !@contestant
|
||||||
not_found and return
|
not_found and return
|
||||||
end
|
end
|
||||||
@@ -235,4 +239,11 @@ class ContestantsController < ApplicationController
|
|||||||
def completion_params
|
def completion_params
|
||||||
params.expect(completion: [ :display_time_from_start, :completed, :missing_pieces, :remaining_pieces, :puzzle_id, :code ])
|
params.expect(completion: [ :display_time_from_start, :completed, :missing_pieces, :remaining_pieces, :puzzle_id, :code ])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def generate_contestants_qrcodes(contest)
|
||||||
|
contest.contestants.where(qrcode: nil).each do |contestant|
|
||||||
|
contestant.generate_qrcode
|
||||||
|
contestant.save
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class UsersController < ApplicationController
|
|||||||
authorize :user
|
authorize :user
|
||||||
|
|
||||||
Contestant.all.each do |contestant|
|
Contestant.all.each do |contestant|
|
||||||
contestant.regenerate_qrcode
|
contestant.generate_qrcode
|
||||||
contestant.save
|
contestant.save
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,13 +28,10 @@ class Contestant < ApplicationRecord
|
|||||||
has_and_belongs_to_many :categories
|
has_and_belongs_to_many :categories
|
||||||
|
|
||||||
before_validation :initialize_time_seconds_if_empty
|
before_validation :initialize_time_seconds_if_empty
|
||||||
before_save :generate_qrcode, if: -> { !qrcode.present? }
|
|
||||||
|
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :time_seconds, presence: true
|
validates :time_seconds, presence: true
|
||||||
|
|
||||||
generates_token_for :token
|
|
||||||
|
|
||||||
def form_name
|
def form_name
|
||||||
if email.present?
|
if email.present?
|
||||||
"#{name} - #{email}"
|
"#{name} - #{email}"
|
||||||
@@ -43,21 +40,9 @@ class Contestant < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def regenerate_qrcode
|
|
||||||
generate_qrcode
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def initialize_time_seconds_if_empty
|
|
||||||
if !self.time_seconds
|
|
||||||
self.time_seconds = 0
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def generate_qrcode
|
def generate_qrcode
|
||||||
host = Rails.application.config.action_controller.default_url_options[:host]
|
host = Rails.application.config.action_controller.default_url_options[:host]
|
||||||
qrcode = RQRCode::QRCode.new("https://#{host}/public/p/#{self.generate_token_for(:token)}")
|
qrcode = RQRCode::QRCode.new("https://#{host}/public/p/#{self.id}")
|
||||||
self.qrcode = qrcode.as_svg(
|
self.qrcode = qrcode.as_svg(
|
||||||
color: "000",
|
color: "000",
|
||||||
shape_rendering: "crispEdges",
|
shape_rendering: "crispEdges",
|
||||||
@@ -67,4 +52,12 @@ class Contestant < ApplicationRecord
|
|||||||
viewbox: true
|
viewbox: true
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def initialize_time_seconds_if_empty
|
||||||
|
if !self.time_seconds
|
||||||
|
self.time_seconds = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ Rails.application.routes.draw do
|
|||||||
get "public/:id/offline/:token", to: "contests#offline_edit"
|
get "public/:id/offline/:token", to: "contests#offline_edit"
|
||||||
patch "public/:id/offline/:token", to: "contests#offline_update"
|
patch "public/:id/offline/:token", to: "contests#offline_update"
|
||||||
get "public/:id/offline/:token/completed", to: "contests#offline_completed"
|
get "public/:id/offline/:token/completed", to: "contests#offline_completed"
|
||||||
get "public/p/:token", to: "contestants#get_public_completion"
|
get "public/p/:contestant_id", to: "contestants#get_public_completion"
|
||||||
post "public/p/:token", to: "contestants#post_public_completion"
|
post "public/p/:contestant_id", to: "contestants#post_public_completion"
|
||||||
get "public/p/:token/updated", to: "contestants#public_completion_updated"
|
get "public/p/:contestant_id/updated", to: "contestants#public_completion_updated"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user