From 1d7812fddd8eb120c7a4479a07c288e73c796a16 Mon Sep 17 00:00:00 2001 From: Kamil Piech Date: Wed, 27 Mar 2024 10:53:06 +0100 Subject: [PATCH] #327 - handy calendar (#411) * #327 - added handy calendar on request show view, moved them into component also * #327 - added handy calendar * #327 - update * #327 - hidden calendar for employee * #327 - csf * #327 - cr fix --- .../Controllers/VacationRequestController.php | 50 ++++- resources/js/Pages/AnnualSummary.vue | 186 +---------------- resources/js/Pages/VacationRequest/Show.vue | 23 +++ resources/js/Shared/CalendarComponent.vue | 189 ++++++++++++++++++ resources/js/Shared/LastUpdate.vue | 4 + 5 files changed, 273 insertions(+), 179 deletions(-) create mode 100644 resources/js/Shared/CalendarComponent.vue diff --git a/app/Infrastructure/Http/Controllers/VacationRequestController.php b/app/Infrastructure/Http/Controllers/VacationRequestController.php index 4f7736b7..ce7302b9 100644 --- a/app/Infrastructure/Http/Controllers/VacationRequestController.php +++ b/app/Infrastructure/Http/Controllers/VacationRequestController.php @@ -23,10 +23,13 @@ use Toby\Domain\VacationRequestStatesRetriever; use Toby\Domain\VacationTypeConfigRetriever; use Toby\Eloquent\Helpers\YearPeriodRetriever; +use Toby\Eloquent\Models\Holiday; use Toby\Eloquent\Models\User; +use Toby\Eloquent\Models\Vacation; use Toby\Eloquent\Models\VacationRequest; use Toby\Infrastructure\Http\Requests\VacationRequestRequest; use Toby\Infrastructure\Http\Resources\SimpleUserResource; +use Toby\Infrastructure\Http\Resources\SimpleVacationRequestResource; use Toby\Infrastructure\Http\Resources\VacationRequestActivityResource; use Toby\Infrastructure\Http\Resources\VacationRequestResource; @@ -127,8 +130,11 @@ public function indexForApprovers( /** * @throws AuthorizationException */ - public function show(VacationRequest $vacationRequest, UserVacationStatsRetriever $statsRetriever): Response - { + public function show( + VacationRequest $vacationRequest, + UserVacationStatsRetriever $statsRetriever, + YearPeriodRetriever $yearPeriodRetriever, + ): Response { $this->authorize("show", $vacationRequest); $vacationRequest->load(["vacations.user.profile", "user.permissions", "user.profile", "activities.user.profile"]); @@ -137,6 +143,29 @@ public function show(VacationRequest $vacationRequest, UserVacationStatsRetrieve $pending = $statsRetriever->getPendingVacationDays($vacationRequest->user, $vacationRequest->yearPeriod); $remaining = $limit - $used - $pending; + $yearPeriod = $yearPeriodRetriever->selected(); + $requestFromDateMonth = $vacationRequest->from->month; + $requestToDateMonth = $vacationRequest->to->month; + + $holidays = $yearPeriod->holidays() + ->get(); + + $user = $vacationRequest->user; + + $vacations = $user + ->vacations() + ->with("vacationRequest.vacations") + ->whereBelongsTo($yearPeriod) + ->approved() + ->get(); + + $pendingVacations = $user + ->vacations() + ->with("vacationRequest.vacations") + ->whereBelongsTo($yearPeriod) + ->pending() + ->get(); + return inertia("VacationRequest/Show", [ "request" => new VacationRequestResource($vacationRequest), "activities" => VacationRequestActivityResource::collection($vacationRequest->activities), @@ -146,6 +175,23 @@ public function show(VacationRequest $vacationRequest, UserVacationStatsRetrieve "pending" => $pending, "remaining" => $remaining, ], + "handyCalendarData" => [ + "holidays" => $holidays->mapWithKeys( + fn(Holiday $holiday): array => [$holiday->date->toDateString() => $holiday->name], + ), + "vacations" => $vacations->mapWithKeys( + fn(Vacation $vacation): array => [ + $vacation->date->toDateString() => new SimpleVacationRequestResource($vacation->vacationRequest), + ], + ), + "pendingVacations" => $pendingVacations->mapWithKeys( + fn(Vacation $vacation): array => [ + $vacation->date->toDateString() => new SimpleVacationRequestResource($vacation->vacationRequest), + ], + ), + "startMonth" => $requestFromDateMonth > 1 ? --$requestFromDateMonth : 1, + "endMonth" => $requestToDateMonth < 12 ? ++$requestToDateMonth : 12, + ], ]); } diff --git a/resources/js/Pages/AnnualSummary.vue b/resources/js/Pages/AnnualSummary.vue index c91702dd..ca75bde6 100644 --- a/resources/js/Pages/AnnualSummary.vue +++ b/resources/js/Pages/AnnualSummary.vue @@ -1,83 +1,12 @@ diff --git a/resources/js/Pages/VacationRequest/Show.vue b/resources/js/Pages/VacationRequest/Show.vue index 212b636d..e754d5ec 100644 --- a/resources/js/Pages/VacationRequest/Show.vue +++ b/resources/js/Pages/VacationRequest/Show.vue @@ -4,12 +4,14 @@ import Activity from '@/Shared/Activity.vue' import Status from '@/Shared/Status.vue' import VacationType from '@/Shared/VacationType.vue' import VacationBar from '@/Shared/VacationBar.vue' +import CalendarComponent from '@/Shared/CalendarComponent.vue' defineProps({ request: Object, activities: Object, stats: Object, auth: Object, + handyCalendarData: Object, }) @@ -271,6 +273,27 @@ defineProps({ +
+
+

+ Kalendarz pracownika +

+
+
+ +
+
diff --git a/resources/js/Shared/CalendarComponent.vue b/resources/js/Shared/CalendarComponent.vue new file mode 100644 index 00000000..1ce458d5 --- /dev/null +++ b/resources/js/Shared/CalendarComponent.vue @@ -0,0 +1,189 @@ + + + diff --git a/resources/js/Shared/LastUpdate.vue b/resources/js/Shared/LastUpdate.vue index 82377be0..1cef1491 100644 --- a/resources/js/Shared/LastUpdate.vue +++ b/resources/js/Shared/LastUpdate.vue @@ -26,3 +26,7 @@ onMounted(() => { setInterval(fetchLastUpdate, import.meta.env.VITE_LAST_UPDATE_TIMEOUT) }) + +