Skip to content

Commit

Permalink
Merge branch 'main' of github.com:sarvaiyanidhi/casa into display-ass…
Browse files Browse the repository at this point in the history
…igned-volunteer
  • Loading branch information
sarvaiyanidhi committed Feb 26, 2024
2 parents 79b7d03 + 318ef27 commit 27ea13b
Show file tree
Hide file tree
Showing 22 changed files with 741 additions and 259 deletions.
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,23 @@ GEM
bigdecimal (3.1.6)
bindex (0.8.1)
blueprinter (0.30.0)
brakeman (6.1.1)
brakeman (6.1.2)
racc
bugsnag (6.26.3)
concurrent-ruby (~> 1.0)
builder (3.2.4)
bullet (7.1.4)
bullet (7.1.6)
activesupport (>= 3.0.0)
uniform_notifier (~> 1.11)
bundler-audit (0.9.1)
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
byebug (11.1.3)
capybara (3.39.2)
capybara (3.40.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
nokogiri (~> 1.11)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
Expand Down Expand Up @@ -261,13 +261,13 @@ GEM
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
io-console (0.7.2)
irb (1.11.1)
irb (1.11.2)
rdoc
reline (>= 0.4.2)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
jsbundling-rails (1.2.2)
jsbundling-rails (1.3.0)
railties (>= 6.0.0)
json (2.6.3)
json-schema (4.1.1)
Expand All @@ -276,7 +276,7 @@ GEM
language_server-protocol (3.17.0.3)
launchy (2.5.0)
addressable (~> 2.7)
letter_opener (1.8.1)
letter_opener (1.9.0)
launchy (>= 2.2, < 3)
lint_roller (1.1.0)
llhttp-ffi (0.4.0)
Expand All @@ -301,7 +301,7 @@ GEM
mini_magick (4.11.0)
mini_mime (1.1.5)
mini_portile2 (2.8.5)
minitest (5.22.0)
minitest (5.22.2)
multi_xml (0.6.0)
multipart-post (2.3.0)
mutex_m (0.2.0)
Expand Down Expand Up @@ -425,7 +425,7 @@ GEM
rspec-mocks (3.12.6)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.12.0)
rspec-rails (6.1.0)
rspec-rails (6.1.1)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
Expand Down Expand Up @@ -539,7 +539,7 @@ GEM
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
webmock (3.19.1)
webmock (3.23.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand Down
13 changes: 13 additions & 0 deletions app/assets/stylesheets/pages/volunteers.scss
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,16 @@ body.volunteers {
}
}
}


table#volunteers.dataTable.hover tbody tr.selected > * {
background-color: rgba(54, 92, 245, 0.1);
box-shadow: none;
color: inherit;
}

table#volunteers.dataTable.hover > tbody > tr.selected:hover > * {
background-color: rgba(54, 92, 245, 0.15);
box-shadow: none !important;
color: inherit;
}
23 changes: 23 additions & 0 deletions app/assets/stylesheets/shared/header.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@use "../base/breakpoints.scss" as screen-sizes;

.header {
.header-left {
.menu-toggle-btn {
display: none;

.main-btn {
border-radius: 4px !important;
}
}
}
}

@media only screen and (max-width: screen-sizes.$mobile) {
.header {
.header-left {
.menu-toggle-btn {
display: block;
}
}
}
}
68 changes: 53 additions & 15 deletions app/controllers/supervisor_volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,73 @@ class SupervisorVolunteersController < ApplicationController

def create
authorize :supervisor_volunteer
supervisor_volunteer = supervisor_volunteer_parent.supervisor_volunteers.find_or_create_by!(supervisor_volunteer_params)
supervisor_volunteer.is_active = true unless supervisor_volunteer&.is_active?
volunteer = supervisor_volunteer.volunteer
supervisor = supervisor_volunteer.supervisor
supervisor_volunteer.save
flash_message = "#{volunteer.display_name} successfully assigned to #{supervisor.display_name}."
volunteer = Volunteer.find(supervisor_volunteer_params[:volunteer_id])
supervisor = set_supervisor
if assign_volunteer_to_supervisor(volunteer, supervisor)
flash[:notice] = "#{volunteer.display_name} successfully assigned to #{supervisor.display_name}."
else
flash[:alert] = "Something went wrong. Please try again."
end

redirect_to request.referer, notice: flash_message
redirect_to request.referer
end

def unassign
authorize :supervisor_volunteer
volunteer = Volunteer.find(params[:id])
supervisor_volunteer = volunteer.supervisor_volunteer
supervisor = volunteer.supervisor
supervisor_volunteer.is_active = false
supervisor_volunteer.save!
flash_message = "#{volunteer.display_name} was unassigned from #{supervisor.display_name}."
supervisor = volunteer.supervisor_volunteer.supervisor
if unassign_volunteers_supervisor(volunteer)
flash[:notice] = "#{volunteer.display_name} was unassigned from #{supervisor.display_name}."
else
flash[:alert] = "Something went wrong. Please try again."
end

redirect_to request.referer, notice: flash_message
redirect_to request.referer
end

def bulk_assignment
authorize :supervisor_volunteer

volunteers = policy_scope(current_organization.volunteers).where(id: params[:supervisor_volunteer][:volunteer_ids])
supervisor = policy_scope(current_organization.supervisors).where(id: params[:supervisor_volunteer][:supervisor_id]).first
if bulk_change_supervisor(supervisor, volunteers)
flash[:notice] = "#{"Volunteer".pluralize(volunteers.count)} successfully assigned to new supervisor."
else
flash[:alert] = "Something went wrong. The #{"volunteer".pluralize(volunteers.count)} could not be assigned."
end

redirect_to volunteers_path
end

private

def supervisor_volunteer_params
params.require(:supervisor_volunteer).permit(:supervisor_id, :volunteer_id)
params.require(:supervisor_volunteer).permit(:supervisor_id, :volunteer_id, volunteer_ids: [])
end

def supervisor_volunteer_parent
def set_supervisor
Supervisor.find(params[:supervisor_id] || supervisor_volunteer_params[:supervisor_id])
end

def bulk_change_supervisor(supervisor, volunteers)
if supervisor
volunteers.each do |volunteer|
assign_volunteer_to_supervisor(volunteer, supervisor)
end
else
volunteers.each do |volunteer|
unassign_volunteers_supervisor(volunteer)
end
end
end

def assign_volunteer_to_supervisor(volunteer, supervisor)
unassign_volunteers_supervisor(volunteer)
supervisor_volunteer = supervisor.supervisor_volunteers.find_or_create_by!(volunteer: volunteer)
supervisor_volunteer.update!(is_active: true)
end

def unassign_volunteers_supervisor(volunteer)
volunteer.supervisor_volunteer&.update(is_active: false)
end
end
1 change: 1 addition & 0 deletions app/controllers/volunteers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class VolunteersController < ApplicationController

def index
authorize Volunteer
@supervisors = policy_scope(current_organization.supervisors)
end

def show
Expand Down
29 changes: 29 additions & 0 deletions app/javascript/controllers/disable_form_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ['submitButton', 'input']
static values = {
unallowed: { type: Array }
}

static classes = ['disabled', 'enabled']

validate () {
let invalid = false
this.inputTargets.forEach(input => {
if (this.unallowedValue.includes(input.value)) {
invalid = true
}
})

if (invalid) {
this.submitButtonTarget.disabled = true
this.submitButtonTarget.classList.add(this.disabledClass)
this.submitButtonTarget.classList.remove(...this.enabledClasses)
} else {
this.submitButtonTarget.disabled = false
this.submitButtonTarget.classList.remove(this.disabledClass)
this.submitButtonTarget.classList.add(...this.enabledClasses)
}
}
}
6 changes: 6 additions & 0 deletions app/javascript/controllers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import AlertController from './alert_controller'

import AutosaveController from './autosave_controller'

import DisableFormController from './disable_form_controller'

import DismissController from './dismiss_controller'

import ExtendedNestedFormController from './extended_nested_form_controller'
Expand All @@ -20,16 +22,20 @@ import MultipleSelectController from './multiple_select_controller'

import NavbarController from './navbar_controller'

import SelectAllController from './select_all_controller'

import SidebarController from './sidebar_controller'

import SidebarGroupController from './sidebar_group_controller'
application.register('alert', AlertController)
application.register('autosave', AutosaveController)
application.register('disable-form', DisableFormController)
application.register('dismiss', DismissController)
application.register('extended-nested-form', ExtendedNestedFormController)
application.register('hello', HelloController)
application.register('icon-toggle', IconToggleController)
application.register('multiple-select', MultipleSelectController)
application.register('navbar', NavbarController)
application.register('select-all', SelectAllController)
application.register('sidebar', SidebarController)
application.register('sidebar-group', SidebarGroupController)
75 changes: 75 additions & 0 deletions app/javascript/controllers/select_all_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { Controller } from '@hotwired/stimulus'

// Connects to data-controller="select-all"
export default class extends Controller {
static targets = ['checkboxAll', 'checkbox', 'button', 'buttonLabel']
static values = {
allChecked: { type: Boolean, default: false },
buttonLabel: { type: String }
}

static classes = ['hidden']

toggleAll () {
this.allCheckedValue = !this.allCheckedValue

this.checkboxTargets.forEach(checkbox => {
checkbox.checked = this.allCheckedValue
})

this.toggleButton()
}

toggleSingle () {
this.toggleCheckedAll()
this.toggleButton()
}

toggleCheckedAll () {
const numChecked = this.getNumberChecked()
const numTotal = this.getTotalCheckboxes()

this.allCheckedValue = numChecked === numTotal
this.checkboxAllTarget.checked = this.allCheckedValue

if (numChecked === 0) {
this.checkboxAllTarget.indeterminate = false
} else {
this.checkboxAllTarget.indeterminate = numChecked < numTotal
}
}

toggleButton () {
if (this.hasButtonTarget) {
const numChecked = this.getNumberChecked()
if (numChecked > 0) {
this.setButtonLabel(numChecked)

this.buttonTarget.classList.remove(this.hiddenClass)
} else {
this.buttonTarget.classList.add(this.hiddenClass)
}
}
}

setButtonLabel (numChecked) {
if (this.hasButtonLabelTarget) {
let label = this.buttonLabelValue

if (numChecked > 1) {
label += 's'
}
label += ' (' + numChecked + ')'

this.buttonLabelTarget.innerHTML = label
}
}

getNumberChecked () {
return this.checkboxTargets.filter((checkbox) => checkbox.checked).length
}

getTotalCheckboxes () {
return this.checkboxTargets.length
}
}
17 changes: 14 additions & 3 deletions app/javascript/src/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,19 @@ $(() => { // JQuery's callback for the DOM loading
}
})
},
order: [[6, 'desc']],
order: [[7, 'desc']],
columns: [
{
data: 'id',
targets: 0,
searchable: false,
orderable: false,
render: (data, type, row, meta) => {
return `
<input type="checkbox" name="supervisor_volunteer[volunteer_ids][]" id="supervisor_volunteer_volunteer_ids_${row.id}" value="${row.id}" class="form-check-input" data-select-all-target="checkbox" data-action="select-all#toggleSingle">
`
}
},
{
name: 'display_name',
render: (data, type, row, meta) => {
Expand Down Expand Up @@ -248,10 +259,10 @@ $(() => { // JQuery's callback for the DOM loading
render: (data, type, row, meta) => {
return `
<span class="mobile-label">Actions</span>
<a href="${editVolunteerPath(row.id)}" class="btn btn-primary">
<a href="${editVolunteerPath(row.id)}" class="btn btn-primary text-white">
Edit
</a>
<a href="${impersonateVolunteerPath(row.id)}" class="btn btn-secondary">
<a href="${impersonateVolunteerPath(row.id)}" class="btn btn-secondary text-white">
Impersonate
</a>
`
Expand Down
2 changes: 1 addition & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def no_attempt_for_two_weeks
if volunteer.supervisor.active? &&
volunteer.case_assignments.any? { |assignment| assignment.active? } &&
(volunteer.case_contacts.none? ||
volunteer.case_contacts.maximum(:occurred_at) < (Time.zone.now - 14.days))
volunteer.case_contacts.maximum(:created_at) < (Time.zone.now - 14.days))

no_attempt_count += 1
end
Expand Down
Loading

0 comments on commit 27ea13b

Please sign in to comment.