diff --git a/src/components/Navigation.vue b/src/components/Navigation.vue index 2ce8834..dd45d8e 100644 --- a/src/components/Navigation.vue +++ b/src/components/Navigation.vue @@ -66,6 +66,13 @@ const burger_menu = ref(false);
+ + Liste des exports + import('@/views/AdminPizza/AdminPizzaExportList.vue'), + beforeEnter: () => { + const { isConnected, user } = useUserStore(); + return (!isConnected || !user.groups.includes('Equipe Bouffe')) ? { path: '/' } : true; + }, + }, { path: '/archives', component: () => import('@/views/Archives.vue'), diff --git a/src/stores/pizza.store.ts b/src/stores/pizza.store.ts index e258c3d..2ab86ca 100644 --- a/src/stores/pizza.store.ts +++ b/src/stores/pizza.store.ts @@ -4,6 +4,7 @@ import { ref } from 'vue'; import type { Order } from '@/models/order'; import type { Pizza } from '@/models/pizza'; import type { AdminTimeslotDeref, Export, Timeslot } from '@/models/timeslot'; +import { frenchFormatFromDate } from '@/utils'; import { useUserStore } from './user.store'; @@ -13,6 +14,7 @@ const { csrf } = storeToRefs(useUserStore()); export const usePizzaStore = defineStore('pizza', () => { const pizzaList = ref>({}); const timeslotList = ref>({}); + const timeslotExportList = ref>({}); async function fetchAllPizzas() { const res = await axios.get('/pizza/pizza/full'); @@ -122,16 +124,32 @@ export const usePizzaStore = defineStore('pizza', () => { } } - function frenchFormatFromDate(date: Date): string { - const mois: string[] = ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre']; - const year = date.getFullYear(); - const dayNumber = date.getDate(); - const month = mois[date.getMonth()]; - const weekday = date.toLocaleDateString('fr-FR', { weekday: 'long' }); - const hours = date.getHours().toString().padStart(2, '0'); - const minutes = date.getMinutes().toString().padStart(2, '0'); + async function fetchTimeslotExports() { + await Promise.all(Object.values(timeslotList.value).map(async ({ id }) => { + const res = await axios.get(`/pizza/timeslot/${id}/export`); + timeslotExportList.value[id] = res.data; + })); + } + + async function deleteExport(exportId: number) { + await get_csrf(); + + const res = await axios.delete(`/pizza/export/${exportId}`, { + withCredentials: true, + headers: { + 'X-CSRFToken': csrf.value, + }, + }); - return `${weekday} ${dayNumber} ${month} ${year} - ${hours}h${minutes}`; + if (res.status === 204) { + Object.values(timeslotList.value).forEach(({ id }) => { + for (let i = 0; i < timeslotExportList.value[id].length; i += 1) { + if (timeslotExportList.value[id][i].id === exportId) { + timeslotExportList.value[id].splice(i, 1); + } + } + }); + } } async function exportOrders(timeslotId: number) { @@ -285,14 +303,16 @@ export const usePizzaStore = defineStore('pizza', () => { return { pizzaList, timeslotList, + timeslotExportList, fetchAllPizzas, fetchNextTimeslots, - frenchFormatFromDate, fetchAdminDetailTimeslot, addOrder, patchOrder, addTimeslot, deleteTimeslot, + fetchTimeslotExports, + deleteExport, exportOrders, addPizza, patchPizza, diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..e7a638d --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,14 @@ +export function frenchFormatFromDate(date: Date): string { + const mois: string[] = [ + 'Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', + 'Septembre', 'Octobre', 'Novembre', 'Décembre', + ]; + const year = date.getFullYear(); + const dayNumber = date.getDate(); + const month = mois[date.getMonth()]; + const weekday = date.toLocaleDateString('fr-FR', { weekday: 'long' }); + const hours = date.getHours().toString().padStart(2, '0'); + const minutes = date.getMinutes().toString().padStart(2, '0'); + + return `${weekday} ${dayNumber} ${month} ${year} - ${hours}h${minutes}`; +} diff --git a/src/views/AdminPizza/AdminPizza.vue b/src/views/AdminPizza/AdminPizza.vue index 77365ec..9214e74 100644 --- a/src/views/AdminPizza/AdminPizza.vue +++ b/src/views/AdminPizza/AdminPizza.vue @@ -10,6 +10,7 @@ import { type Payment, PAYMENT_METHODS } from '@/models/order'; import type { AdminTimeslotDeref } from '@/models/timeslot'; import { useErrorStore } from '@/stores/error.store'; import { usePizzaStore } from '@/stores/pizza.store'; +import { frenchFormatFromDate } from '@/utils'; const { add_error } = useErrorStore(); @@ -17,7 +18,6 @@ const pizzaStore = usePizzaStore(); const { pizzaList, timeslotList } = storeToRefs(pizzaStore); const { fetchNextTimeslots, - frenchFormatFromDate, fetchAdminDetailTimeslot, fetchAllPizzas, addOrder, diff --git a/src/views/AdminPizza/AdminPizzaExportList.vue b/src/views/AdminPizza/AdminPizzaExportList.vue new file mode 100644 index 0000000..ebe10e1 --- /dev/null +++ b/src/views/AdminPizza/AdminPizzaExportList.vue @@ -0,0 +1,138 @@ + + +