wip #VC
This commit is contained in:
		| @@ -2,12 +2,11 @@ function isViewModeKey(key) { | |||||||
|   return this.key === key.value |   return this.key === key.value | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| const modes = [ | export const viewModes = [ | ||||||
|   { key: 'week', name: 'Widok tygodnia', shortcut: 'Tydzień', is: isViewModeKey }, |   { key: 'week', name: 'Widok tygodnia', shortcut: 'Tydzień', is: isViewModeKey }, | ||||||
|   { key: 'month', name: 'Widok miesiąca', shortcut: 'Miesiąc', is: isViewModeKey }, |   { key: 'month', name: 'Widok miesiąca', shortcut: 'Miesiąc', is: isViewModeKey }, | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| export default { | export function find(modeKey) { | ||||||
|   all: modes, |   return viewModes.find(mode => mode.key === modeKey) | ||||||
|   find: whereMode => modes.find(mode => mode.key === whereMode), |  | ||||||
| } | } | ||||||
| @@ -2,7 +2,7 @@ | |||||||
|   <section class="bg-white shadow-md"> |   <section class="bg-white shadow-md"> | ||||||
|     <div class="grid grid-cols-3 grid-rows-1 items-center justify-center p-4 sm:px-6"> |     <div class="grid grid-cols-3 grid-rows-1 items-center justify-center p-4 sm:px-6"> | ||||||
|       <h2 class="text-lg font-medium leading-6 text-gray-900"> |       <h2 class="text-lg font-medium leading-6 text-gray-900"> | ||||||
|         {{ calendarState.monthName }} {{ calendar.currents.year !== selectedYear ? calendar.currents.year : undefined }} |         {{ calendarState.monthName }} {{ calendarState.isActualYear ? undefined : calendar.currents.year }} | ||||||
|       </h2> |       </h2> | ||||||
|       <div class="flex justify-center"> |       <div class="flex justify-center"> | ||||||
|         <div class="flex items-center rounded-md shadow-sm md:items-stretch"> |         <div class="flex items-center rounded-md shadow-sm md:items-stretch"> | ||||||
| @@ -68,7 +68,7 @@ | |||||||
|           <MenuItems class="absolute right-0 mt-3 w-36 origin-top-right overflow-hidden rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"> |           <MenuItems class="absolute right-0 mt-3 w-36 origin-top-right overflow-hidden rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none"> | ||||||
|             <div class="py-1"> |             <div class="py-1"> | ||||||
|               <MenuItem |               <MenuItem | ||||||
|                 v-for="option in viewModes.all" |                 v-for="option in viewModes" | ||||||
|                 :key="option.key" |                 :key="option.key" | ||||||
|                 v-slot="{ active }" |                 v-slot="{ active }" | ||||||
|               > |               > | ||||||
| @@ -143,7 +143,7 @@ import { ref, watch, computed, reactive } from 'vue' | |||||||
| import { DateTime } from 'luxon' | import { DateTime } from 'luxon' | ||||||
| import useCurrentYearPeriodInfo from '@/Composables/yearPeriodInfo' | import useCurrentYearPeriodInfo from '@/Composables/yearPeriodInfo' | ||||||
| import { useMonthInfo } from '@/Composables/monthInfo' | import { useMonthInfo } from '@/Composables/monthInfo' | ||||||
| import viewModes from '@/Shared/Widgets/VacationCalendar/ViewModeOptions' | import { viewModes, find as findViewMode } from '@/Shared/Widgets/Calendar/ViewModeOptions' | ||||||
|  |  | ||||||
| let days = ref([]) | let days = ref([]) | ||||||
| const months = useMonthInfo().getMonths() | const months = useMonthInfo().getMonths() | ||||||
| @@ -161,14 +161,13 @@ const calendar = { | |||||||
|     month: selectedYear === currentDate.year ? currentDate.month : 1, |     month: selectedYear === currentDate.year ? currentDate.month : 1, | ||||||
|     weekPosition: 0, |     weekPosition: 0, | ||||||
|   }), |   }), | ||||||
|   toPreviousActive: computed(() => calendar.currents.month !== 1), |  | ||||||
| } | } | ||||||
|  |  | ||||||
| const calendarState = reactive({ | const calendarState = reactive({ | ||||||
|   viewMode: { |   viewMode: { | ||||||
|     isWeek: computed(() => calendar.viewMode.value === 'week'), |     isWeek: computed(() => calendar.viewMode.value === 'week'), | ||||||
|     isMonth: computed(() => calendar.viewMode.value === 'month'), |     isMonth: computed(() => calendar.viewMode.value === 'month'), | ||||||
|     details: computed(() => viewModes.find(calendar.viewMode.value)), |     details: computed(() => findViewMode(calendar.viewMode.value)), | ||||||
|   }, |   }, | ||||||
|   monthName: computed(() => months[calendar.currents.month - 1]?.name), |   monthName: computed(() => months[calendar.currents.month - 1]?.name), | ||||||
|   isActualYear: computed(() => calendar.currents.year !== selectedYear), |   isActualYear: computed(() => calendar.currents.year !== selectedYear), | ||||||
| @@ -178,21 +177,21 @@ const calendarState = reactive({ | |||||||
|  |  | ||||||
| const customCalendar = { | const customCalendar = { | ||||||
|   generateCalendar() { |   generateCalendar() { | ||||||
|     console.log('Loaded!', DateTime.now()) |     const date = DateTime.fromObject({ | ||||||
|     const currentDate = DateTime.fromObject({ |  | ||||||
|       year: calendar.currents.year, |       year: calendar.currents.year, | ||||||
|       month: calendar.currents.month, |       month: calendar.currents.month, | ||||||
|     }) |     }) | ||||||
|     const start = currentDate.startOf('month').startOf('week') |     days.value = this.generateCalendarData(date) | ||||||
|     const end = currentDate.endOf('month').endOf('week') |  | ||||||
|  |  | ||||||
|     days.value = this.generateCalendarData(start, end) |  | ||||||
|   }, |   }, | ||||||
|   generateCalendarData(start, end) { |   generateCalendarData(date) { | ||||||
|     if (calendarState.viewMode.isWeek) |     const firstMonthDay = date.startOf('month') | ||||||
|       return this.generateWeekData(start) |     const lastMonthDay = date.endOf('month') | ||||||
|     else if (calendarState.viewMode.isMonth) |  | ||||||
|       return this.generateMonthData(start, end) |     if (calendarState.viewMode.isWeek) { | ||||||
|  |       return this.generateWeekData(firstMonthDay.startOf('week')) | ||||||
|  |     } else if (calendarState.viewMode.isMonth) { | ||||||
|  |       return this.generateMonthData(firstMonthDay.startOf('week'), lastMonthDay.endOf('week')) | ||||||
|  |     } | ||||||
|     return [] |     return [] | ||||||
|   }, |   }, | ||||||
|   generateWeekData(start) { |   generateWeekData(start) { | ||||||
| @@ -202,7 +201,6 @@ const customCalendar = { | |||||||
|     for (let day = startWeek; day < endWeek; day = day.plus({ day: 1 })) { |     for (let day = startWeek; day < endWeek; day = day.plus({ day: 1 })) { | ||||||
|       days.push(this.prepareDay(day)) |       days.push(this.prepareDay(day)) | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     return days |     return days | ||||||
|   }, |   }, | ||||||
|   generateMonthData(start, end) { |   generateMonthData(start, end) { | ||||||
| @@ -246,12 +244,20 @@ function toNext() { | |||||||
| function resetCalendar() { | function resetCalendar() { | ||||||
|   calendar.currents.year = selectedYear |   calendar.currents.year = selectedYear | ||||||
|   calendar.currents.month = selectedYear === currentDate.year ? currentDate.month : 1 |   calendar.currents.month = selectedYear === currentDate.year ? currentDate.month : 1 | ||||||
|   // calendar.currents.week = selectedYear === currentDate.year ? currentDate.weekNumber : 1 |  | ||||||
|   calendar.currents.weekPosition = 1 |   calendar.currents.weekPosition = 1 | ||||||
| } | } | ||||||
|  |  | ||||||
| function addWeeks(howMany = 1) { | function addWeeks(howMany = 1) { | ||||||
|   // calendar.currents.week += howMany |   const date = DateTime.fromObject({ | ||||||
|  |     year: calendar.currents.year, | ||||||
|  |     month: calendar.currents.month, | ||||||
|  |   }) | ||||||
|  |   const nextMonth = date.plus({ week: calendar.currents.weekPosition }).month | ||||||
|  |   if (calendarState.viewMode.isWeek && nextMonth !== calendar.currents.month) { | ||||||
|  |     calendar.currents.month = nextMonth | ||||||
|  |     calendar.currents.weekPosition = 0 | ||||||
|  |     return | ||||||
|  |   } | ||||||
|   calendar.currents.weekPosition += howMany |   calendar.currents.weekPosition += howMany | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user