diff --git a/src/front/src/components/calendar_of_events/BigCalendar.vue b/src/front/src/components/calendar_of_events/BigCalendar.vue index 31835473c..6fc32e58a 100644 --- a/src/front/src/components/calendar_of_events/BigCalendar.vue +++ b/src/front/src/components/calendar_of_events/BigCalendar.vue @@ -4,225 +4,41 @@ - + - - - - - - diff --git a/src/front/src/components/calendar_of_events/EventCreate.vue b/src/front/src/components/calendar_of_events/EventCreate.vue index fe5dcd16f..b9479dc98 100644 --- a/src/front/src/components/calendar_of_events/EventCreate.vue +++ b/src/front/src/components/calendar_of_events/EventCreate.vue @@ -531,18 +531,15 @@ watch(eventCalendar, (newCalendar) => { } }); -const delEvent = async (idev) => { - try { - const result = await axiosApiInstance.delete(`api/calendar_of_events/my_events/?delid=${idev}`) - feedalert.alert = true - feedalert.text = result.data.mess - feedalert.ico = 'mdi-check' - feedalert.color = 'orange-accent-1' - emit('getCalendar') - emit('closeDialog') - } catch (e) { - console.error('Ошибка удаления события:', e); - } +const delEvent = (idev) => { + axiosApiInstance.delete(`api/calendar_of_events/my_events/?delid=${idev}`).then((result) => { + feedalert.alert = true; + feedalert.text = result.data.mess; + feedalert.ico = 'mdi-check'; + feedalert.color = 'orange-accent-1'; + emit('getCalendar'); + }); + emit('closeDialog'); }; const newFiles = ref([]); diff --git a/src/front/src/components/calendar_of_events/EventShow.vue b/src/front/src/components/calendar_of_events/EventShow.vue index edfe2d53a..5f4ca8000 100644 --- a/src/front/src/components/calendar_of_events/EventShow.vue +++ b/src/front/src/components/calendar_of_events/EventShow.vue @@ -91,7 +91,9 @@ class="align-center pb-3 mb-3 border-bottom" v-if="eventData.event?.period" > - Повтор события + + Повтор события +
{{ recurrenceText }}
@@ -155,6 +157,17 @@ + + Редактировать + { + const id = props.eventData?.event?.id; + return id ? calendarStore.canEditEvent(id) : false; + }); + + const onEdit = () => { + calendarStore.editFromView(); + }; + return { internalShow, closeDialog, @@ -470,6 +494,8 @@ export default { truncateFileName, showRepeatEnd, formatRepeatEndDate, + canEdit, + onEdit }; }, }; diff --git a/src/front/src/components/calendar_of_events/UI_calendar/CalendarDialogs.vue b/src/front/src/components/calendar_of_events/UI_calendar/CalendarDialogs.vue index 092f815b8..3322de81b 100644 --- a/src/front/src/components/calendar_of_events/UI_calendar/CalendarDialogs.vue +++ b/src/front/src/components/calendar_of_events/UI_calendar/CalendarDialogs.vue @@ -10,15 +10,13 @@ /> - - - + - - diff --git a/src/front/src/store/calendarStore.js b/src/front/src/store/calendarStore.js index 7433f9da5..415b4b5f5 100644 --- a/src/front/src/store/calendarStore.js +++ b/src/front/src/store/calendarStore.js @@ -9,8 +9,6 @@ export const useCalendarStore = defineStore('calendarStore', () => { // State const selectedDate = ref(new Date()); const events = ref([]); - const selectedEvent = ref(null); - const showEventDialog = ref(false); const currentView = ref('dayGridMonth'); // Текущий вид календаря const calendars = ref([]); // Список календарей пользователя const lastUpdatedBy = ref(null); @@ -20,6 +18,11 @@ export const useCalendarStore = defineStore('calendarStore', () => { const dictEmployeesLoaded = ref(false); const employees = ref([]); + const selectedEvent = ref(null); + const showEventDialog = ref(false); + const selectedEventForView = ref(null); + const showViewDialog = ref(false); + // Массив ID скрытых календарей. Загружаем из localStorage при инициализации. const hiddenCalendarIds = ref([]); @@ -175,60 +178,141 @@ export const useCalendarStore = defineStore('calendarStore', () => { return editableEvents.value.some((e) => e.id === id); }; -const fetchHolidays = async (year) => { - if (holidays.value[year] || loadingYears.value.has(year)) { - return holidays.value[year]; - } - loadingYears.value.add(year); - try { - const { data } = await axiosApiInstance.get( - `api/calendar_of_events/exclusion_dates/?year=${year}`, - ); - holidays.value = { ...holidays.value, ...data }; - return holidays.value[year]; - } catch (err) { - console.error('Ошибка загрузки праздников:', err); - throw err; - } finally { - loadingYears.value.delete(year); - } -}; - + const fetchHolidays = async (year) => { + if (holidays.value[year] || loadingYears.value.has(year)) { + return holidays.value[year]; + } + loadingYears.value.add(year); + try { + const { data } = await axiosApiInstance.get( + `api/calendar_of_events/exclusion_dates/?year=${year}`, + ); + holidays.value = { ...holidays.value, ...data }; + return holidays.value[year]; + } catch (err) { + console.error('Ошибка загрузки праздников:', err); + throw err; + } finally { + loadingYears.value.delete(year); + } + }; // Метод для проверки, является ли день выходным или праздничным -const isNonWorkingDay = (dateInput) => { - const date = dateInput instanceof Date ? dateInput : new Date(dateInput); - if (isNaN(date.getTime())) { - return { isNonWorking: false, isWeekendForStyling: false, isHoliday: false }; - } + const isNonWorkingDay = (dateInput) => { + const date = dateInput instanceof Date ? dateInput : new Date(dateInput); + if (isNaN(date.getTime())) { + return { isNonWorking: false, isWeekendForStyling: false, isHoliday: false }; + } - const year = date.getFullYear(); - const month = date.getMonth() + 1; - const iso = `${year}-${String(month).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; + const year = date.getFullYear(); + const month = date.getMonth() + 1; + const iso = `${year}-${String(month).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')}`; - const day = date.getDay(); - const isWeekend = day === 0 || day === 6; - const isHoliday = (holidays.value[year]?.[month] ?? []).includes(iso); + const day = date.getDay(); + const isWeekend = day === 0 || day === 6; + const isHoliday = (holidays.value[year]?.[month] ?? []).includes(iso); - return { - isNonWorking: isWeekend || isHoliday, - isWeekendForStyling: isWeekend, - isHoliday, + return { + isNonWorking: isWeekend || isHoliday, + isWeekendForStyling: isWeekend, + isHoliday, + }; + }; + + const setSelectedEvent = (event) => { + selectedEvent.value = event; + }; + + // Шаблон пустого события (создание) + const getEmptyEventWrapper = () => { + const now = new Date(); + const inHour = new Date(now.getTime() + 60 * 60 * 1000); + return { + event: { + name: '', + description: '', + date_start: now.toISOString(), + date_end: inHour.toISOString(), + allday: false, + period: null, + participant: [accountStore.user.is_idEmployee], + calendar: null, + files: [], + }, + mycalendars: calendars.value, + }; + }; + + // Шаблон обёртки для редактирования + const buildEventWrapper = (fullEvent) => { + return { + event: { + ...fullEvent, + participant: Array.isArray(fullEvent.participant) + ? fullEvent.participant.map((p) => (typeof p === 'object' ? p.id : p)) + : [], + }, + mycalendars: calendars.value, + }; }; -}; // Открыть диалог создания/редактирования - const openEventDialog = (event = null) => { - selectedEvent.value = event; - showEventDialog.value = true; + const openEventDialog = async (eventOrInfo = null) => { + if (eventOrInfo === null) { + selectedEvent.value = getEmptyEventWrapper(); + showEventDialog.value = true; + return; + } + + const id = eventOrInfo?.event?.id ?? eventOrInfo?.id; + if (!id) { + selectedEvent.value = getEmptyEventWrapper(); + showEventDialog.value = true; + return; + } + + try { + const { data } = await axiosApiInstance.get(`api/calendar_of_events/my_events/?id=${id}`); + selectedEvent.value = data; + showEventDialog.value = true; + } catch (error) { + console.error('Ошибка загрузки события:', error); + } }; - // Закрыть диалог const closeEventDialog = () => { showEventDialog.value = false; selectedEvent.value = null; }; + const openEventView = async (eventId) => { + if (!eventId) return; + + try { + const { data } = await axiosApiInstance.get( + `api/calendar_of_events/my_events/?id=${eventId}`, + ); + selectedEventForView.value = data; + showViewDialog.value = true; + } catch (error) { + console.error('Ошибка загрузки события:', error); + } + }; + + const closeEventView = () => { + showViewDialog.value = false; + selectedEventForView.value = null; + }; + + const handleEventClick = (info) => { + const id = info.event?.id ?? info.id; + if (canEditEvent(id)) { + openEventDialog(info); + } else { + openEventView(id); + } + }; + return { // State selectedDate, @@ -262,6 +346,9 @@ const isNonWorkingDay = (dateInput) => { loadCalendars, openEventDialog, closeEventDialog, + openEventView, + closeEventView, + handleEventClick, setSelectedDateFromCalendar, setSelectedDateFromPicker, toggleCalendarVisibility, @@ -269,5 +356,9 @@ const isNonWorkingDay = (dateInput) => { isNonWorkingDay, loadDictEmployees, loadEmployees, + setSelectedEvent, + + getEmptyEventWrapper, + buildEventWrapper, }; });