-
-
Notifications
You must be signed in to change notification settings - Fork 573
Expand file tree
/
Copy pathdistributions_by_county.rb
More file actions
44 lines (41 loc) · 1.25 KB
/
distributions_by_county.rb
File metadata and controls
44 lines (41 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module View
DistributionsByCounty = Data.define(
:breakdown,
:filters,
:items,
:reporting_categories
) do
class << self
def filter_params(params)
return {} unless params.key?(:filters)
params
.require(:filters)
.permit(:by_item_id, :by_reporting_category, :date_range)
end
def from_params(params:, organization:, helpers:)
filters = filter_params(params)
start_date = helpers.selected_range.first.utc.iso8601
end_date = helpers.selected_range.last.utc.iso8601
breakdown = DistributionSummaryByCountyQuery.call(
organization_id: organization.id,
start_date: start_date,
end_date: end_date,
reporting_category: filters[:by_reporting_category].presence,
item_id: filters[:by_item_id].presence
)
new(
breakdown: breakdown,
filters: filters,
reporting_categories: Item.reporting_categories_for_select,
items: organization.items.loose.alphabetized.select(:id, :name)
)
end
end
def selected_reporting_category
filters[:by_reporting_category].presence
end
def selected_item
filters[:by_item_id].presence
end
end
end