Skip to content

Commit

Permalink
conditional service fields
Browse files Browse the repository at this point in the history
* api pagination fix
* require organization, year, and quarter for CSCSM; add bureau
  • Loading branch information
ryanwoldatwork committed Dec 7, 2022
1 parent ea67e9f commit af44964
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 33 deletions.
1 change: 1 addition & 0 deletions app/controllers/admin/services_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def show; end
def new
@service = Service.new
@service.service_owner_id = current_user.id
set_channel_options
end

def edit
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/digital_products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def index
meta: {
size: size,
page: page,
totalPages: (DigitalProduct.count / size).floor
totalPages: (@total_count / size).floor
},
links: links(page, size),
each_serializer: DigitalProductSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def index
meta: {
size: size,
page: page,
totalPages: (DigitalProduct.count / size).floor
totalPages: (@total_count / size).floor
},
links: links(page, size),
each_serializer: DigitalServiceAccountSerializer
Expand Down
3 changes: 3 additions & 0 deletions app/models/cscrm_data_collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
class CscrmDataCollection < ApplicationRecord
belongs_to :organization

validates :year, presence: true
validates :quarter, presence: true

def self.to_csv
collections = CscrmDataCollection.order('year, quarter')

Expand Down
15 changes: 11 additions & 4 deletions app/views/admin/cscrm_data_collections/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,24 @@
<div class="field">
<%= form.label :organization_id,
"Organization" %>
<%= form.select :organization_id, options_for_select(organization_dropdown_options, cscrm_data_collection.organization_id), { prompt: "Which Organization?" }, { class: "usa-select" } %>
<%= form.select :organization_id, options_for_select(organization_dropdown_options, cscrm_data_collection.organization_id), { prompt: "Which Organization?" }, { class: "usa-select", required: true } %>
</div>
<br>

<div class="field">
<%= form.label :bureau_id,
"Bureau" %>
<%= form.select :bureau_id, options_for_select(organization_dropdown_options, cscrm_data_collection.bureau_id), { prompt: "Which Bureau?" }, { class: "usa-select" } %>
</div>

<div class="field">
<%= form.label :year, class: "usa-label" %>
<%= form.text_field :year, class: "usa-input" %>
<%= form.text_field :year, class: "usa-input", required: true %>
</div>

<div class="field">
<%= form.label :quarter, class: "usa-label" %>
<%= form.text_field :quarter, class: "usa-input" %>
<%= form.text_field :quarter, class: "usa-input", required: true %>
</div>

<div class="field">
Expand Down Expand Up @@ -505,6 +512,6 @@
</fieldset>

<p>
<%= form.submit class: "usa-button" %>
<%= form.submit (cscrm_data_collection.persisted? ? "Update CSCRM Data Collection" : "Create CSCRM Data Collection"), class: "usa-button" %>
</p>
<% end %>
71 changes: 45 additions & 26 deletions app/views/admin/services/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<%= form.select :organization_id, options_for_select(organization_dropdown_options, service.organization_id), { prompt: "Which Agency?" }, { class: "usa-select", required: true } %>
</div>

<div class="field" hidden>
<div class="field">
<%= form.label :bureau_id, "Subcomponent/Bureau", class: "usa-label" %>
<%= form.select :bureau_id, options_for_select(organization_dropdown_options, service.bureau_id), { prompt: "Which Bureau?" }, { class: "usa-select" } %>
</div>
Expand Down Expand Up @@ -55,7 +55,7 @@
</div>
</fieldset>

<div class="field hide" id="multi_agency_explanation_option">
<div class="field hide margin-left-5" id="multi_agency_explanation_option">
<%= form.label :multi_agency_explanation, "What other agencies? ", class: "usa-label" %>
<span class="usa-hint font-sans-2xs">
Because "Yes" was selected regarding multiple agencies, please list the other agency or agencies.
Expand Down Expand Up @@ -88,7 +88,7 @@
<% end %>
</fieldset>

<div id="kind_option" class="field" style="1display: none;">
<div id="kind_option" class="field margin-left-5 hide">
<%= form.label :other_service_type, "Other service type", class: "usa-label" %>
<span class="usa-hint font-sans-2xs">
Because "Other" was selected for Service Type,
Expand All @@ -112,8 +112,8 @@
<%= form.select :estimated_annual_volume_of_customers, options_for_select(volume_options, service.service_provider_id), { prompt: "Select Volume of Customers" }, { class: "usa-select" } %>
</div>

<div id="estimated_annual_volume_of_customers_option" class="field" style="display: none;">
<%= form.label :customer_volume_explanation, "Unknown customer volume" , class: "usa-label" %>
<div id="estimated_annual_volume_of_customers_option" class="field margin-left-5 hide">
<%= form.label :customer_volume_explanation, "Unknown customer volume", class: "usa-label" %>
<span class="usa-hint font-sans-2xs">
Because "Unknown" was selected for Customer Volume,
please explain why customer volume cannot currently be estimated.
Expand Down Expand Up @@ -143,7 +143,7 @@
</div>
</fieldset>

<fieldset id="designated_for_improvement_a11_280_option" class="usa-fieldset">
<fieldset id="designated_for_improvement_a11_280_option" class="usa-fieldset margin-left-5 hide">
<%= form.label :designated_for_improvement_a11_280, "Is this service designated for improvement as required by Circular A-11 Section 280?" ,
class: "usa-label" %>
<legend class="usa-legend sr-only">
Expand Down Expand Up @@ -249,26 +249,28 @@
</div>


<fieldset class="usa-fieldset">
<%= form.label :fully_digital_service, "Does this service offer a fully digital option?" , class: "usa-label" %>
<fieldset class="usa-fieldset margin-left-5">
<%= form.label :fully_digital_service, "Does this service offer a fully digital option?", class: "usa-label" %>
<legend class="usa-legend sr-only">
Does this service offer a fully digital option?
</legend>
<div class="usa-radio">
<%= form.radio_button(:fully_digital_service, "Yes" , class: "usa-radio__input usa-radio__input--tile" ) %>
<%= form.radio_button(:fully_digital_service, "Yes" , class: "usa-radio__input usa-radio__input--tile", checked: service.persisted? && service.fully_digital_service ) %>
<%= form.label(:fully_digital_service, class: "usa-radio__label" , value: "Yes" ) %>
</div>
<div class="usa-radio">
<%= form.radio_button(:fully_digital_service, "No" , { class: "usa-radio__input usa-radio__input--tile" }) %>
<%= form.radio_button(:fully_digital_service, "No" , { class: "usa-radio__input usa-radio__input--tile", checked: service.persisted? && !service.fully_digital_service }) %>
<%= form.label(:fully_digital_service, class: "usa-radio__label" , value: "No" ) %>
</div>
</fieldset>

<div class="field">
<%= form.label :barriers_to_fully_digital_service,
"What are the barriers to make this service fully digital? (e.g. existing technologies, procedural changes, regulatory changes, legislative changes)?",
class: "usa-label" %>
<%= form.text_area :barriers_to_fully_digital_service, class: "usa-textarea" %>
<div id="barriers_to_fully_digital_service_option" class="margin-left-5 hide">
<div class="margin-left-5">
<%= form.label :barriers_to_fully_digital_service,
"What are the barriers to make this service fully digital? (e.g. existing technologies, procedural changes, regulatory changes, legislative changes)?",
class: "usa-label" %>
<%= form.text_area :barriers_to_fully_digital_service, class: "usa-textarea" %>
</div>
</div>

<% if service_manager_permissions? && service.persisted? %>
Expand Down Expand Up @@ -363,38 +365,41 @@
// handle the conditions for form elements on change events
// 2 ifs for each applicable form component
$("#service_hisp_yes").on('click', function() {
alert('hi')
$("#service_designated_for_improvement_a11_280").attr('required', true);
$("#designated_for_improvement_a11_280_option").show();
})
$("#service_hisp_no").on('click', function() {
alert('bye')
$("#service_designated_for_improvement_a11_280").attr('required', false);
$("#designated_for_improvement_a11_280_option").hide();
})

$("#service_digital_service_yes").on('click', function() {
alert('hi')
$("#service_designated_for_improvement_a11_280").attr('required', true);
$("#resources_needed_to_provide_digital_service_option").show();
})
$("#service_digital_service_no").on('click', function() {
alert('bye')
$("#service_designated_for_improvement_a11_280").attr('required', false);
$("#resources_needed_to_provide_digital_service_option").hide();
})

$("#service_multi_agency_service_yes").on('click', function() {
alert('hi')
$("#service_multi_agency_explanation").attr('required', true);
$("#multi_agency_explanation_option").show();
})
$("#service_multi_agency_service_no").on('click', function() {
alert('bye')
$("#service_multi_agency_explanation").attr('required', false);
$("#multi_agency_explanation_option").hide();
})

$("#service_fully_digital_service_yes").on('click', function() {
$("#barriers_to_fully_digital_service_option textarea").attr('required', true);
$("#barriers_to_fully_digital_service_option").show();
})
$("#service_fully_digital_service_no").on('click', function() {
$("#barriers_to_fully_digital_service_option textarea").attr('required', false);
$("#barriers_to_fully_digital_service_option").hide();
})

// if "Unknown" is selected
$("#service_estimated_annual_volume_of_customers").on('change', function(e) {
if (e.target.value == 'Unknown') {
Expand All @@ -407,26 +412,40 @@
}
})

$("#service_kind_other").on("click", function(event) {
if (event.target.checked) {
$("#kind_option").show();
$("#kind_option input").attr("required", true)
} else {
$("#kind_option").hide();
$("#kind_option input").attr("required", false)
}
})


<%# Don't try to set existing values when creating a new record %>
<% unless new_admin_service_path %>
<% unless current_page?(new_admin_service_path) %>
// handle selected items on page load
// 1 if for each applicable form component
if ($("#service_hisp_yes").prop('checked', true) ) {

$("#service_designated_for_improvement_a11_280").attr('required', true);
$("#designated_for_improvement_a11_280_option").show();
}
if ($("#service_digital_service_yes").prop('checked', true) ) {

if ($("#service_digital_service_yes:checked") ) {
$("#service_multi_agency_explanation").attr('required', true);
$("#multi_agency_explanation_option").show();
}
if ($("#service_multi_agency_service_yes").prop('checked', true) ) {

if ($("#service_multi_agency_service_yes:checked")) {
$("#service_multi_agency_explanation").attr('required', true);
$("#multi_agency_explanation_option").show();
}

if ($("#service_fully_digital_service_yes:checked")) {
$("#barriers_to_fully_digital_service_option").show();
$("#barriers_to_fully_digital_service_option textarea").attr('required', true);
}

<% end %>

})
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20221207055927_add_bureau_to_cscrm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddBureauToCscrm < ActiveRecord::Migration[7.0]
def change
add_column :cscrm_data_collections, :bureau_id, :integer
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2022_11_29_214736) do
ActiveRecord::Schema[7.0].define(version: 2022_12_07_055927) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

Expand Down Expand Up @@ -98,6 +98,7 @@
t.string "rating"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "bureau_id"
t.index ["organization_id"], name: "index_cscrm_data_collections_on_organization_id"
t.index ["user_id"], name: "index_cscrm_data_collections_on_user_id"
end
Expand Down

0 comments on commit af44964

Please sign in to comment.