fix [P-47]: редактирование и удаление событий
This commit is contained in:
1 parent
678a683e4d
commit
3a7d147c36
5 files changed
+132
-64
No files matched your search
@@ -55,6 +55,7 @@ export default {
|
|||||||
|
|
||||||
const eventFiles = computed({
|
const eventFiles = computed({
|
||||||
get() {
|
get() {
|
||||||
|
if (!props.value) return []
|
||||||
propsFiles.value.forEach((e) =>
|
propsFiles.value.forEach((e) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<mini-calendar />
|
<mini-calendar />
|
||||||
</v-col>
|
</v-col>
|
||||||
<v-col class="d-flex flex-column">
|
<v-col class="d-flex flex-column">
|
||||||
<custom-calendar />
|
<custom-calendar @openEventDialog="openEventDialog" />
|
||||||
</v-col>
|
</v-col>
|
||||||
<!--
|
<!--
|
||||||
<v-navigation-drawer
|
<v-navigation-drawer
|
||||||
@@ -22,8 +22,8 @@
|
|||||||
:myCalendars="calendarStore.myCalendars"
|
:myCalendars="calendarStore.myCalendars"
|
||||||
@getCalendar="getCalendar"
|
@getCalendar="getCalendar"
|
||||||
@update:eventCalendar="eventFromCalendar = $event"
|
@update:eventCalendar="eventFromCalendar = $event"
|
||||||
ref="createEvents"
|
|
||||||
/>
|
/>
|
||||||
|
<!-- ref="createEvents" -->
|
||||||
</v-dialog>
|
</v-dialog>
|
||||||
</v-row>
|
</v-row>
|
||||||
</template>
|
</template>
|
||||||
@@ -65,12 +65,40 @@ export default {
|
|||||||
calendarStore.loadCalendars();
|
calendarStore.loadCalendars();
|
||||||
};
|
};
|
||||||
|
|
||||||
const getEvents = (idEvent, clik) => {
|
// const getEvent = (idEvent) => {
|
||||||
axiosApiInstance
|
// axiosApiInstance
|
||||||
.get(`api/calendar_of_events/my_events/${idEvent === undefined ? '' : `?id=${idEvent}`}`)
|
// .get(`api/calendar_of_events/my_events/${idEvent === undefined ? '' : `?id=${idEvent}`}`)
|
||||||
.then((res) => {
|
// .then((res) => {
|
||||||
if (idEvent === undefined) {
|
// if (idEvent === undefined) {
|
||||||
res.data.event = {
|
// 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();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const createEmptyEvent = () => ({
|
||||||
|
event: {
|
||||||
name: '',
|
name: '',
|
||||||
participant: [accountStore.user.is_idEmployee],
|
participant: [accountStore.user.is_idEmployee],
|
||||||
files: [],
|
files: [],
|
||||||
@@ -79,19 +107,22 @@ export default {
|
|||||||
period: null,
|
period: null,
|
||||||
description: '',
|
description: '',
|
||||||
calendar: null,
|
calendar: null,
|
||||||
};
|
},
|
||||||
}
|
|
||||||
eventFromCalendar.value = res.data;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const openEventDialog = (selectedEvent) => {
|
||||||
|
getEvent(selectedEvent.event.id);
|
||||||
|
calendarStore.openEventDialog();
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
getEvents();
|
getEvent();
|
||||||
week.getWeekend(MyYear.value);
|
week.getWeekend(MyYear.value);
|
||||||
});
|
});
|
||||||
|
|
||||||
const closeEventDialog = () => {
|
const closeEventDialog = () => {
|
||||||
calendarStore.closeEventDialog();
|
calendarStore.closeEventDialog();
|
||||||
|
eventFromCalendar.value = createEmptyEvent(); // Очищаем событие
|
||||||
};
|
};
|
||||||
|
|
||||||
const CheckingStore = () => {
|
const CheckingStore = () => {
|
||||||
@@ -111,11 +142,13 @@ export default {
|
|||||||
showEventDialog,
|
showEventDialog,
|
||||||
calendarForMy,
|
calendarForMy,
|
||||||
getCalendar,
|
getCalendar,
|
||||||
// getEvents,
|
getEvent,
|
||||||
eventFromCalendar,
|
eventFromCalendar,
|
||||||
calendarStore,
|
calendarStore,
|
||||||
accountStore,
|
accountStore,
|
||||||
closeEventDialog,
|
closeEventDialog,
|
||||||
|
openEventDialog,
|
||||||
|
createEmptyEvent,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -69,7 +69,7 @@
|
|||||||
</v-col>
|
</v-col>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import { ref, watch, nextTick, computed } from 'vue';
|
import { ref, watch, nextTick, defineEmits } from 'vue';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
import dayGridPlugin from '@fullcalendar/daygrid';
|
import dayGridPlugin from '@fullcalendar/daygrid';
|
||||||
import timeGridPlugin from '@fullcalendar/timegrid';
|
import timeGridPlugin from '@fullcalendar/timegrid';
|
||||||
@@ -92,7 +92,8 @@ export default {
|
|||||||
default: false,
|
default: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
setup(props) {
|
emits: ['openEventDialog'],
|
||||||
|
setup(props, { emit }) {
|
||||||
const calendarRef = ref(null);
|
const calendarRef = ref(null);
|
||||||
const currentView = ref('dayGridMonth');
|
const currentView = ref('dayGridMonth');
|
||||||
const calendarApi = ref(null);
|
const calendarApi = ref(null);
|
||||||
@@ -101,6 +102,10 @@ export default {
|
|||||||
const calendarStore = useCalendarStore();
|
const calendarStore = useCalendarStore();
|
||||||
const { selectedDate, lastUpdatedBy, allEvents } = storeToRefs(calendarStore);
|
const { selectedDate, lastUpdatedBy, allEvents } = storeToRefs(calendarStore);
|
||||||
|
|
||||||
|
const handleEventClick = (info) => {
|
||||||
|
emit('openEventDialog', info);
|
||||||
|
};
|
||||||
|
|
||||||
const calendarOptions = ref({
|
const calendarOptions = ref({
|
||||||
plugins: [dayGridPlugin, timeGridPlugin, multiMonthPlugin, interactionPlugin, listPlugin],
|
plugins: [dayGridPlugin, timeGridPlugin, multiMonthPlugin, interactionPlugin, listPlugin],
|
||||||
initialView: props.forHomePage ? props.view : currentView.value,
|
initialView: props.forHomePage ? props.view : currentView.value,
|
||||||
@@ -192,9 +197,7 @@ export default {
|
|||||||
editable: true,
|
editable: true,
|
||||||
selectable: true,
|
selectable: true,
|
||||||
|
|
||||||
eventClick: (info) => {
|
eventClick: handleEventClick,
|
||||||
console.log('Event click', info.event.title);
|
|
||||||
},
|
|
||||||
|
|
||||||
dateClick: (info) => {
|
dateClick: (info) => {
|
||||||
calendarStore.setSelectedDateFromCalendar(info);
|
calendarStore.setSelectedDateFromCalendar(info);
|
||||||
@@ -345,6 +348,7 @@ export default {
|
|||||||
handleCalendarDateClick,
|
handleCalendarDateClick,
|
||||||
handleDateSelection,
|
handleDateSelection,
|
||||||
updateCalendarEvents,
|
updateCalendarEvents,
|
||||||
|
handleEventClick,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -112,7 +112,6 @@ export default {
|
|||||||
const filtered = ref('');
|
const filtered = ref('');
|
||||||
const accountStore = useAccountStore();
|
const accountStore = useAccountStore();
|
||||||
const back = ref([]);
|
const back = ref([]);
|
||||||
|
|
||||||
const staffed = computed({
|
const staffed = computed({
|
||||||
get() {
|
get() {
|
||||||
if (props.okey == 'editor') {
|
if (props.okey == 'editor') {
|
||||||
|
|||||||
@@ -62,8 +62,13 @@
|
|||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
<template v-slot:item="{ item, props }">
|
<template v-slot:item="{ item, props }">
|
||||||
<v-list-item :key="item.raw.id" :value="item" color="primary" v-bind="props"
|
<v-list-item
|
||||||
@click.stop="myCalendar = item.raw" >
|
:key="item.raw.id"
|
||||||
|
:value="item"
|
||||||
|
color="primary"
|
||||||
|
v-bind="props"
|
||||||
|
@click.stop="myCalendar = item.raw"
|
||||||
|
>
|
||||||
<template v-slot:prepend>
|
<template v-slot:prepend>
|
||||||
<v-avatar class="cursor-pointer" size="8" :color="item.raw.cl_color" />
|
<v-avatar class="cursor-pointer" size="8" :color="item.raw.cl_color" />
|
||||||
</template>
|
</template>
|
||||||
@@ -211,7 +216,6 @@ export default {
|
|||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
const accountStore = useAccountStore();
|
const accountStore = useAccountStore();
|
||||||
const createDialog = ref(null);
|
const createDialog = ref(null);
|
||||||
const calendarAutocompleteRef = ref(null);
|
|
||||||
|
|
||||||
const propsEvent = computed({
|
const propsEvent = computed({
|
||||||
get: () => {
|
get: () => {
|
||||||
@@ -221,6 +225,7 @@ export default {
|
|||||||
set: (value) => emit('update:eventCalendar', value),
|
set: (value) => emit('update:eventCalendar', value),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// ВАЛИДАЦИЯ
|
// ВАЛИДАЦИЯ
|
||||||
const rules = {
|
const rules = {
|
||||||
name: [
|
name: [
|
||||||
@@ -309,6 +314,56 @@ export default {
|
|||||||
return !!val || 'Поле обязательно';
|
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([]);
|
const staff = ref([]);
|
||||||
|
|
||||||
axiosApiInstance.get('api/calendar_of_events/get_employees/').then((res) => {
|
axiosApiInstance.get('api/calendar_of_events/get_employees/').then((res) => {
|
||||||
@@ -344,7 +399,7 @@ export default {
|
|||||||
|
|
||||||
const newStaff = computed(() => {
|
const newStaff = computed(() => {
|
||||||
// Для нового события - все сотрудники, для существующего - фильтр по календарю
|
// Для нового события - все сотрудники, для существующего - фильтр по календарю
|
||||||
const isNewEvent = !propsEvent.value.event.id;
|
// const isNewEvent = !propsEvent.value.event.id;
|
||||||
|
|
||||||
if (isNewEvent) {
|
if (isNewEvent) {
|
||||||
// НОВОЕ СОБЫТИЕ - все сотрудники
|
// НОВОЕ СОБЫТИЕ - все сотрудники
|
||||||
@@ -362,24 +417,29 @@ export default {
|
|||||||
}))
|
}))
|
||||||
.filter((dept) => dept.employees.length > 0);
|
.filter((dept) => dept.employees.length > 0);
|
||||||
} else {
|
} 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 [];
|
if (!currentCalendar?.participant) return [];
|
||||||
|
|
||||||
const calendarParticipantIds = new Set(currentCalendar.participant.map((p) => p.id));
|
const calendarParticipantIds = new Set(currentCalendar.participant.map((p) => p.id));
|
||||||
const eventParticipantIds = new Set(propsEvent.value.event.participant || []);
|
const eventParticipantIds = new Set(propsEvent.value.event.participant || []);
|
||||||
|
|
||||||
return staff.value
|
return staff.value
|
||||||
.map((dept) => ({
|
.map((department) => ({
|
||||||
...dept,
|
...department,
|
||||||
employees: dept.employees
|
employees: department.employees.map((employee) => ({
|
||||||
.filter((emp) => calendarParticipantIds.has(emp.id))
|
...employee,
|
||||||
.map((emp) => ({
|
selected: eventParticipantIds.has(employee.id),
|
||||||
...emp,
|
// Дополнительная информация для UX
|
||||||
selected:
|
inCalendar: calendarParticipantIds.has(employee.id),
|
||||||
emp.id === accountStore.user.is_idEmployee || eventParticipantIds.has(emp.id),
|
disabled: false, // Всех можно выбирать
|
||||||
})),
|
})),
|
||||||
}))
|
}))
|
||||||
.filter((dept) => dept.employees.length > 0);
|
.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) => {
|
const returnIdParticant = (idPart) => {
|
||||||
idPart.staff.forEach((e) => {
|
idPart.staff.forEach((e) => {
|
||||||
if (e.selected == true && !propsEvent.value.event.participant.includes(e.id)) {
|
if (e.selected == true && !propsEvent.value.event.participant.includes(e.id)) {
|
||||||
@@ -629,7 +662,6 @@ export default {
|
|||||||
newEvent,
|
newEvent,
|
||||||
propsEvent,
|
propsEvent,
|
||||||
dateEvent,
|
dateEvent,
|
||||||
// calendar,
|
|
||||||
staff,
|
staff,
|
||||||
newStaff,
|
newStaff,
|
||||||
returnIdParticant,
|
returnIdParticant,
|
||||||
@@ -637,11 +669,10 @@ export default {
|
|||||||
postData,
|
postData,
|
||||||
rules,
|
rules,
|
||||||
delEvent,
|
delEvent,
|
||||||
// calendar,
|
|
||||||
myCalendar,
|
myCalendar,
|
||||||
safeCalendars,
|
safeCalendars,
|
||||||
isCalendarsReady,
|
isCalendarsReady,
|
||||||
// onCalendarChange,
|
isNewEvent,
|
||||||
|
|
||||||
repeatRules,
|
repeatRules,
|
||||||
returnPeriod,
|
returnPeriod,
|
||||||
|
|||||||
Reference in new issue
Block a user