Compare commits
5 Commits
d681cec9a6
...
94f433de6e
Author | SHA1 | Date | |
---|---|---|---|
94f433de6e | |||
a9c476cb8e | |||
5c3833d4cb | |||
6e627d11c8 | |||
eb644fa494 |
@ -12,8 +12,11 @@ use Toby\Domain\UserVacationStatsRetriever;
|
||||
use Toby\Domain\VacationRequestStatesRetriever;
|
||||
use Toby\Domain\VacationTypeConfigRetriever;
|
||||
use Toby\Eloquent\Helpers\YearPeriodRetriever;
|
||||
use Toby\Eloquent\Models\Holiday;
|
||||
use Toby\Eloquent\Models\Vacation;
|
||||
use Toby\Eloquent\Models\VacationRequest;
|
||||
use Toby\Infrastructure\Http\Resources\HolidayResource;
|
||||
use Toby\Infrastructure\Http\Resources\SimpleVacationRequestResource;
|
||||
use Toby\Infrastructure\Http\Resources\VacationRequestResource;
|
||||
use Toby\Infrastructure\Http\Resources\VacationResource;
|
||||
|
||||
@ -54,6 +57,22 @@ class DashboardController extends Controller
|
||||
->limit(3)
|
||||
->get();
|
||||
|
||||
$allHolidays = $yearPeriod->holidays;
|
||||
|
||||
$approvedVacations = $request->user()
|
||||
->vacations()
|
||||
->with("vacationRequest.vacations")
|
||||
->whereBelongsTo($yearPeriod)
|
||||
->approved()
|
||||
->get();
|
||||
|
||||
$pendingVacations = $request->user()
|
||||
->vacations()
|
||||
->with("vacationRequest.vacations")
|
||||
->whereBelongsTo($yearPeriod)
|
||||
->pending()
|
||||
->get();
|
||||
|
||||
$limit = $vacationStatsRetriever->getVacationDaysLimit($user, $yearPeriod);
|
||||
$used = $vacationStatsRetriever->getUsedVacationDays($user, $yearPeriod);
|
||||
$pending = $vacationStatsRetriever->getPendingVacationDays($user, $yearPeriod);
|
||||
@ -66,6 +85,19 @@ class DashboardController extends Controller
|
||||
"remoteDays" => VacationResource::collection($remoteDays),
|
||||
"vacationRequests" => VacationRequestResource::collection($vacationRequests),
|
||||
"holidays" => HolidayResource::collection($holidays),
|
||||
"allHolidays" => $allHolidays->mapWithKeys(
|
||||
fn(Holiday $holiday): array => [$holiday->date->toDateString() => $holiday->name],
|
||||
),
|
||||
"approvedVacations" => $approvedVacations->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),
|
||||
],
|
||||
),
|
||||
"stats" => [
|
||||
"limit" => $limit,
|
||||
"remaining" => $remaining,
|
||||
|
@ -3,7 +3,11 @@
|
||||
<div class="grid grid-cols-1 gap-4 items-start xl:grid-cols-3 xl:gap-8">
|
||||
<div class="grid grid-cols-1 gap-4 xl:col-span-2">
|
||||
<Welcome :user="auth.user" />
|
||||
<VacationCalendar />
|
||||
<VacationCalendar
|
||||
:holidays="allHolidays"
|
||||
:approved-vacations="approvedVacations"
|
||||
:pending-vacations="pendingVacations"
|
||||
/>
|
||||
<VacationStats :stats="stats" />
|
||||
</div>
|
||||
<div class="grid grid-cols-1 gap-4">
|
||||
@ -50,5 +54,8 @@ defineProps({
|
||||
can: Object,
|
||||
stats: Object,
|
||||
years: Object,
|
||||
allHolidays: Object,
|
||||
approvedVacations: Object,
|
||||
pendingVacations: Object,
|
||||
})
|
||||
</script>
|
||||
|
104
resources/js/Shared/Widgets/Calendar/DayComponent.vue
Normal file
104
resources/js/Shared/Widgets/Calendar/DayComponent.vue
Normal file
@ -0,0 +1,104 @@
|
||||
<template>
|
||||
<div
|
||||
:class="[ (day.isVacation || day.isPendingVacation) && `border-b-2 border-dashed ${getVacationBorder(day)}` ]"
|
||||
>
|
||||
<Popper
|
||||
v-if="day.isHoliday"
|
||||
as="div"
|
||||
open-delay="200"
|
||||
hover
|
||||
offset-distance="0"
|
||||
@mouseover.passive="onMouseover"
|
||||
@mouseleave="onMouseleave"
|
||||
>
|
||||
<time
|
||||
:datetime="day.date"
|
||||
:class="[ day.isToday && 'flex h-6 w-6 items-center justify-center rounded-full bg-blumilk-500 font-semibold text-white', 'text-red-600' ]"
|
||||
>
|
||||
{{ day.dayNumber }}
|
||||
</time>
|
||||
<template #content>
|
||||
<div class="py-2 px-6 text-sm font-semibold text-left text-gray-700 bg-white rounded-lg border border-gray-400">
|
||||
{{ getHolidayDescription(day) }}
|
||||
</div>
|
||||
</template>
|
||||
</Popper>
|
||||
<Popper
|
||||
v-else-if="day.isPendingVacation"
|
||||
as="div"
|
||||
open-delay="200"
|
||||
hover
|
||||
offset-distance="0"
|
||||
@mouseover.passive="onMouseover"
|
||||
@mouseleave="onMouseleave"
|
||||
>
|
||||
<time
|
||||
:datetime="day.date"
|
||||
:class="[ day.isToday && 'flex h-6 w-6 items-center justify-center rounded-full bg-blumilk-500 font-semibold text-white' ]"
|
||||
>
|
||||
{{ day.dayNumber }}
|
||||
</time>
|
||||
<template #content>
|
||||
<VacationPopup :vacation="getVacationInfo(day)" />
|
||||
</template>
|
||||
</Popper>
|
||||
<div
|
||||
v-else-if="day.isWeekend"
|
||||
>
|
||||
<time
|
||||
:datetime="day.date"
|
||||
:class="{ 'flex h-6 w-6 items-center justify-center rounded-full bg-blumilk-500 font-semibold text-white': day.isToday }"
|
||||
>
|
||||
{{ day.dayNumber }}
|
||||
</time>
|
||||
</div>
|
||||
<InertiaLink
|
||||
v-else
|
||||
href="/vacation/requests/create"
|
||||
:data="{ 'from_date': day.date }"
|
||||
@mouseover.passive="onMouseover"
|
||||
@mouseleave="onMouseleave"
|
||||
>
|
||||
<time
|
||||
:datetime="day.date"
|
||||
:class="{ 'flex h-6 w-6 items-center justify-center rounded-full bg-blumilk-500 font-semibold text-white': day.isToday }"
|
||||
>
|
||||
{{ day.dayNumber }}
|
||||
</time>
|
||||
</InertiaLink>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import Popper from 'vue3-popper'
|
||||
import { defineProps, ref } from 'vue'
|
||||
import VacationPopup from '@/Shared/VacationPopup'
|
||||
|
||||
defineProps({
|
||||
day: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
getHolidayDescription: {
|
||||
type: Function,
|
||||
},
|
||||
getVacationBorder: {
|
||||
type: Function,
|
||||
},
|
||||
getVacationInfo: {
|
||||
type: Function,
|
||||
},
|
||||
})
|
||||
|
||||
const isActive = ref(false)
|
||||
|
||||
function onMouseover() {
|
||||
if (!isActive.value)
|
||||
isActive.value = true
|
||||
}
|
||||
|
||||
function onMouseleave() {
|
||||
if (isActive.value)
|
||||
isActive.value = false
|
||||
}
|
||||
</script>
|
@ -120,19 +120,16 @@
|
||||
class="w-full grid grid-cols-7 gap-px"
|
||||
:class="{ 'grid-rows-1': calendarState.viewMode.isWeek }"
|
||||
>
|
||||
<div
|
||||
<DayComponent
|
||||
v-for="(day, index) in days"
|
||||
:key="index"
|
||||
:day="day"
|
||||
class="flex flex-col relative py-2 px-3"
|
||||
:class="[day.isCurrentMonth ? 'bg-white' : 'bg-gray-50 text-gray-500', { 'hover:bg-blumilk-25': day.isCurrentMonth && !day.isWeekend }, { 'day': calendarState.viewMode.isWeek }, { 'bg-red-100': day.isCurrentMonth && day.isWeekend }, { 'bg-red-50': !day.isCurrentMonth && day.isWeekend }, { 'text-red-800': day.isWeekend }]"
|
||||
>
|
||||
<time
|
||||
:datetime="day.date"
|
||||
:class="{ 'flex h-6 w-6 items-center justify-center rounded-full bg-blumilk-500 font-semibold text-white': day.isToday }"
|
||||
>
|
||||
{{ day.dayNumber }}
|
||||
</time>
|
||||
</div>
|
||||
:get-holiday-description="getHolidayDescription"
|
||||
:get-vacation-border="getVacationBorder"
|
||||
:get-vacation-info="getVacationInfo"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -144,19 +141,30 @@ import { CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon } from '@
|
||||
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue'
|
||||
import { ref, watch, computed, reactive } from 'vue'
|
||||
import { DateTime } from 'luxon'
|
||||
import useVacationTypeInfo from '@/Composables/vacationTypeInfo'
|
||||
import useCurrentYearPeriodInfo from '@/Composables/yearPeriodInfo'
|
||||
import { useMonthInfo } from '@/Composables/monthInfo'
|
||||
import { viewModes, find as findViewMode } from '@/Shared/Widgets/Calendar/ViewModeOptions'
|
||||
import DayComponent from '@/Shared/Widgets/Calendar/DayComponent'
|
||||
|
||||
const props = defineProps({
|
||||
holidays: Object,
|
||||
approvedVacations: Object,
|
||||
pendingVacations: Object,
|
||||
})
|
||||
|
||||
let days = ref([])
|
||||
const months = useMonthInfo().getMonths()
|
||||
|
||||
function getCurrentDate() {
|
||||
const { year, month, weekNumber } = DateTime.now()
|
||||
return { year, month, week: weekNumber }
|
||||
}
|
||||
const selectedYear = useCurrentYearPeriodInfo().year.value
|
||||
const currentDate = getCurrentDate()
|
||||
|
||||
const months = useMonthInfo().getMonths()
|
||||
const { findType } = useVacationTypeInfo()
|
||||
const selectedYear = useCurrentYearPeriodInfo().year.value
|
||||
|
||||
const calendar = {
|
||||
viewMode: ref('week'),
|
||||
currents: reactive({
|
||||
@ -221,12 +229,16 @@ const customCalendar = {
|
||||
return days
|
||||
},
|
||||
prepareDay(day) {
|
||||
const isCurrentMonth = isInCurrentMonth(day)
|
||||
return {
|
||||
date: day.toISODate(),
|
||||
dayNumber: day.day,
|
||||
isCurrentMonth: isInCurrentMonth(day),
|
||||
isCurrentMonth: isCurrentMonth,
|
||||
isToday: isToday(day),
|
||||
isWeekend: isWeekend(day),
|
||||
isHoliday: isHoliday(day),
|
||||
isVacation: isCurrentMonth && isVacation(day),
|
||||
isPendingVacation: isCurrentMonth && isPendingVacation(day),
|
||||
}
|
||||
},
|
||||
}
|
||||
@ -325,6 +337,30 @@ function isWeekend(date) {
|
||||
function isToday(date) {
|
||||
return date.toISODate() === DateTime.local().toISODate()
|
||||
}
|
||||
|
||||
function isHoliday(date) {
|
||||
return props.holidays[date.toISODate()] !== undefined
|
||||
}
|
||||
|
||||
function getHolidayDescription(day) {
|
||||
return props.holidays[day.date]
|
||||
}
|
||||
|
||||
function isVacation(date) {
|
||||
return props.approvedVacations[date.toISODate()] !== undefined
|
||||
}
|
||||
|
||||
function isPendingVacation(date) {
|
||||
return props.pendingVacations[date.toISODate()] !== undefined
|
||||
}
|
||||
|
||||
function getVacationBorder(day) {
|
||||
return findType(getVacationInfo(day).type)?.border
|
||||
}
|
||||
|
||||
function getVacationInfo(day) {
|
||||
return day.isVacation ? props.approvedVacations[day.date] : props.pendingVacations[day.date]
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="css">
|
||||
|
Loading…
x
Reference in New Issue
Block a user