From 118c7fcb41a92f54fa8586c40f5ef61e48c54164 Mon Sep 17 00:00:00 2001 From: Adrian Hopek Date: Fri, 25 Oct 2024 11:16:46 +0200 Subject: [PATCH] #328 - highlight and order calendar (#499) * #431 - bump everything * cs fix * fix * fix * #328 - highlight in calendar * #328 - highlight and order calendar * cr fix * fix * fix --- resources/js/Pages/Calendar.vue | 149 +++++++++++++----------- resources/js/Shared/UserProfileLink.vue | 1 + 2 files changed, 84 insertions(+), 66 deletions(-) diff --git a/resources/js/Pages/Calendar.vue b/resources/js/Pages/Calendar.vue index 09f833ea..78138aa0 100644 --- a/resources/js/Pages/Calendar.vue +++ b/resources/js/Pages/Calendar.vue @@ -10,6 +10,8 @@ import { router } from '@inertiajs/vue3' import InertiaLink from '@/Shared/InertiaLink.vue' import { useGlobalProps } from '@/Composables/useGlobalProps' import AppLayout from '@/Shared/Layout/AppLayout.vue' +import { useStorage } from '@vueuse/core' +import Draggable from 'vuedraggable' const props = defineProps({ users: Object, @@ -20,7 +22,10 @@ const props = defineProps({ const { auth } = useGlobalProps() -let activeElement = ref(undefined) +const highlighted = useStorage(`calendar-highlight:${auth.value.user.id}`, []) +const order = useStorage(`calendar-order:${auth.value.user.id}`, props.users.data.map(user => user.id)) + +const usersInOrder = ref([...props.users.data].sort((a, b) => order.value.indexOf(a.id) > order.value.indexOf(b.id) ? 1 : -1)) const currentDate = DateTime.now() @@ -34,6 +39,10 @@ watch(selectedMonth, (value, oldValue) => { router.visit(`/calendar/${value.toFormat('LL-yyyy')}`) }) +watch(usersInOrder, (value) => { + order.value = value.map(item => item.id) +}) + function previousMonth() { selectedMonth.value = selectedMonth.value.minus({ month: 1 }) } @@ -46,19 +55,6 @@ function currentMonth() { selectedMonth.value = currentDate } -function isActiveDay(key) { - return activeElement.value === key -} - -function setActiveDay(key) { - if (activeElement.value === undefined) - activeElement.value = key -} - -function unsetActiveDay() { - activeElement.value = undefined -} - function linkParameters(user, day) { return auth.value.can.createRequestsOnBehalfOfEmployee ? { user: user.id, from_date: day.date } : { from_date: day.date } } @@ -66,6 +62,16 @@ function linkParameters(user, day) { function linkVacationRequest(user) { return auth.value.user.id === user.id || auth.value.can.manageRequestsAsTechnicalApprover || auth.value.can.manageRequestsAsAdministrativeApprover } + +function toggleHighlight(id) { + if (highlighted.value.includes(id)) { + highlighted.value = highlighted.value.filter(item => item !== id) + + return + } + + highlighted.value.push(id) +}