Compare commits

...

3 Commits

Author SHA1 Message Date
e75edc5b15
#152 - added holidays 2022-07-01 14:58:13 +02:00
4392b666e1
#152 - small corrections 2022-07-01 14:57:38 +02:00
e7c1028da1
#152 - updated style 2022-07-01 14:56:55 +02:00
5 changed files with 150 additions and 25 deletions

View File

@ -12,6 +12,7 @@ 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\VacationRequest;
use Toby\Infrastructure\Http\Resources\HolidayResource;
use Toby\Infrastructure\Http\Resources\VacationRequestResource;
@ -54,6 +55,8 @@ class DashboardController extends Controller
->limit(3)
->get();
$allHolidays = $yearPeriod->holidays;
$limit = $vacationStatsRetriever->getVacationDaysLimit($user, $yearPeriod);
$used = $vacationStatsRetriever->getUsedVacationDays($user, $yearPeriod);
$pending = $vacationStatsRetriever->getPendingVacationDays($user, $yearPeriod);
@ -66,6 +69,9 @@ 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],
),
"stats" => [
"limit" => $limit,
"remaining" => $remaining,

View File

@ -3,7 +3,9 @@
<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"
/>
<VacationStats :stats="stats" />
</div>
<div class="grid grid-cols-1 gap-4">
@ -50,5 +52,6 @@ defineProps({
can: Object,
stats: Object,
years: Object,
allHolidays: Object,
})
</script>

View File

@ -0,0 +1,39 @@
import { h, ref } from 'vue'
const ActiveComponent = function(props, { attrs, slots }) {
const key = props.pkey
const isActive = ref(false)
function onMouseover() {
console.log('activated ' + key)
isActive.value = true
}
function onMouseleave() {
console.log('disabled ' + key)
isActive.value = false
}
return h(props.as, {
...attrs,
class: 'hello',
onMouseover,
onMouseleave,
}, [
slots,
slots.default({ isActive }),
])
}
ActiveComponent.props = {
as: {
type: String,
default: 'div',
},
pkey: {
type: Number,
required: true,
},
}
export default ActiveComponent

View File

@ -0,0 +1,70 @@
<template>
<template>
<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>
<div
v-else
:class="{ 'hello': isActive && !day.isWeekend }"
@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>
</div>
</template>
</template>
<script setup>
import Popper from 'vue3-popper'
import { defineProps, ref } from 'vue'
const props = defineProps({
day: {
type: Object,
required: true,
},
holidaydescription: {
type: Function,
},
})
const isActive = ref(false)
function onMouseover() {
if (!isActive.value)
isActive.value = true
}
function onMouseleave() {
if (isActive.value)
isActive.value = false
}
function getHolidayDescription(day) {
return props.holidaydescription(day)
}
</script>

View File

@ -120,19 +120,14 @@
class="w-full grid grid-cols-7 gap-px"
:class="{ 'grid-rows-1': calendarState.viewMode.isWeek }"
>
<div
<DateComponent
v-for="(day, index) in days"
:key="index"
class="flex flex-col"
:class="[day.isCurrentMonth ? 'bg-white' : 'bg-gray-50 text-gray-500', calendarState.viewMode.isWeek && index !== 0 && (index % 5 === 0 || index % 6 === 0) ? 'bg-red-100' : undefined, calendarState.viewMode.isWeek ? 'day' : 'month-day', 'relative py-2 px-3']"
>
<time
:datetime="day.date"
:class="day.isToday ? 'flex h-6 w-6 items-center justify-center rounded-full bg-indigo-600 font-semibold text-white' : undefined"
>
{{ day.date.split('-').pop().replace(/^0/, '') }}
</time>
</div>
: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 }]"
:holidaydescription="getHolidayDescription"
/>
</div>
</div>
</div>
@ -147,16 +142,23 @@ import { DateTime } from 'luxon'
import useCurrentYearPeriodInfo from '@/Composables/yearPeriodInfo'
import { useMonthInfo } from '@/Composables/monthInfo'
import { viewModes, find as findViewMode } from '@/Shared/Widgets/Calendar/ViewModeOptions'
import DateComponent from '@/Shared/Widgets/Calendar/DateComponent'
const props = defineProps({
holidays: 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 selectedYear = useCurrentYearPeriodInfo().year.value
const calendar = {
viewMode: ref('week'),
currents: reactive({
@ -226,6 +228,8 @@ const customCalendar = {
dayNumber: day.day,
isCurrentMonth: isInCurrentMonth(day),
isToday: isToday(day),
isWeekend: isWeekend(day),
isHoliday: isHoliday(day),
}
},
}
@ -256,7 +260,7 @@ function resetCalendar(config = {}) {
calendar.currents.year = isUndefined(config.year) ? selectedYear : config.month
calendar.currents.month = calendarState.isActualYear || !isUndefined(config.year) ? currentMonth : 1
calendar.currents.week = calendarState.isActualYear || !isUndefined(config.year) ? currentWeek : 1
calendar.currents.week = calendarState.isActualYear || !isUndefined(config.week) ? currentWeek : 0
}
function isUndefined(value) {
@ -307,7 +311,7 @@ function goToToday() {
function updateViewMode(type) {
if (type === 'month')
resetCalendar({ week: 1 })
resetCalendar({ week: 0 })
else
resetCalendar()
calendar.viewMode.value = type
@ -317,9 +321,21 @@ function isInCurrentMonth(date) {
return calendar.currents.month === date.month
}
function isWeekend(date) {
return date.weekday === 6 || date.weekday === 7
}
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]
}
</script>
<style lang="css">
@ -343,11 +359,6 @@ function isToday(date) {
content: "Pt";
}
.day:nth-of-type(7n - 1):before,
.day:nth-of-type(7n):before {
color: #991b1b;
}
.day:nth-of-type(7n - 1):before {
content: "Sb";
}
@ -355,8 +366,4 @@ function isToday(date) {
.day:nth-of-type(7n):before {
content: "Nd";
}
.month-day:nth-of-type(7n - 1), .month-day:nth-of-type(7n) {
background-color: #fee2e2;
}
</style>