From 96f0e38e92cc680cea1511944bddb5240ca58a85 Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Mon, 17 Jul 2023 02:17:50 +0200 Subject: [PATCH] Support checking in tickets + show the physical tickets page --- .../admin/ticket_scannings_controller.rb | 5 ++++- app/helpers/date_time_helper.rb | 6 ++++++ .../_physical_ticket.html.haml | 20 +++++++++++++++++-- .../admin/physical_tickets/index.html.haml | 2 ++ app/views/admin/tickets/show.html.haml | 5 +++++ app/views/layouts/_admin_sidebar.html.haml | 4 ++++ 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/ticket_scannings_controller.rb b/app/controllers/admin/ticket_scannings_controller.rb index f66371116..c9ec90815 100644 --- a/app/controllers/admin/ticket_scannings_controller.rb +++ b/app/controllers/admin/ticket_scannings_controller.rb @@ -3,11 +3,14 @@ module Admin class TicketScanningsController < Admin::BaseController before_action :authenticate_user! - load_resource :physical_ticket, find_by: :token + # load_resource :physical_ticket, find_by: :token # We authorize manually in these actions skip_authorize_resource only: [:create] def create + puts "CREATE CALLED #{params}" + @physical_ticket = PhysicalTicket.find_by(token: params[:physical_ticket][:token]) + debugger @ticket_scanning = TicketScanning.new(physical_ticket: @physical_ticket) authorize! :create, @ticket_scanning @ticket_scanning.save diff --git a/app/helpers/date_time_helper.rb b/app/helpers/date_time_helper.rb index 420b086a8..8400fa865 100644 --- a/app/helpers/date_time_helper.rb +++ b/app/helpers/date_time_helper.rb @@ -24,6 +24,12 @@ def format_datetime(obj) obj.strftime('%Y-%m-%d %H:%M') end + def format_all_timestamps(lst, conference) + lst.map do |ts| + "#{format_datetime(ts.in_time_zone(conference.timezone))} #{timezone_text(conference)}" + end.to_sentence + end + def show_time(length) return '0 h 0 min' if length.blank? diff --git a/app/views/admin/physical_tickets/_physical_ticket.html.haml b/app/views/admin/physical_tickets/_physical_ticket.html.haml index ff4dd1850..9aeab7b61 100644 --- a/app/views/admin/physical_tickets/_physical_ticket.html.haml +++ b/app/views/admin/physical_tickets/_physical_ticket.html.haml @@ -1,8 +1,24 @@ %tr %td= physical_ticket.id %td= physical_ticket.ticket.title - %td= physical_ticket.user.email + %td= physical_ticket.ticket.registration_ticket? ? 'Yes' : 'No' + %td= physical_ticket.user&.email %td= humanized_money_with_symbol physical_ticket.ticket_purchase.amount_paid + %td + - if physical_ticket.ticket_scannings.present? + %span Checked in: + %br + = format_all_timestamps(physical_ticket.ticket_scannings.pluck(:created_at), conference) + = form_for(physical_ticket, url: admin_ticket_scanning_path, method: :post) do |f| + = f.hidden_field 'token' + = f.submit "Mark Present", { class: 'btn btn-success' } + -# %form{method: "post", action: admin_ticket_scanning_path} + -# %input{type: "hidden", name: "token", value: physical_ticket.token} + -# %input{type: "submit", class: 'btn btn-success', value: "Mark Present"} + -# = button_to('Mark Attended', + -# admin_ticket_scanning_path(token: physical_ticket.token), + -# method: :post, + -# class: 'btn btn-success') %td .btn-group = link_to 'Show', @@ -13,4 +29,4 @@ conference_physical_ticket_path(conference.short_title, physical_ticket.token, format: :pdf), - class: 'button btn btn-default btn-info' + class: 'button btn btn-info' diff --git a/app/views/admin/physical_tickets/index.html.haml b/app/views/admin/physical_tickets/index.html.haml index a1d14cd3c..b69d089bf 100644 --- a/app/views/admin/physical_tickets/index.html.haml +++ b/app/views/admin/physical_tickets/index.html.haml @@ -20,8 +20,10 @@ %thead %th ID %th Type + %th Registration? %th User %th Paid + %th Attedance %th Actions %tbody - @physical_tickets.each do |physical_ticket| diff --git a/app/views/admin/tickets/show.html.haml b/app/views/admin/tickets/show.html.haml index 704076d4b..0f8fc77ea 100644 --- a/app/views/admin/tickets/show.html.haml +++ b/app/views/admin/tickets/show.html.haml @@ -27,6 +27,9 @@ %th Affiliation %th Paid %th Date + %th + %span.sr-only Delete + ❌ %tbody - @ticket.buyers.each_with_index do |buyer, index| - purchases = buyer.ticket_purchases.where(ticket_id: @ticket.id) @@ -45,6 +48,8 @@ = @ticket.tickets_paid(buyer) %td = purchases.first.created_at + %td + = button_to() - content_for :modals do .modal.fade{ id: "modal-give-ticket-#{@ticket.id}" } diff --git a/app/views/layouts/_admin_sidebar.html.haml b/app/views/layouts/_admin_sidebar.html.haml index 395b48f96..a5425ee8a 100644 --- a/app/views/layouts/_admin_sidebar.html.haml +++ b/app/views/layouts/_admin_sidebar.html.haml @@ -116,6 +116,10 @@ - if can? :update, @conference.tickets.build %li{class: active_nav_li(admin_conference_tickets_path(@conference.short_title)) } = link_to 'Tickets', admin_conference_tickets_path(@conference.short_title) + - if can? :update, @conference.tickets.build + %li{class: active_nav_li(admin_conference_physical_tickets_path(@conference.short_title)) } + = link_to 'Ticket Purchases', admin_conference_physical_tickets_path(@conference.short_title) + - if can? :manage, @conference.booths.build %li = link_to admin_conference_booths_path(@conference.short_title) do