From 5ded4008c725a5446d5390670405d090e0e78ec7 Mon Sep 17 00:00:00 2001 From: Adrian Hopek Date: Fri, 25 Feb 2022 10:29:45 +0100 Subject: [PATCH] wip --- .../Http/Controllers/DashboardController.php | 116 +++++ .../Http/Resources/AbsenceResource.php | 22 + package-lock.json | 4 +- package.json | 2 +- resources/js/Pages/Dashboard.vue | 434 ++++++------------ resources/js/Shared/Layout/AppLayout.vue | 2 +- resources/js/Shared/VacationChart.vue | 81 ++++ routes/web.php | 3 +- 8 files changed, 373 insertions(+), 291 deletions(-) create mode 100644 app/Infrastructure/Http/Controllers/DashboardController.php create mode 100644 app/Infrastructure/Http/Resources/AbsenceResource.php create mode 100644 resources/js/Shared/VacationChart.vue diff --git a/app/Infrastructure/Http/Controllers/DashboardController.php b/app/Infrastructure/Http/Controllers/DashboardController.php new file mode 100644 index 0000000..59291af --- /dev/null +++ b/app/Infrastructure/Http/Controllers/DashboardController.php @@ -0,0 +1,116 @@ +with(["user", "vacationRequest"]) + ->whereDate("date", Carbon::now()) + ->whereRelation( + "vacationRequest", + fn(Builder $query) => $query->states(VacationRequestState::successStates()) + ) + ->get(); + + $vacationRequests = VacationRequest::query() + ->latest("updated_at") + ->limit(3) + ->get(); + + $holidays = Holiday::query() + ->whereDate("date", ">=", Carbon::now()) + ->latest() + ->limit(3) + ->get(); + + $limit = $request->user() + ->vacationLimits() + ->where("year_period_id", $this->yearPeriodRetriever->current()->id) + ->first() + ->days ?? 0; + + $used = $request->user() + ->vacations() + ->whereRelation( + "vacationRequest", + fn(Builder $query) => $query + ->whereIn("type", $this->getLimitableVacationTypes()) + ->noStates(VacationRequestState::successStates()), + ) + ->count(); + + $pending = $request->user() + ->vacations() + ->whereRelation( + "vacationRequest", + fn(Builder $query) => $query + ->whereIn("type", $this->getLimitableVacationTypes()) + ->noStates(VacationRequestState::pendingStates()), + ) + ->count(); + + $other = $request->user() + ->vacations() + ->whereRelation( + "vacationRequest", + fn(Builder $query) => $query + ->whereIn("type", $this->getNotLimitableVacationTypes()) + ->noStates(VacationRequestState::successStates()), + ) + ->count(); + + return inertia("Dashboard", [ + "absences" => AbsenceResource::collection($absences), + "vacationRequests" => VacationRequestResource::collection($vacationRequests), + "holidays" => HolidayResource::collection($holidays), + "stats" => [ + "limit" => $limit, + "remaining" => $limit - $used - $pending, + "used" => $used, + "pending" => $pending, + "other" => $other, + ], + ]); + } + + protected function getLimitableVacationTypes(): Collection + { + $types = new Collection(VacationType::cases()); + + return $types->filter(fn(VacationType $type) => $this->configRetriever->hasLimit($type)); + } + + protected function getNotLimitableVacationTypes(): Collection + { + $types = new Collection(VacationType::cases()); + + return $types->filter(fn(VacationType $type) => !$this->configRetriever->hasLimit($type)); + } +} diff --git a/app/Infrastructure/Http/Resources/AbsenceResource.php b/app/Infrastructure/Http/Resources/AbsenceResource.php new file mode 100644 index 0000000..519ef40 --- /dev/null +++ b/app/Infrastructure/Http/Resources/AbsenceResource.php @@ -0,0 +1,22 @@ + $this->id, + "user" => new UserResource($this->user), + "date" => $this->date->toDisplayString(), + "cause" => $this->vacationRequest->type, + ]; + } +} diff --git a/package-lock.json b/package-lock.json index 1d8d8f7..8994c3c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "application", + "name": "toby", "lockfileVersion": 2, "requires": true, "packages": { @@ -16,7 +16,7 @@ "@vue/compiler-sfc": "^3.2.26", "autoprefixer": "^10.4.2", "axios": "^0.25.0", - "echarts": "^5.2.2", + "echarts": "^5.3.0", "flatpickr": "^4.6.9", "laravel-mix": "^6.0.6", "lodash": "^4.17.21", diff --git a/package.json b/package.json index 9588eff..f35c216 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@vue/compiler-sfc": "^3.2.26", "autoprefixer": "^10.4.2", "axios": "^0.25.0", - "echarts": "^5.2.2", + "echarts": "^5.3.0", "flatpickr": "^4.6.9", "laravel-mix": "^6.0.6", "lodash": "^4.17.21", diff --git a/resources/js/Pages/Dashboard.vue b/resources/js/Pages/Dashboard.vue index 9051660..0587ba2 100644 --- a/resources/js/Pages/Dashboard.vue +++ b/resources/js/Pages/Dashboard.vue @@ -1,17 +1,9 @@ diff --git a/routes/web.php b/routes/web.php index a94d8aa..154523e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,6 +3,7 @@ declare(strict_types=1); use Illuminate\Support\Facades\Route; +use Toby\Infrastructure\Http\Controllers\DashboardController; use Toby\Infrastructure\Http\Controllers\GoogleController; use Toby\Infrastructure\Http\Controllers\HolidayController; use Toby\Infrastructure\Http\Controllers\LogoutController; @@ -14,7 +15,7 @@ use Toby\Infrastructure\Http\Controllers\VacationLimitController; use Toby\Infrastructure\Http\Controllers\VacationRequestController; Route::middleware("auth")->group(function (): void { - Route::get("/", fn() => inertia("Dashboard")) + Route::get("/", DashboardController::class) ->name("dashboard"); Route::post("/logout", LogoutController::class);