From de797c97b7c13d30b8d186a6984d92e83eb73b47 Mon Sep 17 00:00:00 2001 From: Kamil Date: Thu, 11 Jul 2024 14:01:21 +0200 Subject: [PATCH 1/3] #456 - feat: added user profile page, wip --- app/Http/Controllers/UserController.php | 45 ++++++ resources/js/Pages/Calendar.vue | 40 +++-- resources/js/Pages/Dashboard.vue | 4 +- resources/js/Pages/MonthlyUsage.vue | 36 +++-- resources/js/Pages/Users/Index.vue | 128 +++++++++------- resources/js/Pages/Users/Show.vue | 144 ++++++++++++++++++ resources/js/Pages/VacationLimits.vue | 82 +++++----- resources/js/Shared/Widgets/BenefitList.vue | 3 +- .../Shared/Widgets/UserOvertimeRequests.vue | 79 ++++++++++ .../Shared/Widgets/UserVacationRequests.vue | 3 +- routes/web.php | 2 + 11 files changed, 446 insertions(+), 120 deletions(-) create mode 100644 resources/js/Pages/Users/Show.vue create mode 100644 resources/js/Shared/Widgets/UserOvertimeRequests.vue diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 72e81526..ed2a21ee 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -11,11 +11,18 @@ use Toby\Actions\CreateUserAction; use Toby\Actions\SyncUserPermissionsWithRoleAction; use Toby\Actions\UpdateUserAction; +use Toby\Domain\DashboardAggregator; use Toby\Enums\EmploymentForm; use Toby\Enums\Role; +use Toby\Helpers\YearPeriodRetriever; use Toby\Http\Requests\UserRequest; +use Toby\Http\Resources\BirthdayResource; +use Toby\Http\Resources\EquipmentItemResource; +use Toby\Http\Resources\OvertimeRequestResource; use Toby\Http\Resources\UserFormDataResource; use Toby\Http\Resources\UserResource; +use Toby\Http\Resources\VacationRequestResource; +use Toby\Models\EquipmentItem; use Toby\Models\User; class UserController extends Controller @@ -142,4 +149,42 @@ public function restore(User $user): RedirectResponse return back() ->with("success", __("User restored.")); } + + public function show( + User $user, + YearPeriodRetriever $yearPeriodRetriever, + DashboardAggregator $dashboardAggregator, + ): Response { + $this->authorize("manageUsers"); + + $yearPeriod = $yearPeriodRetriever->selected(); + $equipment = EquipmentItem::query() + ->with("assignee") + ->where("assignee_id", $user->id) + ->get(); + $vacationRequests = $user->vacationRequests() + ->with(["user", "vacations", "vacations.user", "vacations.user.profile", "user.permissions", "user.profile"]) + ->whereBelongsTo($yearPeriod) + ->latest("updated_at") + ->limit(2) + ->get(); + $overtimeRequests = $user->overtimeRequests() + ->with(["user", "user.profile", "user.permissions"]) + ->whereBelongsTo($yearPeriod) + ->latest("updated_at") + ->limit(2) + ->get(); + + return inertia("Users/Show", [ + "user" => new UserResource($user), + "vacationRequests" => VacationRequestResource::collection($vacationRequests), + "overtimeRequests" => OvertimeRequestResource::collection($overtimeRequests), + "benefits" => $dashboardAggregator->aggregateUserBenefits($user), + "calendar" => $dashboardAggregator->aggregateCalendarData($user, $yearPeriod), + "stats" => $dashboardAggregator->aggregateStats($user, $yearPeriod), + "equipmentItems" => EquipmentItemResource::collection($equipment), + "upcomingBirthday" => new BirthdayResource($user), + "seniority" => $user->seniority(), + ]); + } } diff --git a/resources/js/Pages/Calendar.vue b/resources/js/Pages/Calendar.vue index 1c53ff43..252fbd32 100644 --- a/resources/js/Pages/Calendar.vue +++ b/resources/js/Pages/Calendar.vue @@ -30,7 +30,7 @@ function isActiveDay(key) { } function setActiveDay(key) { - if(activeElement.value === undefined) + if (activeElement.value === undefined) activeElement.value = key } @@ -42,7 +42,7 @@ function linkParameters(user, day) { return props.auth.can.createRequestsOnBehalfOfEmployee ? { user: user.id, from_date: day.date } : { from_date: day.date } } -function linkVacationRequest(user){ +function linkVacationRequest(user) { return props.auth.user.id === user.id || props.auth.can.manageRequestsAsTechnicalApprover || props.auth.can.manageRequestsAsAdministrativeApprover } @@ -58,8 +58,8 @@ function linkVacationRequest(user){
@@ -72,16 +72,16 @@ function linkVacationRequest(user){ @@ -125,9 +125,9 @@ function linkVacationRequest(user){
{{ day.dayOfMonth }} @@ -144,7 +144,25 @@ function linkVacationRequest(user){ :key="user.id" > -
+ +
+ + + +
+
+ {{ user.name }} +
+
+
+
+
@@ -158,26 +176,26 @@ function linkVacationRequest(user){
diff --git a/resources/js/Shared/Widgets/BenefitList.vue b/resources/js/Shared/Widgets/BenefitList.vue index 2beb59fa..203ad33b 100644 --- a/resources/js/Shared/Widgets/BenefitList.vue +++ b/resources/js/Shared/Widgets/BenefitList.vue @@ -4,6 +4,7 @@ import { GiftIcon } from '@heroicons/vue/24/solid' defineProps({ benefits: Object, + label: String, }) @@ -11,7 +12,7 @@ defineProps({

- Moje benefity + {{ label }}

diff --git a/resources/js/Shared/Widgets/UserOvertimeRequests.vue b/resources/js/Shared/Widgets/UserOvertimeRequests.vue new file mode 100644 index 00000000..aa0b9ed5 --- /dev/null +++ b/resources/js/Shared/Widgets/UserOvertimeRequests.vue @@ -0,0 +1,79 @@ + + + diff --git a/resources/js/Shared/Widgets/UserVacationRequests.vue b/resources/js/Shared/Widgets/UserVacationRequests.vue index 8e5edee1..46b11d61 100644 --- a/resources/js/Shared/Widgets/UserVacationRequests.vue +++ b/resources/js/Shared/Widgets/UserVacationRequests.vue @@ -6,6 +6,7 @@ import { RectangleStackIcon } from '@heroicons/vue/24/solid' defineProps({ requests: Object, + label: String, }) @@ -14,7 +15,7 @@ defineProps({

- Moje wnioski + {{ label }}

diff --git a/routes/web.php b/routes/web.php index e00af083..53aa1a9d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -41,6 +41,8 @@ Route::resource("users", UserController::class) ->except("show") ->whereNumber("user"); + Route::get("/users/{user}", [UserController::class, "show"]) + ->whereNumber("user"); Route::post("/users/{user}/restore", [UserController::class, "restore"]) ->whereNumber("user") ->withTrashed(); From 6657f2c2fb198a5673bd91bab5b966ec8670f51d Mon Sep 17 00:00:00 2001 From: Kamil Date: Fri, 12 Jul 2024 10:24:00 +0200 Subject: [PATCH 2/3] #456 - feat: added user profile page and links around the whole app --- .../AssignedBenefits/AssignedBenefits.vue | 83 ++++++++++------- resources/js/Pages/BenefitsReport/Show.vue | 54 ++++++----- resources/js/Pages/Calendar.vue | 21 +---- resources/js/Pages/EmployeesMilestones.vue | 55 +++++------ resources/js/Pages/Equipment/Index.vue | 83 +++++++++-------- resources/js/Pages/Keys.vue | 91 +++++++++++-------- resources/js/Pages/MonthlyUsage.vue | 7 +- resources/js/Pages/Resumes/Index.vue | 81 ++++++++++------- resources/js/Pages/Users/Index.vue | 7 +- resources/js/Pages/VacationLimits.vue | 7 +- resources/js/Pages/VacationRequest/Show.vue | 56 +++++++----- resources/js/Shared/UserProfileLink.vue | 24 +++++ resources/js/Shared/Widgets/AbsenceList.vue | 46 ++++++---- resources/js/Shared/Widgets/BirthdaysList.vue | 34 ++++--- .../js/Shared/Widgets/RemoteWorkList.vue | 50 +++++----- routes/web.php | 1 + 16 files changed, 403 insertions(+), 297 deletions(-) create mode 100644 resources/js/Shared/UserProfileLink.vue diff --git a/resources/js/Pages/AssignedBenefits/AssignedBenefits.vue b/resources/js/Pages/AssignedBenefits/AssignedBenefits.vue index 78d1d480..2bb79b7a 100644 --- a/resources/js/Pages/AssignedBenefits/AssignedBenefits.vue +++ b/resources/js/Pages/AssignedBenefits/AssignedBenefits.vue @@ -5,6 +5,7 @@ import TextArea from '@/Shared/Forms/TextArea.vue' import { computed, ref, watch } from 'vue' import { useForm } from '@inertiajs/inertia-vue3' import { debounce } from 'lodash' +import UserProfileLink from '@/Shared/UserProfileLink.vue' const props = defineProps({ current: String, @@ -22,7 +23,10 @@ const currentMonth = computed(() => findMonth(props.current)) const form = useForm({ items: props.users.data.map((user) => { - const item = props.assignedBenefits.data ? props.assignedBenefits.data.find((assignedBenefit) => assignedBenefit.user === user.id) : { benefits: [], comment: null } + const item = props.assignedBenefits.data ? props.assignedBenefits.data.find((assignedBenefit) => assignedBenefit.user === user.id) : { + benefits: [], + comment: null, + } return { user: user, @@ -32,8 +36,8 @@ const form = useForm({ return { id: benefit.id, - employee: typeof assignedBenefit !== 'undefined' && assignedBenefit.employee ? assignedBenefit.employee/100 : null, - employer: typeof assignedBenefit !== 'undefined' && assignedBenefit.employer ? assignedBenefit.employer/100 : null, + employee: typeof assignedBenefit !== 'undefined' && assignedBenefit.employee ? assignedBenefit.employee / 100 : null, + employer: typeof assignedBenefit !== 'undefined' && assignedBenefit.employer ? assignedBenefit.employer / 100 : null, } }), } @@ -55,8 +59,8 @@ function submitAssignedBenefits() { user: item.user.id, benefits: item.benefits.map((benefit) => ({ id: benefit.id, - employee: benefit.employee ? benefit.employee*100 : null, - employer: benefit.employer ? benefit.employer*100 : null, + employee: benefit.employee ? benefit.employee * 100 : null, + employer: benefit.employer ? benefit.employer * 100 : null, })), comment: item.comment, } @@ -64,24 +68,28 @@ function submitAssignedBenefits() { })) .put('/assigned-benefits') } + function startCreatingBenefitsReport() { formBenefitsReport.name = `${currentMonth.value.name} ${props.years.selected.year}` creatingBenefitsReport.value = true } + function submitCreateBenefitsReport() { formBenefitsReport.post('/benefits-reports') } + function calculateSumOfBenefits(benefits) { let sum = 0 - for(const benefit of benefits){ - if(benefit.employer){ - sum += benefit.employer*100 + for (const benefit of benefits) { + if (benefit.employer) { + sum += benefit.employer * 100 } } return (new Intl.NumberFormat('pl-PL', { style: 'currency', currency: 'PLN' })).format(sum / 100) } + function isBenefitHasCompanion(benefitId) { return props.benefits.data.find((benefit) => benefit.id === benefitId && benefit.companion === true) } @@ -98,10 +106,10 @@ function isBenefitHasCompanion(benefitId) {
@@ -247,8 +260,8 @@ function isBenefitHasCompanion(benefitId) {
@@ -301,9 +314,9 @@ function isBenefitHasCompanion(benefitId) {

diff --git a/resources/js/Pages/BenefitsReport/Show.vue b/resources/js/Pages/BenefitsReport/Show.vue index d7ccb9a6..289f3bae 100644 --- a/resources/js/Pages/BenefitsReport/Show.vue +++ b/resources/js/Pages/BenefitsReport/Show.vue @@ -1,5 +1,6 @@ + + diff --git a/resources/js/Shared/Widgets/AbsenceList.vue b/resources/js/Shared/Widgets/AbsenceList.vue index 50f46aff..47c901ed 100644 --- a/resources/js/Shared/Widgets/AbsenceList.vue +++ b/resources/js/Shared/Widgets/AbsenceList.vue @@ -1,7 +1,8 @@ @@ -82,11 +89,19 @@ defineProps({ class="mt-6" > Zobacz wszystkie + + Zobacz wszystkie +