Fix update of timblock

This commit is contained in:
2024-04-30 17:04:55 -04:00
parent b66afb5692
commit 28600578f1
4 changed files with 48 additions and 43 deletions

View File

@@ -90,17 +90,13 @@ interface BoatData extends Boat {
const scheduleStore = useScheduleStore(); const scheduleStore = useScheduleStore();
const boatStore = useBoatStore(); const boatStore = useBoatStore();
const selectedBlock = ref<Timeblock | null>(null); const selectedBlock = defineModel<Timeblock | null>();
const selectedDate = ref(today()); const selectedDate = ref(today());
const boatData = ref<BoatData[]>(boatStore.boats); const boatData = ref<BoatData[]>(boatStore.boats);
const calendar = ref<QCalendarDay | null>(null); const calendar = ref<QCalendarDay | null>(null);
const emit = defineEmits<{
updateBoatTime: [block: Timeblock];
}>();
function handleSwipe({ ...event }) { function handleSwipe({ ...event }) {
event.direction === 'right' ? calendar.value?.prev() : calendar.value?.next(); event.direction === 'right' ? calendar.value?.prev() : calendar.value?.next();
} }
@@ -168,8 +164,6 @@ function selectBlock(event: MouseEvent, scope: DayBodyScope, block: Timeblock) {
selectedBlock.value === block selectedBlock.value === block
? (selectedBlock.value = null) ? (selectedBlock.value = null)
: (selectedBlock.value = block); : (selectedBlock.value = block);
emit('updateBoatTime', block);
} }
function changeEvent({ start }: { start: string }) { function changeEvent({ start }: { start: string }) {

View File

@@ -24,7 +24,7 @@
Use the calendar to pick a date. Select an available boat and Use the calendar to pick a date. Select an available boat and
timeslot below. timeslot below.
</q-banner> </q-banner>
<BoatScheduleTableComponent @updateBoatTime="updateBoat" /> <BoatScheduleTableComponent v-model="timeblock" />
<q-banner <q-banner
rounded rounded
@@ -79,11 +79,20 @@ import { useScheduleStore } from 'src/stores/schedule';
import { Reservation, Timeblock } from 'src/stores/schedule.types'; import { Reservation, 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 {
bookingId: string;
name?: string;
boat?: Boat;
startDate?: string;
endDate?: string;
}
const auth = useAuthStore(); 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 bookingForm = reactive({ const timeblock = ref<Timeblock>();
const bookingForm = ref<BookingForm>({
bookingId: scheduleStore.getNewId(), bookingId: scheduleStore.getNewId(),
name: auth.currentUser?.name, name: auth.currentUser?.name,
boat: <Boat | undefined>undefined, boat: <Boat | undefined>undefined,
@@ -91,22 +100,21 @@ const bookingForm = reactive({
endDate: date.formatDate(new Date(), dateFormat), endDate: date.formatDate(new Date(), dateFormat),
}); });
watch(bookingForm, (b, a) => { watch(timeblock, (tb_new) => {
const newRes = <Reservation>{ console.log('Hi');
id: b.bookingId, bookingForm.value.boat = useBoatStore().boats.find(
user: b.name, (b) => b.$id === tb_new?.boatId
resource: b.boat, );
start: date.extractDate(b.startDate, dateFormat), bookingForm.value.startDate = date.formatDate(tb_new?.start, dateFormat);
end: date.extractDate(b.endDate, dateFormat), bookingForm.value.endDate = date.formatDate(tb_new?.end, dateFormat);
reservationDate: new Date(), console.log(tb_new);
status: 'tentative',
};
//TODO: Turn this into a validator.
scheduleStore.isReservationOverlapped(newRes)
? Dialog.create({ message: 'This booking overlaps another!' })
: scheduleStore.addOrCreateReservation(newRes);
}); });
// //TODO: Turn this into a validator.
// scheduleStore.isReservationOverlapped(newRes)
// ? Dialog.create({ message: 'This booking overlaps another!' })
// : scheduleStore.addOrCreateReservation(newRes);
const onReset = () => { const onReset = () => {
// TODO // TODO
}; };
@@ -115,27 +123,27 @@ const onSubmit = () => {
// TODO // TODO
}; };
const updateBoat = (block: Timeblock) => {
bookingForm.boat = useBoatStore().boats.find((b) => b.$id === block.boatId);
bookingForm.startDate = date.formatDate(block.start, dateFormat);
bookingForm.endDate = date.formatDate(block.end, dateFormat);
console.log(bookingForm.startDate);
};
const bookingDuration = computed(() => { const bookingDuration = computed(() => {
const diff = date.getDateDiff( if (bookingForm.value.endDate && bookingForm.value.startDate) {
bookingForm.endDate, const diff = date.getDateDiff(
bookingForm.startDate, bookingForm.value.endDate,
'minutes' bookingForm.value.startDate,
); 'minutes'
return diff <= 0 );
? 'Invalid' return diff <= 0
: (diff > 60 ? Math.trunc(diff / 60) + ' hours' : '') + ? 'Invalid'
(diff % 60 > 0 ? ' ' + (diff % 60) + ' minutes' : ''); : (diff > 60 ? Math.trunc(diff / 60) + ' hours' : '') +
(diff % 60 > 0 ? ' ' + (diff % 60) + ' minutes' : '');
} else {
return 0;
}
}); });
const bookingSummary = computed(() => { const bookingSummary = computed(() => {
return bookingForm.boat && bookingForm.startDate && bookingForm.endDate return bookingForm.value.boat &&
? `${bookingForm.boat.name} @ ${bookingForm.startDate} for ${bookingDuration.value}` bookingForm.value.startDate &&
bookingForm.value.endDate
? `${bookingForm.value.boat.name} @ ${bookingForm.value.startDate} for ${bookingDuration.value}`
: ''; : '';
}); });
</script> </script>

View File

@@ -81,9 +81,12 @@ export const useScheduleStore = defineStore('schedule', () => {
return isResourceTimeOverlapped(res.resource, res.start, res.end); return isResourceTimeOverlapped(res.resource, res.start, res.end);
}; };
const getNewId = () => { const getNewId = (): string => {
return [...Array(20)]
.map(() => Math.floor(Math.random() * 16).toString(16))
.join('');
// Trivial placeholder // Trivial placeholder
return Math.max(...reservations.value.map((item) => item.id)) + 1; //return Math.max(...reservations.value.map((item) => item.id)) + 1;
}; };
const addOrCreateReservation = (reservation: Reservation) => { const addOrCreateReservation = (reservation: Reservation) => {

View File

@@ -2,7 +2,7 @@ import type { Boat } from './boat';
export type StatusTypes = 'tentative' | 'confirmed' | 'pending' | undefined; export type StatusTypes = 'tentative' | 'confirmed' | 'pending' | undefined;
export interface Reservation { export interface Reservation {
id: number; id: string;
user: string; user: string;
start: Date; start: Date;
end: Date; end: Date;