Convert type to interface
All checks were successful
Build BAB Application Deployment Artifact / build (push) Successful in 2m1s

This commit is contained in:
2024-04-29 08:37:15 -04:00
parent cb2131ae7e
commit d9cfa4ab56
6 changed files with 72 additions and 48 deletions

View File

@@ -118,7 +118,7 @@ import { date } from 'quasar';
import { computed } from 'vue'; import { computed } from 'vue';
import type { StatusTypes } from 'src/stores/schedule'; import type { StatusTypes } from 'src/stores/schedule';
type EventData = { interface EventData {
event: object; event: object;
scope: { scope: {
timestamp: object; timestamp: object;
@@ -126,16 +126,16 @@ type EventData = {
activeDate: boolean; activeDate: boolean;
droppable: boolean; droppable: boolean;
}; };
}; }
const durations = [1, 1.5, 2, 2.5, 3, 3.5, 4]; const durations = [1, 1.5, 2, 2.5, 3, 3.5, 4];
type ResourceIntervalScope = { interface ResourceIntervalScope {
resource: Boat; resource: Boat;
intervals: []; intervals: [];
timeStartPosX(start: TimestampOrNull): number; timeStartPosX(start: TimestampOrNull): number;
timeDurationWidth(duration: number): number; timeDurationWidth(duration: number): number;
}; }
const statusLookup = { const statusLookup = {
confirmed: ['#14539a', 'white'], confirmed: ['#14539a', 'white'],

View File

@@ -20,7 +20,7 @@ import { computed } from 'vue';
import { date } from 'quasar'; import { date } from 'quasar';
import BoatScheduleTableComponent from './boat/BoatScheduleTableComponent.vue'; import BoatScheduleTableComponent from './boat/BoatScheduleTableComponent.vue';
type EventData = { interface EventData {
event: object; event: object;
scope: { scope: {
timestamp: object; timestamp: object;
@@ -28,7 +28,7 @@ type EventData = {
activeDate: boolean; activeDate: boolean;
droppable: boolean; droppable: boolean;
}; };
}; }
const calendar = ref(); const calendar = ref();
const scheduleStore = useScheduleStore(); const scheduleStore = useScheduleStore();

View File

@@ -8,6 +8,11 @@
flat flat
animated animated
dense dense
:disabled-before="disabledBefore"
interval-height="24"
interval-count="18"
interval-start="06:00"
:short-interval-label="true"
v-model="selectedDate" v-model="selectedDate"
:column-count="boats.length" :column-count="boats.length"
@change="scrollToEvent()" @change="scrollToEvent()"
@@ -19,10 +24,7 @@
</template> </template>
<template #day-body="{ scope }"> <template #day-body="{ scope }">
<div <div v-for="block in blocklist" :key="block.id">
v-for="block in scheduleStore.getTimeblocksForDate(scope.timestamp)"
:key="block.id"
>
<div <div
class="timeblock" class="timeblock"
:style=" :style="
@@ -45,18 +47,24 @@ import {
Timestamp, Timestamp,
diffTimestamp, diffTimestamp,
today, today,
parsed,
parseTimestamp,
addToDate,
} from '@quasar/quasar-ui-qcalendar'; } from '@quasar/quasar-ui-qcalendar';
import CalendarHeaderComponent from './CalendarHeaderComponent.vue'; import CalendarHeaderComponent from './CalendarHeaderComponent.vue';
import { ref } from 'vue'; import { ref, reactive, computed } from 'vue';
import { useBoatStore } from 'src/stores/boat'; import { useBoatStore } from 'src/stores/boat';
import { Timeblock, useScheduleStore } from 'src/stores/schedule'; import { Timeblock, useScheduleStore } from 'src/stores/schedule';
const scheduleStore = useScheduleStore(); const scheduleStore = useScheduleStore();
const boatStore = useBoatStore(); const boatStore = useBoatStore();
const selectedBlock = ref<Timeblock | null>(null);
const selectedDate = ref(today()); const selectedDate = ref(today());
const blocklist = reactive<Timeblock[]>(
scheduleStore.getTimeblocksForDate(parsed(today()) as Timestamp)
);
const boats = boatStore.boats; const boats = boatStore.boats;
const calendar = ref<QCalendarDay | null>(null); const calendar = ref<QCalendarDay | null>(null);
@@ -69,6 +77,7 @@ function blockStyles(
const s = { const s = {
top: '', top: '',
height: '', height: '',
opacity: '',
}; };
if (timeStartPos && timeDurationHeight) { if (timeStartPos && timeDurationHeight) {
s.top = timeStartPos(block.start.time) + 'px'; s.top = timeStartPos(block.start.time) + 'px';
@@ -77,6 +86,9 @@ function blockStyles(
diffTimestamp(block.start, block.end, false) / 1000 / 60 diffTimestamp(block.start, block.end, false) / 1000 / 60
) + 'px'; ) + 'px';
} }
if (selectedBlock.value?.id === block.id) {
s.opacity = '1.0';
}
return s; return s;
} }
@@ -88,20 +100,25 @@ interface DayBodyScope {
} }
function selectBlock(event: MouseEvent, scope: DayBodyScope, block: Timeblock) { function selectBlock(event: MouseEvent, scope: DayBodyScope, block: Timeblock) {
const target = event.target as HTMLDivElement; // TODO: Disable blocks before today with updateDisabled and/or comparison
target.classList.add('selected'); selectedBlock.value = block;
target.textContent = 'selected';
} }
function scrollToEvent() { function scrollToEvent() {
setTimeout(() => calendar.value?.scrollToTime('09:00'), 0); // Should figure out why we need this setTimeout... setTimeout(() => calendar.value?.scrollToTime('09:00'), 10); // Should figure out why we need this setTimeout...
} }
const disabledBefore = computed(() => {
let ts = parseTimestamp(today());
ts = addToDate(ts, { day: -1 });
return ts.date;
});
</script> </script>
<style lang="sass"> <style lang="sass">
.boat-schedule-table-component .boat-schedule-table-component
display: flex display: flex
height: 40vh height: 60vh
.timeblock .timeblock
display: flex display: flex
position: absolute position: absolute
@@ -119,4 +136,6 @@ function scrollToEvent() {
border: 2px solid black border: 2px solid black
.selected .selected
opacity: 1 !important opacity: 1 !important
.q-calendar-day__interval--text
font-size: 0.8em
</style> </style>

View File

@@ -17,13 +17,13 @@
@click="selectedDate = day.date" @click="selectedDate = day.date"
> >
<span class="q-calendar__focus-helper" tabindex="-1" /> <span class="q-calendar__focus-helper" tabindex="-1" />
<div style="width: 100%"> <div style="width: 100%; font-size: 0.9em">
{{ monthFormatter(day, true) }} {{ monthFormatter(day, true) }}
</div> </div>
<div style="width: 100%; font-size: 16px; font-weight: 700"> <div style="width: 100%; font-size: 1.2em; font-weight: 700">
{{ dayFormatter(day, false) }} {{ dayFormatter(day, false) }}
</div> </div>
<div style="width: 100%; font-size: 10px"> <div style="width: 100%; font-size: 1em">
{{ weekdayFormatter(day, true) }} {{ weekdayFormatter(day, true) }}
</div> </div>
</button> </button>

View File

View File

@@ -3,16 +3,10 @@ import { ref } from 'vue';
import { Boat, useBoatStore } from './boat'; import { Boat, useBoatStore } from './boat';
import { date } from 'quasar'; import { date } from 'quasar';
import { DateOptions } from 'quasar'; import { DateOptions } from 'quasar';
import { import { Timestamp, parseDate } from '@quasar/quasar-ui-qcalendar';
Timestamp,
parseDate,
updateRelative,
today,
parsed,
} from '@quasar/quasar-ui-qcalendar';
export type StatusTypes = 'tentative' | 'confirmed' | 'pending' | undefined; export type StatusTypes = 'tentative' | 'confirmed' | 'pending' | undefined;
export type Reservation = { export interface Reservation {
id: number; id: number;
user: string; user: string;
start: Date; start: Date;
@@ -20,42 +14,53 @@ export type Reservation = {
resource: Boat; resource: Boat;
reservationDate: Date; reservationDate: Date;
status?: StatusTypes; status?: StatusTypes;
}; }
// 24 hrs in advance only 2 weekday, and 1 weekend slot // 24 hrs in advance only 2 weekday, and 1 weekend slot
// Within 24 hrs, any available slot // Within 24 hrs, any available slot
/* TODO: Figure out how best to separate out where qcalendar bits should be. /* TODO: Figure out how best to separate out where qcalendar bits should be.
e.g.: Should there be any qcalendar stuff in this store? Or should we have just JS Date e.g.: Should there be any qcalendar stuff in this store? Or should we have just JS Date
objects in here? */ objects in here? */
export type Timeblock = { export interface Timeblock {
id: number;
start: Timestamp; start: Timestamp;
end: Timestamp; end: Timestamp;
}; selected?: false;
}
const sampleBlocks = [ const weekdayBlocks = [
{ {
id: 1, start: { time: '08:00', hour: 8, minute: 0 },
start: { time: '09:00', hour: 9, minute: 0, hasTime: true }, end: { time: '12:00', hour: 12, minute: 0 },
end: { time: '11:30', hour: 12, minute: 0, hasTime: true },
}, },
{ {
id: 2, start: { time: '12:00', hour: 12, minute: 0 },
start: { time: '12:00', hour: 12, minute: 0, hasTime: true }, end: { time: '16:00', hour: 16, minute: 0 },
end: { time: '15:00', hour: 15, minute: 0, hasTime: true },
}, },
{ {
id: 3, start: { time: '17:00', hour: 17, minute: 0 },
start: { time: '15:00', hour: 15, minute: 0, hasTime: true }, end: { time: '21:00', hour: 21, minute: 0 },
end: { time: '18:00', hour: 18, minute: 0, hasTime: true },
},
{
id: 4,
start: { time: '18:00', hour: 18, minute: 0, hasTime: true },
end: { time: '21:00', hour: 21, minute: 0, hasTime: true },
}, },
] as Timeblock[]; ] as Timeblock[];
const weekendBlocks = [
{
start: { time: '07:00', hour: 7, minute: 0 },
end: { time: '10:00', hour: 10, minute: 0 },
},
{
start: { time: '10:00', hour: 10, minute: 0 },
end: { time: '13:00', hour: 13, minute: 0 },
},
{
start: { time: '13:00', hour: 13, minute: 0 },
end: { time: '16:00', hour: 16, minute: 0 },
},
{
start: { time: '16:00', hour: 16, minute: 0 },
end: { time: '19:00', hour: 19, minute: 0 },
},
];
function getSampleReservations(): Reservation[] { function getSampleReservations(): Reservation[] {
const sampleData = [ const sampleData = [
{ {
@@ -137,7 +142,7 @@ function getSampleReservations(): Reservation[] {
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[]>(getSampleReservations()); const reservations = ref<Reservation[]>(getSampleReservations());
const timeblocks = sampleBlocks; const timeblocks = weekdayBlocks;
const getTimeblocksForDate = (date: Timestamp): Timeblock[] => { const getTimeblocksForDate = (date: Timestamp): Timeblock[] => {
return timeblocks.map((t) => { return timeblocks.map((t) => {