@@ -6,7 +6,7 @@ class DonationsController < ApplicationController
66
77 def index
88 @donations = current_organization . donations
9- . includes ( :line_items , :storage_location , :donation_site , :diaper_drive_participant )
9+ . includes ( :line_items , :storage_location , :donation_site , :diaper_drive_participant , :manufacturer )
1010 . order ( created_at : :desc )
1111 . class_filter ( filter_params )
1212 # Are these going to be inefficient with large datasets?
@@ -22,8 +22,10 @@ def index
2222 @diaper_drives = @donations . collect do |d |
2323 d . source == Donation ::SOURCES [ :diaper_drive ] ? d . diaper_drive_participant : nil
2424 end . compact . uniq
25-
2625 @selected_diaper_drive = filter_params [ :by_diaper_drive_participant ]
26+ @manufacturers = @donations . collect ( &:manufacturer ) . compact . uniq
27+ @selected_manufacturer = filter_params [ :from_manufacturer ]
28+
2729 @selected_date = date_filter
2830 end
2931
@@ -102,13 +104,14 @@ def load_form_collections
102104 @storage_locations = current_organization . storage_locations
103105 @donation_sites = current_organization . donation_sites
104106 @diaper_drive_participants = current_organization . diaper_drive_participants
107+ @manufacturers = current_organization . manufacturers
105108 @items = current_organization . items . alphabetized
106109 end
107110
108111 def donation_params
109112 strip_unnecessary_params
110113 params = compact_line_items
111- params . require ( :donation ) . permit ( :source , :comment , :storage_location_id , :money_raised , :issued_at , :donation_site_id , :diaper_drive_participant_id , line_items_attributes : %i( id item_id quantity _destroy ) ) . merge ( organization : current_organization )
114+ params . require ( :donation ) . permit ( :source , :comment , :storage_location_id , :money_raised , :issued_at , :donation_site_id , :diaper_drive_participant_id , :manufacturer_id , line_items_attributes : %i( id item_id quantity _destroy ) ) . merge ( organization : current_organization )
112115 end
113116
114117 def donation_item_params
@@ -118,7 +121,7 @@ def donation_item_params
118121 def filter_params
119122 return { } unless params . key? ( :filters )
120123
121- fp = params . require ( :filters ) . slice ( :at_storage_location , :by_source , :from_donation_site , :by_diaper_drive_participant )
124+ fp = params . require ( :filters ) . slice ( :at_storage_location , :by_source , :from_donation_site , :by_diaper_drive_participant , :from_manufacturer )
122125 fp . merge ( by_issued_at : date_filter )
123126 end
124127
@@ -136,6 +139,7 @@ def date_filter
136139 # Omits donation_site_id or diaper_drive_participant_id if those aren't selected as source
137140 def strip_unnecessary_params
138141 params [ :donation ] . delete ( :donation_site_id ) unless params [ :donation ] [ :source ] == Donation ::SOURCES [ :donation_site ]
142+ params [ :donation ] . delete ( :manufacturer_id ) unless params [ :donation ] [ :source ] == Donation ::SOURCES [ :manufacturer ]
139143 params [ :donation ] . delete ( :diaper_drive_participant_id ) unless params [ :donation ] [ :source ] == Donation ::SOURCES [ :diaper_drive ]
140144 params
141145 end
0 commit comments