-
-
Notifications
You must be signed in to change notification settings - Fork 530
Add page to manage volunteer case assignments #210
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
Changes from all commits
c91a94d
b185bf5
94bcd22
ea0f899
bdc5357
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| class CaseAssignmentsController < ApplicationController | ||
| before_action :must_be_admin | ||
|
|
||
| def index | ||
| @volunteer = User.find(params[:volunteer_id]).decorate | ||
| end | ||
|
|
||
| def create | ||
| volunteer = User.find(params[:volunteer_id]) | ||
| case_assignment = volunteer.case_assignments.new(case_assignment_params) | ||
|
compwron marked this conversation as resolved.
|
||
|
|
||
| case_assignment.save | ||
|
|
||
| redirect_to volunteer_case_assignments_path(volunteer) | ||
| end | ||
|
|
||
| def destroy | ||
| volunteer = User.find(params[:volunteer_id]) | ||
| case_assignment = volunteer.case_assignments.find(params[:id]) | ||
|
|
||
| case_assignment.destroy | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eventually we will want to use |
||
|
|
||
| redirect_to volunteer_case_assignments_path(volunteer) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def case_assignment_params | ||
| params.require(:case_assignment).permit(:casa_case_id) | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ class CaseContact < ApplicationRecord | |
| enum contact_type: CONTACT_TYPES.zip(CONTACT_TYPES).to_h | ||
|
|
||
| def humanized_type | ||
| "#{contact_type.humanize.titleize}" | ||
| contact_type.humanize.titleize.to_s | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :) |
||
| end | ||
|
|
||
| # Generate array of attributes for All Case Contacts report | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <%= link_to 'Back', root_path %> | ||
|
|
||
| <h1>Edit Volunteer Assignments for <%= @volunteer.name %></h1> | ||
|
|
||
| <br> | ||
|
|
||
| <% if @volunteer.casa_cases %> | ||
| <table class='table case-list' id='casa_cases'> | ||
| <thead> | ||
| <tr> | ||
| <th>Case Number</th> | ||
| <th>Transition Aged Youth</th> | ||
| <th>Actions</th> | ||
| </tr> | ||
| </thead> | ||
| <tbody> | ||
| <% @volunteer.case_assignments.each do |assignment| %> | ||
| <tr> | ||
| <td><%= assignment.casa_case.case_number %></td> | ||
| <td><%= assignment.casa_case.transition_aged_youth %></td> | ||
| <td><%= button_to 'Unassign Case', volunteer_case_assignment_path(@volunteer, assignment), method: :delete, class: "btn btn-danger" %></td> | ||
| </tr> | ||
| <% end %> | ||
| </tbody> | ||
| </table> | ||
| <% end %> | ||
|
|
||
| <br> | ||
|
|
||
| <div class="row"> | ||
| <div class="col-sm-6"> | ||
| <h3>Assign a New Case</h3> | ||
|
|
||
| <%= form_for CaseAssignment.new, url: volunteer_case_assignments_path do |form| %> | ||
|
|
||
| <div class='form-group'> | ||
| <label for="case_assignment_casa_case_id">Select a Case</label> | ||
| <select class='form-control'> | ||
| <% CasaCase.all.each do |casa_case| %> | ||
| <option value="<%= casa_case.id %>"><%= casa_case.case_number %></option> | ||
| <% end %> | ||
| </select> | ||
| </div> | ||
|
|
||
| <%= form.submit 'Assign Case', class: 'btn btn-primary' %> | ||
| <% end %> | ||
| </div> | ||
| </div> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,26 +1,26 @@ | ||
| <!DOCTYPE html> | ||
| <html> | ||
| <head> | ||
| <title>PG CASA</title> | ||
| <%= csrf_meta_tags %> | ||
| <%= csp_meta_tag %> | ||
| <%= render 'shared/favicons' %> | ||
| <head> | ||
| <title>PG CASA</title> | ||
| <%= csrf_meta_tags %> | ||
| <%= csp_meta_tag %> | ||
| <%= render 'shared/favicons' %> | ||
|
|
||
| <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> | ||
| <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> | ||
| </head> | ||
| <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %> | ||
| <%= javascript_pack_tag 'application', 'data-turbolinks-track': 'reload' %> | ||
| </head> | ||
|
|
||
| <body> | ||
| <%= render 'layouts/header' %> | ||
| <body> | ||
| <%= render 'layouts/header' %> | ||
|
|
||
| <div class="container"> | ||
| <% if notice %> | ||
| <p class="notice alert alert-success"><%= notice %></p> | ||
| <% elsif alert %> | ||
| <p class="notice alert alert-danger"><%= alert %></p> | ||
| <% end %> | ||
| <div class="container"> | ||
| <% if notice %> | ||
| <p class="notice alert alert-success"><%= notice %></p> | ||
| <% elsif alert %> | ||
| <p class="notice alert alert-danger"><%= alert %></p> | ||
| <% end %> | ||
|
|
||
| <%= yield %> | ||
| </div> | ||
| </body> | ||
| <%= yield %> | ||
| </div> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,3 @@ | ||
| <h1>Editing Volunteer</h1> | ||
|
|
||
| <%= link_to 'Back', root_path %> | ||
|
|
||
| <h1>Editing Volunteer</h1> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe '/case_assignments', type: :request do | ||
| describe 'GET /index' do | ||
| context 'with a volunteer signed in' do | ||
| it 'redirects back to dashboard with an unauthorized notice' do | ||
| volunteer = create(:user, :volunteer) | ||
| sign_in volunteer | ||
|
|
||
| get volunteer_case_assignments_path(volunteer) | ||
|
|
||
| expect(response).to redirect_to(root_path) | ||
| end | ||
| end | ||
|
|
||
| context 'with an admin signed in' do | ||
| it 'renders a successful response' do | ||
| admin = create(:user, :casa_admin) | ||
| volunteer = create(:user, :volunteer) | ||
| sign_in admin | ||
|
|
||
| get volunteer_case_assignments_path(volunteer) | ||
|
|
||
| expect(response).to be_successful | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe 'POST /create' do | ||
| it 'creates a new case assignment' do | ||
| admin = create(:user, :casa_admin) | ||
| volunteer = create(:user, :volunteer) | ||
| casa_case = create(:casa_case) | ||
|
|
||
| sign_in admin | ||
|
|
||
| expect do | ||
| post volunteer_case_assignments_url(volunteer), | ||
| params: { case_assignment: { casa_case_id: casa_case.id } } | ||
| end.to change(volunteer.casa_cases, :count).by(1) | ||
|
|
||
| expect(response).to redirect_to volunteer_case_assignments_path(volunteer) | ||
| end | ||
| end | ||
|
|
||
| describe 'DELETE /destroy' do | ||
| it 'destroys the case assignment' do | ||
| admin = create(:user, :casa_admin) | ||
| volunteer = create(:user, :volunteer) | ||
| casa_case = create(:casa_case) | ||
| assignment = create(:case_assignment, volunteer: volunteer, casa_case: casa_case) | ||
|
|
||
| sign_in admin | ||
|
|
||
| expect do | ||
| delete volunteer_case_assignment_url(volunteer, assignment) | ||
| end.to change(volunteer.casa_cases, :count).by(-1) | ||
|
|
||
| expect(response).to redirect_to volunteer_case_assignments_path(volunteer) | ||
| end | ||
| end | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)