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

Adds medium_type and contact_made fields to case_contacts #138

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 0 additions & 9 deletions app/assets/stylesheets/dashboard.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,3 @@
color: white;
}
}

.case-contacts-table {
border-collapse: collapse;
tr td {
border-width: 2px;
border-color: black;
border-style: solid;
}
}
4 changes: 2 additions & 2 deletions app/controllers/case_contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def create

respond_to do |format|
if @case_contact.save
format.html { redirect_to @case_contact.decorate, notice: 'Case contact was successfully created.' }
format.html { redirect_to root_path, notice: 'Case contact was successfully created.' }
format.json { render :show, status: :created, location: @case_contact }
else
format.html { render :new }
Expand All @@ -44,7 +44,7 @@ def create
def update
respond_to do |format|
if @case_contact.update(case_contact_params)
format.html { redirect_to @case_contact.decorate, notice: 'Case contact was successfully updated.' }
format.html { redirect_to root_path, notice: 'Case contact was successfully updated.' }
format.json { render :show, status: :ok, location: @case_contact }
else
format.html { render :edit }
Expand Down
16 changes: 16 additions & 0 deletions app/decorators/case_contact_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,20 @@ def duration_minutes
"#{formatted_hour_value} #{'hour'.pluralize(formatted_hour_value)} #{formatted_minutes_value} minutes"
end
end

def contact_made
if object.contact_made
'Yes'
else
'No'
end
end

def medium_type
if object.medium_type.blank?
'Unknown'
else
object.medium_type.titleize
end
end
end
4 changes: 2 additions & 2 deletions app/helpers/case_contacts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def duration_minutes_select(form, case_contact)
durations.push(OpenStruct.new(value: duration, label: "#{duration} minutes"))
end

form.select :duration_minutes, options_from_collection_for_select(durations, 'value', 'label', case_contact.duration_minutes&.remainder(60))
form.select :duration_minutes, options_from_collection_for_select(durations, 'value', 'label', case_contact.duration_minutes&.remainder(60)), {}, class: 'custom-select'
end

def duration_hours_select(form, case_contact)
Expand All @@ -21,6 +21,6 @@ def duration_hours_select(form, case_contact)
durations.push(OpenStruct.new(value: duration, label: "#{duration} #{'hour'.pluralize(i)}"))
end

form.select :duration_hours, options_from_collection_for_select(durations, 'value', 'label', case_contact.duration_minutes&.div(60))
form.select :duration_hours, options_from_collection_for_select(durations, 'value', 'label', case_contact.duration_minutes&.div(60)), {}, class: 'custom-select'
end
end
1 change: 0 additions & 1 deletion app/javascript/packs/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// that code so it'll be compiled.

require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("jquery")
Expand Down
7 changes: 5 additions & 2 deletions app/javascript/packs/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ $('document').ready(() => {
}
);

var table = $('#volunteers').DataTable();
// Enable all data tables on dashboard but only filter on volunteers table
var volunteers_table = $('table#volunteers').DataTable();
$('table#casa_cases').DataTable({"searching": false});
$('table#case_contacts').DataTable({"searching": false});

$('.volunteer-filters input[type="checkbox"]').on('click', function() {
table.draw();
volunteers_table.draw();
})
});
10 changes: 10 additions & 0 deletions app/models/case_contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class CaseContact < ApplicationRecord
belongs_to :creator, class_name: 'User'
belongs_to :casa_case

validates :contact_type, presence: true

CONTACT_TYPES = %w[
youth
school
Expand All @@ -18,6 +20,14 @@ class CaseContact < ApplicationRecord
court
other
].freeze

CONTACT_MEDIUMS = %w[
in-person
text/email
video
voice-only
letter
].freeze
enum contact_type: CONTACT_TYPES.zip(CONTACT_TYPES).to_h

def humanized_type
Expand Down
2 changes: 1 addition & 1 deletion app/values/case_contact_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class CaseContactParameters < SimpleDelegator
def initialize(params)
params = params
.require(:case_contact)
.permit(:contact_type, :other_type_text, :duration_minutes, :occurred_at)
.permit(:contact_type, :other_type_text, :duration_minutes, :occurred_at, :contact_made, :medium_type)

super(params)
end
Expand Down
46 changes: 33 additions & 13 deletions app/views/case_contacts/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,52 @@
</ul>
</div>
<% end %>
<div class="field casa-case">

<div class="field casa-case form-group">
<%= form.label :casa_case_id %>
<%= form.select :casa_case_id, options_from_collection_for_select(current_user.casa_cases, 'id', 'case_number') %>
<%= form.select :casa_case_id, options_from_collection_for_select(current_user.casa_cases, 'id', 'case_number', case_contact.casa_case_id), {}, class: "custom-select" %>
</div>
<div class="field contact-type">

<div class="field contact-type form-group">
<%= form.label :contact_type %>
<% case_contacts = CaseContact::CONTACT_TYPES.map { |contact_type| OpenStruct.new(value: contact_type, label: contact_type.titleize) } %>
<%= form.select :contact_type, options_from_collection_for_select(case_contacts, 'value', 'label') %>
<% contact_types = CaseContact::CONTACT_TYPES.map { |contact_type| OpenStruct.new(value: contact_type, label: contact_type.titleize) } %>
<%= form.select :contact_type, options_from_collection_for_select(contact_types, 'value', 'label', case_contact.contact_type), {}, class: "custom-select" %>
</div>
<div class="field other-contact-type" hidden>

<div class="field other-contact-type form-group" hidden>
<%= form.label :other_type_text %>
<%= form.text_field :other_type_text %>
<%= form.text_field :other_type_text, class: "form-control" %>
</div>

<div class="field contact-type form-group">
<%= form.label "Contact Made" %>
<%= form.select :contact_made, options_for_select([['Yes', true], ['No', false]], case_contact.contact_made), {}, class: "custom-select" %>
</div>

<div class="field contact-type form-group">
<%= form.label "Contact Medium" %>
<% contact_mediums = CaseContact::CONTACT_MEDIUMS.map { |contact_medium| OpenStruct.new(value: contact_medium, label: contact_medium.titleize) } %>
<%= form.select :medium_type, options_from_collection_for_select(contact_mediums, 'value', 'label', case_contact.medium_type), {}, class: "custom-select" %>
</div>

<div class="field duration-minutes">
<div class="field duration-minutes form-group">
<%= form.label "Duration" %>
<%= duration_hours_select(form, @case_contact) %>
<%= duration_minutes_select(form, @case_contact) %>
<div class="row">
<div class="col-sm-6">
<%= duration_hours_select(form, @case_contact) %>
</div>
<div class="col-sm-6">
<%= duration_minutes_select(form, @case_contact) %>
</div>
</div>
</div>

<div class="field occurred-at">
<div class="field occurred-at form-group">
<%= form.label :occurred_at %>
<%= form.date_field :occurred_at, :value => Time.now.strftime('%Y-%m-%d') %>
<%= form.date_field :occurred_at, value: Time.now.strftime('%Y-%m-%d'), class: "form-control" %>
</div>

<div class="actions">
<%= form.submit "Submit" %>
<%= form.submit "Submit", class: "btn btn-primary" %>
</div>
<% end %>
12 changes: 10 additions & 2 deletions app/views/case_contacts/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
<h1>Editing Case Contact</h1>

<%= render 'form', case_contact: @case_contact %>
<br>

<div class="row">
<div class="col-sm-6">
<%= render 'form', case_contact: @case_contact %>
</div>
</div>

<br>

<%= link_to 'Show', @case_contact %> |
<%= link_to 'Back', case_contacts_path %>
<%= link_to 'Back', :back %>
12 changes: 10 additions & 2 deletions app/views/case_contacts/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<h1>New Case Contact</h1>

<%= render 'form', case_contact: @case_contact %>
<br>

<%= link_to 'Back', case_contacts_path %>
<div class="row">
<div class="col-sm-6">
<%= render 'form', case_contact: @case_contact %>
</div>
</div>

<br>

<%= link_to 'Back', :back %>
56 changes: 34 additions & 22 deletions app/views/dashboard/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,23 @@
</div>
<% end %>
</div>
<table class="table table-striped table-bordered case-list">
<tr>
<th>Case Number</th>
<th>Teen Program Eligible</th>
<th>Actions</th>
</tr>
<% @casa_cases.each do |casa_case| %>
<table class="table case-list" id="casa_cases">
<thead>
<tr>
<td><%= casa_case.case_number %></td>
<td><%= casa_case.teen_program_eligible %></td>
<td><%= link_to("Edit", edit_casa_case_path(casa_case)) %></td>
<th>Case Number</th>
<th>Teen Program Eligible</th>
<th>Actions</th>
</tr>
<% end %>
</thead>
<tbody>
<% @casa_cases.each do |casa_case| %>
<tr>
<td><%= casa_case.case_number %></td>
<td><%= casa_case.teen_program_eligible %></td>
<td><%= link_to("Edit", edit_casa_case_path(casa_case)) %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<div class="row">
Expand All @@ -73,18 +77,26 @@
</div>
</div>

<table class="table case-contacts-table">
<tr>
<th>Date</th>
<th>Duration</th>
<th>Type</th>
</tr>
<% @case_contacts.each do |contact| %>
<table class="table case-contacts-table" id="case_contacts">
<thead>
<tr>
<td><%= contact.occurred_at.strftime('%B %e, %Y') %></td>
<td><%= contact.duration_minutes %></td>
<td><%= contact.humanized_type %></td>
<th>Date</th>
<th>Duration</th>
<th>Contact Made</th>
<th>Contact Medium</th>
<th>Type</th>
</tr>
<% end %>
</thead>
<tbody>
<% @case_contacts.each do |contact| %>
<tr>
<td><%= contact.occurred_at.strftime('%B %e, %Y') %></td>
<td><%= contact.duration_minutes %></td>
<td><%= contact.contact_made %></td>
<td><%= contact.medium_type %></td>
<td><%= contact.humanized_type %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddMediumTypeAndContactMadeToCaseContacts < ActiveRecord::Migration[6.0]
def change
add_column :case_contacts, :contact_made, :boolean, default: false
add_column :case_contacts, :medium_type, :string
end
end
4 changes: 3 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: 2020_04_05_112910) do
ActiveRecord::Schema.define(version: 2020_04_20_004403) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -60,6 +60,8 @@
t.datetime "occurred_at", null: false
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.boolean "contact_made", default: false
t.string "medium_type"
t.index ["casa_case_id"], name: "index_case_contacts_on_casa_case_id"
t.index ["creator_id"], name: "index_case_contacts_on_creator_id"
end
Expand Down
36 changes: 36 additions & 0 deletions spec/decorators/case_contact_decorator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,40 @@
end
end
end

describe '#contact_made' do
context 'when contact_made is false' do
it 'returns No' do
case_contact = create(:case_contact, contact_made: false)

expect(case_contact.decorate.contact_made).to eq 'No'
end
end

context 'when contact_made is true' do
it 'returns Yes' do
case_contact = create(:case_contact, contact_made: true)

expect(case_contact.decorate.contact_made).to eq 'Yes'
end
end
end

describe '#medium_type' do
context 'when medium_type is nil' do
it 'returns Unknown' do
case_contact = create(:case_contact, medium_type: nil)

expect(case_contact.decorate.medium_type).to eq 'Unknown'
end
end

context 'when medium_type is not nil' do
it 'returns the titleized medium_type' do
case_contact = create(:case_contact, medium_type: "in-person")

expect(case_contact.decorate.medium_type).to eq 'In Person'
end
end
end
end