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
1 change: 1 addition & 0 deletions app/models/casa_case.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class CasaCase < ApplicationRecord
has_many :case_assignments, dependent: :destroy
has_many(:volunteers, through: :case_assignments, source: :volunteer, class_name: "User")
has_many :case_contacts, dependent: :destroy
has_many :past_court_dates, dependent: :destroy
validates :case_number, uniqueness: {case_sensitive: false}, presence: true
belongs_to :hearing_type, optional: true
belongs_to :judge, optional: true
Expand Down
22 changes: 22 additions & 0 deletions app/models/past_court_date.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class PastCourtDate < ApplicationRecord
belongs_to :casa_case
end

# == Schema Information
#
# Table name: past_court_dates
#
# id :bigint not null, primary key
# date :datetime not null
# created_at :datetime not null
# updated_at :datetime not null
# casa_case_id :bigint not null
#
# Indexes
#
# index_past_court_dates_on_casa_case_id (casa_case_id)
#
# Foreign Keys
#
# fk_rails_... (casa_case_id => casa_cases.id)
#
15 changes: 15 additions & 0 deletions app/views/casa_cases/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@
<%= render 'form', casa_case: @casa_case %>
<% end %>

<div class="card card-container">
<div class="card-body">
<h6><strong>Past court dates:</strong></h6>
<% if @casa_case.past_court_dates.size > 0 %>
<ul>
<% @casa_case.past_court_dates.each do |pcd| %>
<p><%= pcd.date.strftime("%B %e, %Y") %></p>
<% end %>
</ul>
<% else %>
No past court dates
<% end %>
</div>
</div>

<% if Pundit.policy(current_user, @casa_case).assign_volunteers? %>
<%= render "volunteer_assignment" %>
<% end %>
10 changes: 10 additions & 0 deletions db/migrate/20201024113046_create_past_court_dates.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class CreatePastCourtDates < ActiveRecord::Migration[6.0]
def change
create_table :past_court_dates do |t|
t.datetime :date, null: false
t.references :casa_case, null: false, foreign_key: true

t.timestamps
end
end
end
11 changes: 11 additions & 0 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@
t.index ["casa_org_id"], name: "index_hearing_types_on_casa_org_id"
end

create_table "past_court_dates", force: :cascade do |t|
t.datetime "date", null: false
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_past_court_dates_on_casa_case_id"
end

create_table "judges", force: :cascade do |t|
t.bigint "casa_org_id", null: false
t.datetime "created_at", precision: 6, null: false
Expand Down Expand Up @@ -225,6 +233,9 @@
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 "past_court_dates", "casa_cases"
add_foreign_key "judges", "casa_orgs"
add_foreign_key "supervisor_volunteers", "users", column: "supervisor_id"
add_foreign_key "supervisor_volunteers", "users", column: "volunteer_id"
Expand Down
5 changes: 4 additions & 1 deletion lib/tasks/scheduler.rake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ end
desc "Clear court dates and report information when date has passed, run by heroku scheduler"
task clear_passed_dates: :environment do
puts "Checking case due dates..."
CasaCase.due_date_passed.each { |key| key.clear_court_dates }
CasaCase.due_date_passed.each do |cc|
PastCourtDate.create!(date: cc.court_date, casa_case_id: cc.id)
cc.clear_court_dates
end
puts "done."
end