Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1731] Add Court Mandates to Edit CASA Case page #1795

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
6 changes: 3 additions & 3 deletions app/javascript/__tests__/dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
import { defineCaseContactsTable } from '../src/dashboard'

require('jest')
var $ = require('jquery')
var _ = require('lodash')
const $ = require('jquery')
const _ = require('lodash')
global.$ = $

describe('dashboard.js', () => {
describe('DataTable tests', () => {
function initializeDocumentWithTable (id, numberOfRows = 1, classes = '') {
var mockTable = `<table id=${id} class=${classes}>` +
let mockTable = `<table id=${id} class=${classes}>` +
'<thead>' +
'<tr> <th>Column1</th> <th>Column2</th> <th>Column3</th> </tr>' +
'</thead> <tbody>'
Expand Down
1 change: 1 addition & 0 deletions app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ require('select2/dist/css/select2')

require('src/case_contact')
require('src/case_emancipation')
require('src/casa_case')
require('src/emancipations')
require('src/select')
require('src/dashboard')
Expand Down
15 changes: 15 additions & 0 deletions app/javascript/src/casa_case.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function add_court_mandate_input () {
const list = '#mandates-list-container'
const index = $(`${list} textarea`).length

const textarea_html = `<textarea name="casa_case[case_court_mandates_attributes][${index}][mandate_text]"\
id="casa_case_case_court_mandates_attributes_1_mandate_text">\
</textarea>`

$(list).append(textarea_html)
$(list).children(':last').trigger('focus')
}

$('document').ready(() => {
$('button#add-mandate-button').on('click', add_court_mandate_input)
})
38 changes: 19 additions & 19 deletions app/javascript/src/dashboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global $ */
var defineCaseContactsTable = function () {
const defineCaseContactsTable = function () {
$('table#case_contacts').DataTable(
{
scrollX: true,
Expand All @@ -9,7 +9,7 @@ var defineCaseContactsTable = function () {
)
}

var defineSupervisorsDataTable = function () {
const defineSupervisorsDataTable = function () {
$('table#supervisors').DataTable(
{
columnDefs: [
Expand All @@ -29,11 +29,11 @@ $('document').ready(() => {
return true
}

var statusArray = []
var assignedToVolunteerArray = []
var assignedToMoreThanOneVolunteerArray = []
var assignedToTransitionYouthArray = []
var caseNumberPrefixArray = []
const statusArray = []
const assignedToVolunteerArray = []
const assignedToMoreThanOneVolunteerArray = []
const assignedToTransitionYouthArray = []
const caseNumberPrefixArray = []

$('.status-options').find('input[type="checkbox"]').each(function () {
if ($(this).is(':checked')) {
Expand Down Expand Up @@ -65,12 +65,12 @@ $('document').ready(() => {
}
})

var status = data[3]
var assignedToVolunteer = (data[5] !== '' && data[5].split(',').length >= 1) ? 'Yes' : 'No'
var assignedToMoreThanOneVolunteer = (data[5] !== '' && data[5].split(',').length > 1) ? 'Yes' : 'No'
var assignedToTransitionYouth = data[4]
var regex = /^(CINA|TPR)/g
var caseNumberPrefix = data[0].match(regex) ? data[0].match(regex)[0] : ''
const status = data[3]
const assignedToVolunteer = (data[5] !== '' && data[5].split(',').length >= 1) ? 'Yes' : 'No'
const assignedToMoreThanOneVolunteer = (data[5] !== '' && data[5].split(',').length > 1) ? 'Yes' : 'No'
const assignedToTransitionYouth = data[4]
const regex = /^(CINA|TPR)/g
const caseNumberPrefix = data[0].match(regex) ? data[0].match(regex)[0] : ''

if (statusArray.includes(status) &&
assignedToVolunteerArray.includes(assignedToVolunteer) &&
Expand Down Expand Up @@ -106,7 +106,7 @@ $('document').ready(() => {
const editSupervisorPath = id => `/supervisors/${id}/edit`
const editVolunteerPath = id => `/volunteers/${id}/edit`
const casaCasePath = id => `/casa_cases/${id}`
var volunteersTable = $('table#volunteers').DataTable({
const volunteersTable = $('table#volunteers').DataTable({
autoWidth: false,
stateSave: false,
columns: [
Expand Down Expand Up @@ -226,12 +226,12 @@ $('document').ready(() => {
// Because the table saves state, we have to check/uncheck modal inputs based on what
// columns are visible
volunteersTable.columns().every(function (index) {
var columnVisible = this.visible()
const columnVisible = this.visible()

if (columnVisible) { $('#visibleColumns input[data-column="' + index + '"]').prop('checked', true) } else { $('#visibleColumns input[data-column="' + index + '"]').prop('checked', false) }
})

var casaCasesTable = $('table#casa-cases').DataTable({
const casaCasesTable = $('table#casa-cases').DataTable({
autoWidth: false,
stateSave: false,
columnDefs: [],
Expand All @@ -241,7 +241,7 @@ $('document').ready(() => {
})

casaCasesTable.columns().every(function (index) {
var columnVisible = this.visible()
const columnVisible = this.visible()

if (columnVisible) {
$('#visibleColumns input[data-column="' + index + '"]').prop('checked', true)
Expand Down Expand Up @@ -279,11 +279,11 @@ $('document').ready(() => {

$('input.toggle-visibility').on('click', function (e) {
// Get the column API object and toggle the visibility
var column = volunteersTable.column($(this).attr('data-column'))
const column = volunteersTable.column($(this).attr('data-column'))
column.visible(!column.visible())
volunteersTable.columns.adjust().draw()

var caseColumn = casaCasesTable.column($(this).attr('data-column'))
const caseColumn = casaCasesTable.column($(this).attr('data-column'))
caseColumn.visible(!caseColumn.visible())
casaCasesTable.columns.adjust().draw()
})
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/src/emancipations.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$('document').ready(() => {
var emancipationsTable = $('table#all-case-emancipations').DataTable({
const emancipationsTable = $('table#all-case-emancipations').DataTable({
autoWidth: false,
searching: false,
stateSave: false,
Expand Down
43 changes: 43 additions & 0 deletions app/javascript/src/stylesheets/pages/casa_cases.scss
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,47 @@ body.casa_cases {
width: 130px;
padding-bottom: 15px;
}

.court-mandates {
textarea {
display: block;
margin-bottom: 5px;
}

textarea, .add-court-mandate {
width: 500px;
}
}

.add-court-mandate-container {
display: flex;
justify-content: flex-start;
align-items: center;
gap: 10px;
}

#add-mandate-button {
background-color: #{$primary};
color: white;

font-size: 1.25em;

padding: 0.25em 1.5em;
border-radius: 10px;
border: none;

:hover {
cursor: pointer;
}
}
}

@media only screen and (max-width: 640px) {
body.casa_cases {
.court-mandates {
textarea, .add-court-mandate {
width: 100%;
}
}
}
}
3 changes: 3 additions & 0 deletions app/models/casa_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class CasaCase < ApplicationRecord
has_many :contact_types, through: :casa_case_contact_types, source: :contact_type
accepts_nested_attributes_for :casa_case_contact_types

has_many :case_court_mandates, -> { order "id asc" }, dependent: :destroy
accepts_nested_attributes_for :case_court_mandates, reject_if: :all_blank

enum court_report_status: {not_submitted: 0, submitted: 1, in_review: 2, completed: 3}, _prefix: :court_report

scope :ordered, -> { order(updated_at: :desc) }
Expand Down
24 changes: 24 additions & 0 deletions app/models/case_court_mandate.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class CaseCourtMandate < ApplicationRecord
belongs_to :casa_case

validates :mandate_text, presence: true
end

# == Schema Information
#
# Table name: case_court_mandates
#
# id :bigint not null, primary key
# mandate_text :string
# created_at :datetime not null
# updated_at :datetime not null
# casa_case_id :bigint not null
#
# Indexes
#
# index_case_court_mandates_on_casa_case_id (casa_case_id)
#
# Foreign Keys
#
# fk_rails_... (casa_case_id => casa_cases.id)
#
3 changes: 3 additions & 0 deletions app/policies/casa_case_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def can_see_filters?
alias_method :update_hearing_type?, :admin_or_supervisor?
alias_method :update_judge?, :admin_or_supervisor?
alias_method :update_court_report_due_date?, :admin_or_supervisor?
alias_method :update_court_mandates?, :admin_or_supervisor?

def permitted_attributes
common_attrs = [
Expand All @@ -58,8 +59,10 @@ def permitted_attributes
case @user
when CasaAdmin
common_attrs.concat(%i[case_number birth_month_year_youth court_date court_report_due_date hearing_type_id judge_id])
common_attrs << {case_court_mandates_attributes: %i[mandate_text id]}
when Supervisor
common_attrs.concat(%i[court_date court_report_due_date hearing_type_id judge_id])
common_attrs << {case_court_mandates_attributes: %i[mandate_text id]}
else
common_attrs
end
Expand Down
26 changes: 26 additions & 0 deletions app/views/casa_cases/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@
CasaCase.court_report_statuses&.map { |status| [status.first.humanize, status.first] } %>
</div>

<% if casa_case.persisted? %>
<div class="field form-group court-mandates">
<%= form.label :case_court_mandates, "Court Mandates" %>

<% if policy(casa_case).update_court_mandates? %>
<div id="mandates-list-container">
<%= form.fields_for :case_court_mandates do |ff| %>
<%= ff.text_area :mandate_text %>
<% end %>
</div>
<div class="add-court-mandate-container">
<button type="button" id="add-mandate-button">
<i class="fa fa-plus" aria-hidden="true"></i>
</button>
<strong>Add a court mandate</strong>
</div>
<% else %>
<div id="mandate-list-container">
<% @casa_case.case_court_mandates.each do |mandate| %>
<textarea disabled><%= mandate.mandate_text %></textarea>
<% end %>
</div>
<% end %>
</div>
<% end %>

<% if Pundit.policy(current_user, casa_case).update_contact_types? %>
<div id="contact-type-form" class="field contact-type form-group">
<h2 id="contact-type-label"><%= form.label :contact_types %></h2>
Expand Down
10 changes: 5 additions & 5 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
module.exports = function (api) {
var validEnv = ['development', 'test', 'production']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
var isTestEnv = api.env('test')
const validEnv = ['development', 'test', 'production']
const currentEnv = api.env()
const isDevelopmentEnv = api.env('development')
const isProductionEnv = api.env('production')
const isTestEnv = api.env('test')

if (!validEnv.includes(currentEnv)) {
throw new Error(
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20210223133248_create_case_court_mandates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreateCaseCourtMandates < ActiveRecord::Migration[6.1]
def change
create_table :case_court_mandates do |t|
t.string :mandate_text
t.references :casa_case, foreign_key: true, null: false

t.timestamps
end
end
end
11 changes: 10 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.define(version: 2021_01_17_185614) do
ActiveRecord::Schema.define(version: 2021_02_23_133248) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -145,6 +145,14 @@
t.check_constraint "(miles_driven IS NOT NULL) OR (NOT want_driving_reimbursement)", name: "want_driving_reimbursement_only_when_miles_driven"
end

create_table "case_court_mandates", force: :cascade do |t|
t.string "mandate_text"
t.bigint "casa_case_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["casa_case_id"], name: "index_case_court_mandates_on_casa_case_id"
end

create_table "contact_type_groups", force: :cascade do |t|
t.bigint "casa_org_id", null: false
t.string "name", null: false
Expand Down Expand Up @@ -289,6 +297,7 @@
add_foreign_key "case_assignments", "users", column: "volunteer_id"
add_foreign_key "case_contacts", "casa_cases"
add_foreign_key "case_contacts", "users", column: "creator_id"
add_foreign_key "case_court_mandates", "casa_cases"
add_foreign_key "emancipation_options", "emancipation_categories"
add_foreign_key "followups", "users", column: "creator_id"
add_foreign_key "judges", "casa_orgs"
Expand Down
1 change: 1 addition & 0 deletions spec/factories/casa_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
hearing_type
judge
court_report_status { :not_submitted }
case_court_mandates { [] }

trait :with_case_assignments do
after(:create) do |casa_case, _|
Expand Down
5 changes: 5 additions & 0 deletions spec/factories/case_court_mandates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FactoryBot.define do
factory :case_court_mandate do
mandate_text { Faker::Lorem.paragraph(sentence_count: 5, supplemental: true, random_sentences_to_add: 20) }
end
end
1 change: 1 addition & 0 deletions spec/models/casa_case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
it { is_expected.to belong_to(:judge).optional }
it { is_expected.to validate_presence_of(:case_number) }
it { is_expected.to validate_uniqueness_of(:case_number).scoped_to(:casa_org_id).case_insensitive }
it { is_expected.to have_many(:case_court_mandates).dependent(:destroy) }
it { is_expected.to have_many(:volunteers).through(:case_assignments) }

describe ".ordered" do
Expand Down
9 changes: 9 additions & 0 deletions spec/models/case_court_mandate_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require "rails_helper"

RSpec.describe CaseCourtMandate, type: :model do
subject { build(:case_court_mandate) }

it { is_expected.to belong_to(:casa_case) }

it { is_expected.to validate_presence_of(:mandate_text) }
end
Loading