Skip to content

Commit

Permalink
Merge pull request #294 from fnf-org/mfl/view-addons
Browse files Browse the repository at this point in the history
Mfl/view addons
  • Loading branch information
beingmattlevy authored Sep 6, 2024
2 parents 71f97c5 + 45cc3be commit f0cc478
Show file tree
Hide file tree
Showing 12 changed files with 218 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.12
1.3.14
33 changes: 33 additions & 0 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,41 @@ def download_guest_list
type: 'text/csv')
end

def active_addons_passes
active_addons
end

def active_addons_camping
active_addons
end

private

def active_addons
@ticket_requests = TicketRequest
.includes(:event, :payment, :user)
.where(event_id: @event)
.order('created_at DESC')
.to_a

@stats = %i[pending awaiting_payment completed].each_with_object({}) do |status, stats|
requests = @ticket_requests.select { |tr| tr.send("#{status}?") }

stats[status] = {
requests: requests.count,
addon_passes: requests.sum(&:active_addon_pass_sum),
addon_camping: requests.sum(&:active_addon_camp_sum)
}
end

@stats[:total] ||= Hash.new { |h, k| h[k] = 0 }
%i[requests addon_passes addon_camping].each do |measure|
%i[pending awaiting_payment completed].each do |status|
@stats[:total][measure] += @stats[status][measure]
end
end
end

def params_symbolized_hash
@params_symbolized_hash ||= permitted_params.to_h.tap(&:symbolize_keys!)
end
Expand Down
4 changes: 4 additions & 0 deletions app/models/ticket_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ def active_sorted_addons
@active_sorted_addons ||= active_addons.sort_by { |e| [e.category, e.price, e.name] }
end

def active_sorted_addons_by_category(category)
@active_sorted_addons_by_category ||= active_addons.select { |addon| addon.category == category }.sort_by { |e| [e.price, e.name] }
end

def active_addon_pass_sum
@active_addon_pass_sum ||= active_addon_sum_quantity_by_category(Addon::CATEGORY_PASS)
end
Expand Down
47 changes: 47 additions & 0 deletions app/views/events/_table_addons_camping_statuses.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.card
.card-body
.vertical-20

%table.table.border-dark-subtle.border-2.overflow-scroll.w-100.shadow-lg#camping-permits-summary

%thead.border-dark-subtle.border-2

%tr
%th.text-nowrap.bg-dark-subtle.text-left Tickets Status
%th.bg-dark-subtle.text-center Requests
- if event.active_event_addons_camping_count > 0
%th.bg-dark-subtle.text-center
=Addon::HUMANIZED_CATEGORIES[Addon::CATEGORY_CAMP]

%tbody.border-2.border-dark-subtle

%tr.fs-6
%td.bg-success-subtle
%span.text-nowrap Paid
%td.text-center.bg-success-subtle
%span= stats[:completed][:requests]
- if event.active_event_addons_camping_count > 0
%td.text-center.bg-success-subtle
%span= stats[:completed][:addon_camping]

%tr.fs-6
%td.text-nowrap.bg-warning
Pending Approval
%td.text-center.bg-warning= stats[:pending][:requests]
- if event.active_event_addons_camping_count > 0
%td.text-center.bg-warning= stats[:pending][:addon_camping]

%tr.fs-6
%td.text-nowrap.bg-warning-subtle
Awaiting Payment
%td.text-center.bg-warning-subtle= stats[:awaiting_payment][:requests]
- if event.active_event_addons_camping_count > 0
%td.text-center.bg-warning-subtle= stats[:awaiting_payment][:addon_camping]

%tr.muted.border-1.border-dark-subtle.fs-6
%td.bg-dark-subtle.text-start
%strong
Total
%td.bg-dark-subtle.text-center= stats[:total][:requests]
- if event.active_event_addons_camping_count > 0
%td.bg-dark-subtle.text-center= stats[:total][:addon_camping]
41 changes: 41 additions & 0 deletions app/views/events/_table_addons_passes_statuses.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
.card
.card-body
.vertical-20

%table.table.border-dark-subtle.border-2.overflow-scroll.w-100.shadow-lg#event-passes-summary

%thead.border-dark-subtle.border-2

%tr
%th.text-nowrap.bg-dark-subtle.text-left Payment Status
- if event.active_event_addons_passes_count > 0
%th.bg-dark-subtle.text-center
=Addon::HUMANIZED_CATEGORIES[Addon::CATEGORY_PASS]

%tbody.border-2.border-dark-subtle

%tr.fs-6
%td.bg-success-subtle
%span.text-nowrap Paid
- if event.active_event_addons_passes_count > 0
%td.text-center.bg-success-subtle
%span= stats[:completed][:addon_passes]

%tr.fs-6
%td.text-nowrap.bg-warning
Pending Approval
- if event.active_event_addons_passes_count > 0
%td.text-center.bg-warning= stats[:pending][:addon_passes]

%tr.fs-6
%td.text-nowrap.bg-warning-subtle
Awaiting Payment
- if event.active_event_addons_passes_count > 0
%td.text-center.bg-warning-subtle= stats[:awaiting_payment][:addon_passes]

%tr.muted.border-1.border-dark-subtle.fs-6
%td.bg-dark-subtle.text-start
%strong
Total
- if event.active_event_addons_passes_count > 0
%td.bg-dark-subtle.text-center= stats[:total][:addon_passes]
38 changes: 38 additions & 0 deletions app/views/events/_table_camping_permits.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

.card
.card-body.overflow-x-scroll
%table.table.border-dark-subtle.border-2.shadow-lg
%thead.border-dark-subtle.border-2
%tr
%th.bg-dark-subtle Name
- if event.require_role
%th.bg-dark-subtle Role
%th.bg-dark-subtle.text-center Type
%th.bg-dark-subtle.text-center Count
%th.bg-dark-subtle.text-center Date
%th.bg-dark-subtle.text-center Status

%tbody.border-dark-subtle.border-2
- ticket_requests.each do |ticket_request|
- next unless ticket_request.active_addon_camp_sum > 0
%tr{ class: "ticket-request-row" }
%td.align-content-center.ticket-user
= link_to event_ticket_request_path(event, ticket_request) do
= ticket_request.user.name
- if event.require_role
%td.muted.align-content-center
= TicketRequest::ROLES[ticket_request.role]
- ticket_request.active_sorted_addons_by_category(Addon::CATEGORY_CAMP).each do |tr_event_addon|
%td.align-content-center.text-center
= "#{tr_event_addon.name}"
%td.align-content-center.text-center
= "#{tr_event_addon.quantity}"

%td.align-content-center.text-center
= ticket_request.created_at.to_date

%td.align-content-center.text-center.ticket-status
%span.p-2.rounded.small.bi-credit-card.text-black{ class: text_class_for_status(ticket_request) }
= text_for_status ticket_request
38 changes: 38 additions & 0 deletions app/views/events/_table_event_passes.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

.card
.card-body.overflow-x-scroll
%table.table.border-dark-subtle.border-2.shadow-lg
%thead.border-dark-subtle.border-2
%tr
%th.bg-dark-subtle Name
- if event.require_role
%th.bg-dark-subtle Role
%th.bg-dark-subtle.text-center Type
%th.bg-dark-subtle.text-center Count
%th.bg-dark-subtle.text-center Date
%th.bg-dark-subtle.text-center Status

%tbody.border-dark-subtle.border-2
- ticket_requests.each do |ticket_request|
- next unless ticket_request.active_addon_pass_sum > 0
%tr{ class: "ticket-request-row" }
%td.align-content-center.ticket-user
= link_to event_ticket_request_path(event, ticket_request) do
= ticket_request.user.name
- if event.require_role
%td.muted.align-content-center
= TicketRequest::ROLES[ticket_request.role]
- ticket_request.active_sorted_addons_by_category(Addon::CATEGORY_PASS).each do |tr_event_addon|
%td.align-content-center.text-center
= "#{tr_event_addon.name}"
%td.align-content-center.text-center
= "#{tr_event_addon.quantity}"

%td.align-content-center.text-center
= ticket_request.created_at.to_date

%td.align-content-center.text-center.ticket-status
%span.p-2.rounded.small.bi-credit-card.text-black{ class: text_class_for_status(ticket_request) }
= text_for_status ticket_request
3 changes: 3 additions & 0 deletions app/views/events/active_addons_camping.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= render partial: 'shared/nav_event', locals: { event: @event, active_tab: { camping_permits: 'active' } }
= render partial: 'table_addons_camping_statuses', locals: { event: @event, stats: @stats }
= render partial: 'table_camping_permits', locals: { event: @event, ticket_requests: @ticket_requests }
3 changes: 3 additions & 0 deletions app/views/events/active_addons_passes.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= render partial: 'shared/nav_event', locals: { event: @event, active_tab: { event_passes: 'active' } }
= render partial: 'table_addons_passes_statuses', locals: { event: @event, stats: @stats }
= render partial: 'table_event_passes', locals: { event: @event, ticket_requests: @ticket_requests }
15 changes: 7 additions & 8 deletions app/views/shared/_nav_event_tabs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@
= link_to event_ticket_requests_path(event), class: "nav-link #{active_tab[:ticket_requests]}" do
Ticket Requests

-# XXX Re-enable me when ready
-# %li.nav-item
-# = link_to event_ticket_requests_path(event), class: "nav-link #{active_tab[:passes]}" do
-# Event Passes
-# %li.nav-item
-# = link_to event_ticket_requests_path(event), class: "nav-link #{active_tab[:passes]}" do
-# Camping Permits
%li.nav-item
= link_to active_addons_passes_event_path(event), class: "nav-link #{active_tab[:event_passes]}" do
Event Passes

%li.nav-item
= link_to active_addons_camping_event_path(event), class: "nav-link #{active_tab[:camping_permits]}" do
Camping Permits


%li.nav-item
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
post :remove_admin
get :guest_list
get :download_guest_list
get :active_addons_passes
get :active_addons_camping
end

resources :jobs do
Expand Down
2 changes: 1 addition & 1 deletion spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
require 'timeout'

def example_with_timeout(example)
Timeout.timeout(20) { example.run }
Timeout.timeout(30) { example.run }
end

RSpec.configure do |config|
Expand Down

0 comments on commit f0cc478

Please sign in to comment.