Rename TimeBlock to Interva. More Interval functionality.
Some checks failed
Build BAB Application Deployment Artifact / build (push) Failing after 1m40s
Some checks failed
Build BAB Application Deployment Artifact / build (push) Failing after 1m40s
This commit is contained in:
@@ -14,8 +14,8 @@ defineComponent({
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await useAuthStore().init();
|
await useAuthStore().init();
|
||||||
await useScheduleStore().fetchTimeBlockTemplates();
|
await useScheduleStore().fetchIntervalTemplates();
|
||||||
await useScheduleStore().fetchTimeBlocks();
|
await useScheduleStore().fetchIntervals();
|
||||||
await useBoatStore().fetchBoats();
|
await useBoatStore().fetchBoats();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
expand-icon-toggle
|
expand-icon-toggle
|
||||||
draggable="true"
|
draggable="true"
|
||||||
@dragstart="onDragStart($event, template)"
|
@dragstart="onDragStart($event, template)"
|
||||||
|
v-model="expanded"
|
||||||
>
|
>
|
||||||
<template v-slot:header>
|
<template v-slot:header>
|
||||||
<q-item-section>
|
<q-item-section>
|
||||||
@@ -21,7 +22,7 @@
|
|||||||
<q-card-section horizontal>
|
<q-card-section horizontal>
|
||||||
<q-card-section class="q-pt-xs">
|
<q-card-section class="q-pt-xs">
|
||||||
<q-list dense>
|
<q-list dense>
|
||||||
<q-item v-for="item in template.timeTuples" :key="item[0]">
|
<q-item v-for="(item, index) in template.timeTuples" :key="item[0]">
|
||||||
<q-input
|
<q-input
|
||||||
class="q-mx-sm"
|
class="q-mx-sm"
|
||||||
dense
|
dense
|
||||||
@@ -29,8 +30,7 @@
|
|||||||
type="time"
|
type="time"
|
||||||
label="Start"
|
label="Start"
|
||||||
:borderless="!edit"
|
:borderless="!edit"
|
||||||
:readonly="!edit"
|
:readonly="!edit" />
|
||||||
/>
|
|
||||||
<q-input
|
<q-input
|
||||||
class="q-mx-sm"
|
class="q-mx-sm"
|
||||||
dense
|
dense
|
||||||
@@ -39,8 +39,17 @@
|
|||||||
label="End"
|
label="End"
|
||||||
:borderless="!edit"
|
:borderless="!edit"
|
||||||
:readonly="!edit"
|
:readonly="!edit"
|
||||||
/> </q-item></q-list
|
>
|
||||||
></q-card-section>
|
<template v-slot:after>
|
||||||
|
<q-btn
|
||||||
|
v-if="edit"
|
||||||
|
round
|
||||||
|
dense
|
||||||
|
flat
|
||||||
|
icon="delete"
|
||||||
|
@click="template.timeTuples.splice(index, 1)"
|
||||||
|
/> </template></q-input></q-item
|
||||||
|
></q-list>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="edit"
|
v-if="edit"
|
||||||
dense
|
dense
|
||||||
@@ -48,8 +57,8 @@
|
|||||||
size="sm"
|
size="sm"
|
||||||
label="Add interval"
|
label="Add interval"
|
||||||
@click="template.timeTuples.push(['00:00', '00:00'])"
|
@click="template.timeTuples.push(['00:00', '00:00'])"
|
||||||
/>
|
/></q-card-section>
|
||||||
<q-card-actions align="right" vertical>
|
<q-card-actions vertical>
|
||||||
<q-btn
|
<q-btn
|
||||||
v-if="!edit"
|
v-if="!edit"
|
||||||
color="primary"
|
color="primary"
|
||||||
@@ -105,24 +114,24 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import {
|
||||||
copyTimeBlockTemplate,
|
copyIntervalTemplate,
|
||||||
timeTuplesOverlapped,
|
timeTuplesOverlapped,
|
||||||
useScheduleStore,
|
useScheduleStore,
|
||||||
} from 'src/stores/schedule';
|
} from 'src/stores/schedule';
|
||||||
import { TimeBlockTemplate } from 'src/stores/schedule.types';
|
import { IntervalTemplate } from 'src/stores/schedule.types';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
const alert = ref(false);
|
const alert = ref(false);
|
||||||
const overlapped = ref();
|
const overlapped = ref();
|
||||||
const scheduleStore = useScheduleStore();
|
const scheduleStore = useScheduleStore();
|
||||||
const props = defineProps<{ edit?: boolean; modelValue: TimeBlockTemplate }>();
|
const props = defineProps<{ edit?: boolean; modelValue: IntervalTemplate }>();
|
||||||
const edit = ref(props.edit);
|
const edit = ref(props.edit);
|
||||||
const template = ref(copyTimeBlockTemplate(props.modelValue));
|
const expanded = ref(props.edit);
|
||||||
|
const template = ref(copyIntervalTemplate(props.modelValue));
|
||||||
|
|
||||||
const emit = defineEmits<{ (e: 'cancel'): void }>();
|
const emit = defineEmits<{ (e: 'cancel'): void; (e: 'saved'): void }>();
|
||||||
|
|
||||||
const revert = () => {
|
const revert = () => {
|
||||||
template.value = copyTimeBlockTemplate(props.modelValue);
|
template.value = copyIntervalTemplate(props.modelValue);
|
||||||
console.log(template.value, props.modelValue);
|
|
||||||
edit.value = false;
|
edit.value = false;
|
||||||
emit('cancel');
|
emit('cancel');
|
||||||
};
|
};
|
||||||
@@ -133,33 +142,33 @@ const toggleEdit = () => {
|
|||||||
|
|
||||||
const deleteTemplate = (
|
const deleteTemplate = (
|
||||||
event: Event,
|
event: Event,
|
||||||
template: TimeBlockTemplate | undefined
|
template: IntervalTemplate | undefined
|
||||||
) => {
|
) => {
|
||||||
if (template?.$id) scheduleStore.deleteTimeBlockTemplate(template.$id);
|
if (template?.$id) scheduleStore.deleteIntervalTemplate(template.$id);
|
||||||
};
|
};
|
||||||
|
|
||||||
function onDragStart(e: DragEvent, template: TimeBlockTemplate) {
|
function onDragStart(e: DragEvent, template: IntervalTemplate) {
|
||||||
if (e.dataTransfer) {
|
if (e.dataTransfer) {
|
||||||
console.log('Drag start: ', e);
|
|
||||||
e.dataTransfer.dropEffect = 'copy';
|
e.dataTransfer.dropEffect = 'copy';
|
||||||
e.dataTransfer.effectAllowed = 'move';
|
e.dataTransfer.effectAllowed = 'move';
|
||||||
e.dataTransfer.setData('ID', template.$id || '');
|
e.dataTransfer.setData('ID', template.$id || '');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const saveTemplate = (evt: Event, template: TimeBlockTemplate | undefined) => {
|
const saveTemplate = (evt: Event, template: IntervalTemplate | undefined) => {
|
||||||
|
console.log(template);
|
||||||
if (!template) return false;
|
if (!template) return false;
|
||||||
overlapped.value = timeTuplesOverlapped(template.timeTuples);
|
overlapped.value = timeTuplesOverlapped(template.timeTuples);
|
||||||
if (overlapped.value.length > 0) {
|
if (overlapped.value.length > 0) {
|
||||||
alert.value = true;
|
alert.value = true;
|
||||||
} else {
|
} else {
|
||||||
|
edit.value = false;
|
||||||
if (template.$id && template.$id !== 'unsaved') {
|
if (template.$id && template.$id !== 'unsaved') {
|
||||||
console.log(template.$id);
|
console.log(template.$id);
|
||||||
scheduleStore.updateTimeBlockTemplate(template, template.$id);
|
scheduleStore.updateIntervalTemplate(template, template.$id);
|
||||||
} else {
|
} else {
|
||||||
scheduleStore.createTimeBlockTemplate(template);
|
scheduleStore.createIntervalTemplate(template);
|
||||||
template.$id = '';
|
emit('saved');
|
||||||
}
|
}
|
||||||
edit.value = false;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
@@ -76,12 +76,12 @@ import CalendarHeaderComponent from './CalendarHeaderComponent.vue';
|
|||||||
import { ref, computed } from 'vue';
|
import { ref, computed } from 'vue';
|
||||||
import { useBoatStore } from 'src/stores/boat';
|
import { useBoatStore } from 'src/stores/boat';
|
||||||
import { useScheduleStore } from 'src/stores/schedule';
|
import { useScheduleStore } from 'src/stores/schedule';
|
||||||
import { TimeBlock } from 'src/stores/schedule.types';
|
import { Interval } from 'src/stores/schedule.types';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
|
|
||||||
const scheduleStore = useScheduleStore();
|
const scheduleStore = useScheduleStore();
|
||||||
const { boats } = storeToRefs(useBoatStore());
|
const { boats } = storeToRefs(useBoatStore());
|
||||||
const selectedBlock = defineModel<TimeBlock | null>();
|
const selectedBlock = defineModel<Interval | null>();
|
||||||
const selectedDate = ref(today());
|
const selectedDate = ref(today());
|
||||||
|
|
||||||
const calendar = ref<QCalendarDay | null>(null);
|
const calendar = ref<QCalendarDay | null>(null);
|
||||||
@@ -103,7 +103,7 @@ function handleSwipe({ ...event }) {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
function blockStyles(
|
function blockStyles(
|
||||||
block: TimeBlock,
|
block: Interval,
|
||||||
timeStartPos: (t: string) => string,
|
timeStartPos: (t: string) => string,
|
||||||
timeDurationHeight: (d: number) => string
|
timeDurationHeight: (d: number) => string
|
||||||
) {
|
) {
|
||||||
@@ -154,7 +154,7 @@ interface DayBodyScope {
|
|||||||
timestamp: Timestamp;
|
timestamp: Timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectBlock(event: MouseEvent, scope: DayBodyScope, block: TimeBlock) {
|
function selectBlock(event: MouseEvent, scope: DayBodyScope, block: Interval) {
|
||||||
// TODO: Disable blocks before today with updateDisabled and/or comparison
|
// TODO: Disable blocks before today with updateDisabled and/or comparison
|
||||||
selectedBlock.value === block
|
selectedBlock.value === block
|
||||||
? (selectedBlock.value = null)
|
? (selectedBlock.value = null)
|
||||||
@@ -162,12 +162,12 @@ function selectBlock(event: MouseEvent, scope: DayBodyScope, block: TimeBlock) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface BoatBlocks {
|
interface BoatBlocks {
|
||||||
[key: string]: TimeBlock[];
|
[key: string]: Interval[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const boatBlocks = computed((): BoatBlocks => {
|
const boatBlocks = computed((): BoatBlocks => {
|
||||||
return scheduleStore
|
return scheduleStore
|
||||||
.getTimeBlocksForDate(selectedDate.value)
|
.getIntervalsForDate(selectedDate.value)
|
||||||
.reduce((result, tb) => {
|
.reduce((result, tb) => {
|
||||||
if (!result[tb.boatId]) result[tb.boatId] = [];
|
if (!result[tb.boatId]) result[tb.boatId] = [];
|
||||||
result[tb.boatId].push(tb);
|
result[tb.boatId].push(tb);
|
||||||
@@ -175,14 +175,14 @@ const boatBlocks = computed((): BoatBlocks => {
|
|||||||
}, <BoatBlocks>{});
|
}, <BoatBlocks>{});
|
||||||
});
|
});
|
||||||
|
|
||||||
function getBoatBlocks(scope: DayBodyScope): TimeBlock[] {
|
function getBoatBlocks(scope: DayBodyScope): Interval[] {
|
||||||
return boats.value[scope.columnIndex]
|
return boats.value[scope.columnIndex]
|
||||||
? boatBlocks.value[boats.value[scope.columnIndex].$id]
|
? boatBlocks.value[boats.value[scope.columnIndex].$id]
|
||||||
: [];
|
: [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// function changeEvent({ start }: { start: string }) {
|
// function changeEvent({ start }: { start: string }) {
|
||||||
// const newBlocks = scheduleStore.getTimeBlocksForDate(start);
|
// const newBlocks = scheduleStore.getIntervalsForDate(start);
|
||||||
// const reservations = scheduleStore.getBoatReservations(
|
// const reservations = scheduleStore.getBoatReservations(
|
||||||
// parsed(start) as Timestamp
|
// parsed(start) as Timestamp
|
||||||
// );
|
// );
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ import { useAuthStore } from 'src/stores/auth';
|
|||||||
import { Boat, useBoatStore } from 'src/stores/boat';
|
import { Boat, useBoatStore } from 'src/stores/boat';
|
||||||
import { date } from 'quasar';
|
import { date } from 'quasar';
|
||||||
import { useScheduleStore } from 'src/stores/schedule';
|
import { useScheduleStore } from 'src/stores/schedule';
|
||||||
import { TimeBlock } from 'src/stores/schedule.types';
|
import { Interval } from 'src/stores/schedule.types';
|
||||||
import BoatScheduleTableComponent from 'src/components/scheduling/boat/BoatScheduleTableComponent.vue';
|
import BoatScheduleTableComponent from 'src/components/scheduling/boat/BoatScheduleTableComponent.vue';
|
||||||
|
|
||||||
interface BookingForm {
|
interface BookingForm {
|
||||||
@@ -119,7 +119,7 @@ const auth = useAuthStore();
|
|||||||
const dateFormat = 'MMM D, YYYY h:mm A';
|
const dateFormat = 'MMM D, YYYY h:mm A';
|
||||||
const resourceView = ref(true);
|
const resourceView = ref(true);
|
||||||
const scheduleStore = useScheduleStore();
|
const scheduleStore = useScheduleStore();
|
||||||
const timeblock = ref<TimeBlock>();
|
const timeblock = ref<Interval>();
|
||||||
const bookingForm = ref<BookingForm>({
|
const bookingForm = ref<BookingForm>({
|
||||||
bookingId: scheduleStore.getNewId(),
|
bookingId: scheduleStore.getNewId(),
|
||||||
name: auth.currentUser?.name,
|
name: auth.currentUser?.name,
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="fit row wrap justify-start items-start content-start">
|
<div class="fit row wrap justify-start items-start content-start">
|
||||||
<div class="col-9 q-pa-md">
|
<div class="q-pa-md">
|
||||||
<div class="scheduler">
|
<div class="scheduler" style="max-width: 1200px">
|
||||||
<NavigationBar @next="onNext" @today="onToday" @prev="onPrev" />
|
<NavigationBar @next="onNext" @today="onToday" @prev="onPrev" />
|
||||||
<q-calendar-scheduler
|
<q-calendar-scheduler
|
||||||
ref="calendar"
|
ref="calendar"
|
||||||
@@ -11,7 +11,6 @@
|
|||||||
resource-label="name"
|
resource-label="name"
|
||||||
view="week"
|
view="week"
|
||||||
:weekdays="[1, 2, 3, 4, 5, 6, 0]"
|
:weekdays="[1, 2, 3, 4, 5, 6, 0]"
|
||||||
hoverable
|
|
||||||
animated
|
animated
|
||||||
bordered
|
bordered
|
||||||
:drag-enter-func="onDragEnter"
|
:drag-enter-func="onDragEnter"
|
||||||
@@ -19,15 +18,14 @@
|
|||||||
:drag-leave-func="onDragLeave"
|
:drag-leave-func="onDragLeave"
|
||||||
:drop-func="onDrop"
|
:drop-func="onDrop"
|
||||||
:day-min-height="50"
|
:day-min-height="50"
|
||||||
:cell-width="140"
|
:cell-width="150"
|
||||||
:day-height="0"
|
:day-height="0"
|
||||||
>
|
>
|
||||||
<template #day="{ scope }">
|
<template #day="{ scope }">
|
||||||
<div
|
<div
|
||||||
v-if="getTimeBlocks(scope.timestamp, scope.resource)"
|
v-if="getIntervals(scope.timestamp, scope.resource)"
|
||||||
style="
|
style="
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 1 0 auto;
|
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: space-evenly;
|
justify-content: space-evenly;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
@@ -35,20 +33,63 @@
|
|||||||
"
|
"
|
||||||
>
|
>
|
||||||
<template
|
<template
|
||||||
v-for="event in getTimeBlocks(scope.timestamp, scope.resource)"
|
v-for="block in getIntervals(
|
||||||
:key="event.id"
|
scope.timestamp,
|
||||||
|
scope.resource
|
||||||
|
).sort((a, b) => Date.parse(a.start) - Date.parse(b.start))"
|
||||||
|
:key="block.id"
|
||||||
>
|
>
|
||||||
<q-chip clickable square icon="schedule">
|
<q-chip class="cursor-pointer">
|
||||||
{{ date.formatDate(event.start, 'HH:mm') }} -
|
{{ date.formatDate(block.start, 'HH:mm') }} -
|
||||||
{{ date.formatDate(event.end, 'HH:mm') }}</q-chip
|
{{ date.formatDate(block.end, 'HH:mm') }}
|
||||||
|
<q-popup-edit
|
||||||
|
:model-value="block"
|
||||||
|
v-slot="scope"
|
||||||
|
buttons
|
||||||
|
@save="updateInterval(block)"
|
||||||
>
|
>
|
||||||
|
<q-input
|
||||||
|
:model-value="date.formatDate(scope.value.start, 'HH:mm')"
|
||||||
|
dense
|
||||||
|
autofocus
|
||||||
|
type="time"
|
||||||
|
label="start"
|
||||||
|
@keyup.enter="scope.set"
|
||||||
|
@update:model-value="
|
||||||
|
(t) =>
|
||||||
|
(block.start = buildISODate(
|
||||||
|
date.formatDate(scope.value.start, 'YYYY-MM-DD'),t as string
|
||||||
|
))
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
<!-- TODO: Clean this up -->
|
||||||
|
<q-input
|
||||||
|
:model-value="date.formatDate(scope.value.end, 'HH:mm')"
|
||||||
|
dense
|
||||||
|
type="time"
|
||||||
|
label="end"
|
||||||
|
@keyup.enter="scope.set"
|
||||||
|
@update:model-value="
|
||||||
|
(t) =>
|
||||||
|
(block.end = buildISODate(
|
||||||
|
date.formatDate(scope.value.end, 'YYYY-MM-DD'),t as string
|
||||||
|
))
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</q-popup-edit> </q-chip
|
||||||
|
><q-btn
|
||||||
|
size="xs"
|
||||||
|
icon="delete"
|
||||||
|
round
|
||||||
|
@click="deleteBlock(block)"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
</q-calendar-scheduler>
|
</q-calendar-scheduler>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-3 q-pa-md">
|
<div class="q-pa-md" style="width: 400">
|
||||||
<q-list padding bordered class="rounded-borders">
|
<q-list padding bordered class="rounded-borders">
|
||||||
<q-item>
|
<q-item>
|
||||||
<q-item-section>
|
<q-item-section>
|
||||||
@@ -63,13 +104,14 @@
|
|||||||
<q-btn label="Add Template" color="primary" @click="createTemplate" />
|
<q-btn label="Add Template" color="primary" @click="createTemplate" />
|
||||||
</q-card-actions>
|
</q-card-actions>
|
||||||
<q-item v-if="newTemplate.$id === 'unsaved'"
|
<q-item v-if="newTemplate.$id === 'unsaved'"
|
||||||
><TimeBlockTemplateComponent
|
><IntervalTemplateComponent
|
||||||
:model-value="newTemplate"
|
:model-value="newTemplate"
|
||||||
:edit="true"
|
:edit="true"
|
||||||
@cancel="cancelNewTemplate"
|
@cancel="resetNewTemplate"
|
||||||
|
@saved="resetNewTemplate"
|
||||||
/></q-item>
|
/></q-item>
|
||||||
<q-separator spaced />
|
<q-separator spaced />
|
||||||
<TimeBlockTemplateComponent
|
<IntervalTemplateComponent
|
||||||
v-for="template in timeblockTemplates"
|
v-for="template in timeblockTemplates"
|
||||||
:key="template.$id"
|
:key="template.$id"
|
||||||
:model-value="template"
|
:model-value="template"
|
||||||
@@ -77,6 +119,19 @@
|
|||||||
</q-list>
|
</q-list>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<q-dialog v-model="alert">
|
||||||
|
<q-card>
|
||||||
|
<q-card-section>
|
||||||
|
<div class="text-h6">Warning!</div>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section class="q-pt-none">
|
||||||
|
This will overwrite existing blocks!
|
||||||
|
{{ overlapped }}
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-actions align="right">
|
||||||
|
<q-btn flat label="OK" color="primary" v-close-popup />
|
||||||
|
</q-card-actions> </q-card
|
||||||
|
></q-dialog>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
@@ -86,50 +141,85 @@ import {
|
|||||||
today,
|
today,
|
||||||
} from '@quasar/quasar-ui-qcalendar';
|
} from '@quasar/quasar-ui-qcalendar';
|
||||||
import { Boat, useBoatStore } from 'src/stores/boat';
|
import { Boat, useBoatStore } from 'src/stores/boat';
|
||||||
import { buildTimeBlock, useScheduleStore } from 'src/stores/schedule';
|
import {
|
||||||
|
blocksOverlapped,
|
||||||
|
buildInterval,
|
||||||
|
useScheduleStore,
|
||||||
|
buildISODate,
|
||||||
|
} from 'src/stores/schedule';
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import type { TimeBlockTemplate, TimeTuple } from 'src/stores/schedule.types';
|
import type {
|
||||||
|
Interval,
|
||||||
|
IntervalTemplate,
|
||||||
|
TimeTuple,
|
||||||
|
} from 'src/stores/schedule.types';
|
||||||
import { date } from 'quasar';
|
import { date } from 'quasar';
|
||||||
import TimeBlockTemplateComponent from 'src/components/scheduling/TimeBlockTemplateComponent.vue';
|
import IntervalTemplateComponent from 'src/components/scheduling/IntervalTemplateComponent.vue';
|
||||||
import NavigationBar from 'src/components/scheduling/NavigationBar.vue';
|
import NavigationBar from 'src/components/scheduling/NavigationBar.vue';
|
||||||
import { storeToRefs } from 'pinia';
|
import { storeToRefs } from 'pinia';
|
||||||
|
|
||||||
const selectedDate = ref(today());
|
const selectedDate = ref(today());
|
||||||
const { fetchBoats } = useBoatStore();
|
const { fetchBoats } = useBoatStore();
|
||||||
const { getTimeBlocks, fetchTimeBlocks, fetchTimeBlockTemplates } =
|
const { getIntervals, fetchIntervals, updateInterval, fetchIntervalTemplates } =
|
||||||
useScheduleStore();
|
useScheduleStore();
|
||||||
const { boats } = storeToRefs(useBoatStore());
|
const { boats } = storeToRefs(useBoatStore());
|
||||||
const { timeblockTemplates } = storeToRefs(useScheduleStore());
|
const { timeblockTemplates } = storeToRefs(useScheduleStore());
|
||||||
const calendar = ref();
|
const calendar = ref();
|
||||||
const blankTemplate: TimeBlockTemplate = {
|
const overlapped = ref();
|
||||||
|
const blankTemplate: IntervalTemplate = {
|
||||||
$id: '',
|
$id: '',
|
||||||
name: 'NewTemplate',
|
name: 'NewTemplate',
|
||||||
timeTuples: [['00:00', '00:00']],
|
timeTuples: [['09:00', '12:00']],
|
||||||
};
|
};
|
||||||
const newTemplate = ref<TimeBlockTemplate>({ ...blankTemplate });
|
const newTemplate = ref<IntervalTemplate>({ ...blankTemplate });
|
||||||
|
const alert = ref(false);
|
||||||
|
|
||||||
|
/* TODOS:
|
||||||
|
* Need more validation:
|
||||||
|
- Interval start < end
|
||||||
|
- Intervals don't overlap
|
||||||
|
* Need to handle case of overnight blocks.
|
||||||
|
*/
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await fetchBoats();
|
await fetchBoats();
|
||||||
await fetchTimeBlocks();
|
await fetchIntervals();
|
||||||
await fetchTimeBlockTemplates();
|
await fetchIntervalTemplates();
|
||||||
});
|
});
|
||||||
|
|
||||||
function cancelNewTemplate() {
|
function resetNewTemplate() {
|
||||||
newTemplate.value = { ...blankTemplate };
|
newTemplate.value = { ...blankTemplate };
|
||||||
console.log(newTemplate.value);
|
|
||||||
}
|
}
|
||||||
function createTemplate() {
|
function createTemplate() {
|
||||||
newTemplate.value.$id = 'unsaved';
|
newTemplate.value.$id = 'unsaved';
|
||||||
}
|
}
|
||||||
function createTimeBlock(boat: Boat, templateId: string, date: string) {
|
function createIntervals(boat: Boat, templateId: string, date: string) {
|
||||||
const timeBlock = timeblockTemplates.value.find((t) => t.$id === templateId);
|
timeBlocksFromTemplate(boat, templateId, date)?.map((block) =>
|
||||||
timeBlock?.timeTuples.map((tb: TimeTuple) =>
|
useScheduleStore().createInterval(block)
|
||||||
useScheduleStore().createTimeBlock(buildTimeBlock(boat, tb, date))
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function timeBlocksFromTemplate(
|
||||||
|
boat: Boat,
|
||||||
|
templateId: string,
|
||||||
|
date: string
|
||||||
|
): Interval[] {
|
||||||
|
const timeBlock = timeblockTemplates.value.find((t) => t.$id === templateId);
|
||||||
|
return (
|
||||||
|
timeBlock?.timeTuples.map((tb: TimeTuple) =>
|
||||||
|
buildInterval(boat, tb, date)
|
||||||
|
) || []
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteBlock(block: Interval) {
|
||||||
|
if (block.$id) {
|
||||||
|
useScheduleStore().deleteInterval(block.$id);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
function onDragEnter(e: DragEvent, type: string) {
|
function onDragEnter(e: DragEvent, type: string) {
|
||||||
console.log('onDragEnter', e, type);
|
|
||||||
if (type === 'day' || type === 'head-day') {
|
if (type === 'day' || type === 'head-day') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (e.target instanceof HTMLDivElement)
|
if (e.target instanceof HTMLDivElement)
|
||||||
@@ -138,7 +228,6 @@ function onDragEnter(e: DragEvent, type: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onDragOver(e: DragEvent, type: string) {
|
function onDragOver(e: DragEvent, type: string) {
|
||||||
console.log('onDragOver');
|
|
||||||
if (type === 'day' || type === 'head-day') {
|
if (type === 'day' || type === 'head-day') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return true;
|
return true;
|
||||||
@@ -146,29 +235,49 @@ function onDragOver(e: DragEvent, type: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function onDragLeave(e: DragEvent, type: string) {
|
function onDragLeave(e: DragEvent, type: string) {
|
||||||
console.log('onDragLeave');
|
|
||||||
if (type === 'day' || type === 'head-day') {
|
if (type === 'day' || type === 'head-day') {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (e.target instanceof HTMLDivElement)
|
if (e.target instanceof HTMLDivElement)
|
||||||
e.target.classList.remove('bg-secondary');
|
e.target.classList.remove('bg-secondary');
|
||||||
console.log(e.target);
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onDrop(
|
function onDrop(
|
||||||
|
//TODO: Move all overlap checking to the store. This is too messy right now.
|
||||||
e: DragEvent,
|
e: DragEvent,
|
||||||
type: string,
|
type: string,
|
||||||
scope: { resource: Boat; timestamp: Timestamp }
|
scope: { resource: Boat; timestamp: Timestamp }
|
||||||
) {
|
) {
|
||||||
console.log('onDrop', e, type, scope);
|
|
||||||
if ((type === 'day' || type === 'head-day') && e.dataTransfer) {
|
if ((type === 'day' || type === 'head-day') && e.dataTransfer) {
|
||||||
const templateId = e.dataTransfer.getData('ID');
|
const templateId = e.dataTransfer.getData('ID');
|
||||||
const date = scope.timestamp.date;
|
const date = scope.timestamp.date;
|
||||||
if (type === 'head-day') {
|
if (type === 'head-day') {
|
||||||
boats.value.map((r) => createTimeBlock(r, templateId, date));
|
overlapped.value = boats.value.map((boat) =>
|
||||||
|
blocksOverlapped(
|
||||||
|
getIntervals(scope.timestamp, boat).concat(
|
||||||
|
timeBlocksFromTemplate(boat, templateId, date)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
console.log(overlapped);
|
||||||
|
if (overlapped.value.length === 0) {
|
||||||
|
boats.value.map((b) => createIntervals(b, templateId, date));
|
||||||
} else {
|
} else {
|
||||||
createTimeBlock(scope.resource, templateId, date);
|
alert.value = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
overlapped.value = blocksOverlapped(
|
||||||
|
getIntervals(scope.timestamp, scope.resource).concat(
|
||||||
|
timeBlocksFromTemplate(scope.resource, templateId, date)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (overlapped.value.length === 0) {
|
||||||
|
createIntervals(scope.resource, templateId, date);
|
||||||
|
} else {
|
||||||
|
alert.value = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (e.target instanceof HTMLDivElement)
|
if (e.target instanceof HTMLDivElement)
|
||||||
|
|||||||
@@ -10,12 +10,12 @@ import {
|
|||||||
import type {
|
import type {
|
||||||
StatusTypes,
|
StatusTypes,
|
||||||
Reservation,
|
Reservation,
|
||||||
TimeBlockTemplate,
|
IntervalTemplate,
|
||||||
TimeBlock,
|
Interval,
|
||||||
TimeTuple,
|
TimeTuple,
|
||||||
} from '../schedule.types';
|
} from '../schedule.types';
|
||||||
|
|
||||||
export const templateA: TimeBlockTemplate = {
|
export const templateA: IntervalTemplate = {
|
||||||
id: '1',
|
id: '1',
|
||||||
name: 'WeekdayBlocks',
|
name: 'WeekdayBlocks',
|
||||||
timeTuples: [
|
timeTuples: [
|
||||||
@@ -25,7 +25,7 @@ export const templateA: TimeBlockTemplate = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export const templateB: TimeBlockTemplate = {
|
export const templateB: IntervalTemplate = {
|
||||||
id: '2',
|
id: '2',
|
||||||
name: 'WeekendBlocks',
|
name: 'WeekendBlocks',
|
||||||
timeTuples: [
|
timeTuples: [
|
||||||
@@ -36,18 +36,18 @@ export const templateB: TimeBlockTemplate = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getSampleTimeBlocks(): TimeBlock[] {
|
export function getSampleIntervals(): Interval[] {
|
||||||
// Hard-code 30 days worth of blocks, for now. Make them random templates
|
// Hard-code 30 days worth of blocks, for now. Make them random templates
|
||||||
const boats = useBoatStore().boats;
|
const boats = useBoatStore().boats;
|
||||||
const result: TimeBlock[] = [];
|
const result: Interval[] = [];
|
||||||
const tsToday: Timestamp = parseTimestamp(today()) as Timestamp;
|
const tsToday: Timestamp = parseTimestamp(today()) as Timestamp;
|
||||||
|
|
||||||
for (let i = 0; i <= 30; i++) {
|
for (let i = 0; i <= 30; i++) {
|
||||||
const template = templateB;
|
const template = templateB;
|
||||||
result.push(
|
result.push(
|
||||||
...boats
|
...boats
|
||||||
.map((b): TimeBlock[] => {
|
.map((b): Interval[] => {
|
||||||
return template.blocks.map((t: TimeTuple): TimeBlock => {
|
return template.blocks.map((t: TimeTuple): Interval => {
|
||||||
return {
|
return {
|
||||||
$id: 'id' + Math.random().toString(32).slice(2),
|
$id: 'id' + Math.random().toString(32).slice(2),
|
||||||
boatId: b.$id,
|
boatId: b.$id,
|
||||||
|
|||||||
@@ -10,18 +10,13 @@ import {
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
Reservation,
|
Reservation,
|
||||||
TimeBlockTemplate,
|
IntervalTemplate,
|
||||||
TimeTuple,
|
TimeTuple,
|
||||||
TimeBlock,
|
Interval,
|
||||||
} from './schedule.types';
|
} from './schedule.types';
|
||||||
import { AppwriteIds, databases } from 'src/boot/appwrite';
|
import { AppwriteIds, databases } from 'src/boot/appwrite';
|
||||||
import { ID, Models } from 'appwrite';
|
import { ID, Models } from 'appwrite';
|
||||||
|
|
||||||
export type Interval = {
|
|
||||||
start: string;
|
|
||||||
end: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export function arrayToTimeTuples(arr: string[]) {
|
export function arrayToTimeTuples(arr: string[]) {
|
||||||
const timeTuples: TimeTuple[] = [];
|
const timeTuples: TimeTuple[] = [];
|
||||||
for (let i = 0; i < arr.length; i += 2) {
|
for (let i = 0; i < arr.length; i += 2) {
|
||||||
@@ -34,16 +29,17 @@ export function timeTuplesOverlapped(tuples: TimeTuple[]): Interval[] {
|
|||||||
return blocksOverlapped(
|
return blocksOverlapped(
|
||||||
tuples.map((tuples) => {
|
tuples.map((tuples) => {
|
||||||
return {
|
return {
|
||||||
|
boatId: '',
|
||||||
start: '01/01/2001 ' + tuples[0],
|
start: '01/01/2001 ' + tuples[0],
|
||||||
end: '01/01/2001 ' + tuples[1],
|
end: '01/01/2001 ' + tuples[1],
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
).map((t) => {
|
).map((t) => {
|
||||||
return { start: t.start.split(' ')[1], end: t.end.split(' ')[1] };
|
return { ...t, start: t.start.split(' ')[1], end: t.end.split(' ')[1] };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function blocksOverlapped(blocks: TimeBlock[] | Interval[]): Interval[] {
|
export function blocksOverlapped(blocks: Interval[] | Interval[]): Interval[] {
|
||||||
return Array.from(
|
return Array.from(
|
||||||
new Set(
|
new Set(
|
||||||
blocks
|
blocks
|
||||||
@@ -60,26 +56,30 @@ export function blocksOverlapped(blocks: TimeBlock[] | Interval[]): Interval[] {
|
|||||||
export function copyTimeTuples(tuples: TimeTuple[]): TimeTuple[] {
|
export function copyTimeTuples(tuples: TimeTuple[]): TimeTuple[] {
|
||||||
return tuples.map((t) => Object.assign([], t));
|
return tuples.map((t) => Object.assign([], t));
|
||||||
}
|
}
|
||||||
export function copyTimeBlockTemplate(
|
export function copyIntervalTemplate(
|
||||||
template: TimeBlockTemplate
|
template: IntervalTemplate
|
||||||
): TimeBlockTemplate {
|
): IntervalTemplate {
|
||||||
return {
|
return {
|
||||||
...template,
|
...template,
|
||||||
timeTuples: copyTimeTuples(template.timeTuples),
|
timeTuples: copyTimeTuples(template.timeTuples || []),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function buildTimeBlock(
|
export function buildISODate(date: string, time: string | null): string {
|
||||||
|
return new Date(date + 'T' + time || '00:00').toISOString();
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildInterval(
|
||||||
resource: Boat,
|
resource: Boat,
|
||||||
time: TimeTuple,
|
time: TimeTuple,
|
||||||
blockDate: string
|
blockDate: string
|
||||||
): TimeBlock {
|
): Interval {
|
||||||
/* When the time zone offset is absent, date-only forms are interpreted
|
/* When the time zone offset is absent, date-only forms are interpreted
|
||||||
as a UTC time and date-time forms are interpreted as local time. */
|
as a UTC time and date-time forms are interpreted as local time. */
|
||||||
const result = {
|
const result = {
|
||||||
boatId: resource.$id,
|
boatId: resource.$id,
|
||||||
start: new Date(blockDate + 'T' + time[0]).toISOString(),
|
start: buildISODate(blockDate, time[0]),
|
||||||
end: new Date(blockDate + 'T' + time[1]).toISOString(),
|
end: buildISODate(blockDate, time[1]),
|
||||||
};
|
};
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -87,10 +87,10 @@ export function buildTimeBlock(
|
|||||||
export const useScheduleStore = defineStore('schedule', () => {
|
export const useScheduleStore = defineStore('schedule', () => {
|
||||||
// TODO: Implement functions to dynamically pull this data.
|
// TODO: Implement functions to dynamically pull this data.
|
||||||
const reservations = ref<Reservation[]>([]);
|
const reservations = ref<Reservation[]>([]);
|
||||||
const timeblocks = ref<TimeBlock[]>([]);
|
const timeblocks = ref<Interval[]>([]);
|
||||||
const timeblockTemplates = ref<TimeBlockTemplate[]>([]);
|
const timeblockTemplates = ref<IntervalTemplate[]>([]);
|
||||||
|
|
||||||
const getTimeBlocks = (date: Timestamp, boat: Boat): TimeBlock[] => {
|
const getIntervals = (date: Timestamp, boat: Boat): Interval[] => {
|
||||||
return timeblocks.value.filter((block) => {
|
return timeblocks.value.filter((block) => {
|
||||||
return (
|
return (
|
||||||
compareDate(parseDate(new Date(block.start)) as Timestamp, date) &&
|
compareDate(parseDate(new Date(block.start)) as Timestamp, date) &&
|
||||||
@@ -98,7 +98,7 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const getTimeBlocksForDate = (date: string): TimeBlock[] => {
|
const getIntervalsForDate = (date: string): Interval[] => {
|
||||||
// TODO: This needs to actually make sure we have the dates we need, stay in sync, etc.
|
// TODO: This needs to actually make sure we have the dates we need, stay in sync, etc.
|
||||||
return timeblocks.value.filter((b) => {
|
return timeblocks.value.filter((b) => {
|
||||||
return compareDate(
|
return compareDate(
|
||||||
@@ -123,37 +123,37 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
async function fetchTimeBlocks() {
|
async function fetchIntervals() {
|
||||||
try {
|
try {
|
||||||
const response = await databases.listDocuments(
|
const response = await databases.listDocuments(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlock
|
AppwriteIds.collection.timeBlock
|
||||||
);
|
);
|
||||||
timeblocks.value = response.documents as TimeBlock[];
|
timeblocks.value = response.documents as Interval[];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch timeblocks', error);
|
console.error('Failed to fetch timeblocks', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchTimeBlockTemplates() {
|
async function fetchIntervalTemplates() {
|
||||||
try {
|
try {
|
||||||
const response = await databases.listDocuments(
|
const response = await databases.listDocuments(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlockTemplate
|
AppwriteIds.collection.timeBlockTemplate
|
||||||
);
|
);
|
||||||
timeblockTemplates.value = response.documents.map(
|
timeblockTemplates.value = response.documents.map(
|
||||||
(d: Models.Document): TimeBlockTemplate => {
|
(d: Models.Document): IntervalTemplate => {
|
||||||
return {
|
return {
|
||||||
...d,
|
...d,
|
||||||
timeTuples: arrayToTimeTuples(d.timeTuple),
|
timeTuples: arrayToTimeTuples(d.timeTuple),
|
||||||
} as TimeBlockTemplate;
|
} as IntervalTemplate;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch timeblock templates', error);
|
console.error('Failed to fetch timeblock templates', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// const getConflicts = (timeblock: TimeBlock, boat: Boat) => {
|
// const getConflicts = (timeblock: Interval, boat: Boat) => {
|
||||||
// const start = date.buildDate({
|
// const start = date.buildDate({
|
||||||
// hour: timeblock.start.hour,
|
// hour: timeblock.start.hour,
|
||||||
// minute: timeblock.start.minute,
|
// minute: timeblock.start.minute,
|
||||||
@@ -212,21 +212,50 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
: reservations.value.push(reservation);
|
: reservations.value.push(reservation);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createTimeBlock = async (block: TimeBlock) => {
|
const createInterval = async (interval: Interval) => {
|
||||||
try {
|
try {
|
||||||
const response = await databases.createDocument(
|
const response = await databases.createDocument(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlock,
|
AppwriteIds.collection.timeBlock,
|
||||||
ID.unique(),
|
ID.unique(),
|
||||||
block
|
interval
|
||||||
);
|
);
|
||||||
timeblocks.value.push(response as TimeBlock);
|
timeblocks.value.push(response as Interval);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error creating TimeBlock: ' + e);
|
console.error('Error creating Interval: ' + e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const updateInterval = async (interval: Interval) => {
|
||||||
const createTimeBlockTemplate = async (template: TimeBlockTemplate) => {
|
try {
|
||||||
|
if (interval.$id) {
|
||||||
|
const response = await databases.updateDocument(
|
||||||
|
AppwriteIds.databaseId,
|
||||||
|
AppwriteIds.collection.timeBlock,
|
||||||
|
interval.$id,
|
||||||
|
{ ...interval, $id: undefined }
|
||||||
|
);
|
||||||
|
timeblocks.value.push(response as Interval);
|
||||||
|
console.log(interval, response);
|
||||||
|
} else {
|
||||||
|
console.error('Update interval called without an ID');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error updating Interval: ' + e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const deleteInterval = async (id: string) => {
|
||||||
|
try {
|
||||||
|
await databases.deleteDocument(
|
||||||
|
AppwriteIds.databaseId,
|
||||||
|
AppwriteIds.collection.timeBlock,
|
||||||
|
id
|
||||||
|
);
|
||||||
|
timeblocks.value = timeblocks.value.filter((block) => block.$id !== id);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error deleting Interval: ' + e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const createIntervalTemplate = async (template: IntervalTemplate) => {
|
||||||
try {
|
try {
|
||||||
const response = await databases.createDocument(
|
const response = await databases.createDocument(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
@@ -234,12 +263,12 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
ID.unique(),
|
ID.unique(),
|
||||||
{ name: template.name, timeTuple: template.timeTuples.flat(2) }
|
{ name: template.name, timeTuple: template.timeTuples.flat(2) }
|
||||||
);
|
);
|
||||||
timeblockTemplates.value.push(response as TimeBlockTemplate);
|
timeblockTemplates.value.push(response as IntervalTemplate);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error updating TimeBlockTemplate: ' + e);
|
console.error('Error updating IntervalTemplate: ' + e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const deleteTimeBlockTemplate = async (id: string) => {
|
const deleteIntervalTemplate = async (id: string) => {
|
||||||
try {
|
try {
|
||||||
await databases.deleteDocument(
|
await databases.deleteDocument(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
@@ -250,11 +279,11 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
(template) => template.$id !== id
|
(template) => template.$id !== id
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error deleting TimeBlockTemplate: ' + e);
|
console.error('Error deleting IntervalTemplate: ' + e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const updateTimeBlockTemplate = async (
|
const updateIntervalTemplate = async (
|
||||||
template: TimeBlockTemplate,
|
template: IntervalTemplate,
|
||||||
id: string
|
id: string
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
@@ -268,10 +297,15 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
timeblockTemplates.value = timeblockTemplates.value.map((b) =>
|
timeblockTemplates.value = timeblockTemplates.value.map((b) =>
|
||||||
b.$id !== id ? b : (response as TimeBlockTemplate)
|
b.$id !== id
|
||||||
|
? b
|
||||||
|
: ({
|
||||||
|
...response,
|
||||||
|
timeTuples: arrayToTimeTuples(response.timeTuple),
|
||||||
|
} as IntervalTemplate)
|
||||||
);
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error updating TimeBlockTemplate: ' + e);
|
console.error('Error updating IntervalTemplate: ' + e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -281,16 +315,18 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
timeblockTemplates,
|
timeblockTemplates,
|
||||||
getBoatReservations,
|
getBoatReservations,
|
||||||
getConflictingReservations,
|
getConflictingReservations,
|
||||||
getTimeBlocksForDate,
|
getIntervalsForDate,
|
||||||
getTimeBlocks,
|
getIntervals,
|
||||||
fetchTimeBlocks,
|
fetchIntervals,
|
||||||
fetchTimeBlockTemplates,
|
fetchIntervalTemplates,
|
||||||
getNewId,
|
getNewId,
|
||||||
addOrCreateReservation,
|
addOrCreateReservation,
|
||||||
createTimeBlock,
|
createInterval,
|
||||||
createTimeBlockTemplate,
|
updateInterval,
|
||||||
deleteTimeBlockTemplate,
|
deleteInterval,
|
||||||
updateTimeBlockTemplate,
|
createIntervalTemplate,
|
||||||
|
deleteIntervalTemplate,
|
||||||
|
updateIntervalTemplate,
|
||||||
isReservationOverlapped,
|
isReservationOverlapped,
|
||||||
isResourceTimeOverlapped,
|
isResourceTimeOverlapped,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ export interface Reservation {
|
|||||||
objects in here? */
|
objects in here? */
|
||||||
|
|
||||||
export type TimeTuple = [start: string, end: string];
|
export type TimeTuple = [start: string, end: string];
|
||||||
export type TimeBlock = Partial<Models.Document> & {
|
export type Interval = Partial<Models.Document> & {
|
||||||
boatId: string;
|
boatId: string;
|
||||||
start: string;
|
start: string;
|
||||||
end: string;
|
end: string;
|
||||||
selected?: false;
|
selected?: false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TimeBlockTemplate = Partial<Models.Document> & {
|
export type IntervalTemplate = Partial<Models.Document> & {
|
||||||
name: string;
|
name: string;
|
||||||
timeTuples: TimeTuple[];
|
timeTuples: TimeTuple[];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user