2025-03-11 14:12:33 +01:00
|
|
|
<template>
|
|
|
|
<figure>
|
|
|
|
<table>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>id</th>
|
|
|
|
<th>name</th>
|
|
|
|
<th>description</th>
|
|
|
|
<th v-if="edit"></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr
|
2025-06-14 19:22:53 +02:00
|
|
|
v-for="location in schedule.locations.values()"
|
2025-03-11 14:12:33 +01:00
|
|
|
:key="location.id"
|
2025-06-14 19:22:53 +02:00
|
|
|
:class="{ removed: location.deleted }"
|
2025-03-11 14:12:33 +01:00
|
|
|
>
|
|
|
|
<template v-if='edit'>
|
|
|
|
<td>{{ location.id }}</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
:value="location.name"
|
2025-06-14 19:22:53 +02:00
|
|
|
@input="editLocation(location, { name: ($event as any).target.value })"
|
2025-03-11 14:12:33 +01:00
|
|
|
>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
:value="location.description"
|
2025-06-14 19:22:53 +02:00
|
|
|
@input="editLocation(location, { description: ($event as any).target.value })"
|
2025-03-11 14:12:33 +01:00
|
|
|
>
|
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<button
|
2025-06-14 19:22:53 +02:00
|
|
|
:disabled="location.deleted"
|
2025-03-11 14:12:33 +01:00
|
|
|
type="button"
|
2025-06-14 19:22:53 +02:00
|
|
|
@click="editLocation(location, { deleted: true })"
|
2025-03-11 14:12:33 +01:00
|
|
|
>Remove</button>
|
|
|
|
<button
|
2025-06-14 19:22:53 +02:00
|
|
|
v-if="schedule.isModifiedLocation(location.id)"
|
2025-03-11 14:12:33 +01:00
|
|
|
type="button"
|
|
|
|
@click="revertLocation(location.id)"
|
|
|
|
>Revert</button>
|
|
|
|
</td>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<td>{{ location.id }}</td>
|
|
|
|
<td>{{ location.name }}</td>
|
|
|
|
<td>{{ location.description }}</td>
|
|
|
|
</template>
|
|
|
|
</tr>
|
|
|
|
<tr v-if='edit'>
|
|
|
|
<td>
|
2025-06-14 19:22:53 +02:00
|
|
|
{{ schedule.nextClientId }}
|
2025-03-11 14:12:33 +01:00
|
|
|
</td>
|
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
v-model="newLocationName"
|
|
|
|
>
|
|
|
|
</td>
|
2025-06-14 19:22:53 +02:00
|
|
|
<td>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
v-model="newLocationDescription"
|
|
|
|
>
|
|
|
|
</td>
|
|
|
|
<td colspan="1">
|
2025-03-11 14:12:33 +01:00
|
|
|
<button
|
|
|
|
type="button"
|
2025-06-14 19:22:53 +02:00
|
|
|
@click="newLocation()"
|
2025-03-11 14:12:33 +01:00
|
|
|
>Add Location</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</figure>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
2025-06-14 19:22:53 +02:00
|
|
|
import { DateTime } from '~/shared/utils/luxon';
|
|
|
|
import type { Id } from '~/shared/types/common';
|
2025-03-11 14:12:33 +01:00
|
|
|
|
|
|
|
defineProps<{
|
|
|
|
edit?: boolean
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const schedule = await useSchedule();
|
|
|
|
|
2025-06-14 19:22:53 +02:00
|
|
|
const newLocationName = ref("");
|
|
|
|
const newLocationDescription = ref("");
|
2025-03-11 14:12:33 +01:00
|
|
|
|
2025-06-14 19:22:53 +02:00
|
|
|
function editLocation(
|
|
|
|
location: ClientScheduleLocation,
|
|
|
|
edits: Parameters<ClientSchedule["editLocation"]>[1],
|
2025-03-11 14:12:33 +01:00
|
|
|
) {
|
|
|
|
try {
|
2025-06-14 19:22:53 +02:00
|
|
|
schedule.value.editLocation(location, edits);
|
2025-03-11 14:12:33 +01:00
|
|
|
} catch (err: any) {
|
2025-06-14 19:22:53 +02:00
|
|
|
alert(err.message);
|
2025-03-11 14:12:33 +01:00
|
|
|
}
|
|
|
|
}
|
2025-06-14 19:22:53 +02:00
|
|
|
function revertLocation(id: Id) {
|
|
|
|
schedule.value.restoreLocation(id);
|
|
|
|
}
|
|
|
|
function newLocation() {
|
|
|
|
const location = new ClientScheduleLocation(
|
|
|
|
schedule.value.nextClientId--,
|
|
|
|
DateTime.now(),
|
|
|
|
false,
|
|
|
|
newLocationName.value,
|
|
|
|
newLocationDescription.value,
|
|
|
|
);
|
|
|
|
schedule.value.setLocation(location);
|
|
|
|
newLocationName.value = "";
|
|
|
|
newLocationDescription.value = "";
|
|
|
|
}
|
2025-03-11 14:12:33 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
table {
|
|
|
|
border-spacing: 0;
|
|
|
|
}
|
|
|
|
table th {
|
|
|
|
text-align: left;
|
|
|
|
border-bottom: 1px solid var(--foreground);
|
|
|
|
}
|
|
|
|
table :is(th, td) + :is(th, td) {
|
|
|
|
padding-inline-start: 0.4em;
|
|
|
|
}
|
|
|
|
.removed :is(td, input) {
|
|
|
|
text-decoration: line-through;
|
|
|
|
}
|
|
|
|
</style>
|