Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/controllers/casa_admins_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ def index
@admins = policy_scope(current_organization.casa_admins)
end

def edit; end
def edit
end

def update
if @casa_admin.update(update_casa_admin_params)
Expand Down
17 changes: 9 additions & 8 deletions app/controllers/contact_type_groups_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ def create
end
end

def edit; end
def edit
end

def update
if @contact_type_group.update(contact_type_group_params)
Expand All @@ -26,13 +27,13 @@ def update
end
end

private
private

def contact_type_group_params
params.require(:contact_type_group).permit(:name, :active)
end
def contact_type_group_params
params.require(:contact_type_group).permit(:name, :active)
end

def set_contact_type_group
@contact_type_group = ContactTypeGroup.find(params[:id])
end
def set_contact_type_group
@contact_type_group = ContactTypeGroup.find(params[:id])
end
end
5 changes: 3 additions & 2 deletions app/controllers/contact_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def create
end
end

def edit; end;
def edit
end

def update
if @contact_type.update(contact_type_params)
Expand All @@ -29,7 +30,7 @@ def update
end
end

private
private

def set_group_options
@group_options = ContactTypeGroup.for_organization(current_organization).collect { |group| [group.name, group.id] }
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/imports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def create

# If there were failed imports
if import[:exported_rows]
message << "<p class='mt-4'>" + link_to("Click here to download failed rows.", download_failed_imports_path) +
message << "<p class='mt-4'>" + link_to("Click here to download failed rows.", download_failed_imports_path) +
"</p>" + "<p>#{ERR_FAILED_IMPORT_NOTE}</p>"
session[:exported_rows] = import[:exported_rows]
end
Expand Down Expand Up @@ -51,7 +51,7 @@ def header
{
"volunteer" => VolunteerImporter::IMPORT_HEADER,
"supervisor" => SupervisorImporter::IMPORT_HEADER,
"casa_case" => CaseImporter::IMPORT_HEADER,
"casa_case" => CaseImporter::IMPORT_HEADER
}
end

Expand Down Expand Up @@ -98,10 +98,10 @@ def validate_file(file, import_type)

unless header_valid?(file_header, import_type)
message = "#{ERR_INVALID_HEADER}<p class='mt-4'>" \
"<b>Expected Header</b>: #{header[import_type].to_s}.</p>" \
"<p><b>Received Header</b>: #{file_header.to_s}</p>"
return {type: :error, message: message}
"<b>Expected Header</b>: #{header[import_type]}.</p>" \
"<p><b>Received Header</b>: #{file_header}</p>"

{type: :error, message: message}
end
end
end
4 changes: 4 additions & 0 deletions app/decorators/casa_case_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def transition_aged_youth_only_icon
object.transition_aged_youth ? "🐛🦋" : ""
end

def court_report_submission
object.court_report_submitted ? "Submitted" : "Not Submitted"
end

def case_contacts_ordered_by_occurred_at
object.case_contacts.sort_by(&:occurred_at)
end
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/ui_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ def grouped_options_for_assigning_case(volunteer)
"Not Assigned",
CasaCase
.not_assigned(@volunteer.casa_org)
.map{ |casa_case| [casa_case.case_number, casa_case.id] }
.map { |casa_case| [casa_case.case_number, casa_case.id] }
],
[
"Assigned",
CasaCase
.actively_assigned_excluding_volunteer(@volunteer)
.map{ |casa_case| [casa_case.case_number, casa_case.id] }
.map { |casa_case| [casa_case.case_number, casa_case.id] }
]
]
end
Expand Down
3 changes: 1 addition & 2 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@
// this is how stylesheets are loaded into the running application
import 'src/stylesheets/application.scss'


import 'bootstrap'
import 'bootstrap-select'
import Select2 from 'select2'
require('@rails/ujs').start()
require('@rails/activestorage').start()
require('channels')
require('jquery')
require('bootstrap-datepicker')
require('datatables.net-dt')
require('datatables.net-dt/css/jquery.dataTables.css')
import Select2 from 'select2'
require('select2')
require('select2/dist/css/select2')

Expand Down
24 changes: 12 additions & 12 deletions app/javascript/src/case_contact.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,29 +70,29 @@ window.onload = function () {
}

function validateNoteContent (e) {
const note_content = document.getElementById('case_contact_notes').value;
const note_content = document.getElementById('case_contact_notes').value
if (note_content != '') {
e.preventDefault();
$('#confirm-submit').modal('show');
document.getElementById('note-content').innerHTML = note_content;
e.preventDefault()
$('#confirm-submit').modal('show')
document.getElementById('note-content').innerHTML = note_content
}
}

$('#casa-contact-form').submit(function(e) {
$('#casa-contact-form').submit(function (e) {
validateNoteContent(e)
});
})

$("#confirm-submit").on("focus", function () {
document.getElementById('modal-case-contact-submit').disabled = false;
});
$('#confirm-submit').on('focus', function () {
document.getElementById('modal-case-contact-submit').disabled = false
})

$("#confirm-submit").on("hide.bs.modal", function () {
$('#confirm-submit').on('hide.bs.modal', function () {
caseContactSubmit.disabled = false
});
})

const caseContactSubmitFromModal = document.getElementById('modal-case-contact-submit')
caseContactSubmitFromModal.onclick = function () {
$('#casa-contact-form').unbind("submit");
$('#casa-contact-form').unbind('submit')
}

caseContactSubmit.onclick = function (e) {
Expand Down
10 changes: 5 additions & 5 deletions app/javascript/src/sidebar.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
/* global $ */
function toggleSidebar() {
const isOpen = $( "#sidebar-js" ).hasClass( "sidebar-open" );
function toggleSidebar () {
const isOpen = $('#sidebar-js').hasClass('sidebar-open')
if (isOpen) {
$('#sidebar-js').removeClass('sidebar-open');
$('#sidebar-js').removeClass('sidebar-open')
} else {
$('#sidebar-js').addClass('sidebar-open');
$('#sidebar-js').addClass('sidebar-open')
}
}

$('document').ready(() => {
$('#toggle-sidebar-js, #sidebar-js').on("click", toggleSidebar);
$('#toggle-sidebar-js, #sidebar-js').on('click', toggleSidebar)
})
19 changes: 8 additions & 11 deletions app/lib/importers/case_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,31 @@ def import_cases
failures << "Case #{case_number} already exists" if result[:existing]
volunteers = email_addresses_to_users(Volunteer, String(row[:case_assignment]))
volunteers.each do |volunteer|
begin
if volunteer.casa_cases.exists?(casa_case.id)
failures << "Volunteer #{volunteer.email} already assigned to #{case_number}"
else
casa_case.volunteers << volunteer
end
rescue StandardError => error
failures << error.to_s
if volunteer.casa_cases.exists?(casa_case.id)
failures << "Volunteer #{volunteer.email} already assigned to #{case_number}"
else
casa_case.volunteers << volunteer
end
rescue => error
failures << error.to_s
end

raise failures.join("\n") unless failures.empty?
end
end
end


private

def create_casa_case(row_data)
casa_case_params = row_data.to_hash.slice(:case_number, :transition_aged_youth, :birth_month_year_youth)
casa_case = CasaCase.find_by(casa_case_params)
return { casa_case: casa_case, existing: true } if casa_case.present?
return {casa_case: casa_case, existing: true} if casa_case.present?

casa_case = CasaCase.new(casa_case_params)
casa_case.casa_org_id = org_id
casa_case.save!

{ casa_case: casa_case, existing: false }
{casa_case: casa_case, existing: false}
end
end
10 changes: 5 additions & 5 deletions app/lib/importers/file_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def import
@file_no_rows = false
yield(row)
@number_imported += 1
rescue StandardError => error
rescue => error
# email for supervisor or volunteer
# display name for supervisor or volunteer
# case number for casa_case
Expand All @@ -41,14 +41,14 @@ def import
}
end

private
private

def failed?
!failed_imports.blank?
end

def success?
!failed? && !@file_no_rows
!failed? && !@file_no_rows
end

def message
Expand Down Expand Up @@ -86,12 +86,12 @@ def email_addresses_to_users(clazz, comma_separated_emails)
def create_user_record(user_class, row_data)
user_params = row_data.to_hash.slice(:display_name, :email)
user = user_class.find_by(user_params)
return { user: user, existing: true } if user.present?
return {user: user, existing: true} if user.present?

user = user_class.new(user_params)
user.casa_org_id, user.password = org_id, SecureRandom.hex(10)
user.save!
user.invite!
{ user: user, existing: false }
{user: user, existing: false}
end
end
18 changes: 8 additions & 10 deletions app/lib/importers/supervisor_importer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class SupervisorImporter < FileImporter
IMPORT_HEADER = ["email", "display_name", "supervisor_volunteers"]

def self.import_supervisors(csv_filespec, org_id)
new(csv_filespec, org_id).import_supervisors
end
Expand All @@ -17,17 +17,15 @@ def import_supervisors
failures = []
failures << "Supervisor #{supervisor.email} already exists" if result[:existing]
email_addresses_to_users(Volunteer, String(row[:supervisor_volunteers])).each do |volunteer|
begin
if volunteer.supervisor
next if volunteer.supervisor == supervisor
if volunteer.supervisor
next if volunteer.supervisor == supervisor

failures << "Volunteer #{volunteer.email} already has a supervisor"
else
supervisor.volunteers << volunteer
end
rescue StandardError => error
failures << error.to_s
failures << "Volunteer #{volunteer.email} already has a supervisor"
else
supervisor.volunteers << volunteer
end
rescue => error
failures << error.to_s
end
end

Expand Down
2 changes: 1 addition & 1 deletion app/lib/importers/volunteer_importer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
class VolunteerImporter < FileImporter
IMPORT_HEADER = ["display_name", "email"]

def self.import_volunteers(csv_filespec, org_id)
new(csv_filespec, org_id).import_volunteers
end
Expand Down
10 changes: 5 additions & 5 deletions app/models/casa_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ class CasaCase < ApplicationRecord
case_assignments: {volunteer: volunteer, is_active: true}
)
}
scope :actively_assigned_excluding_volunteer, -> (volunteer) {
scope :actively_assigned_excluding_volunteer, ->(volunteer) {
joins(:case_assignments)
.where(case_assignments: { is_active: true })
.where.not(case_assignments: { volunteer: volunteer })
.where(case_assignments: {is_active: true})
.where.not(case_assignments: {volunteer: volunteer})
.order(:case_number)
}
scope :not_assigned, -> (casa_org) {
scope :not_assigned, ->(casa_org) {
where(casa_org_id: casa_org.id)
.left_outer_joins(:case_assignments)
.where(case_assignments: { id: nil })
.where(case_assignments: {id: nil})
.order(:case_number)
}

Expand Down
6 changes: 4 additions & 2 deletions app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ class CaseContact < ApplicationRecord
where(want_driving_reimbursement: want_driving_reimbursement) if want_driving_reimbursement == true || want_driving_reimbursement == false
}
scope :contact_type, ->(contact_type = nil) {
joins(:db_contact_types)
.where("contact_types.name in (?)", contact_type) if contact_type.present?
if contact_type.present?
joins(:db_contact_types)
.where("contact_types.name in (?)", contact_type)
end
}

IN_PERSON = "in-person".freeze
Expand Down
2 changes: 1 addition & 1 deletion app/models/contact_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ContactType < ApplicationRecord

scope :for_organization, ->(org) {
joins(:contact_type_group)
.where(contact_type_groups: { casa_org: org })
.where(contact_type_groups: {casa_org: org})
}
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def no_contact_for_two_weeks
# Get ACTIVE volunteers that have ACTIVE supervisor assignments with at least one ACTIVE case
# 1st condition: Volunteer has not created a contact AT ALL within the past 14 days
# 2nd condition: Volunteer has ONLY created contacts in which contact_made = false within the past 14 days

volunteers
.includes(:case_assignments)
.joins("LEFT JOIN case_contacts cc on cc.creator_id = users.id AND cc.occurred_at > (CURRENT_DATE - INTERVAL '14 days')")
Expand Down
2 changes: 1 addition & 1 deletion app/policies/casa_case_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def assign_volunteers?
def permitted_attributes
common_attrs = [
:court_report_submitted,
casa_case_contact_types_attributes: [:contact_type_id],
casa_case_contact_types_attributes: [:contact_type_id]
]

case @user
Expand Down
Loading