2025-03-09 22:21:13 +01:00
|
|
|
<template>
|
2025-06-14 19:22:53 +02:00
|
|
|
<main>
|
2025-03-09 22:21:13 +01:00
|
|
|
<h1>Edit</h1>
|
2025-03-15 22:47:32 +01:00
|
|
|
<label>
|
|
|
|
Crew Filter:
|
|
|
|
<select
|
|
|
|
v-model="crewFilter"
|
|
|
|
>
|
|
|
|
<option
|
|
|
|
:value="undefined"
|
|
|
|
:selected="crewFilter === undefined"
|
|
|
|
><All Crew></option>
|
|
|
|
<option
|
|
|
|
v-for="account in accounts?.filter(a => a.type === 'crew' || a.type === 'admin')"
|
|
|
|
:key="account.id"
|
|
|
|
:value="String(account.id)"
|
|
|
|
:selected="crewFilter === String(account.id)"
|
|
|
|
>{{ account.name }}</option>
|
|
|
|
</select>
|
|
|
|
</label>
|
2025-06-18 00:23:43 +02:00
|
|
|
<Timetable :schedule :eventSlotFilter :shiftSlotFilter />
|
|
|
|
<Tabs
|
|
|
|
:tabs
|
|
|
|
default="locations"
|
|
|
|
>
|
|
|
|
<template #locations>
|
|
|
|
<TableScheduleLocations :edit="accountStore.canEditPublic" />
|
|
|
|
</template>
|
|
|
|
<template #events>
|
|
|
|
<TableScheduleEvents :edit="true" />
|
|
|
|
</template>
|
|
|
|
<template #eventSlots>
|
|
|
|
<label>
|
|
|
|
Location Filter:
|
|
|
|
<select
|
|
|
|
v-model="locationFilter"
|
|
|
|
>
|
|
|
|
<option
|
|
|
|
:value="undefined"
|
|
|
|
:selected="locationFilter === undefined"
|
|
|
|
><All locations></option>
|
|
|
|
<option
|
|
|
|
v-for="location in schedule.locations.values()"
|
|
|
|
:key="location.id"
|
|
|
|
:value="location.id"
|
|
|
|
:disabled="location.deleted"
|
|
|
|
:selected="locationFilter === location.id"
|
|
|
|
>{{ location.name }}</option>
|
|
|
|
</select>
|
|
|
|
</label>
|
|
|
|
<TableScheduleEventSlots :edit="true" :locationId="locationFilter" :eventSlotFilter />
|
|
|
|
</template>
|
|
|
|
<template #roles>
|
|
|
|
<TableScheduleRoles :edit="true" />
|
|
|
|
</template>
|
|
|
|
<template #shifts>
|
|
|
|
<TableScheduleShifts :edit="true" :roleId="roleFilter" />
|
|
|
|
</template>
|
|
|
|
<template #shiftSlots>
|
|
|
|
<label>
|
|
|
|
Role Filter:
|
|
|
|
<select
|
|
|
|
v-model="roleFilter"
|
|
|
|
>
|
|
|
|
<option
|
|
|
|
:value="undefined"
|
|
|
|
:selected="roleFilter === undefined"
|
|
|
|
><All roles></option>
|
|
|
|
<option
|
|
|
|
v-for="role in schedule.roles.values()"
|
|
|
|
:key="role.id"
|
|
|
|
:value="role.id"
|
|
|
|
:disabled="role.deleted"
|
|
|
|
:selected="roleFilter === role.id"
|
|
|
|
>{{ role.name }}</option>
|
|
|
|
</select>
|
|
|
|
</label>
|
2025-06-18 01:00:51 +02:00
|
|
|
<TableScheduleShiftSlots :edit="true" :roleId="roleFilter" :shiftSlotFilter />
|
2025-06-18 00:23:43 +02:00
|
|
|
</template>
|
|
|
|
</Tabs>
|
2025-06-14 19:22:53 +02:00
|
|
|
<p v-if="schedule.modified">
|
|
|
|
Changes are not saved yet.
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
@click="saveChanges"
|
|
|
|
>Save Changes</button>
|
|
|
|
</p>
|
2025-03-09 22:21:13 +01:00
|
|
|
</main>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
definePageMeta({
|
|
|
|
middleware: ["authenticated"],
|
|
|
|
allowedAccountTypes: ["crew", "admin"],
|
2025-03-11 14:12:33 +01:00
|
|
|
});
|
|
|
|
|
2025-06-18 00:23:43 +02:00
|
|
|
const tabs = [
|
|
|
|
{ id: "locations", title: "Locations" },
|
|
|
|
{ id: "events", title: "Events" },
|
|
|
|
{ id: "eventSlots", title: "Event Slots" },
|
|
|
|
{ id: "roles", title: "Roles" },
|
|
|
|
{ id: "shifts", title: "Shifts" },
|
|
|
|
{ id: "shiftSlots", title: "Shifts Slots" },
|
|
|
|
];
|
|
|
|
|
2025-03-14 18:19:58 +01:00
|
|
|
const schedule = await useSchedule();
|
2025-03-15 22:47:32 +01:00
|
|
|
const { data: accounts } = await useAccounts();
|
2025-05-24 20:01:23 +02:00
|
|
|
const accountStore = useAccountStore();
|
2025-03-14 18:19:58 +01:00
|
|
|
|
|
|
|
const route = useRoute();
|
2025-03-15 22:47:32 +01:00
|
|
|
const crewFilter = computed({
|
|
|
|
get: () => queryToString(route.query.crew),
|
|
|
|
set: (value: string | undefined) => navigateTo({
|
|
|
|
path: route.path,
|
|
|
|
query: {
|
|
|
|
...route.query,
|
|
|
|
crew: value,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
const eventSlotFilter = computed(() => {
|
2025-05-24 20:01:23 +02:00
|
|
|
if (crewFilter.value === undefined || !accountStore.valid) {
|
2025-03-15 22:47:32 +01:00
|
|
|
return () => true;
|
|
|
|
}
|
|
|
|
const cid = parseInt(crewFilter.value);
|
2025-06-14 19:22:53 +02:00
|
|
|
return (slot: ClientScheduleEventSlot) => slot.assigned.has(cid);
|
2025-03-15 22:47:32 +01:00
|
|
|
});
|
|
|
|
const shiftSlotFilter = computed(() => {
|
2025-05-24 20:01:23 +02:00
|
|
|
if (crewFilter.value === undefined || !accountStore.valid) {
|
2025-03-15 22:47:32 +01:00
|
|
|
return () => true;
|
|
|
|
}
|
|
|
|
const cid = parseInt(crewFilter.value);
|
2025-06-14 19:22:53 +02:00
|
|
|
return (slot: ClientScheduleShiftSlot) => slot.assigned.has(cid);
|
2025-03-15 22:47:32 +01:00
|
|
|
});
|
|
|
|
|
2025-03-14 18:19:58 +01:00
|
|
|
const locationFilter = computed({
|
2025-06-11 21:05:17 +02:00
|
|
|
get: () => queryToNumber(route.query.location),
|
|
|
|
set: (value: number | undefined) => navigateTo({
|
2025-03-14 18:19:58 +01:00
|
|
|
path: route.path,
|
|
|
|
query: {
|
|
|
|
...route.query,
|
2025-06-11 21:05:17 +02:00
|
|
|
location: value !== undefined ? String(value) : undefined,
|
2025-03-14 18:19:58 +01:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
|
2025-03-15 16:45:02 +01:00
|
|
|
const roleFilter = computed({
|
2025-06-11 21:05:17 +02:00
|
|
|
get: () => queryToNumber(route.query.role),
|
2025-03-15 16:45:02 +01:00
|
|
|
set: (value: string | undefined) => navigateTo({
|
|
|
|
path: route.path,
|
|
|
|
query: {
|
|
|
|
...route.query,
|
|
|
|
role: value,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
});
|
2025-06-14 19:22:53 +02:00
|
|
|
|
|
|
|
async function saveChanges() {
|
|
|
|
try {
|
|
|
|
await $fetch("/api/schedule", {
|
|
|
|
method: "PATCH",
|
|
|
|
body: schedule.value.toApi(true),
|
|
|
|
});
|
|
|
|
} catch (err: any) {
|
|
|
|
console.error(err);
|
|
|
|
alert(err?.data?.message ?? err.message);
|
|
|
|
}
|
|
|
|
}
|
2025-03-09 22:21:13 +01:00
|
|
|
</script>
|