fix [P-290]: фикс обновления календарей при удалении

This commit is contained in:
Inna committed 2025-10-02 10:41:43 +03:00
1 parent b110909b33
commit 18caac1bb7
5 files changed
+24 -151

No files matched your search

@@ -13,6 +13,7 @@
block block
elevation="1" elevation="1"
@click="openEventDialog" @click="openEventDialog"
:disabled="!myCalendars || myCalendars.length === 0"
>Создать событие</v-btn >Создать событие</v-btn
> >
</v-col> </v-col>
@@ -50,7 +51,7 @@ import { useCalendarStore } from '@/store/calendarStore';
import { useAccountStore } from '@/store/AccountStore'; import { useAccountStore } from '@/store/AccountStore';
import CalendarMy from '@/components/calendar_of_events/calendar-my.vue'; import CalendarMy from '@/components/calendar_of_events/calendar-my.vue';
import SearchEvents from '@/components/calendar_of_events/UI_calendar/SearchEvents.vue'; import SearchEvents from '@/components/calendar_of_events/UI_calendar/SearchEvents.vue';
import { onMounted, watch, nextTick } from 'vue'; import { onMounted, watch, nextTick } from 'vue';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
export default { export default {
@@ -67,7 +67,7 @@
</template> </template>
<script> <script>
import { ref, computed, watch } from 'vue'; import { ref, computed } from 'vue';
import { formatComa } from '@/utils/universal_functions'; import { formatComa } from '@/utils/universal_functions';
export default { export default {
props: { props: {
@@ -76,7 +76,7 @@
</template> </template>
<script> <script>
import { ref } from 'vue'; import { ref, watch } from 'vue';
import calendarCreate from '@/components/calendar_of_events/calendar-create.vue'; import calendarCreate from '@/components/calendar_of_events/calendar-create.vue';
import { useAccountStore } from '@/store/AccountStore'; import { useAccountStore } from '@/store/AccountStore';
import { storeToRefs } from 'pinia'; import { storeToRefs } from 'pinia';
@@ -102,7 +102,7 @@ export default {
const accountStore = useAccountStore(); const accountStore = useAccountStore();
const { user } = storeToRefs(accountStore); const { user } = storeToRefs(accountStore);
const calendarStore = useCalendarStore(); const calendarStore = useCalendarStore();
const { toggleCalendarVisibility } = calendarStore; const { toggleCalendarVisibility, hiddenCalendarIds } = calendarStore;
const calendar = ref({}); const calendar = ref({});
const openGroup = ref([0]); const openGroup = ref([0]);
@@ -124,9 +124,23 @@ export default {
}; };
const toggleVisiblityEvents = (cal) => { const toggleVisiblityEvents = (cal) => {
toggleCalendarVisibility(cal.id, cal.visible); toggleCalendarVisibility(cal.id);
}; };
watch(
hiddenCalendarIds,
(newHiddenIds) => {
},
{ deep: true },
);
watch(
() => props.calendars,
(newCalendars) => {
},
{ deep: true },
);
return { return {
accountStore, accountStore,
user, user,
@@ -353,140 +353,11 @@ export default {
staff.value = res.data.filter((e) => e.employees.length > 0); staff.value = res.data.filter((e) => e.employees.length > 0);
}); });
// const newStaff = computed({
// get() {
// let ns = [];
// let indCal = safeCalendars.value.findIndex((e) => e.id == myCalendar.id);
// staff.value.forEach((e) => {
// let emp = { ...e };
// emp.employees = e.employees.filter((n) => {
// if (
// n.id == accountStore.user.is_idEmployee ||
// propsEvent.value.event.participant.some((e) => n.id == e)
// ) {
// n.selected = true;
// }
// return propsEvent.value.mycalendars[indCal].participant.some(
// (part) => part.id === n.id,
// );
// });
// if (emp.employees.length > 0) ns.push(emp);
// });
// return ns;
// },
// });
// const newStaff = computed(() => {
// if (isNewEvent.value) {
// const participants = myCalendar.value.participant || [];
// // 2. Создаем Set из id участников
// const calendarParticipantIds = new Set(participants.map((p) => p.participant_calendar));
// return staff.value
// .map((department) => {
// // ФИЛЬТРУЕМ сотрудников - оставляем только тех, кто в календаре
// const employees = department.employees
// .filter((employee) => calendarParticipantIds.has(employee.id))
// .map((employee) => ({
// ...employee,
// }));
// return {
// ...department,
// employees,
// };
// })
// .filter((dept) => dept.employees.length > 0);
// } else {
// // СУЩЕСТВУЮЩЕЕ СОБЫТИЕ - фильтр по календарю
// const eventCalendarId = propsEvent.value.event.calendar;
// const currentCalendar = propsEvent.value.mycalendars?.find(
// (cal) => parseInt(cal.id) === parseInt(eventCalendarId),
// );
// 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((department) => {
// // ФИЛЬТРУЕМ сотрудников - оставляем только тех, кто в календаре
// const employees = department.employees
// .filter((employee) => calendarParticipantIds.has(employee.id))
// .map((employee) => ({
// ...employee,
// selected:
// employee.id === accountStore.user.is_idEmployee ||
// eventParticipantIds.has(employee.id),
// }));
// return {
// ...department,
// employees,
// };
// })
// .filter((dept) => dept.employees.length > 0);
// }
// });
// const newStaff = computed({
// get() {
// if (isNewEvent.value) {
// const participants = myCalendar.value.participant || [];
// const calendarParticipantIds = new Set(participants.map((p) => p.participant_calendar));
// staff.value.forEach((department) => {
// department.employees.forEach((employee) => {
// if (calendarParticipantIds.has(employee.id)) {
// employee.selected = true;
// // employee.editor = ... если нужно
// } else {
// employee.selected = false;
// // employee.editor = false;
// }
// });
// });
// } else {
// const eventCalendarId = propsEvent.value.event.calendar;
// const currentCalendar = propsEvent.value.mycalendars?.find(
// (cal) => parseInt(cal.id) === parseInt(eventCalendarId),
// );
// if (currentCalendar?.participant) {
// const calendarParticipantIds = new Set(currentCalendar.participant.map((p) => p.id));
// const eventParticipantIds = new Set(propsEvent.value.event.participant || []);
// staff.value.forEach((department) => {
// department.employees.forEach((employee) => {
// if (calendarParticipantIds.has(employee.id)) {
// employee.selected =
// employee.id === accountStore.user.is_idEmployee ||
// eventParticipantIds.has(employee.id);
// } else {
// employee.selected = false;
// }
// });
// });
// }
// }
// return staff.value;
// },
// });
const newStaff = computed({ const newStaff = computed({
get() { get() {
let filteredStaff = []; let filteredStaff = [];
if (isNewEvent.value) { if (isNewEvent.value) {
if(myCalendar.value == null) return []
const participants = myCalendar.value.participant || []; const participants = myCalendar.value.participant || [];
const calendarParticipantIds = new Set(participants.map((p) => p.participant_calendar)); const calendarParticipantIds = new Set(participants.map((p) => p.participant_calendar));
+3 -16
View File
@@ -17,7 +17,7 @@ export const useCalendarStore = defineStore('calendarStore', () => {
const holidays = ref([]); const holidays = ref([]);
// Массив ID скрытых календарей. Загружаем из localStorage при инициализации. // Массив ID скрытых календарей. Загружаем из localStorage при инициализации.
const hiddenCalendarIds = ref(JSON.parse(localStorage.getItem('hiddenCalendars')) || []); const hiddenCalendarIds = ref([]);
// Getters // Getters
const formattedSelectedDate = computed(() => selectedDate.value.toISOString().split('T')[0]); const formattedSelectedDate = computed(() => selectedDate.value.toISOString().split('T')[0]);
@@ -56,17 +56,6 @@ export const useCalendarStore = defineStore('calendarStore', () => {
})), })),
); );
// Watcher: автоматически сохраняем hiddenCalendarIds в localStorage при изменении
watch(
() => {
hiddenCalendarIds.value;
},
(newValue) => {
localStorage.setItem('hiddenCalendars', JSON.stringify(newValue));
},
{ deep: true },
);
const eventsForSelectedDate = computed(() => const eventsForSelectedDate = computed(() =>
events.value.filter((event) => event.date_start.split('T')[0] === formattedSelectedDate.value), events.value.filter((event) => event.date_start.split('T')[0] === formattedSelectedDate.value),
); );
@@ -94,10 +83,8 @@ export const useCalendarStore = defineStore('calendarStore', () => {
const loadCalendars = async () => { const loadCalendars = async () => {
try { try {
const response = await axiosApiInstance.get('api/calendar_of_events/my_calendars/'); const response = await axiosApiInstance.get('api/calendar_of_events/my_calendars/');
calendars.value = response.data.map((calendar) => ({ calendars.value = response.data;
...calendar, hiddenCalendarIds.value = [];
// visible: true,
}));
} catch (error) { } catch (error) {
console.error('Ошибка загрузки календарей:', error); console.error('Ошибка загрузки календарей:', error);
} }