Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] add qr code page to check in #2419

Merged
merged 7 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/controllers/admin/qr_code_for_stamp_rallies_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Admin::QrCodeForStampRalliesController < ApplicationController
include SecuredAdmin

def show
@stamp_rally_check_point = StampRallyCheckPoint.find(params[:id])
@qr_code_for_stamp_rally = QrCodeForStampRally.new(@stamp_rally_check_point, @conference)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def destroy
private

def stamp_rally_check_point_params
params.require(:stamp_rally_check_point).permit(:sponsor_id, :type)
params.require(:stamp_rally_check_point).permit(:sponsor_id, :type, :name, :description)
end

def turbo_stream_flash
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ def home_controller?
controller_name == 'home'
end

def qr_code_for_stamp_rallies_controller?
controller_name == 'qr_code_for_stamp_rallies'
end

def admin_controller?
controller_name == 'admin'
end
Expand All @@ -62,8 +66,8 @@ def talk_difficulty(talk)
@talk_difficulties.find(talk.talk_difficulty_id)
end

helper_method :home_controller?, :admin_controller?, :event_name, :production?, :talks_checked?, :talk_category, :talk_difficulty, :display_speaker_dashboard_link?, :display_dashboard_link?, :display_proposals?, :display_talks?,
:display_timetable?, :display_contact_url?
helper_method :home_controller?, :qr_code_for_stamp_rallies_controller?, :admin_controller?, :event_name, :production?, :talks_checked?, :talk_category, :talk_difficulty, :display_speaker_dashboard_link?, :display_dashboard_link?,
:display_proposals?, :display_talks?, :display_timetable?, :display_contact_url?

def render_403
render(template: 'errors/error_403', status: 403, layout: 'application', content_type: 'text/html')
Expand Down
34 changes: 34 additions & 0 deletions app/models/qr_code_for_stamp_rally.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class QrCodeForStampRally
include ActiveModel::Model
attr_accessor :stamp_rally_check_point, :event

def initialize(stamp_rally_check_point, event)
@stamp_rally_check_point = stamp_rally_check_point
@event = event
end

def url
Rails.application.routes.url_helpers.new_stamp_rally_check_in_url(
event: event.abbr,
params: { stamp_rally_check_point: stamp_rally_check_point.id },
host: Rails.application.default_url_options[:host]
)
end

def url_qrcode_image
Base64.strict_encode64(RQRCode::QRCode.new([{ data: url, mode: :byte_8bit }]).as_png(size: 300).to_s)
end

def h1_text
case @stamp_rally_check_point.type
when StampRallyCheckPoint.name
'スタンプラリーチェックポイント'
when StampRallyCheckPointBooth.name
'スタンプラリーチェックポイント(ブース)'
when StampRallyCheckPointFinish.name
'スタンプラリーチェックポイント(ゴール)'
else
raise(NotImplementedError)
end
end
end
2 changes: 2 additions & 0 deletions app/models/stamp_rally_check_point.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Table name: stamp_rally_check_points
#
# id :string(26) not null, primary key
# description :string(255) not null
# name :string(255) not null
# type :string(255) not null
# conference_id :bigint not null
# sponsor_id :bigint
Expand Down
2 changes: 2 additions & 0 deletions app/models/stamp_rally_check_point_booth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Table name: stamp_rally_check_points
#
# id :string(26) not null, primary key
# description :string(255) not null
# name :string(255) not null
# type :string(255) not null
# conference_id :bigint not null
# sponsor_id :bigint
Expand Down
2 changes: 2 additions & 0 deletions app/models/stamp_rally_check_point_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Table name: stamp_rally_check_points
#
# id :string(26) not null, primary key
# description :string(255) not null
# name :string(255) not null
# type :string(255) not null
# conference_id :bigint not null
# sponsor_id :bigint
Expand Down
17 changes: 17 additions & 0 deletions app/views/admin/qr_code_for_stamp_rallies/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<title>EntrySheet</title>
</head>
<body>
<div class="qr_view">
<button class="btn btn-secondary btn-xl" id="printButton" onclick="window.print();">印刷する</button>
<p class="warning">印刷プレビューでレイアウトをご確認ください</p>
<h1><%= @qr_code_for_stamp_rally.h1_text %></h1>
<h2><%= @qr_code_for_stamp_rally.stamp_rally_check_point.name %></h2>
<p><%= @qr_code_for_stamp_rally.stamp_rally_check_point.description %></p>
<img src=<%= "data:image/png;base64,#{@qr_code_for_stamp_rally.url_qrcode_image}" %> />
</div>
</body>
</html>

8 changes: 8 additions & 0 deletions app/views/admin/stamp_rally_check_points/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
</ul>
<% end %>
<div class="row py-2 border-top" data-controller="sponsor">
<div class="mb-3">
<%= form.label :name, class: "form-label" %>
<%= form.text_field :name, class: "form-control" %>
</div>
<div class="mb-3">
<%= form.label :description, class: "form-label" %>
<%= form.text_area :description, class: "form-control" %>
</div>
<div class="mb-3">
<%= form.label :type, class: "form-label" %>
<%= form.select :type, options_for_select(type_options, selected: stamp_rally_check_point.type), {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<%= turbo_frame_tag stamp_rally_check_point do %>
<div class="row py-2 border-top">
<div class="col-2 my-auto">
<%= stamp_rally_check_point.id %>
<%= stamp_rally_check_point.type %>
</div>
<div class="col-2 my-auto">
<%= stamp_rally_check_point.type %>
<%= stamp_rally_check_point.name %>
</div>
<div class="col-2 my-auto">
<%= stamp_rally_check_point.description %>
</div>
<div class="col-2 my-auto">
<%= stamp_rally_check_point.sponsor&.name %>
</div>
<div class="col-2 my-auto">
<%= new_stamp_rally_check_in_url(event: @conference.abbr, params: {stamp_rally_check_point_id: stamp_rally_check_point.id}) %>
<%= link_to 'QRコードを印刷', admin_qr_code_for_stamp_rally_path(id: stamp_rally_check_point.id), data: { turbo: false } %>
</div>
<div class="col-2">
<div class="col-2 my-auto">
<div class="d-flex justify-content-end">
<% p stamp_rally_check_point.conference %>
<%= link_to "編集", edit_admin_stamp_rally_check_point_path(event: stamp_rally_check_point.conference.abbr, id: stamp_rally_check_point.id), class: "btn btn-sm btn-outline-primary me-2", data: { turbo_frame: "modal" } %>
<%= link_to "削除", admin_stamp_rally_check_point_path(event: stamp_rally_check_point.conference.abbr, id: stamp_rally_check_point.id), class: "btn btn-sm btn-outline-danger", data: { turbo_method: :delete, turbo_confirm: "本当に削除しますか?" } %>
</div>
Expand Down
7 changes: 4 additions & 3 deletions app/views/admin/stamp_rally_check_points/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@


<div class="row py-2 border-top">
<div class="col-2 my-auto">ID</div>
<div class="col-2 my-auto">Type</div>
<div class="col-2 my-auto">Name</div>
<div class="col-2 my-auto">Description</div>
<div class="col-2 my-auto">Sponsor Name</div>
<div class="col-2 my-auto">Check In Url</div>
<div class="col-2"></div>
<div class="col-2 my-auto"></div>
<div class="col-2 my-auto"></div>
</div>
<div id="stamp_rally_check_points">
<% @stamp_rally_check_points.each do |stamp_rally_check_point| %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<div id="fb-root"></div>
<script async defer crossorigin="anonymous" src="https://connect.facebook.net/ja_JP/sdk.js#xfbml=1&version=v7.0&appId=300575407747858&autoLogAppEvents=1" nonce="G1Hsaf0L"></script>
<div id="wrapper">
<% unless home_controller? %>
<% unless home_controller? || qr_code_for_stamp_rallies_controller? %>
<%= render partial: "layouts/event_header" %>
<% end %>

Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
resources :speaker_announcements
resources :streamings
resources :stamp_rally_check_points
resources :qr_code_for_stamp_rallies, only: [:show]
post 'create_aws_resources' => 'streamings#create_aws_resources'
post 'delete_aws_resources' => 'streamings#delete_aws_resources'
post 'start_media_live_channel' => 'media_live_channel#start_channel'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddColumnsToStampRalyCheckPoints < ActiveRecord::Migration[7.0]
def change
add_column :stamp_rally_check_points, :name, :string, null: false
add_column :stamp_rally_check_points, :description, :string, null: false
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2024_10_20_052204) do
ActiveRecord::Schema[7.0].define(version: 2024_11_02_104024) do
create_table "admin_profiles", charset: "utf8mb4", collation: "utf8mb4_0900_ai_ci", force: :cascade do |t|
t.bigint "conference_id", null: false
t.string "sub"
Expand Down Expand Up @@ -462,6 +462,8 @@
t.bigint "conference_id", null: false
t.bigint "sponsor_id"
t.string "type", null: false
t.string "name", null: false
t.string "description", null: false
t.index ["conference_id"], name: "index_stamp_rally_check_points_on_conference_id"
t.index ["sponsor_id"], name: "index_stamp_rally_check_points_on_sponsor_id"
end
Expand Down
2 changes: 2 additions & 0 deletions spec/factories/stamp_rally_check_point_booth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@

FactoryBot.define do
factory :stamp_rally_check_point_booth, class: StampRallyCheckPointBooth do
name { 'スタンプラリーのブース' }
description { 'スタンプラリーのブースの説明' }
end
end
2 changes: 2 additions & 0 deletions spec/factories/stamp_rally_check_point_finish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@

FactoryBot.define do
factory :stamp_rally_check_point_finish, class: StampRallyCheckPointFinish do
name { 'スタンプラリーのチェックポイント' }
description { 'スタンプラリーのチェックポイントの説明' }
end
end
Loading