From b957ad082f56144258bb1d2b3022c49447ecb3b9 Mon Sep 17 00:00:00 2001 From: Matt Levy Date: Fri, 6 Sep 2024 10:24:18 -0700 Subject: [PATCH 1/3] add earn to add on views memoize event addons methods add earn to views clean up code --- app/controllers/events_controller.rb | 9 ++--- app/models/event.rb | 12 +++---- app/models/ticket_request.rb | 13 +++++++ .../_table_addons_camping_statuses.html.haml | 35 +++++++++---------- .../_table_addons_passes_statuses.html.haml | 30 +++++++++------- app/views/shared/_nav_event_tabs.html.haml | 16 +++++---- 6 files changed, 68 insertions(+), 47 deletions(-) diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index 8b9f40a9..ee677c84 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -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_passes: requests.sum(&:active_addon_pass_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 diff --git a/app/models/event.rb b/app/models/event.rb index f51b3c0f..e4ffc360 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -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) @@ -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? diff --git a/app/models/ticket_request.rb b/app/models/ticket_request.rb index 10fa20e8..74b5c2c0 100644 --- a/app/models/ticket_request.rb +++ b/app/models/ticket_request.rb @@ -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 diff --git a/app/views/events/_table_addons_camping_statuses.html.haml b/app/views/events/_table_addons_camping_statuses.html.haml index d1c2967f..2b316df8 100644 --- a/app/views/events/_table_addons_camping_statuses.html.haml +++ b/app/views/events/_table_addons_camping_statuses.html.haml @@ -7,11 +7,10 @@ %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 @@ -19,29 +18,29 @@ %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) diff --git a/app/views/events/_table_addons_passes_statuses.html.haml b/app/views/events/_table_addons_passes_statuses.html.haml index a3d77966..894da4ad 100644 --- a/app/views/events/_table_addons_passes_statuses.html.haml +++ b/app/views/events/_table_addons_passes_statuses.html.haml @@ -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) diff --git a/app/views/shared/_nav_event_tabs.html.haml b/app/views/shared/_nav_event_tabs.html.haml index 1fbc0624..d197ee37 100644 --- a/app/views/shared/_nav_event_tabs.html.haml +++ b/app/views/shared/_nav_event_tabs.html.haml @@ -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 From 612e6894e993e21d70b79b42a473b56da1fbdb88 Mon Sep 17 00:00:00 2001 From: Matt Levy Date: Fri, 6 Sep 2024 10:24:38 -0700 Subject: [PATCH 2/3] bump --- .version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.version b/.version index 5bdcf5c3..25b22e06 100644 --- a/.version +++ b/.version @@ -1 +1 @@ -1.3.15 +1.3.16 From db30a0d7e24c8e58fab41d61067b6d066f86965c Mon Sep 17 00:00:00 2001 From: Matt Levy Date: Fri, 6 Sep 2024 11:14:48 -0700 Subject: [PATCH 3/3] fix spacing --- app/controllers/events_controller.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index ee677c84..7f1bb7cf 100644 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -138,10 +138,10 @@ def active_addons requests = @ticket_requests.select { |tr| tr.send("#{status}?") } stats[status] = { - addon_passes: requests.sum(&:active_addon_pass_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) + addon_passes: requests.sum(&:active_addon_pass_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