Skip to content

Commit

Permalink
Merge b337932 into 16a8bc5
Browse files Browse the repository at this point in the history
  • Loading branch information
weedySeaDragon committed Jun 17, 2022
2 parents 16a8bc5 + b337932 commit 6186a88
Show file tree
Hide file tree
Showing 33 changed files with 693 additions and 290 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/shf_application.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@ function enable_submit_button () {

function remove_change_callback_for_radio_buttons (radio_buttons) {
radio_buttons.each(function () {
$(this).off('change');
// $(this).off('change');
});
}
34 changes: 34 additions & 0 deletions app/assets/stylesheets/shf-application-2.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,40 @@
font-size: 16px;
}


.shfapplication {

.file-delivery-choices {

.file-delivery-selection {
//font-size: 1.2em;
//font-weight: bold;
//line-height: 2em;
}

.delivery-choice {
margin-left: 1em;

.form-check.form-check-inline {
margin-right: 2em;
margin-top: 0;

input {
margin-right: .25em;
}
}

.file-delivery-footnotes {
font-size: smaller;
line-height: 3em;
margin-left: 2em;
}
}

}
}


.edit_shf_application {

.section-instructions {
Expand Down
38 changes: 29 additions & 9 deletions app/assets/stylesheets/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}

#company-pay-modal p, #company-pay-modal pre {
margin-bottom:0;
margin-bottom: 0;
}


Expand Down Expand Up @@ -174,8 +174,8 @@ a.btn.disabled, {
}

.company-story img {
max-width:100%;
height:auto!important;
max-width: 100%;
height: auto !important;
}

.company_search {
Expand Down Expand Up @@ -227,7 +227,7 @@ nav.navbar .dropdown-menu li a {
}

.form-check-label {
margin: 5px 0 0 0;
margin: 5px 0 0 0;
}

.files-to-upload-title {
Expand Down Expand Up @@ -313,6 +313,24 @@ margin: 5px 0 0 0;
font-weight: 900;
}

.addtl-category-qs {
.addtl-category-qs-instructions {

}

.category-link {
a {
border-bottom: none;
text-decoration: none;
}

i {
font-size: 60%;
vertical-align: super;
}
}
}

.no-padding {
margin: 0 !important;
padding: 0 !important;
Expand Down Expand Up @@ -369,12 +387,12 @@ margin: 5px 0 0 0;
}

.table {
margin-top:20px;
margin-top: 20px;
}


.table th {
border-top:none;
border-top: none;
padding: .15rem .75rem;
}

Expand Down Expand Up @@ -523,12 +541,14 @@ h6 {
}

label {
margin-bottom: 0;
margin-top: .5rem;
margin-bottom: 0;
margin-top: .5rem;
}


.address label {margin: 0;}
.address label {
margin: 0;
}

nav.navbar {
background-color: $white;
Expand Down
7 changes: 1 addition & 6 deletions app/controllers/business_categories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ def index


def show

@companies = @business_category.companies.includes(:addresses).order(:name)

@companies = @companies.searchable unless current_user.admin?

end


def new

authorize BusinessCategory
@business_category = BusinessCategory.new

Expand Down Expand Up @@ -56,7 +52,6 @@ def create
@business_category.parent_id = params[:parent_cat_id] if context == 'subcategory'

saved = @business_category.save

respond_to do |format|
format.html do
if saved
Expand Down Expand Up @@ -193,7 +188,7 @@ def set_business_category

# Never trust parameters from the scary internet, only allow the white list through.
def business_category_params
params.require(:business_category).permit(:name, :description)
params.require(:business_category).permit(:name, :description, :apply_qs_url)
end


Expand Down
115 changes: 60 additions & 55 deletions app/controllers/shf_applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,30 +106,21 @@ def edit
end


# @fixme this logic is ugly. clean. it. up.
def create
@shf_application = ShfApplication.new(shf_application_params
.merge(user: current_user))
@shf_application = ShfApplication.new(shf_application_params.merge(user: current_user))

numbers_str = params[:company_number]

companies_and_numbers, all_valid = validate_company_numbers(@shf_application,
numbers_str)

@shf_application.companies = companies_and_numbers[:companies] if all_valid
companies_and_numbers, co_nums_valid = validate_company_numbers(@shf_application, numbers_str)
@shf_application.companies = companies_and_numbers[:companies] if co_nums_valid

file_delivery_selected = user_selected_file_delivery_option?

if all_valid && @shf_application.save
if co_nums_valid && @shf_application.save
add_biz_category_addtl_qs_to_flash(@shf_application.business_categories)

if process_upload_files_without_error?(params)

unless set_flash_messages_for_missing_application_files?(@shf_application,
file_delivery_selected,
'create')
helpers.flash_message(:notice,
t('.success', email_address: @shf_application.contact_email))
end

set_flash_messages_incl_application_files(@shf_application, file_delivery_selected, 'create')
redirect_to user_path(@shf_application.user)

else
Expand All @@ -145,29 +136,25 @@ def create
end


# @fixme duplicates code in create method
# @todo Rails 7 is able to track changes to associations. Use that capability instead of manually checking the business_categories than have changed with original_biz_cat_ids and post_save_biz_cat_ids
def update
numbers_str = params[:company_number]

companies_and_numbers, all_valid = validate_company_numbers(@shf_application,
numbers_str)

@shf_application.companies = companies_and_numbers[:companies] if all_valid
companies_and_numbers, co_nums_valid = validate_company_numbers(@shf_application, numbers_str)
@shf_application.companies = companies_and_numbers[:companies] if co_nums_valid

file_delivery_selected = user_selected_file_delivery_option?

if all_valid && @shf_application.update(shf_application_params) && process_upload_files_without_error?(params)

original_biz_cat_ids = @shf_application.business_categories.pluck(:id)
if co_nums_valid && @shf_application.update(shf_application_params) && process_upload_files_without_error?(params)
check_and_mark_if_ready_for_review(params['shf_application'])

unless set_flash_messages_for_missing_application_files?(@shf_application,
file_delivery_selected,
'update')
helpers.flash_message(:notice, t('.success'))
end
post_save_biz_cat_ids = @shf_application.business_categories.pluck(:id)
show_and_email_for_new_biz_cats(@shf_application, original_biz_cat_ids, post_save_biz_cat_ids)

set_flash_messages_incl_application_files(@shf_application, file_delivery_selected, 'update')
redirect_to define_path(evaluate_update(params))
else

create_or_update_error(t('.error'), companies_and_numbers, numbers_str, :edit)
end
end
Expand Down Expand Up @@ -258,31 +245,35 @@ def cancel_need_info

private

def set_flash_messages_for_missing_application_files?(shf_application,
file_delivery_selected,
action)

return false if shf_application.uploaded_files.present?
# Append message to flash if the applicant needs to be warned/notified that they need to still provide files.
# @todo rename to something like 'append...' or 'add..' instead of 'set'
def set_flash_messages_incl_application_files(shf_application, file_delivery_selected, action)
i18n_scope = "shf_applications.#{action}"

helpers.flash_message(:notice,
t("shf_applications.#{action}.success_with_app_files_missing"))

if file_delivery_selected
if shf_application.uploaded_files.present?
helpers.flash_message(:notice, t("#{i18n_scope}.success", email_address: @shf_application.contact_email))
false
else
helpers.flash_message(:notice, t("#{i18n_scope}.success_with_app_files_missing"))
if file_delivery_selected
if shf_application.file_delivery_method.default_option
helpers.flash_message(:warn, t("#{i18n_scope}.upload_file_or_select_method"))
else
helpers.flash_message(:warn, t("#{i18n_scope}.remember_to_deliver_files"))
end

if shf_application.file_delivery_method.default_option
helpers.flash_message(:warn,
t("shf_applications.#{action}.upload_file_or_select_method"))
else
helpers.flash_message(:warn,
t("shf_applications.#{action}.remember_to_deliver_files"))
helpers.flash_message(:warn, t("#{i18n_scope}.upload_file_or_select_method"))
end

else

helpers.flash_message(:warn,
t("shf_applications.#{action}.upload_file_or_select_method"))
true
end
true
end

# Add instructions and info to flash message about additional questions for the business categories
def add_biz_category_addtl_qs_to_flash(biz_categories)
addtl_qs_info = helpers.instructions_for_additional_category_qs(biz_categories, 'shf_applications.create')
helpers.flash_message(:notice, addtl_qs_info)
end

def user_selected_file_delivery_option?
Expand All @@ -299,11 +290,13 @@ def user_selected_file_delivery_option?
file_delivery_selected
end

# @todo rename because this is onlyabout deleting/destroying
def define_path(user_deleted_file)
return edit_shf_application_path(@shf_application) if user_deleted_file
shf_application_path(@shf_application)
end

# @todo rename because this is only about deleting/destroying
def evaluate_update(params)
params.dig(:shf_application, :uploaded_files_attributes)&.key?('_destroy')
end
Expand All @@ -327,7 +320,7 @@ def authorize_shf_application
def check_and_mark_if_ready_for_review(app_params)
return unless app_params

if app_params.fetch('marked_ready_for_review', false) && app_params['marked_ready_for_review'] != "0"
if app_params.fetch('marked_ready_for_review', false) && app_params['marked_ready_for_review'] != '0'
@shf_application.is_ready_for_review!
end
end
Expand All @@ -343,10 +336,10 @@ def set_allowed_file_types
@allowed_file_types = UploadedFile::ALLOWED_FILE_TYPES
end


# Returns true if no errors, false otherwise
# (*true* return value does NOT mean that one or more files were actually uploaded)
# @return [True, False]
def process_upload_files_without_error?(params)
# Returns true if no errors, false otherwise
# (*true* return value does NOT mean that one or more files were actually uploaded)

successful = true

Expand Down Expand Up @@ -395,7 +388,7 @@ def create_or_update_error(error_message, companies_and_numbers,
# validation - for the file delivery method - to the model errors hash.
# This means model errors will have 2 errors for the same problem (File
# delivery method not selected by the user). This line removes one of those:
@shf_application.errors.delete(:"user.shf_application.file_delivery_method")
@shf_application.errors.delete(:'user.shf_application.file_delivery_method')

@shf_application = add_company_errors_to_model(@shf_application,
companies_and_numbers)
Expand Down Expand Up @@ -476,9 +469,21 @@ def validate_company_numbers(application, numbers_str)
[{ companies: companies, numbers: numbers }, ! companies.include?(nil)]
end

# Show info about and email links for additional questions for categories that were added
def show_and_email_for_new_biz_cats(shf_app, original_biz_ids, post_save_biz_ids)
new_biz_cat_ids = post_save_biz_ids - original_biz_ids
return if new_biz_cat_ids.empty?

def send_new_app_emails(new_shf_app)
new_biz_cats = BusinessCategory.where(id: new_biz_cat_ids)
add_biz_category_addtl_qs_to_flash(new_biz_cats)
begin
ShfApplicationMailer.additional_qs_for_biz_cats(shf_app, new_biz_cats).deliver_now
rescue => _mail_error
helpers.flash_message(:error, t('mailers.shf_application_mailer.additional_qs_for_biz_cats.error_sending', email: shf_app.user.email))
end
end

def send_new_app_emails(new_shf_app)
begin
ShfApplicationMailer.acknowledge_received(new_shf_app).deliver_now
rescue => _mail_error
Expand All @@ -488,7 +493,6 @@ def send_new_app_emails(new_shf_app)
# No rescue for the following because if there is a problem sending email to the admin,
# do not display an error to the user
send_new_shf_application_notice_to_admins(new_shf_app) if AdminOnly::AppConfiguration.config_to_use.email_admin_new_app_received_enabled

end


Expand All @@ -498,4 +502,5 @@ def send_new_shf_application_notice_to_admins(new_shf_app)
end
end


end

0 comments on commit 6186a88

Please sign in to comment.