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

[#1734] Add Implementation Status to Court Mandates #1908

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: 6 additions & 0 deletions app/decorators/casa_case_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ def court_report_select_option
]
end

def court_mandate_select_options
CaseCourtMandate.implementation_statuses.map do |status|
[status[0].humanize, status[0]]
end
end

def inactive_class
!object.active ? "table-secondary" : ""
end
Expand Down
30 changes: 25 additions & 5 deletions app/javascript/src/casa_case.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
function add_court_mandate_input () {
const list = '#mandates-list-container'
const index = $(`${list} textarea`).length
const html = court_mandate_html(index)

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(html.entry)
let last_entry = $(list).children(':last')

$(list).append(textarea_html)
$(list).children(':last').trigger('focus')
$(last_entry).append(html.textarea)
$(last_entry).append(html.select)
$(last_entry).children(':first').trigger('focus')
}

function remove_mandate_with_confirmation () {
Expand Down Expand Up @@ -60,6 +61,25 @@ function remove_mandate_action (ctx) {
})
}

function court_mandate_html(index) {
const select_options = `<option value="">Set Implementation Status</option>\
<option value="not_implemented">Not implemented</option>\
<option value="partially_implemented">Partially implemented</option>\
<option value="implemented">Implemented</option>`
return {
entry: `<div class="court-mandate-entry"></div>`,

textarea: `<textarea name="casa_case[case_court_mandates_attributes][${index}][mandate_text]"\
id="casa_case_case_court_mandates_attributes_${index}_mandate_text"></textarea>`,

select: `<select class="implementation-status"\
name="casa_case[case_court_mandates_attributes][${index}][implementation_status]"\
id="casa_case_case_court_mandates_attributes_${index}_implementation_status">\
${select_options}\
</select>`
}
}

$('document').ready(() => {
$('button#add-mandate-button').on('click', add_court_mandate_input)
$('button.remove-mandate-button').on('click', remove_mandate_with_confirmation)
Expand Down
44 changes: 30 additions & 14 deletions app/javascript/src/stylesheets/pages/casa_cases.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,30 @@ body.casa_cases {
}
}

.court-mandate-entry {
display: flex;
gap: 8px;
align-items: center;
#add-mandate-button {
background-color: #{$primary};

.remove-mandate-button {
background-color: #{$red};
padding: 0.25em 1.5em;
border-radius: 10px;
}

border-radius: 100%;
.remove-mandate-button {
background-color: #{$red};

max-width: 30px;
max-height: 30px;
}
border-radius: 100%;

max-width: 30px;
max-height: 30px;
}

#add-mandate-button {
background-color: #{$primary};
.court-mandate-entry {
display: flex;
gap: 8px;
align-items: center;
}

padding: 0.25em 1.5em;
border-radius: 10px;
select {
padding: 5px;
}
}

Expand All @@ -79,5 +83,17 @@ body.casa_cases {
width: 100%;
}
}

.court-mandate-entry {
display: grid;
grid-template-columns: minmax(100px, 100%) 1fr;
gap: 2px;

.implementation-status {
grid-row: 2;
}

margin: 1em 1em 2em 1em;
}
}
}
13 changes: 8 additions & 5 deletions app/models/case_court_mandate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ class CaseCourtMandate < ApplicationRecord
belongs_to :casa_case

validates :mandate_text, presence: true

enum implementation_status: {not_implemented: 1, partially_implemented: 2, implemented: 3}
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
# id :bigint not null, primary key
# implementation_status :integer
# mandate_text :string
# created_at :datetime not null
# updated_at :datetime not null
# casa_case_id :bigint not null
#
# Indexes
#
Expand Down
8 changes: 6 additions & 2 deletions app/policies/casa_case_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +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]}
common_attrs << case_court_mandates_attributes
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]}
common_attrs << case_court_mandates_attributes
else
common_attrs
end
Expand Down Expand Up @@ -100,4 +100,8 @@ def is_in_same_org?
def is_volunteer_actively_assigned_to_case?
record.case_assignments.exists?(volunteer_id: user.id, active: true)
end

def case_court_mandates_attributes
{case_court_mandates_attributes: %i[mandate_text implementation_status id]}
end
end
17 changes: 16 additions & 1 deletion app/views/casa_cases/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@
<%= form.fields_for :case_court_mandates do |ff| %>
<div class="court-mandate-entry">
<%= ff.text_area :mandate_text %>
<%=
ff.select :implementation_status,
@casa_case.decorate.court_mandate_select_options,
{include_blank: 'Set Implementation Status', selected: ff.object.implementation_status},
{class: 'implementation-status'}
%>
<button type="button" class="remove-mandate-button">
<i class="fa fa-minus" aria-hidden="true"></i>
</button>
Expand All @@ -140,7 +146,16 @@
<% else %>
<div id="mandate-list-container">
<% @casa_case.case_court_mandates.each do |mandate| %>
<textarea disabled><%= mandate.mandate_text %></textarea>
<div class="court-mandate-entry">
<textarea disabled><%= mandate.mandate_text %></textarea>

<% if mandate.implementation_status %>
<p class="implementation-status">
<strong>Status:</strong>
<%= mandate.implementation_status.humanize %>
</p>
<% end %>
</div>
<% end %>
</div>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddImplementationStatusToEditCaseCourtMandates < ActiveRecord::Migration[6.1]
def change
add_column :case_court_mandates, :implementation_status, :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.define(version: 2021_04_01_161710) do
ActiveRecord::Schema.define(version: 2021_04_01_182359) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -152,6 +152,7 @@
t.bigint "casa_case_id", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.integer "implementation_status"
t.index ["casa_case_id"], name: "index_case_court_mandates_on_casa_case_id"
end

Expand Down
1 change: 1 addition & 0 deletions spec/factories/case_court_mandates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
factory :case_court_mandate do
casa_case
mandate_text { Faker::Lorem.paragraph(sentence_count: 5, supplemental: true, random_sentences_to_add: 20) }
implementation_status { [:not_implemented, :partially_implemented, :implemented].sample }
end
end
16 changes: 14 additions & 2 deletions spec/requests/casa_cases_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
let(:invalid_attributes) { {case_number: nil} }
let(:casa_case) { create(:casa_case, casa_org: organization, case_number: "111") }
let(:mandate_texts) { ["1-New Mandate Text One", "0-New Mandate Text Two"] }
let(:mandates_attributes) { {"0" => {mandate_text: mandate_texts[0]}, "1" => {mandate_text: mandate_texts[1]}} }
let(:implementation_statuses) { ["not_implemented", nil] }
let(:mandates_attributes) do
{
"0" => {mandate_text: mandate_texts[0], implementation_status: implementation_statuses[0]},
"1" => {mandate_text: mandate_texts[1], implementation_status: implementation_statuses[1]}
}
end

before { sign_in user }

Expand Down Expand Up @@ -182,7 +188,9 @@
expect(casa_case.hearing_type).to eq hearing_type
expect(casa_case.judge).to eq judge
expect(casa_case.case_court_mandates[0].mandate_text).to eq mandate_texts[0]
expect(casa_case.case_court_mandates[0].implementation_status).to eq implementation_statuses[0]
expect(casa_case.case_court_mandates[1].mandate_text).to eq mandate_texts[1]
expect(casa_case.case_court_mandates[1].implementation_status).to eq implementation_statuses[1]
end

it "redirects to the casa_case" do
Expand All @@ -205,7 +213,8 @@
{
case_court_mandates_attributes: {
"0" => {
mandate_text: "New Mandate Text One Updated"
mandate_text: "New Mandate Text One Updated",
implementation_status: :not_implemented
},
"1" => {
mandate_text: ""
Expand Down Expand Up @@ -474,7 +483,10 @@
expect(casa_case.court_report_completed?).to be true

expect(casa_case.case_court_mandates[0].mandate_text).to eq mandate_texts[0]
expect(casa_case.case_court_mandates[0].implementation_status).to eq implementation_statuses[0]

expect(casa_case.case_court_mandates[1].mandate_text).to eq mandate_texts[1]
expect(casa_case.case_court_mandates[1].implementation_status).to eq implementation_statuses[1]
end

it "redirects to the casa_case" do
Expand Down
38 changes: 35 additions & 3 deletions spec/system/casa_cases/edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@
context "when admin" do
let(:organization) { create(:casa_org) }
let(:admin) { create(:casa_admin, casa_org: organization) }
let(:casa_case) { create(:casa_case, casa_org: organization) }
let(:casa_case) { create(:casa_case, :with_one_court_mandate, casa_org: organization) }
let!(:judge) { create(:judge, casa_org: organization) }
let(:contact_type_group) { create(:contact_type_group, casa_org: organization) }
let!(:school) { create(:contact_type, name: "School", contact_type_group: contact_type_group) }
let!(:therapist) { create(:contact_type, name: "Therapist", contact_type_group: contact_type_group) }

before { sign_in admin }

it "shows court mandates" do
visit edit_casa_case_path(casa_case)

court_mandate = casa_case.case_court_mandates.first

expect(page).to have_text(court_mandate.mandate_text)
expect(page).to have_text(court_mandate.implementation_status.humanize)
end

it "clicks back button after editing case" do
visit edit_casa_case_path(casa_case)
select "Submitted", from: "casa_case_court_report_status"
Expand Down Expand Up @@ -76,7 +85,7 @@
context "supervisor user" do
let(:casa_org) { create(:casa_org) }
let(:supervisor) { create(:supervisor, casa_org: casa_org) }
let(:casa_case) { create(:casa_case, casa_org: casa_org) }
let(:casa_case) { create(:casa_case, :with_one_court_mandate, casa_org: casa_org) }
let!(:contact_type_group) { create(:contact_type_group, casa_org: casa_org) }
let!(:contact_type_1) { create(:contact_type, name: "Youth", contact_type_group: contact_type_group) }
let!(:contact_type_2) { create(:contact_type, name: "Supervisor", contact_type_group: contact_type_group) }
Expand All @@ -103,6 +112,10 @@
page.find("#add-mandate-button").click
find("#mandates-list-container").first("textarea").send_keys("Court Mandate Text One")

select "Partially implemented", from: "casa_case[case_court_mandates_attributes][0][implementation_status]"

expect(page).to have_text("Set Implementation Status")

click_on "Update CASA Case"
has_checked_field? "Youth"
has_no_checked_field? "Supervisor"
Expand All @@ -115,6 +128,7 @@
expect(page).to have_text("November")
expect(page).to have_text("September")
expect(page).to have_text("Court Mandate Text One")
expect(page).to have_text("Partially implemented")

visit casa_case_path(casa_case)

Expand Down Expand Up @@ -170,6 +184,15 @@
expect(page).not_to have_text("Update Casa Case")
end

it "shows court mandates" do
visit edit_casa_case_path(casa_case)

court_mandate = casa_case.case_court_mandates.first

expect(page).to have_text(court_mandate.mandate_text)
expect(page).to have_text(court_mandate.implementation_status.humanize)
end

context "When a Casa instance has no judge names added" do
it "does not display judge names details" do
casa_case = create(:casa_case, casa_org: casa_org, judge: nil)
Expand Down Expand Up @@ -330,7 +353,7 @@ def sign_in_and_assign_volunteer

context "volunteer user" do
let(:volunteer) { create(:volunteer) }
let(:casa_case) { create(:casa_case, casa_org: volunteer.casa_org) }
let(:casa_case) { create(:casa_case, :with_one_court_mandate, casa_org: volunteer.casa_org) }
let!(:case_assignment) { create(:case_assignment, volunteer: volunteer, casa_case: casa_case) }

let!(:court_dates) do
Expand Down Expand Up @@ -366,6 +389,15 @@ def sign_in_and_assign_volunteer
expect(page).to have_text(I18n.l(court_dates[1].date, format: :full, default: nil))
end

it "shows court mandates" do
visit edit_casa_case_path(casa_case)

court_mandate = casa_case.case_court_mandates.first

expect(page).to have_text(court_mandate.mandate_text)
expect(page).to have_text(court_mandate.implementation_status.humanize)
end

it "clicks back button after editing case" do
visit edit_casa_case_path(casa_case)

Expand Down