Skip to content

Commit 2b5cea6

Browse files
authored
Merge branch 'main' into 4678_add_package_count_option_to_distribution_export
2 parents 34def31 + 3742718 commit 2b5cea6

File tree

24 files changed

+383
-135
lines changed

24 files changed

+383
-135
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**

app/assets/stylesheets/custom.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@
112112
max-width: 100%;
113113
}
114114
}
115+
116+
.cursor-default {
117+
cursor: default !important;
118+
}

app/controllers/admin/users_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ def add_role
8787
redirect_back(fallback_location: admin_users_path, notice: "Role added!")
8888
end
8989

90+
def resend_invitation
91+
user = User.find(params[:user_id])
92+
user.invite!
93+
redirect_back(fallback_location: admin_users_path, notice: "#{user.name} reinvited!")
94+
end
95+
9096
def remove_role
9197
RemoveRoleService.call(user_id: params[:user_id], role_id: params[:role_id])
9298
redirect_back(fallback_location: admin_users_path, notice: "Role removed!")

app/controllers/donations_controller.rb

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,14 @@ def print
1818
def index
1919
setup_date_range_picker
2020

21-
@donations = current_organization.donations
22-
.includes(:storage_location, :donation_site, :product_drive, :product_drive_participant, :manufacturer, line_items: [:item])
23-
.order(created_at: :desc)
24-
.class_filter(filter_params)
25-
.during(helpers.selected_range)
26-
@item_categories = current_organization.item_categories.pluck(:name).uniq
27-
@paginated_donations = @donations.page(params[:page])
28-
29-
@product_drives = current_organization.product_drives.alphabetized
30-
@product_drive_participants = current_organization.product_drive_participants.alphabetized
31-
32-
# Are these going to be inefficient with large datasets?
33-
# Using the @donations allows drilling down instead of always starting with the total dataset
34-
@donations_quantity = @donations.collect(&:total_quantity).sum
35-
@paginated_donations_quantity = @paginated_donations.collect(&:total_quantity).sum
36-
@total_value_all_donations = total_value(@donations)
37-
@paginated_in_kind_value = total_value(@paginated_donations)
38-
@total_money_raised = total_money_raised(@donations)
39-
@storage_locations = @donations.filter_map { |donation| donation.storage_location if !donation.storage_location.discarded_at }.compact.uniq.sort
40-
@selected_storage_location = filter_params[:at_storage_location]
41-
@sources = @donations.collect(&:source).uniq.sort
42-
@selected_source = filter_params[:by_source]
43-
@selected_item_category = filter_params[:by_category]
44-
@donation_sites = @donations.collect(&:donation_site).compact.uniq.sort_by { |site| site.name.downcase }
45-
@selected_donation_site = filter_params[:from_donation_site]
46-
@selected_product_drive = filter_params[:by_product_drive]
47-
@selected_product_drive_participant = filter_params[:by_product_drive_participant]
48-
@manufacturers = @donations.collect(&:manufacturer).compact.uniq.sort
49-
@selected_manufacturer = filter_params[:from_manufacturer]
21+
@donation_info = View::Donations.from_params(params: params, organization: current_organization, helpers: helpers)
5022

5123
respond_to do |format|
5224
format.html
5325
format.csv do
54-
send_data Exports::ExportDonationsCSVService.new(donation_ids: @donations.map(&:id), organization: current_organization).generate_csv, filename: "Donations-#{Time.zone.today}.csv"
26+
send_data Exports::ExportDonationsCSVService.new(donation_ids: @donation_info.donations.map(&:id),
27+
organization: current_organization).generate_csv,
28+
filename: "Donations-#{Time.zone.today}.csv"
5529
end
5630
end
5731
end
@@ -177,16 +151,4 @@ def compact_line_items
177151
params[:donation][:line_items_attributes].delete_if { |_row, data| data["quantity"].blank? && data["item_id"].blank? }
178152
params
179153
end
180-
181-
def total_value(donations)
182-
total_value_all_donations = 0
183-
donations.each do |donation|
184-
total_value_all_donations += donation.value_per_itemizable
185-
end
186-
total_value_all_donations
187-
end
188-
189-
def total_money_raised(donations)
190-
donations.sum { |d| d.money_raised.to_i }
191-
end
192154
end

app/controllers/requests_controller.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def index
88
.undiscarded
99
.during(helpers.selected_range)
1010
.class_filter(filter_params)
11-
@unfulfilled_requests_count = current_organization.requests.where(status: [:pending, :started]).count
11+
@unfulfilled_requests_count = current_organization.requests.where(status: [:pending, :started]).during(helpers.selected_range).class_filter(filter_params).count
1212
@paginated_requests = @requests.includes(:partner).page(params[:page])
1313
@calculate_product_totals = RequestsTotalItemsService.new(requests: @requests).calculate
1414
@items = current_organization.items.alphabetized.select(:id, :name)
@@ -65,6 +65,8 @@ def print_unfulfilled
6565
.includes(:item_requests, partner: [:profile])
6666
.where(status: [:pending, :started])
6767
.order(created_at: :desc)
68+
.during(helpers.selected_range)
69+
.class_filter(filter_params)
6870

6971
respond_to do |format|
7072
format.any do

app/helpers/partners_helper.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,22 @@ def partner_status_badge(partner)
5050
tag.span partner.display_status, class: %w(badge badge-pill badge-info bg-info float-right)
5151
end
5252
end
53+
54+
def partner_status_label(status)
55+
status_options = {
56+
"uninvited" => {icon: "exclamation-circle"},
57+
"invited" => {icon: "check", type: "info"},
58+
"awaiting_review" => {icon: "check", type: "warning"},
59+
"approved" => {icon: "check", type: "success"},
60+
"recertification_required" => {icon: "minus", type: "danger"},
61+
"deactivated" => {icon: "minus", type: "secondary"}
62+
}
63+
return content_tag :span, "Errored", class: "label label-teal" unless status_options[status]
64+
65+
status_label(
66+
status.humanize,
67+
status_options[status][:icon],
68+
status_options[status][:type] || "default"
69+
)
70+
end
5371
end

app/helpers/ui_helper.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,13 @@ def view_button_to(link, options = {})
148148
_link_to link, { icon: "search", type: "info", text: "View", size: "xs" }.merge(options)
149149
end
150150

151+
def status_label(text, icon, type)
152+
css_class = "cursor-default btn btn-xs btn-#{type}"
153+
content_tag :span, class: css_class do
154+
fa_icon icon, text: text
155+
end
156+
end
157+
151158
def invite_button_to(link, options = {}, properties = {})
152159
properties = { method: options[:method]&.to_sym || :post, rel: "nofollow", data: { confirm: options[:confirm] || "Are you sure?" } }.merge(properties)
153160
_link_to link, { icon: "envelope", type: "warning", text: "Invite", size: "xs" }.merge(options), properties

app/models/user.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# last_sign_in_ip :inet
2121
# name :string
2222
# organization_admin :boolean
23+
# pending_role_invites :text
2324
# provider :string
2425
# remember_created_at :datetime
2526
# reset_password_sent_at :datetime

app/models/view/donations.rb

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
module View
2+
Donations = Data.define(
3+
:donations,
4+
:filters,
5+
:item_categories,
6+
:paginated_donations,
7+
:product_drives,
8+
:product_drive_participants,
9+
:storage_locations,
10+
:donation_sites,
11+
:manufacturers
12+
) do
13+
include DateRangeHelper
14+
15+
class << self
16+
def filter_params(params)
17+
if params.key?(:filters)
18+
params.require(:filters).permit(
19+
:at_storage_location, :by_source, :from_donation_site,
20+
:by_product_drive, :by_product_drive_participant,
21+
:from_manufacturer, :by_category
22+
)
23+
else
24+
{}
25+
end
26+
end
27+
28+
def from_params(params:, organization:, helpers:)
29+
filters = filter_params(params)
30+
donations = organization.donations
31+
.includes(:storage_location,
32+
:donation_site,
33+
:product_drive,
34+
:product_drive_participant,
35+
:manufacturer,
36+
line_items: [:item])
37+
.order(created_at: :desc)
38+
.class_filter(filters)
39+
.during(helpers.selected_range)
40+
41+
paginated_donations = donations.page(params[:page])
42+
43+
storage_locations = donations.filter_map do |donation|
44+
donation.storage_location unless donation.storage_location.discarded_at
45+
end.compact.uniq.sort
46+
47+
manufacturers = donations.collect(&:manufacturer).compact.uniq.sort
48+
49+
new(
50+
donations: donations,
51+
filters: filters,
52+
item_categories: organization.item_categories.pluck(:name).uniq,
53+
paginated_donations: paginated_donations,
54+
product_drives: organization.product_drives.alphabetized,
55+
product_drive_participants: organization.product_drive_participants.alphabetized,
56+
storage_locations: storage_locations,
57+
donation_sites: donations.map(&:donation_site).compact.uniq.sort_by { |site| site.name.downcase },
58+
manufacturers: manufacturers
59+
)
60+
end
61+
end
62+
63+
def selected_storage_location
64+
filters[:at_storage_location]
65+
end
66+
67+
def selected_source
68+
filters[:by_source]
69+
end
70+
71+
def selected_item_category
72+
filters[:by_category]
73+
end
74+
75+
def sources
76+
donations.map(&:source).uniq.sort
77+
end
78+
79+
def donations_quantity
80+
donations.map(&:total_quantity).sum
81+
end
82+
83+
def selected_donation_site
84+
filters[:from_donation_site]
85+
end
86+
87+
def selected_product_drive
88+
filters[:by_product_drive]
89+
end
90+
91+
def selected_product_drive_participant
92+
filters[:by_product_drive_participant]
93+
end
94+
95+
def selected_manufacturer
96+
filters[:from_manufacturer]
97+
end
98+
99+
def paginated_donations_quantity
100+
paginated_donations.map(&:total_quantity).sum
101+
end
102+
103+
def paginated_in_kind_value
104+
paginated_donations.sum { |donation| donation.value_per_itemizable }
105+
end
106+
107+
def total_money_raised
108+
donations.sum { |d| d.money_raised.to_i }
109+
end
110+
111+
def total_value_all_donations
112+
donations.sum { |donation| donation.value_per_itemizable }
113+
end
114+
end
115+
end

app/pdfs/picklists_pdf.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require "prawn/table"
22

3-
# Configures a Prawn PDF template for generating Distribution manifests
3+
# Configures a Prawn PDF template for generating Picklist pdfs
44
class PicklistsPdf
55
include Prawn::View
66
include ItemsHelper

0 commit comments

Comments
 (0)