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

Separates Admin and Volunteer Dashboards #161

Merged
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
9 changes: 9 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class User < ApplicationRecord
has_many :casa_cases, through: :case_assignments
has_one :supervisor_volunteer, foreign_key: 'volunteer_id'
has_one :supervisor, through: :supervisor_volunteer
has_many :case_contacts, foreign_key: 'creator_id'

ALL_ROLES = %w[inactive volunteer supervisor casa_admin].freeze
enum role: ALL_ROLES.zip(ALL_ROLES).to_h
Expand All @@ -17,6 +18,14 @@ def case_contacts_for(casa_case_id)
found_casa_case = casa_cases.find { |cc| cc.id == casa_case_id }
found_casa_case.case_contacts.filter { |contact| contact.creator_id == id }
end

def recent_contacts_made(days_counter = 60)
case_contacts.where(contact_made: true, occurred_at: days_counter.days.ago..Date.today).count
end

def most_recent_contact
case_contacts.where(contact_made: true).order(:occurred_at).first
end
end

# == Schema Information
Expand Down
73 changes: 73 additions & 0 deletions app/views/dashboard/_admin_dashboard.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<div class="row">
<div class="col-sm-12 dashboard-table-header">
<h1>Volunteers</h1>
<%= link_to "New Volunteer", new_volunteer_path, class: "btn btn-primary" %>
</div>
</div>
<hr>

<%= render "volunteer_filters" %>

<table class="table table-striped table-bordered" id="volunteers">
<thead>
<tr>
<th>Volunteer</th>
<th>Supervisor</th>
<th>Status</th>
<th>Assigned To Transition Aged Youth</th>
<th>Case Number(s)</th>
<th>Last Contact Made</th>
<th>Contacts Made in Past 60 Days</th>
<th>Actions</th>
</tr>
</thead>

<tbody>
<% @volunteers.each do |volunteer| %>
<tr>
<td><%= volunteer.email %></td>
<td id="supervisor-column"><%= volunteer&.supervisor&.email %></td>
<td id="status-column"><%= volunteer.status %></td>
<td><%= volunteer&.assigned_to_transition_aged_youth? %></td>
<td><%= volunteer&.casa_cases&.pluck(:case_number)&.join(', ') %></td>
<td><%= volunteer&.most_recent_contact&.occurred_at&.strftime('%B %e, %Y') %></td>
<td><%= volunteer&.recent_contacts_made %></td>
<td>
<%= link_to 'Edit', edit_volunteer_path(volunteer) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<br>
<div class="row">
<div class="col-sm-12 dashboard-table-header">
<h1>Cases</h1>
<% if policy(:dashboard).see_volunteers_section? %>
<%= link_to "New Case", new_casa_case_path, class: "btn btn-primary" %>
<% end %>
</div>
</div>
<table class="table case-list" id="casa_cases">
<thead>
<tr>
<th>Case Number</th>
<th>Teen Program Eligible</th>
<th>Assigned To</th>
<th>Actions</th>
<th></th>
</tr>
</thead>
<tbody>
<% @casa_cases.each do |casa_case| %>
<tr>
<td><%= casa_case.case_number %></td>
<td><%= casa_case.teen_program_eligible %></td>
<td><%= casa_case&.volunteers&.pluck(:email)&.join(",") %></td>
<td><%= link_to 'Detail View', casa_case_path(casa_case) %></td>
<td><%= link_to 'Edit', edit_casa_case_path(casa_case) %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
56 changes: 56 additions & 0 deletions app/views/dashboard/_volunteer_dashboard.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<div class="row">
<div class="col-sm-12 dashboard-table-header">
<h1>Your <%= "Case".pluralize(@casa_cases.count) %></h1>
</div>
</div>
<table class="table case-list">
<thead>
<tr>
<th>Case Number</th>
<th>Teen Program Eligible</th>
<th>Actions</th>
<th></th>
</tr>
</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">
<div class="col-sm-12 dashboard-table-header">
<h1>Case Contacts</h1>
<% if policy(:dashboard).create_case_contacts? %>
<%= link_to "New Case Contact", new_case_contact_path, class: "btn btn-primary" %>
<% end %>
</div>
</div>

<table class="table case-contacts-table" id="case_contacts">
<thead>
<tr>
<th>Date</th>
<th>Duration</th>
<th>Contact Made</th>
<th>Contact Medium</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<% @case_contacts.each do |contact| %>
<tr>
<td data-sort="<%= contact.occurred_at.strftime("%Y%m%d%H%M%s") %>"><%= 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>
107 changes: 4 additions & 103 deletions app/views/dashboard/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,104 +1,5 @@
<% if policy(:dashboard).see_volunteers_section? %>
<div class="row">
<div class="col-sm-12 dashboard-table-header">
<h1>Volunteers</h1>
<%= link_to "New Volunteer", new_volunteer_path, class: "btn btn-primary" %>
</div>
</div>
<hr>

<%= render "volunteer_filters" %>

<table class="table table-striped table-bordered" id="volunteers">
<thead>
<tr>
<th>Volunteer</th>
<th>Supervisor</th>
<th>Status</th>
<th>Assigned To Transition Aged Youth</th>
<th>Case Number</th>
<th>Actions</th>
</tr>
</thead>

<tbody>
<% @volunteers.each do |volunteer| %>
<tr>
<td><%= volunteer.email %></td>
<td id="supervisor-column"><%= volunteer&.supervisor&.email %></td>
<td id="status-column"><%= volunteer.status %></td>
<td><%= volunteer.assigned_to_transition_aged_youth? %></td>
<td><%= volunteer.casa_cases.pluck(:case_number).join(', ') %></td>
<td>
<%= link_to 'Edit', edit_volunteer_path(volunteer) %>
</td>
</tr>
<% end %>
</tbody>
</table>
<br>
<% end %>


<% if policy(:dashboard).see_cases_section? %>
<div class="row">
<div class="col-sm-12 dashboard-table-header">
<h1>Cases</h1>
<% if policy(:dashboard).see_volunteers_section? %>
<%= link_to "New Case", new_casa_case_path, class: "btn btn-primary" %>
<% end %>
</div>
</div>
<table class="table case-list" id="casa_cases">
<thead>
<tr>
<th>Case Number</th>
<th>Teen Program Eligible</th>
<th>Actions</th>
<th></th>
</tr>
</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 'Detail View', casa_case_path(casa_case) %></td>
<td><%= link_to 'Edit', edit_casa_case_path(casa_case) %></td>
</tr>
<% end %>
</tbody>
</table>
<br>
<div class="row">
<div class="col-sm-12 dashboard-table-header">
<h1>Case Contacts</h1>
<% if policy(:dashboard).create_case_contacts? %>
<%= link_to "New Case Contact", new_case_contact_path, class: "btn btn-primary" %>
<% end %>
</div>
</div>

<table class="table case-contacts-table" id="case_contacts">
<thead>
<tr>
<th>Date</th>
<th>Duration</th>
<th>Contact Made</th>
<th>Contact Medium</th>
<th>Type</th>
</tr>
</thead>
<tbody>
<% @case_contacts.each do |contact| %>
<tr>
<td data-sort="<%= contact.occurred_at.strftime("%Y%m%d%H%M%s") %>"><%= 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>
<% if current_user.casa_admin? %>
<%= render 'admin_dashboard' %>
<% else %>
<%= render 'volunteer_dashboard' %>
<% end %>