Sorted out reactivity with storeToRefs
Some checks failed
Build BAB Application Deployment Artifact / build (push) Failing after 2m1s
Some checks failed
Build BAB Application Deployment Artifact / build (push) Failing after 2m1s
This commit is contained in:
19
src/components/scheduling/NavigationBar.vue
Normal file
19
src/components/scheduling/NavigationBar.vue
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<template>
|
||||||
|
<div class="row justify-center">
|
||||||
|
<div class="q-pa-md q-gutter-sm row">
|
||||||
|
<q-btn no-caps class="button" style="margin: 2px" @click="$emit('today')">
|
||||||
|
Today
|
||||||
|
</q-btn>
|
||||||
|
<q-btn no-caps class="button" style="margin: 2px" @click="$emit('prev')">
|
||||||
|
< Prev
|
||||||
|
</q-btn>
|
||||||
|
<q-btn no-caps class="button" style="margin: 2px" @click="$emit('next')">
|
||||||
|
Next >
|
||||||
|
</q-btn>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineEmits(['today', 'prev', 'next']);
|
||||||
|
</script>
|
||||||
129
src/components/scheduling/TimeBlockTemplateComponent.vue
Normal file
129
src/components/scheduling/TimeBlockTemplateComponent.vue
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
<template>
|
||||||
|
<q-card>
|
||||||
|
<q-card-section horizontal>
|
||||||
|
<div>
|
||||||
|
<q-input
|
||||||
|
label="Template name"
|
||||||
|
filled
|
||||||
|
dense
|
||||||
|
v-model="template.name"
|
||||||
|
v-if="editable"
|
||||||
|
/>
|
||||||
|
<q-list dense>
|
||||||
|
<q-item v-for="item in template.timeTuples" :key="item[0]">
|
||||||
|
<q-input
|
||||||
|
dense
|
||||||
|
:filled="editable"
|
||||||
|
v-model="item[0]"
|
||||||
|
type="time"
|
||||||
|
label="Start"
|
||||||
|
:readonly="!editable"
|
||||||
|
/>
|
||||||
|
<q-input
|
||||||
|
:filled="editable"
|
||||||
|
dense
|
||||||
|
v-model="item[1]"
|
||||||
|
type="time"
|
||||||
|
label="End"
|
||||||
|
:readonly="!editable"
|
||||||
|
/> </q-item></q-list
|
||||||
|
><q-btn
|
||||||
|
v-if="editable"
|
||||||
|
dense
|
||||||
|
color="primary"
|
||||||
|
size="sm"
|
||||||
|
label="Add interval"
|
||||||
|
@click="template.timeTuples.push(['00:00', '00:00'])"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<q-card-actions align="right" vertical>
|
||||||
|
<q-btn
|
||||||
|
v-if="!editable"
|
||||||
|
color="primary"
|
||||||
|
icon="edit"
|
||||||
|
label="Edit"
|
||||||
|
@click="editable = !editable"
|
||||||
|
/>
|
||||||
|
<q-btn
|
||||||
|
v-if="editable"
|
||||||
|
color="primary"
|
||||||
|
icon="save"
|
||||||
|
label="Save"
|
||||||
|
@click="saveTemplate($event, template)"
|
||||||
|
/>
|
||||||
|
<q-btn
|
||||||
|
v-if="editable"
|
||||||
|
color="secondary"
|
||||||
|
icon="cancel"
|
||||||
|
label="Cancel"
|
||||||
|
@click="revert"
|
||||||
|
/>
|
||||||
|
<q-btn
|
||||||
|
color="negative"
|
||||||
|
icon="delete"
|
||||||
|
label="Delete"
|
||||||
|
@click="deleteTemplate($event, template)"
|
||||||
|
/>
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card-section>
|
||||||
|
</q-card>
|
||||||
|
<q-dialog v-model="alert">
|
||||||
|
<q-card>
|
||||||
|
<q-card-section>
|
||||||
|
<div class="text-h6">Overlapped blocks!</div>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section class="q-pt-none">
|
||||||
|
<q-chip
|
||||||
|
square
|
||||||
|
icon="schedule"
|
||||||
|
v-for="item in overlapped"
|
||||||
|
:key="item.start"
|
||||||
|
>
|
||||||
|
{{ item.start }}-{{ item.end }}</q-chip
|
||||||
|
>
|
||||||
|
</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>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { timeTuplesOverlapped, useScheduleStore } from 'src/stores/schedule';
|
||||||
|
import { TimeBlockTemplate } from 'src/stores/schedule.types';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
const editable = ref(false);
|
||||||
|
const alert = ref(false);
|
||||||
|
const overlapped = ref();
|
||||||
|
const scheduleStore = useScheduleStore();
|
||||||
|
const template = defineModel<TimeBlockTemplate>({ required: true });
|
||||||
|
|
||||||
|
const revert = () => {
|
||||||
|
editable.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteTemplate = (
|
||||||
|
event: Event,
|
||||||
|
template: TimeBlockTemplate | undefined
|
||||||
|
) => {
|
||||||
|
if (template?.$id) scheduleStore.deleteTimeBlockTemplate(template.$id);
|
||||||
|
};
|
||||||
|
// const edit = () => {
|
||||||
|
// // TODO: Make it so that editing the template does not affect the store. Need to be able to "cancel" editing, and revert to original data
|
||||||
|
// };
|
||||||
|
const saveTemplate = (evt: Event, template: TimeBlockTemplate | undefined) => {
|
||||||
|
if (!template) return false;
|
||||||
|
overlapped.value = timeTuplesOverlapped(template.timeTuples);
|
||||||
|
if (overlapped.value.length > 0) {
|
||||||
|
alert.value = true;
|
||||||
|
} else {
|
||||||
|
if (template.$id) {
|
||||||
|
console.log(template.$id);
|
||||||
|
scheduleStore.updateTimeBlockTemplate(template, template.$id);
|
||||||
|
} else {
|
||||||
|
scheduleStore.createTimeBlockTemplate(template);
|
||||||
|
}
|
||||||
|
editable.value = false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
interval-start="06:00"
|
interval-start="06:00"
|
||||||
:short-interval-label="true"
|
:short-interval-label="true"
|
||||||
v-model="selectedDate"
|
v-model="selectedDate"
|
||||||
:column-count="boatData.length"
|
:column-count="boats.length"
|
||||||
v-touch-swipe.left.right="handleSwipe"
|
v-touch-swipe.left.right="handleSwipe"
|
||||||
>
|
>
|
||||||
<template #head-day="{ scope }">
|
<template #head-day="{ scope }">
|
||||||
@@ -34,12 +34,12 @@
|
|||||||
:id="block.id"
|
:id="block.id"
|
||||||
@click="selectBlock($event, scope, block)"
|
@click="selectBlock($event, scope, block)"
|
||||||
>
|
>
|
||||||
{{ boatData[scope.columnIndex].name }}<br />
|
{{ boats[scope.columnIndex].name }}<br />
|
||||||
{{ selectedBlock?.$id === block.$id ? 'Selected' : 'Available' }}
|
{{ selectedBlock?.$id === block.$id ? 'Selected' : 'Available' }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<!-- <div
|
<!-- <div
|
||||||
v-for="r in boatData[scope.columnIndex].reservations"
|
v-for="r in boats[scope.columnIndex].reservations"
|
||||||
:key="r.id"
|
:key="r.id"
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
@@ -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 { TimeBlock } from 'src/stores/schedule.types';
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
|
||||||
const scheduleStore = useScheduleStore();
|
const scheduleStore = useScheduleStore();
|
||||||
const boatStore = useBoatStore();
|
const { boats } = storeToRefs(useBoatStore());
|
||||||
const boatData = boatStore.boats;
|
const selectedBlock = defineModel<TimeBlock | null>();
|
||||||
const selectedBlock = defineModel<Timeblock | 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: TimeBlock,
|
||||||
timeStartPos: (t: string) => string,
|
timeStartPos: (t: string) => string,
|
||||||
timeDurationHeight: (d: number) => string
|
timeDurationHeight: (d: number) => string
|
||||||
) {
|
) {
|
||||||
@@ -116,8 +116,8 @@ function blockStyles(
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getBoatDisplayName(scope: DayBodyScope) {
|
function getBoatDisplayName(scope: DayBodyScope) {
|
||||||
return boatData && boatData.value[scope.columnIndex]
|
return boats && boats.value[scope.columnIndex]
|
||||||
? boatData.value[scope.columnIndex].displayName
|
? boats.value[scope.columnIndex].displayName
|
||||||
: '';
|
: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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: TimeBlock) {
|
||||||
// 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]: TimeBlock[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const boatBlocks = computed((): BoatBlocks => {
|
const boatBlocks = computed((): BoatBlocks => {
|
||||||
return scheduleStore
|
return scheduleStore
|
||||||
.getTimeblocksForDate(selectedDate.value)
|
.getTimeBlocksForDate(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,18 +175,18 @@ const boatBlocks = computed((): BoatBlocks => {
|
|||||||
}, <BoatBlocks>{});
|
}, <BoatBlocks>{});
|
||||||
});
|
});
|
||||||
|
|
||||||
function getBoatBlocks(scope: DayBodyScope): Timeblock[] {
|
function getBoatBlocks(scope: DayBodyScope): TimeBlock[] {
|
||||||
return boatData.value[scope.columnIndex]
|
return boats.value[scope.columnIndex]
|
||||||
? boatBlocks.value[boatData.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.getTimeBlocksForDate(start);
|
||||||
// const reservations = scheduleStore.getBoatReservations(
|
// const reservations = scheduleStore.getBoatReservations(
|
||||||
// parsed(start) as Timestamp
|
// parsed(start) as Timestamp
|
||||||
// );
|
// );
|
||||||
// boatData.value.map((boat) => {
|
// boats.value.map((boat) => {
|
||||||
// boat.reservations = reservations.filter(
|
// boat.reservations = reservations.filter(
|
||||||
// (reservation) => reservation.resource === boat
|
// (reservation) => reservation.resource === boat
|
||||||
// );
|
// );
|
||||||
|
|||||||
@@ -264,7 +264,7 @@ const columns = <QTableProps['columns']>[
|
|||||||
align: 'left',
|
align: 'left',
|
||||||
label: 'Boat',
|
label: 'Boat',
|
||||||
field: (row) =>
|
field: (row) =>
|
||||||
useBoatStore().boats.value.find((boat) => boat.$id === row.boat)?.name,
|
useBoatStore().boats.find((boat) => boat.$id === row.boat)?.name,
|
||||||
sortable: true,
|
sortable: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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 { TimeBlock } 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<TimeBlock>();
|
||||||
const bookingForm = ref<BookingForm>({
|
const bookingForm = ref<BookingForm>({
|
||||||
bookingId: scheduleStore.getNewId(),
|
bookingId: scheduleStore.getNewId(),
|
||||||
name: auth.currentUser?.name,
|
name: auth.currentUser?.name,
|
||||||
@@ -131,7 +131,7 @@ const bookingForm = ref<BookingForm>({
|
|||||||
});
|
});
|
||||||
|
|
||||||
watch(timeblock, (tb_new) => {
|
watch(timeblock, (tb_new) => {
|
||||||
bookingForm.value.boat = useBoatStore().boats.value.find(
|
bookingForm.value.boat = useBoatStore().boats.find(
|
||||||
(b) => b.$id === tb_new?.boatId
|
(b) => b.$id === tb_new?.boatId
|
||||||
);
|
);
|
||||||
bookingForm.value.startDate = date.formatDate(tb_new?.start, dateFormat);
|
bookingForm.value.startDate = date.formatDate(tb_new?.start, dateFormat);
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
<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="col-9 q-pa-md">
|
||||||
<div class="scheduler">
|
<div class="scheduler">
|
||||||
|
<NavigationBar @next="onNext" @today="onToday" @prev="onPrev" />
|
||||||
<q-calendar-scheduler
|
<q-calendar-scheduler
|
||||||
ref="calendar"
|
ref="calendar"
|
||||||
v-model="selectedDate"
|
v-model="selectedDate"
|
||||||
v-model:model-resources="resources"
|
v-model:model-resources="boats"
|
||||||
resource-key="$id"
|
resource-key="$id"
|
||||||
resource-label="name"
|
resource-label="name"
|
||||||
view="week"
|
view="week"
|
||||||
@@ -22,9 +23,7 @@
|
|||||||
>
|
>
|
||||||
<template #day="{ scope }">
|
<template #day="{ scope }">
|
||||||
<div
|
<div
|
||||||
v-if="
|
v-if="getTimeBlocks(scope.timestamp, scope.resource)"
|
||||||
scheduleStore.getTimeblocks(scope.timestamp, scope.resource)
|
|
||||||
"
|
|
||||||
style="
|
style="
|
||||||
display: flex;
|
display: flex;
|
||||||
flex: 1 0 auto;
|
flex: 1 0 auto;
|
||||||
@@ -35,13 +34,10 @@
|
|||||||
"
|
"
|
||||||
>
|
>
|
||||||
<template
|
<template
|
||||||
v-for="event in scheduleStore.getTimeblocks(
|
v-for="event in getTimeBlocks(scope.timestamp, scope.resource)"
|
||||||
scope.timestamp,
|
|
||||||
scope.resource
|
|
||||||
)"
|
|
||||||
:key="event.id"
|
:key="event.id"
|
||||||
>
|
>
|
||||||
<q-chip square icon="schedule">
|
<q-chip clickable square icon="schedule">
|
||||||
{{ date.formatDate(event.start, 'HH:mm') }} -
|
{{ date.formatDate(event.start, 'HH:mm') }} -
|
||||||
{{ date.formatDate(event.end, 'HH:mm') }}</q-chip
|
{{ date.formatDate(event.end, 'HH:mm') }}</q-chip
|
||||||
>
|
>
|
||||||
@@ -62,6 +58,9 @@
|
|||||||
>
|
>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
|
<q-card-actions align="right">
|
||||||
|
<q-btn label="Add Template" color="primary" @click="addTemplate" />
|
||||||
|
</q-card-actions>
|
||||||
<q-separator spaced />
|
<q-separator spaced />
|
||||||
<q-expansion-item
|
<q-expansion-item
|
||||||
v-for="template in timeblockTemplates"
|
v-for="template in timeblockTemplates"
|
||||||
@@ -74,72 +73,10 @@
|
|||||||
draggable="true"
|
draggable="true"
|
||||||
@dragstart="onDragStart($event, template)"
|
@dragstart="onDragStart($event, template)"
|
||||||
>
|
>
|
||||||
<q-card>
|
<TimeBlockTemplateComponent
|
||||||
<q-card-section>
|
:model-value="template"
|
||||||
<q-input
|
/> </q-expansion-item
|
||||||
label="Template name"
|
|
||||||
filled
|
|
||||||
dense
|
|
||||||
v-model="template.name"
|
|
||||||
v-if="editable"
|
|
||||||
/>
|
|
||||||
<q-list dense>
|
|
||||||
<q-item v-for="item in template.timeTuples" :key="item[0]">
|
|
||||||
<q-input
|
|
||||||
dense
|
|
||||||
:filled="editable"
|
|
||||||
v-model="item[0]"
|
|
||||||
type="time"
|
|
||||||
label="Start"
|
|
||||||
:readonly="!editable"
|
|
||||||
/>
|
|
||||||
<q-input
|
|
||||||
:filled="editable"
|
|
||||||
dense
|
|
||||||
v-model="item[1]"
|
|
||||||
type="time"
|
|
||||||
label="End"
|
|
||||||
:readonly="!editable"
|
|
||||||
/> </q-item
|
|
||||||
></q-list>
|
|
||||||
</q-card-section>
|
|
||||||
<div class="row justify-end q-pa-sm">
|
|
||||||
<q-btn
|
|
||||||
v-if="!editable"
|
|
||||||
color="primary"
|
|
||||||
icon="edit"
|
|
||||||
label="Edit"
|
|
||||||
@click="editable = !editable"
|
|
||||||
/>
|
|
||||||
<q-btn
|
|
||||||
v-if="editable"
|
|
||||||
color="accent"
|
|
||||||
icon="save"
|
|
||||||
label="Save"
|
|
||||||
@click="saveTemplate($event, template)"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</q-card> </q-expansion-item
|
|
||||||
></q-list>
|
></q-list>
|
||||||
<q-dialog v-model="alert">
|
|
||||||
<q-card>
|
|
||||||
<q-card-section>
|
|
||||||
<div class="text-h6">Overlapped blocks!</div>
|
|
||||||
</q-card-section>
|
|
||||||
<q-card-section class="q-pt-none">
|
|
||||||
<q-chip
|
|
||||||
square
|
|
||||||
icon="schedule"
|
|
||||||
v-for="item in overlapped"
|
|
||||||
:key="item.start"
|
|
||||||
>
|
|
||||||
{{ item.start }}-{{ item.end }}</q-chip
|
|
||||||
>
|
|
||||||
</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>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -151,42 +88,35 @@ 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 {
|
import { buildTimeBlock, useScheduleStore } from 'src/stores/schedule';
|
||||||
buildTimeBlock,
|
|
||||||
timeTuplesOverlapped,
|
|
||||||
useScheduleStore,
|
|
||||||
} 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 { TimeBlockTemplate, TimeTuple } from 'src/stores/schedule.types';
|
||||||
import { date } from 'quasar';
|
import { date } from 'quasar';
|
||||||
|
import TimeBlockTemplateComponent from 'src/components/scheduling/TimeBlockTemplateComponent.vue';
|
||||||
|
import NavigationBar from 'src/components/scheduling/NavigationBar.vue';
|
||||||
|
import { storeToRefs } from 'pinia';
|
||||||
|
|
||||||
const selectedDate = ref(today());
|
const selectedDate = ref(today());
|
||||||
const scheduleStore = useScheduleStore();
|
const { fetchBoats } = useBoatStore();
|
||||||
const boatStore = useBoatStore();
|
const { getTimeBlocks, fetchTimeBlocks, fetchTimeBlockTemplates } =
|
||||||
const resources = boatStore.boats;
|
useScheduleStore();
|
||||||
const timeblockTemplates = scheduleStore.timeblockTemplates;
|
const { boats } = storeToRefs(useBoatStore());
|
||||||
const editable = ref(false);
|
const { timeblockTemplates } = storeToRefs(useScheduleStore());
|
||||||
const alert = ref(false);
|
const calendar = ref();
|
||||||
const overlapped = ref<{ start: string; end: string }[]>();
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await boatStore.fetchBoats();
|
await fetchBoats();
|
||||||
await scheduleStore.fetchTimeBlockTemplates();
|
await fetchTimeBlocks();
|
||||||
await scheduleStore.fetchTimeBlockTemplates();
|
await fetchTimeBlockTemplates();
|
||||||
});
|
});
|
||||||
|
|
||||||
const saveTemplate = (evt: Event, template: TimeBlockTemplate) => {
|
function addTemplate() {
|
||||||
overlapped.value = timeTuplesOverlapped(template.timeTuples);
|
timeblockTemplates.value.push({ name: 'New Template', timeTuples: [] });
|
||||||
console.log(overlapped.value);
|
}
|
||||||
alert.value = overlapped.value.length > 0;
|
function createTimeBlock(boat: Boat, templateId: string, date: string) {
|
||||||
editable.value = false;
|
const timeBlock = timeblockTemplates.value.find((t) => t.$id === templateId);
|
||||||
console.log(evt, template);
|
|
||||||
};
|
|
||||||
|
|
||||||
function createTimeblock(boat: Boat, templateId: string, date: string) {
|
|
||||||
const timeBlock = timeblockTemplates.find((t) => t.$id === templateId);
|
|
||||||
timeBlock?.timeTuples.map((tb: TimeTuple) =>
|
timeBlock?.timeTuples.map((tb: TimeTuple) =>
|
||||||
scheduleStore.createTimeblock(buildTimeBlock(boat, tb, date))
|
useScheduleStore().createTimeBlock(buildTimeBlock(boat, tb, date))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,13 +166,23 @@ function onDrop(
|
|||||||
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') {
|
||||||
resources.value.map((r) => createTimeblock(r, templateId, date));
|
boats.value.map((r) => createTimeBlock(r, templateId, date));
|
||||||
} else {
|
} else {
|
||||||
createTimeblock(scope.resource, templateId, date);
|
createTimeBlock(scope.resource, templateId, date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (e.target instanceof HTMLDivElement)
|
if (e.target instanceof HTMLDivElement)
|
||||||
e.target.classList.remove('bg-secondary');
|
e.target.classList.remove('bg-secondary');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onToday() {
|
||||||
|
calendar.value.moveToToday();
|
||||||
|
}
|
||||||
|
function onPrev() {
|
||||||
|
calendar.value.prev();
|
||||||
|
}
|
||||||
|
function onNext() {
|
||||||
|
calendar.value.next();
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Models } from 'appwrite';
|
import { Models } from 'appwrite';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { AppwriteIds, databases } from 'src/boot/appwrite';
|
import { AppwriteIds, databases } from 'src/boot/appwrite';
|
||||||
import { computed, ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
|
|
||||||
// const boatSource = null;
|
// const boatSource = null;
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ export interface Boat extends Models.Document {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const useBoatStore = defineStore('boat', () => {
|
export const useBoatStore = defineStore('boat', () => {
|
||||||
const boatData = ref<Boat[]>([]);
|
const boats = ref<Boat[]>([]);
|
||||||
|
|
||||||
async function fetchBoats() {
|
async function fetchBoats() {
|
||||||
try {
|
try {
|
||||||
@@ -33,18 +33,11 @@ export const useBoatStore = defineStore('boat', () => {
|
|||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.boat
|
AppwriteIds.collection.boat
|
||||||
);
|
);
|
||||||
boatData.value = response.documents as Boat[];
|
boats.value = response.documents as Boat[];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch boats', error);
|
console.error('Failed to fetch boats', error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const boats = computed(() => {
|
|
||||||
if (!boatData.value) {
|
|
||||||
fetchBoats();
|
|
||||||
}
|
|
||||||
return boatData;
|
|
||||||
});
|
|
||||||
|
|
||||||
return { boats, fetchBoats };
|
return { boats, fetchBoats };
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import type {
|
|||||||
StatusTypes,
|
StatusTypes,
|
||||||
Reservation,
|
Reservation,
|
||||||
TimeBlockTemplate,
|
TimeBlockTemplate,
|
||||||
Timeblock,
|
TimeBlock,
|
||||||
TimeTuple,
|
TimeTuple,
|
||||||
} from '../schedule.types';
|
} from '../schedule.types';
|
||||||
|
|
||||||
@@ -36,18 +36,18 @@ export const templateB: TimeBlockTemplate = {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
export function getSampleTimeBlocks(): Timeblock[] {
|
export function getSampleTimeBlocks(): TimeBlock[] {
|
||||||
// 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: TimeBlock[] = [];
|
||||||
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.value
|
...boats
|
||||||
.map((b): Timeblock[] => {
|
.map((b): TimeBlock[] => {
|
||||||
return template.blocks.map((t: TimeTuple): Timeblock => {
|
return template.blocks.map((t: TimeTuple): TimeBlock => {
|
||||||
return {
|
return {
|
||||||
$id: 'id' + Math.random().toString(32).slice(2),
|
$id: 'id' + Math.random().toString(32).slice(2),
|
||||||
boatId: b.$id,
|
boatId: b.$id,
|
||||||
@@ -127,7 +127,7 @@ export function getSampleReservations(): Reservation[] {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return sampleData.map((entry): Reservation => {
|
return sampleData.map((entry): Reservation => {
|
||||||
const boat = <Boat>boatStore.boats.value.find((b) => b.$id == entry.boat);
|
const boat = <Boat>boatStore.boats.find((b) => b.$id == entry.boat);
|
||||||
return {
|
return {
|
||||||
id: entry.id,
|
id: entry.id,
|
||||||
user: entry.user,
|
user: entry.user,
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import {
|
|||||||
Reservation,
|
Reservation,
|
||||||
TimeBlockTemplate,
|
TimeBlockTemplate,
|
||||||
TimeTuple,
|
TimeTuple,
|
||||||
Timeblock,
|
TimeBlock,
|
||||||
} 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';
|
||||||
@@ -43,7 +43,7 @@ export function timeTuplesOverlapped(tuples: TimeTuple[]): Interval[] {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function blocksOverlapped(blocks: Timeblock[] | Interval[]): Interval[] {
|
export function blocksOverlapped(blocks: TimeBlock[] | Interval[]): Interval[] {
|
||||||
return Array.from(
|
return Array.from(
|
||||||
new Set(
|
new Set(
|
||||||
blocks
|
blocks
|
||||||
@@ -61,7 +61,7 @@ export function buildTimeBlock(
|
|||||||
resource: Boat,
|
resource: Boat,
|
||||||
time: TimeTuple,
|
time: TimeTuple,
|
||||||
blockDate: string
|
blockDate: string
|
||||||
): Timeblock {
|
): TimeBlock {
|
||||||
/* 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 = {
|
||||||
@@ -75,10 +75,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<TimeBlock[]>([]);
|
||||||
const timeblockTemplates = ref<TimeBlockTemplate[]>([]);
|
const timeblockTemplates = ref<TimeBlockTemplate[]>([]);
|
||||||
|
|
||||||
const getTimeblocks = (date: Timestamp, boat: Boat): Timeblock[] => {
|
const getTimeBlocks = (date: Timestamp, boat: Boat): TimeBlock[] => {
|
||||||
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) &&
|
||||||
@@ -86,7 +86,7 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
const getTimeblocksForDate = (date: string): Timeblock[] => {
|
const getTimeBlocksForDate = (date: string): TimeBlock[] => {
|
||||||
// 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(
|
||||||
@@ -117,7 +117,7 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlock
|
AppwriteIds.collection.timeBlock
|
||||||
);
|
);
|
||||||
timeblocks.value = response.documents as Timeblock[];
|
timeblocks.value = response.documents as TimeBlock[];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch timeblocks', error);
|
console.error('Failed to fetch timeblocks', error);
|
||||||
}
|
}
|
||||||
@@ -141,7 +141,7 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
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: TimeBlock, 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,
|
||||||
@@ -200,7 +200,7 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
: reservations.value.push(reservation);
|
: reservations.value.push(reservation);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createTimeblock = async (block: Timeblock) => {
|
const createTimeBlock = async (block: TimeBlock) => {
|
||||||
try {
|
try {
|
||||||
const response = await databases.createDocument(
|
const response = await databases.createDocument(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
@@ -208,9 +208,58 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
ID.unique(),
|
ID.unique(),
|
||||||
block
|
block
|
||||||
);
|
);
|
||||||
timeblocks.value.push(response as Timeblock);
|
timeblocks.value.push(response as TimeBlock);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log('Error creating Timeblock: ' + e);
|
console.error('Error creating TimeBlock: ' + e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const createTimeBlockTemplate = async (template: TimeBlockTemplate) => {
|
||||||
|
try {
|
||||||
|
const response = await databases.createDocument(
|
||||||
|
AppwriteIds.databaseId,
|
||||||
|
AppwriteIds.collection.timeBlockTemplate,
|
||||||
|
ID.unique(),
|
||||||
|
{ name: template.name, timeTuple: template.timeTuples.flat(2) }
|
||||||
|
);
|
||||||
|
timeblockTemplates.value.push(response as TimeBlockTemplate);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error updating TimeBlockTemplate: ' + e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const deleteTimeBlockTemplate = async (id: string) => {
|
||||||
|
try {
|
||||||
|
await databases.deleteDocument(
|
||||||
|
AppwriteIds.databaseId,
|
||||||
|
AppwriteIds.collection.timeBlockTemplate,
|
||||||
|
id
|
||||||
|
);
|
||||||
|
timeblockTemplates.value = timeblockTemplates.value.filter(
|
||||||
|
(template) => template.$id !== id
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error deleting TimeBlockTemplate: ' + e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const updateTimeBlockTemplate = async (
|
||||||
|
template: TimeBlockTemplate,
|
||||||
|
id: string
|
||||||
|
) => {
|
||||||
|
try {
|
||||||
|
const response = await databases.updateDocument(
|
||||||
|
AppwriteIds.databaseId,
|
||||||
|
AppwriteIds.collection.timeBlockTemplate,
|
||||||
|
id,
|
||||||
|
{
|
||||||
|
name: template.name,
|
||||||
|
timeTuple: template.timeTuples.flat(2),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
timeblockTemplates.value = timeblockTemplates.value.map((b) =>
|
||||||
|
b.$id !== id ? b : (response as TimeBlockTemplate)
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error updating TimeBlockTemplate: ' + e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -220,13 +269,16 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
timeblockTemplates,
|
timeblockTemplates,
|
||||||
getBoatReservations,
|
getBoatReservations,
|
||||||
getConflictingReservations,
|
getConflictingReservations,
|
||||||
getTimeblocksForDate,
|
getTimeBlocksForDate,
|
||||||
getTimeblocks,
|
getTimeBlocks,
|
||||||
fetchTimeBlocks,
|
fetchTimeBlocks,
|
||||||
fetchTimeBlockTemplates,
|
fetchTimeBlockTemplates,
|
||||||
getNewId,
|
getNewId,
|
||||||
addOrCreateReservation,
|
addOrCreateReservation,
|
||||||
createTimeblock,
|
createTimeBlock,
|
||||||
|
createTimeBlockTemplate,
|
||||||
|
deleteTimeBlockTemplate,
|
||||||
|
updateTimeBlockTemplate,
|
||||||
isReservationOverlapped,
|
isReservationOverlapped,
|
||||||
isResourceTimeOverlapped,
|
isResourceTimeOverlapped,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ 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 TimeBlock = Partial<Models.Document> & {
|
||||||
boatId: string;
|
boatId: string;
|
||||||
start: string;
|
start: string;
|
||||||
end: string;
|
end: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user