fix [P-47]: редактирование и удаление событий

This commit is contained in:
Inna committed 2025-09-23 13:36:43 +03:00
1 parent 678a683e4d
commit 3a7d147c36
5 files changed
+148 -80

No files matched your search

@@ -55,9 +55,10 @@ export default {
const eventFiles = computed({
get() {
if (!props.value) return []
propsFiles.value.forEach((e) =>
{
arrFiles.value.push(
dataURLtoFile(
"data:text/plain;base64,aGVsbG8gd29ybGQ=",
@@ -82,8 +83,8 @@ export default {
}
emit("postFiles", newFile);
},
});
//
@@ -101,8 +102,8 @@ export default {
return new File([u8arr], filename, { type: mime });
}
// const eventFiles = computed({
// get() {
// if (propsFiles.value.length > 0) {
@@ -141,7 +142,7 @@ export default {
return {
eventFiles,
arrFiles,
};
},
};
@@ -4,7 +4,7 @@
<mini-calendar />
</v-col>
<v-col class="d-flex flex-column">
<custom-calendar />
<custom-calendar @openEventDialog="openEventDialog" />
</v-col>
<!--
<v-navigation-drawer
@@ -22,8 +22,8 @@
:myCalendars="calendarStore.myCalendars"
@getCalendar="getCalendar"
@update:eventCalendar="eventFromCalendar = $event"
ref="createEvents"
/>
<!-- ref="createEvents" -->
</v-dialog>
</v-row>
</template>
@@ -65,33 +65,64 @@ export default {
calendarStore.loadCalendars();
};
const getEvents = (idEvent, clik) => {
axiosApiInstance
.get(`api/calendar_of_events/my_events/${idEvent === undefined ? '' : `?id=${idEvent}`}`)
.then((res) => {
if (idEvent === undefined) {
res.data.event = {
name: '',
participant: [accountStore.user.is_idEmployee],
files: [],
date_start: new Date(),
date_end: new Date(),
period: null,
description: '',
calendar: null,
};
}
// const getEvent = (idEvent) => {
// axiosApiInstance
// .get(`api/calendar_of_events/my_events/${idEvent === undefined ? '' : `?id=${idEvent}`}`)
// .then((res) => {
// if (idEvent === undefined) {
// res.data.event = {
// name: '',
// participant: [accountStore.user.is_idEmployee],
// files: [],
// date_start: new Date(),
// date_end: new Date(),
// period: null,
// description: '',
// calendar: null,
// };
// }
// eventFromCalendar.value = res.data;
// });
// };
const getEvent = (idEvent) => {
if (!idEvent) {
eventFromCalendar.value = createEmptyEvent();
return;
} else {
axiosApiInstance.get(`api/calendar_of_events/my_events/?id=${idEvent}`).then((res) => {
eventFromCalendar.value = res.data;
calendarStore.openEventDialog();
});
}
};
onMounted(() => {
getEvents();
const createEmptyEvent = () => ({
event: {
name: '',
participant: [accountStore.user.is_idEmployee],
files: [],
date_start: new Date(),
date_end: new Date(),
period: null,
description: '',
calendar: null,
},
});
const openEventDialog = (selectedEvent) => {
getEvent(selectedEvent.event.id);
calendarStore.openEventDialog();
};
onMounted(() => {
getEvent();
week.getWeekend(MyYear.value);
});
const closeEventDialog = () => {
calendarStore.closeEventDialog();
eventFromCalendar.value = createEmptyEvent(); // Очищаем событие
};
const CheckingStore = () => {
@@ -102,7 +133,7 @@ export default {
}
};
return {
return {
selectedDate,
getMonth,
getYear,
@@ -111,11 +142,13 @@ export default {
showEventDialog,
calendarForMy,
getCalendar,
// getEvents,
getEvent,
eventFromCalendar,
calendarStore,
accountStore,
closeEventDialog,
openEventDialog,
createEmptyEvent,
};
},
};
@@ -69,7 +69,7 @@
</v-col>
</template>
<script>
import { ref, watch, nextTick, computed } from 'vue';
import { ref, watch, nextTick, defineEmits } from 'vue';
import { storeToRefs } from 'pinia';
import dayGridPlugin from '@fullcalendar/daygrid';
import timeGridPlugin from '@fullcalendar/timegrid';
@@ -92,7 +92,8 @@ export default {
default: false,
},
},
setup(props) {
emits: ['openEventDialog'],
setup(props, { emit }) {
const calendarRef = ref(null);
const currentView = ref('dayGridMonth');
const calendarApi = ref(null);
@@ -101,6 +102,10 @@ export default {
const calendarStore = useCalendarStore();
const { selectedDate, lastUpdatedBy, allEvents } = storeToRefs(calendarStore);
const handleEventClick = (info) => {
emit('openEventDialog', info);
};
const calendarOptions = ref({
plugins: [dayGridPlugin, timeGridPlugin, multiMonthPlugin, interactionPlugin, listPlugin],
initialView: props.forHomePage ? props.view : currentView.value,
@@ -192,9 +197,7 @@ export default {
editable: true,
selectable: true,
eventClick: (info) => {
console.log('Event click', info.event.title);
},
eventClick: handleEventClick,
dateClick: (info) => {
calendarStore.setSelectedDateFromCalendar(info);
@@ -345,6 +348,7 @@ export default {
handleCalendarDateClick,
handleDateSelection,
updateCalendarEvents,
handleEventClick,
};
},
};
@@ -112,7 +112,6 @@ export default {
const filtered = ref('');
const accountStore = useAccountStore();
const back = ref([]);
const staffed = computed({
get() {
if (props.okey == 'editor') {
@@ -62,8 +62,13 @@
</span>
</template>
<template v-slot:item="{ item, props }">
<v-list-item :key="item.raw.id" :value="item" color="primary" v-bind="props"
@click.stop="myCalendar = item.raw" >
<v-list-item
:key="item.raw.id"
:value="item"
color="primary"
v-bind="props"
@click.stop="myCalendar = item.raw"
>
<template v-slot:prepend>
<v-avatar class="cursor-pointer" size="8" :color="item.raw.cl_color" />
</template>
@@ -211,7 +216,6 @@ export default {
setup(props, { emit }) {
const accountStore = useAccountStore();
const createDialog = ref(null);
const calendarAutocompleteRef = ref(null);
const propsEvent = computed({
get: () => {
@@ -221,6 +225,7 @@ export default {
set: (value) => emit('update:eventCalendar', value),
});
// ВАЛИДАЦИЯ
const rules = {
name: [
@@ -309,6 +314,56 @@ export default {
return !!val || 'Поле обязательно';
};
const titleCard = ref('');
const newEvent = ref(false);
const calendarNewOrOld = () => {
if (propsEvent.value.event.hasOwnProperty('id')) {
titleCard.value = 'Редактирование события';
newEvent.value = false;
} else {
titleCard.value = 'Новое событие';
newEvent.value = true;
}
};
const myCalendar = ref(null);
const selectedCalendar = ref(null);
const isNewEvent = computed(() => !propsEvent.value.event.id);
// Computed property с защитой от undefined
const safeCalendars = computed(() => props.myCalendars || []);
const isCalendarsReady = computed(() => safeCalendars.value.length > 0);
// Автовыбор при появлении данных
// watch(isCalendarsReady, (ready) => {
// if (ready && !myCalendar.value && safeCalendars.value[0]) {
// myCalendar.value = safeCalendars.value[0];
// }
// });
watch(
() => propsEvent.value,
(newEvent) => {
if (!newEvent || !safeCalendars.value.length) return;
const isNewEvent = !newEvent.event.id;
if (isNewEvent) {
// НОВОЕ СОБЫТИЕ - первый календарь из списка или календарь по умолчанию
myCalendar.value = safeCalendars.value[0];
} else {
// РЕДАКТИРОВАНИЕ - календарь из события
const eventCalendar = safeCalendars.value.find(
(cal) => cal.id === newEvent.event.calendar,
);
myCalendar.value = eventCalendar || safeCalendars.value[0];
}
},
{ immediate: true, deep: true },
);
const staff = ref([]);
axiosApiInstance.get('api/calendar_of_events/get_employees/').then((res) => {
@@ -344,7 +399,7 @@ export default {
const newStaff = computed(() => {
// Для нового события - все сотрудники, для существующего - фильтр по календарю
const isNewEvent = !propsEvent.value.event.id;
// const isNewEvent = !propsEvent.value.event.id;
if (isNewEvent) {
// НОВОЕ СОБЫТИЕ - все сотрудники
@@ -362,25 +417,30 @@ export default {
}))
.filter((dept) => dept.employees.length > 0);
} else {
// СУЩЕСТВУЮЩЕЕ СОБЫТИЕ - фильтр по календарю (старая логика)
if (!myCalendar.value || !safeCalendars.value.length) return [];
// СУЩЕСТВУЮЩЕЕ СОБЫТИЕ - фильтр по календарю
const eventCalendarId = propsEvent.value.event.calendar;
if (!eventCalendarId) return [];
const currentCalendar = propsEvent.value.mycalendars?.find(
(cal) => parseInt(cal.id) === parseInt(eventCalendarId),
);
const currentCalendar = safeCalendars.value.find((cal) => cal.id === myCalendar.value.id);
if (!currentCalendar?.participant) return [];
const calendarParticipantIds = new Set(currentCalendar.participant.map((p) => p.id));
const eventParticipantIds = new Set(propsEvent.value.event.participant || []);
return staff.value
.map((dept) => ({
...dept,
employees: dept.employees
.filter((emp) => calendarParticipantIds.has(emp.id))
.map((emp) => ({
...emp,
selected:
emp.id === accountStore.user.is_idEmployee || eventParticipantIds.has(emp.id),
})),
.map((department) => ({
...department,
employees: department.employees.map((employee) => ({
...employee,
selected: eventParticipantIds.has(employee.id),
// Дополнительная информация для UX
inCalendar: calendarParticipantIds.has(employee.id),
disabled: false, // Всех можно выбирать
})),
}))
.filter((dept) => dept.employees.length > 0);
}
@@ -433,33 +493,6 @@ export default {
// },
// });
const myCalendar = ref(null);
// Computed property с защитой от undefined
const safeCalendars = computed(() => props.myCalendars || []);
const isCalendarsReady = computed(() => safeCalendars.value.length > 0);
// Автовыбор при появлении данных
watch(isCalendarsReady, (ready) => {
if (ready && !myCalendar.value && safeCalendars.value[0]) {
myCalendar.value = safeCalendars.value[0];
}
});
const titleCard = ref('');
const newEvent = ref(false);
const calendarNewOrOld = () => {
if (propsEvent.value.event.hasOwnProperty('id')) {
titleCard.value = 'Редактирование события';
newEvent.value = false;
} else {
titleCard.value = 'Новое событие';
newEvent.value = true;
}
};
const returnIdParticant = (idPart) => {
idPart.staff.forEach((e) => {
if (e.selected == true && !propsEvent.value.event.participant.includes(e.id)) {
@@ -629,7 +662,6 @@ export default {
newEvent,
propsEvent,
dateEvent,
// calendar,
staff,
newStaff,
returnIdParticant,
@@ -637,11 +669,10 @@ export default {
postData,
rules,
delEvent,
// calendar,
myCalendar,
safeCalendars,
isCalendarsReady,
// onCalendarChange,
isNewEvent,
repeatRules,
returnPeriod,