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

Mfl/view addons #296

Merged
merged 3 commits into from
Sep 6, 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
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.3.15
1.3.16
7 changes: 4 additions & 3 deletions app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,15 @@ def active_addons
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)
addon_camping: requests.sum(&:active_addon_camp_sum),
pass_raised: requests.sum(&:active_addon_pass_sum_price),
camp_raised: requests.sum(&:active_addon_camp_sum_price)
}
end

@stats[:total] ||= Hash.new { |h, k| h[k] = 0 }
%i[requests addon_passes addon_camping].each do |measure|
%i[addon_passes addon_camping pass_raised camp_raised].each do |measure|
%i[pending awaiting_payment completed].each do |status|
@stats[:total][measure] += @stats[status][measure]
end
Expand Down
12 changes: 6 additions & 6 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,19 @@ def build_default_event_addons
end

def active_event_addons
event_addons.where('price > ?', 0)
@active_event_addons ||= event_addons.where('price > ?', 0)
end

def active_event_addons?
event_addons.where('price > ?', 0).count.positive?
active_event_addons.count.positive?
end

def active_event_addons_passes_count
active_event_addons_by_category(Addon::CATEGORY_PASS).count
@active_event_addons_passes_count ||= active_event_addons_by_category(Addon::CATEGORY_PASS).count
end

def active_event_addons_camping_count
active_event_addons_by_category(Addon::CATEGORY_CAMP).count
@active_event_addons_camping_count ||= active_event_addons_by_category(Addon::CATEGORY_CAMP).count
end

def active_event_addons_by_category(category)
Expand All @@ -238,11 +238,11 @@ def active_event_addons_by_category(category)
end

def active_sorted_event_addons
event_addons.where('price > ?', 0).sort_by { |e| [e.category, e.price, e.name] }
@active_sorted_event_addons ||= event_addons.where('price > ?', 0).sort_by { |e| [e.category, e.price, e.name] }
end

def sorted_event_addons
event_addons.sort_by { |e| [e.category, e.id] }
@sorted_event_addons ||= event_addons.sort_by { |e| [e.category, e.id] }
end

def passes?
Expand Down
13 changes: 13 additions & 0 deletions app/models/ticket_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,19 @@ def active_addon_sum_quantity_by_category(category)
@active_addon_sum_quantity_by_category[category] ||= active_addons.select { |addon| addon.category == category }.sum(&:quantity)
end

def active_addon_pass_sum_price
@active_addon_pass_sum_price ||= active_addon_sum_price_by_category(Addon::CATEGORY_PASS)
end

def active_addon_camp_sum_price
@active_addon_camp_sum_price ||= active_addon_sum_price_by_category(Addon::CATEGORY_CAMP)
end

def active_addon_sum_price_by_category(category)
@active_addon_sum_price_by_category ||= {}
@active_addon_sum_price_by_category[category] ||= active_addons.select { |addon| addon.category == category }.sum(&:price)
end

def ticket_request_event_addons?
active_addons.count.positive?
end
Expand Down
35 changes: 17 additions & 18 deletions app/views/events/_table_addons_camping_statuses.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,40 @@
%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]
%th.text-nowrap.bg-dark-subtle.text-left Payment Status
%th.bg-dark-subtle.text-center
=Addon::HUMANIZED_CATEGORIES[Addon::CATEGORY_CAMP]
%th.bg-dark-subtle.text-end Earn

%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]
%span= stats[:completed][:addon_camping]
%td.text-end.bg-success-subtle
%span
= number_to_currency(stats[:completed][:camp_raised], precision: 0)

%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]
%td.text-center.bg-warning= stats[:pending][:addon_camping]
%td.text-end.bg-warning.fs-6
= number_to_currency(stats[:pending][:camp_raised], precision: 0)

%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]
%td.text-center.bg-warning-subtle= stats[:awaiting_payment][:addon_camping]
%td.text-end.bg-warning-subtle.fs-6
= number_to_currency(stats[:awaiting_payment][:camp_raised], precision: 0)

%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]
%td.bg-dark-subtle.text-center= stats[:total][:addon_camping]
%td.bg-dark-subtle.text-end.fs-6
= number_to_currency(stats[:total][:camp_raised], precision: 0)
30 changes: 18 additions & 12 deletions app/views/events/_table_addons_passes_statuses.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,40 @@

%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]
%th.bg-dark-subtle.text-center
=Addon::HUMANIZED_CATEGORIES[Addon::CATEGORY_PASS]
%th.bg-dark-subtle.text-end Earn

%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]
%td.text-center.bg-success-subtle
%span= stats[:completed][:addon_passes]
%td.text-end.bg-success-subtle
%span
= number_to_currency(stats[:completed][:pass_raised], precision: 0)

%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]
%td.text-center.bg-warning= stats[:pending][:addon_passes]
%td.text-end.bg-warning.fs-6
= number_to_currency(stats[:pending][:pass_raised], precision: 0)

%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]
%td.text-center.bg-warning-subtle= stats[:awaiting_payment][:addon_passes]
%td.text-end.bg-warning-subtle.fs-6
= number_to_currency(stats[:awaiting_payment][:pass_raised], precision: 0)

%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]
%td.bg-dark-subtle.text-center= stats[:total][:addon_passes]

%td.bg-dark-subtle.text-end.fs-6
= number_to_currency(stats[:total][:pass_raised], precision: 0)
16 changes: 9 additions & 7 deletions app/views/shared/_nav_event_tabs.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
= link_to event_ticket_requests_path(event), class: "nav-link #{active_tab[:ticket_requests]}" do
Ticket Requests

%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
- if event.active_event_addons_passes_count > 0
%li.nav-item
= link_to active_addons_passes_event_path(event), class: "nav-link #{active_tab[:event_passes]}" do
Event Passes

- if event.active_event_addons_camping_count > 0
%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