Skip to content

Commit 33ae6fc

Browse files
authored
Merge branch 'main' into 4517-inactive-items-in-distribution-reports
2 parents abd1235 + 9e2c232 commit 33ae6fc

34 files changed

Lines changed: 512 additions & 151 deletions

.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/donation_sites_controller.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,18 @@ def create
1818
@donation_site = current_organization.donation_sites.new(donation_site_params)
1919
respond_to do |format|
2020
if @donation_site.save
21+
format.turbo_stream
2122
format.html do
2223
redirect_to donation_sites_path,
2324
notice: "Donation site #{@donation_site.name} added!"
2425
end
2526
else
27+
flash.now[:error] = "Something didn't work quite right -- try again?"
28+
if request.format.turbo_stream?
29+
format.html { render partial: "donation_sites/new_modal", status: :unprocessable_entity }
30+
end
31+
2632
format.html do
27-
flash.now[:error] = "Something didn't work quite right -- try again?"
2833
render action: :new
2934
end
3035
end
@@ -33,6 +38,11 @@ def create
3338

3439
def new
3540
@donation_site = current_organization.donation_sites.new
41+
if turbo_frame_request?
42+
render partial: "donation_sites/new_modal", layout: false
43+
else
44+
render :new
45+
end
3646
end
3747

3848
def edit

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/donations_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ def total_number_of_drives(range = selected_range)
2121
current_organization.product_drives.within_date_range(formatted_range).count
2222
end
2323

24+
def options_with_new(records)
25+
model_class = records.klass
26+
label = "---Create New #{model_class.model_name.human}---"
27+
records.map { |record| [record.name, record.id] } << [label, "new"]
28+
end
29+
2430
private
2531

2632
def total_received_donations_unformatted(range = selected_range)

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
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { Controller } from "@hotwired/stimulus"
2+
3+
export default class extends Controller {
4+
connect() {
5+
document.addEventListener("turbo:frame-render", this.openModalHandler)
6+
document.addEventListener("turbo:submit-end", this.closeModalHandler)
7+
}
8+
9+
disconnect() {
10+
document.removeEventListener("turbo:frame-render", this.openModalHandler)
11+
document.removeEventListener("turbo:submit-end", this.closeModalHandler)
12+
}
13+
14+
handleNewSelect(event) {
15+
const value = event.target.value
16+
if (value === "new") {
17+
const url = event.target.dataset.url
18+
Turbo.visit(url, { frame: 'modal-new' })
19+
}
20+
}
21+
22+
openModalHandler = () => {
23+
const modal = document.getElementById("modal-new")
24+
const instance = bootstrap.Modal.getOrCreateInstance(modal)
25+
instance.show()
26+
}
27+
28+
closeModalHandler = (event) => {
29+
if (event.detail.success) {
30+
const modal = document.getElementById("modal-new")
31+
const instance = bootstrap.Modal.getOrCreateInstance(modal)
32+
instance.hide()
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)