Rename and refactor the types passed over the API to be based on an entity that's either living or a tombstone. A living entity has a deleted property that's either undefined or false, while a tombstone has a deleted property set to true. All entities have a numeric id and an updatedAt timestamp. To sync entities, an array of replacements are passed around. Living entities are replaced with tombstones when they're deleted. And tombstones are replaced with living entities when restored.
135 lines
3.4 KiB
Vue
135 lines
3.4 KiB
Vue
<template>
|
|
<main v-if="schedule.deleted">
|
|
<h1>Error</h1>
|
|
<p>
|
|
Schedule has been deleted.
|
|
</p>
|
|
</main>
|
|
<main v-else>
|
|
<h1>Edit</h1>
|
|
<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>
|
|
<h2>Locations</h2>
|
|
<LocationsTable :edit="accountStore.canEditPublic" />
|
|
<h2>Schedule</h2>
|
|
<label>
|
|
Location Filter:
|
|
<select
|
|
v-model="locationFilter"
|
|
>
|
|
<option
|
|
:value="undefined"
|
|
:selected="locationFilter === undefined"
|
|
><All locations></option>
|
|
<option
|
|
v-for="location in schedule.locations?.filter(l => !l.deleted)"
|
|
:key="location.id"
|
|
:value="location.id"
|
|
:selected="locationFilter === location.id"
|
|
>{{ location.name }}</option>
|
|
</select>
|
|
</label>
|
|
<ScheduleTable :edit="true" :location="locationFilter" :eventSlotFilter :shiftSlotFilter />
|
|
<h2>Events</h2>
|
|
<EventsTable :edit="true" />
|
|
<h2>Roles</h2>
|
|
<RolesTable :edit="true" />
|
|
<h2>Shift Schedule</h2>
|
|
<label>
|
|
Role Filter:
|
|
<select
|
|
v-model="roleFilter"
|
|
>
|
|
<option
|
|
:value="undefined"
|
|
:selected="roleFilter === undefined"
|
|
><All roles></option>
|
|
<option
|
|
v-for="role in schedule.roles?.filter(r => !r.deleted)"
|
|
:key="role.id"
|
|
:value="role.id"
|
|
:selected="roleFilter === role.id"
|
|
>{{ role.name }}</option>
|
|
</select>
|
|
</label>
|
|
<ShiftScheduleTable :edit="true" :roleId="roleFilter" :eventSlotFilter :shiftSlotFilter />
|
|
<h2>Shifts</h2>
|
|
<ShiftsTable :edit="true" :roleId="roleFilter" />
|
|
</main>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import type { ApiScheduleEventSlot, ApiScheduleShiftSlot } from '~/shared/types/api';
|
|
|
|
definePageMeta({
|
|
middleware: ["authenticated"],
|
|
allowedAccountTypes: ["crew", "admin"],
|
|
});
|
|
|
|
const schedule = await useSchedule();
|
|
const { data: accounts } = await useAccounts();
|
|
const accountStore = useAccountStore();
|
|
|
|
const route = useRoute();
|
|
const crewFilter = computed({
|
|
get: () => queryToString(route.query.crew),
|
|
set: (value: string | undefined) => navigateTo({
|
|
path: route.path,
|
|
query: {
|
|
...route.query,
|
|
crew: value,
|
|
},
|
|
}),
|
|
});
|
|
const eventSlotFilter = computed(() => {
|
|
if (crewFilter.value === undefined || !accountStore.valid) {
|
|
return () => true;
|
|
}
|
|
const cid = parseInt(crewFilter.value);
|
|
return (slot: ApiScheduleEventSlot) => slot.assigned?.some(id => id === cid) || false;
|
|
});
|
|
const shiftSlotFilter = computed(() => {
|
|
if (crewFilter.value === undefined || !accountStore.valid) {
|
|
return () => true;
|
|
}
|
|
const cid = parseInt(crewFilter.value);
|
|
return (slot: ApiScheduleShiftSlot) => slot.assigned?.some(id => id === cid) || false;
|
|
});
|
|
|
|
const locationFilter = computed({
|
|
get: () => queryToNumber(route.query.location),
|
|
set: (value: number | undefined) => navigateTo({
|
|
path: route.path,
|
|
query: {
|
|
...route.query,
|
|
location: value !== undefined ? String(value) : undefined,
|
|
},
|
|
}),
|
|
});
|
|
|
|
const roleFilter = computed({
|
|
get: () => queryToNumber(route.query.role),
|
|
set: (value: string | undefined) => navigateTo({
|
|
path: route.path,
|
|
query: {
|
|
...route.query,
|
|
role: value,
|
|
},
|
|
}),
|
|
});
|
|
</script>
|