Skip to content

Commit f43336f

Browse files
authored
Merge pull request #4931 from Benjamin-Couey/4241-change-agency-type-to-enum
4241 change agency type to enum -- LGTM!
2 parents e8b3026 + 01a9ebf commit f43336f

File tree

13 files changed

+239
-167
lines changed

13 files changed

+239
-167
lines changed

app/models/partner.rb

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -71,50 +71,6 @@ class Partner < ApplicationRecord
7171
where(status: status.to_sym)
7272
}
7373

74-
AGENCY_TYPES = {
75-
"CAREER" => "Career technical training",
76-
"ABUSE" => "Child abuse resource center",
77-
"BNB" => "Basic Needs Bank",
78-
"CHURCH" => "Church outreach ministry",
79-
"COLLEGE" => "College and Universities",
80-
"CDC" => "Community development corporation",
81-
"HEALTH" => "Community health program or clinic",
82-
"OUTREACH" => "Community outreach services",
83-
"LEGAL" => "Correctional Facilities / Jail / Prison / Legal System",
84-
"CRISIS" => "Crisis/Disaster services",
85-
"DISAB" => "Developmental disabilities program",
86-
"DISTRICT" => "School District",
87-
"DOMV" => "Domestic violence shelter",
88-
"ECE" => "Early Childhood Education/Childcare",
89-
"CHILD" => "Early childhood services",
90-
"EDU" => "Education program",
91-
"FAMILY" => "Family resource center",
92-
"FOOD" => "Food bank/pantry",
93-
"FOSTER" => "Foster Program",
94-
"GOVT" => "Government Agency/Affiliate",
95-
"HEADSTART" => "Head Start/Early Head Start",
96-
"HOMEVISIT" => "Home visits",
97-
"HOMELESS" => "Homeless resource center",
98-
"HOSP" => "Hospital",
99-
"INFPAN" => "Infant/Child Pantry/Closet",
100-
"LIB" => "Library",
101-
"MHEALTH" => "Mental Health",
102-
"MILITARY" => "Military Bases/Veteran Services",
103-
"POLICE" => "Police Station",
104-
"PREG" => "Pregnancy resource center",
105-
"PRESCH" => "Preschool",
106-
"REF" => "Refugee resource center",
107-
"ES" => "School - Elementary School",
108-
"HS" => "School - High School",
109-
"MS" => "School - Middle School",
110-
"SENIOR" => "Senior Center",
111-
"TRIBAL" => "Tribal/Native-Based Organization",
112-
"TREAT" => "Treatment clinic",
113-
"2YCOLLEGE" => "Two-Year College",
114-
"WIC" => "Women, Infants and Children",
115-
"OTHER" => "Other"
116-
}.freeze
117-
11874
ALL_PARTIALS = %w[
11975
media_information
12076
agency_stability
@@ -241,13 +197,14 @@ def agency_info
241197

242198
return {} if profile.blank?
243199

200+
symbolic_agency_type = profile.agency_type&.to_sym
244201
@agency_info = {
245202
address: [profile.address1, profile.address2].select(&:present?).join(', '),
246203
city: profile.city,
247204
state: profile.state,
248205
zip_code: profile.zip_code,
249206
website: profile.website,
250-
agency_type: (profile.agency_type == AGENCY_TYPES["OTHER"]) ? "#{AGENCY_TYPES["OTHER"]}: #{profile.other_agency_type}" : profile.agency_type
207+
agency_type: (symbolic_agency_type == :other) ? "#{I18n.t symbolic_agency_type, scope: :partners_profile}: #{profile.other_agency_type}" : (I18n.t symbolic_agency_type, scope: :partners_profile)
251208
}
252209
end
253210

app/models/partners/profile.rb

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,49 @@ class Profile < Base
9595
accepts_nested_attributes_for :served_areas, allow_destroy: true
9696

9797
has_many_attached :documents
98+
enum :agency_type,
99+
other: "OTHER",
100+
career: "CAREER",
101+
abuse: "ABUSE",
102+
bnb: "BNB",
103+
church: "CHURCH",
104+
college: "COLLEGE",
105+
cdc: "CDC",
106+
health: "HEALTH",
107+
outreach: "OUTREACH",
108+
legal: "LEGAL",
109+
crisis: "CRISIS",
110+
disab: "DISAB",
111+
district: "DISTRICT",
112+
domv: "DOMV",
113+
ece: "ECE",
114+
child: "CHILD",
115+
edu: "EDU",
116+
family: "FAMILY",
117+
food: "FOOD",
118+
foster: "FOSTER",
119+
govt: "GOVT",
120+
headstart: "HEADSTART",
121+
homevisit: "HOMEVISIT",
122+
homeless: "HOMELESS",
123+
hosp: "HOSP",
124+
infpan: "INFPAN",
125+
lib: "LIB",
126+
mhealth: "MHEALTH",
127+
military: "MILITARY",
128+
police: "POLICE",
129+
preg: "PREG",
130+
presch: "PRESCH",
131+
ref: "REF",
132+
es: "ES",
133+
hs: "HS",
134+
ms: "MS",
135+
senior: "SENIOR",
136+
tribal: "TRIBAL",
137+
treat: "TREAT",
138+
twoycollege: "2YCOLLEGE",
139+
wic: "WIC"
140+
98141
validate :check_social_media, on: :edit
99142

100143
validate :client_share_is_0_or_100
@@ -131,6 +174,11 @@ def county_list_by_region
131174
counties.order(%w(lower(region) lower(name))).pluck(:name).join("; ")
132175
end
133176

177+
def self.agency_types_for_selection
178+
# alphabetize based on the translated version, as that is the text users will actually read
179+
agency_types.keys.map(&:to_sym).sort_by { |sym| I18n.t(sym, scope: :partners_profile) }.partition { |v| v != :other }.flatten
180+
end
181+
134182
private
135183

136184
def check_social_media

app/services/reports/partner_info_report_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def report
1616

1717
entries = { 'Number of Partner Agencies' => partner_agencies }
1818
partner_agency_counts.each do |agency, count|
19-
entries["Agency Type: #{agency || 'Unknown'}"] = count
19+
entries["Agency Type: #{(I18n.t agency, scope: [:partners_profile]) || 'Unknown'}"] = count
2020
end
2121
entries['Zip Codes Served'] = partner_zipcodes_serviced
2222
@report = { name: 'Partner Agencies and Service Area', entries: entries }

app/views/partners/profiles/edit/_agency_information.html.erb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
</div>
99
<div class="card-body">
1010
<%= form.input :name, label: "Agency Name", class: "form-control", wrapper: :input_group %>
11-
<%= profile_form.input :agency_type, collection: Partner::AGENCY_TYPES.values, label: "Agency Type", class: "form-control", wrapper: :input_group %>
11+
<%= profile_form.input :agency_type,
12+
# Symbolize keys, because simple_form will only do a I18n lookup for
13+
# symbols
14+
collection: Partners::Profile.agency_types_for_selection,
15+
label: "Agency Type",
16+
class: "form-control",
17+
wrapper: :input_group %>
1218
<%= profile_form.input :other_agency_type, label: "Other Agency Type", class: "form-control", wrapper: :input_group %>
1319

1420
<%= render "shared/custom_file_input",

app/views/partners/profiles/show/_agency_information.html.erb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66
<dd><%= profile.partner.name %></dd>
77

88
<dt>Agency Type</dt>
9-
<dd><%= profile.agency_type %></dd>
10-
11-
<% if profile.agency_type == "Other" %>
9+
<dd><%= t profile.agency_type, scope: :partners_profile %></dd>
10+
<% if profile.agency_type&.to_sym == :other %>
1211
<dt>Other Agency Type</dt>
1312
<dd><%= profile.other_agency_type %></dd>
1413
<% end %>

app/views/partners/profiles/step/_agency_information_form.html.erb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55
<%= f.fields_for :profile, profile do |pf| %>
66
<div class="form-group">
7-
<%= pf.input :agency_type, collection: Partner::AGENCY_TYPES.values, label: "Agency Type", class: "form-control", wrapper: :input_group %>
7+
<%= pf.input :agency_type,
8+
# Symbolize keys, because simple_form will only do a I18n lookup for
9+
# symbols
10+
collection: Partners::Profile.agency_types_for_selection,
11+
label: "Agency Type",
12+
class: "form-control",
13+
wrapper: :input_group %>
814
</div>
915

1016
<div class="form-group">

app/views/profiles/_show.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<%# The field for inputting the name registers it as partner.name, %>
66
<%# not partner_profile.name, so this pulls from partner.name %>
77
<p>Name: <%= @partner.name %></p>
8-
<p>Agency Type: <%= partner_profile.agency_type %>
9-
<% if partner_profile.agency_type == "Other" && partner_profile.other_agency_type %>
8+
<p>Agency Type: <%= t partner_profile.agency_type, scope: :partners_profile %>
9+
<% if partner_profile.agency_type&.to_sym == :other && partner_profile.other_agency_type %>
1010
(<%= partner_profile.other_agency_type %>)
1111
<% end %>
1212
</p>
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
agency_type_map: &agency_type_map
2+
other: "Other"
3+
career: "Career technical training"
4+
abuse: "Child abuse resource center"
5+
bnb: "Basic Needs Bank"
6+
church: "Church outreach ministry"
7+
college: "College and Universities"
8+
cdc: "Community development corporation"
9+
health: "Community health program or clinic"
10+
outreach: "Community outreach services"
11+
legal: "Correctional Facilities / Jail / Prison / Legal System"
12+
crisis: "Crisis/Disaster services"
13+
disab: "Developmental disabilities program"
14+
district: "School District"
15+
domv: "Domestic violence shelter"
16+
ece: "Early Childhood Education/Childcare"
17+
child: "Early childhood services"
18+
edu: "Education program"
19+
family: "Family resource center"
20+
food: "Food bank/pantry"
21+
foster: "Foster Program"
22+
govt: "Government Agency/Affiliate"
23+
headstart: "Head Start/Early Head Start"
24+
homevisit: "Home visits"
25+
homeless: "Homeless resource center"
26+
hosp: "Hospital"
27+
infpan: "Infant/Child Pantry/Closet"
28+
lib: "Library"
29+
mhealth: "Mental Health"
30+
military: "Military Bases/Veteran Services"
31+
police: "Police Station"
32+
preg: "Pregnancy resource center"
33+
presch: "Preschool"
34+
ref: "Refugee resource center"
35+
es: "School - Elementary School"
36+
hs: "School - High School"
37+
ms: "School - Middle School"
38+
senior: "Senior Center"
39+
tribal: "Tribal/Native-Based Organization"
40+
treat: "Treatment clinic"
41+
twoycollege: "Two-Year College"
42+
wic: "Women, Infants and Children"
43+
44+
en:
45+
partners_profile:
46+
*agency_type_map
47+
48+
simple_form:
49+
options:
50+
profile:
51+
agency_type:
52+
*agency_type_map

db/migrate/20241122201255_cleanup_partner_agency_types.rb

Lines changed: 0 additions & 109 deletions
This file was deleted.

0 commit comments

Comments
 (0)