Skip to content

Commit

Permalink
[rubyforgood#4504] implement logic to determine next open partial bas…
Browse files Browse the repository at this point in the history
…ed on currently submitted partial
  • Loading branch information
danielabar committed Sep 22, 2024
1 parent 6ced4b3 commit 9d7017c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
18 changes: 15 additions & 3 deletions app/controllers/partners/profiles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ def update
# Make use of partner.partials_to_show for dynamic sections
# | Partial | Converted to Step | Type | Default | Next |
# | ------------------------------- | ----------------- | ------- | --------- | ------------------------------- |
# | agency_information_form | true | static | expanded | program_delivery_address_form |
# | program_delivery_address_form | true | static | collapsed | media_information |
# | agency_information | true | static | expanded | program_delivery_address |
# | program_delivery_address | true | static | collapsed | media_information |
# | media_information | true | dynamic | collapsed | agency_stability |
# | agency_stability | true | dynamic | collapsed | organizational_capacity |
# | organizational_capacity | true | dynamic | collapsed | sources_of_funding |
Expand All @@ -59,14 +59,26 @@ def next_step(submitted_partial)
when "agency_information"
"program_delivery_address"
when "program_delivery_address"
"media_information"
current_partner.partials_to_show.first
when current_partner.partials_to_show.include?(submitted_partial)
next_partner_partial(submitted_partial)
when "partner_settings"
"NA"
else
"agency_information"
end
end

# TODO: 4504 move this to somewhere easier to test like a service
def next_partner_partial(submitted_partial)
index = current_partner.partials_to_show.index(submitted_partial)
if index
current_partner.partials_to_show[index + 1]
else
"agency_information"
end
end

def partner_params
params.require(:partner).permit(:name)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@
</div>
<% end %>
<%# FIXME: 4504 need separate actions for these %>
<%# TODO: 4504 hidden field may not be the best way to populate open_section %>
<%# FIXME: 4504 Implement Submit for Approval, that's different logic than Save and Next %>
<div class="form-group mt-4 d-flex justify-content-start">
<%= hidden_field_tag :open_section, 'program_delivery_address' %>
<%= f.button :submit, 'Save and Next', class: 'btn btn-primary mr-2' %>
<%= f.button :submit, 'Submit for Approval', class: 'btn btn-success' %>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for partner, url: partners_profile_path do |f| %>
<%= simple_form_for partner, url: partners_profile_path(submitted_partial: "media_information") do |f| %>
<%= f.fields_for :profile, profile do |pf| %>
<div class="form-group">
<%= pf.input :website, label: "Website", class: "form-control" %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<% end %>

<!-- Submit Buttons -->
<%# TODO: 4504 remove Save and Next button because this is the last section %>
<div class="form-group mt-4 d-flex justify-content-start">
<%= f.button :submit, 'Save and Next', class: 'btn btn-primary mr-2' %>
<%= f.button :submit, 'Submit for Approval', class: 'btn btn-success' %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= simple_form_for partner, url: partners_profile_path do |f| %>
<%= simple_form_for partner, url: partners_profile_path(submitted_partial: "program_delivery_address") do |f| %>
<%= f.fields_for :profile, profile do |pf| %>
<div class="form-group">
<%= pf.input :program_address1, label: "Address (line 1)", class: "form-control" %>
Expand Down
6 changes: 1 addition & 5 deletions app/views/partners/profiles/step/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
</section>

<%# TODO: 4504 more descriptive id than accordionExample %>
<%# TODO: 4504 make use of open_section instance var to target accordion sections for which should be open and the rest should be collapsed %>
<div class="accordion" id="accordionExample">

<%# Agency Information: By default, this section is expanded and is always rendered %>
Expand Down Expand Up @@ -56,11 +57,6 @@
</div>
</div>

<%# TODO: 4504 loop through `current_partner.partials_to_show.each do |partial|` rendering accordion sections %>
<%# Make sure to name the new partials in `step` subdir matching `ALL_PARTIALS` in app/models/partner.rb %>
<%# Have to figure out which one should be open and the rest are collapsed based on what section user just finished editing %>
<%# Then always render partner_settings %>
<%# See `app/views/partners/profiles/edit.html.erb` for original logic %>
<% current_partner.partials_to_show.each do |partial| %>
<div class="accordion-item">
<h2 class="accordion-header">
Expand Down

0 comments on commit 9d7017c

Please sign in to comment.