Skip to content

Commit

Permalink
leave report: add filter for dept employee appt status (#206)
Browse files Browse the repository at this point in the history
  • Loading branch information
jxjj authored Sep 13, 2024
1 parent 72b3373 commit 196afe7
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 19 deletions.
6 changes: 3 additions & 3 deletions app/Http/Controllers/CoursePlanning/GroupPersonController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Http\Controllers\Controller;
use App\Group;
use App\Http\Resources\PersonResource;
use App\Http\Resources\DeptInstructorResource;
use Illuminate\Http\Request;
use App\Library\Bandaid;
use App\Library\UserService;
Expand All @@ -23,8 +23,8 @@ public function __construct(Bandaid $bandaid, UserService $userService) {
public function index(Request $request, Group $group) {
abort_unless($request->user()->can(Permissions::VIEW_PLANNED_COURSES) || $request->user()->managesGroup($group), 403);

$users = $this->userService->getDeptInstructors($group->dept_id);
$allDeptInstructors = $this->userService->getDeptInstructors($group->dept_id);

return PersonResource::collection($users);
return DeptInstructorResource::collection($allDeptInstructors);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Http\Resources\Json\JsonResource;
use App\Library\Utilities;

class PersonResource extends JsonResource {
class DeptInstructorResource extends JsonResource {
/**
* Transform the resource into an array.
*
Expand All @@ -22,6 +22,7 @@ public function toArray($request) {
'title' => $this->title,
'leaveIds' => $this->leaveIds,
'academicAppointment' => Utilities::trimWithFallback($this->jobCategory),
'hasActiveDeptAppointment' => $this->hasActiveDeptAppointment,
'jobCode' => $this->jobCode,
'emplid' => $this->emplid,
'sslEligible' => $this->ssl_eligible,
Expand Down
19 changes: 13 additions & 6 deletions app/Library/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,17 +142,24 @@ public function getDeptInstructors(string $deptId, array $options = []): Collect

// get employee info from bandaid for job code and category
// note: only active employees will have a job code
$activeDeptEmployees = $this->bandaid->getEmployees($allDeptEmplids);
$allDeptInstructors = $this->bandaid->getEmployees($allDeptEmplids);

$allDeptInstructorLookup = collect($allDeptInstructors)->keyBy('EMPLID');

// get active employees for dept
$activeDeptEmployees = collect($this->bandaid->getEmployeesForDepartment($deptId))
->keyBy('EMPLID');

$activeDeptEmployeeLookup = collect($activeDeptEmployees)->keyBy('EMPLID');

$instructors = $this
->findOrCreateManyByEmplId($allDeptEmplids)
->map(function ($user) use ($activeDeptEmployeeLookup) {
$activeDeptEmployee = $activeDeptEmployeeLookup->get($user->emplid) ?? null;
->map(function ($user) use ($allDeptInstructorLookup, $activeDeptEmployees) {
$instructor = $allDeptInstructorLookup->get($user->emplid) ?? null;

$user->hasActiveDeptAppointment = $activeDeptEmployees->has($user->emplid);

$user->jobCategory = $activeDeptEmployee?->CATEGORY ?? null;
$user->jobCode = $activeDeptEmployee?->JOBCODE ?? null;
$user->jobCategory = $instructor?->CATEGORY ?? null;
$user->jobCode = $instructor?->JOBCODE ?? null;
return $user;
})
->values();
Expand Down
7 changes: 7 additions & 0 deletions resources/js/pages/CoursePlanningPage/CoursePlanningPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,13 @@ function handleTabChange(tab: Tab) {
setTimeout(() => {
coursePlanningStore.setIncludedEnrollmentRoles(tabRoleLookup[tab.id]);
// the default active appointment filter will mean that no TA's are shown
// so we need to change it to show all appointments if the tab is the TA tab
// not sure if this is the best way to do this... but it works
if (tab.id === "tas") {
coursePlanningStore.filters.onlyActiveAppointments = false;
}
}, 0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,14 +124,35 @@
<span class="tw-text-neutral-400 tw-text-xs ml-1">({{ count }})</span>
</label>
</fieldset>
<fieldset>
<div class="tw-flex tw-items-baseline tw-mb-1">
<legend
class="tw-uppercase tw-text-xs tw-text-neutral-500 tw-tracking-wide tw-font-semibold tw-my-1"
>
Minimum Enrollment
</legend>
</div>
<fieldset class="tw-flex tw-flex-col tw-text-sm tw-mt-1.5">
<legend
class="tw-uppercase tw-text-xs tw-text-neutral-500 tw-tracking-wide tw-font-semibold"
>
Appointment Status
</legend>
<label :class="{ active: filters.onlyActiveAppointments }">
<input
v-model="filters.onlyActiveAppointments"
type="radio"
:value="true"
/>
Active
</label>
<label :class="{ active: !filters.onlyActiveAppointments }">
<input
v-model="filters.onlyActiveAppointments"
type="radio"
:value="false"
/>
All
</label>
</fieldset>
<fieldset class="tw-mt-1.5">
<legend
class="tw-uppercase tw-text-xs tw-text-neutral-500 tw-tracking-wide tw-font-semibold tw-my-1"
>
Minimum Enrollment
</legend>
<InputGroup
v-model="minSectionEnrollmentRaw"
label="Minimum Enrollment"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const useCoursePlanningStore = defineStore("coursePlanning", () => {
excludedCourseLevels: new Set(),
excludedAcadAppts: new Set(),
includedEnrollmentRoles: new Set(["PI"]),
onlyActiveAppointments: true,
minSectionEnrollment: 0,
search: "",
},
Expand Down Expand Up @@ -205,7 +206,9 @@ export const useCoursePlanningStore = defineStore("coursePlanning", () => {
const isPersonVisibleLookupByEmplId: Record<T.Person["emplid"], boolean> =
{};

const people = stores.personStore.allPeople;
const people = state.filters.onlyActiveAppointments
? stores.personStore.peopleWithActiveAppointments
: stores.personStore.allPeople;

people.forEach((person) => {
const hasVisibleRole = methods.isPersonEnrolledWithVisibleRole(person);
Expand Down Expand Up @@ -730,6 +733,7 @@ export const useCoursePlanningStore = defineStore("coursePlanning", () => {
excludedCourseLevels: new Set(),
excludedAcadAppts: new Set(),
includedEnrollmentRoles: new Set(["PI"]),
onlyActiveAppointments: true,
minSectionEnrollment: 0,
search: "",
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export const usePersonStore = defineStore("person", () => {
) as T.Person[];
return people.sort(sortByName);
}),
peopleWithActiveAppointments: computed((): T.Person[] => {
return getters.allPeople.value.filter((p) => p.hasActiveDeptAppointment);
}),
getPersonByEmplId: computed(
() =>
(emplId: T.Person["emplid"]): T.Person | null => {
Expand Down
2 changes: 2 additions & 0 deletions resources/js/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ export interface Person {
emplid: number;
title: string;
jobCode: string;
hasActiveDeptAppointment: boolean;
givenName: string;
surName: string;
displayName: string;
Expand Down Expand Up @@ -380,6 +381,7 @@ export interface CoursePlanningFilters {
excludedAcadAppts: Set<string>;
minSectionEnrollment: number;
includedEnrollmentRoles: Set<EnrollmentRole>;
onlyActiveAppointments: boolean;
search: string;
inPlanningMode: boolean;
}
Expand Down
4 changes: 4 additions & 0 deletions tests/Feature/api/users/leaves/GetAllUserLeavesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@

$BANDAID_API = config('bandaid.baseUri');
Http::fake([
// mock the getEmployeesForDept response, needed for checking
// whether the instructor has an active status
"{$BANDAID_API}/department/*/employees" => mockResponse("Bandaid/mockGetEmployeesForDept.json"),

// Now, put the $instructor1 in the mock
// reponse for getEmployeesForDept($deptId)
"{$BANDAID_API}/classes/list/{$deptId}" => Http::response([
Expand Down

0 comments on commit 196afe7

Please sign in to comment.