Compare commits
12 Commits
76b0498a18
...
59d2729719
| Author | SHA1 | Date | |
|---|---|---|---|
|
59d2729719
|
|||
|
9f398e5509
|
|||
|
2fb236cf97
|
|||
|
7bc0573455
|
|||
|
68a2b8ffff
|
|||
|
ce696a5a04
|
|||
|
b0d6ec877b
|
|||
|
c03ad48615
|
|||
|
55bc1acbb3
|
|||
|
cd692a6f3b
|
|||
|
737de91bbc
|
|||
|
a6e357f973
|
@@ -1,9 +0,0 @@
|
|||||||
root = true
|
|
||||||
|
|
||||||
[*]
|
|
||||||
charset = utf-8
|
|
||||||
indent_style = space
|
|
||||||
indent_size = 2
|
|
||||||
end_of_line = lf
|
|
||||||
insert_final_newline = true
|
|
||||||
trim_trailing_whitespace = true
|
|
||||||
2
.env.production
Normal file
2
.env.production
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
APPWRITE_API_ENDPOINT='https://appwrite.oys.undock.ca/v1'
|
||||||
|
APPWRITE_API_PROJECT='bab'
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
{
|
|
||||||
"singleQuote": true,
|
|
||||||
"semi": true
|
|
||||||
}
|
|
||||||
@@ -21,7 +21,8 @@
|
|||||||
"file": "^0.2.2",
|
"file": "^0.2.2",
|
||||||
"pinia": "^2.1.7",
|
"pinia": "^2.1.7",
|
||||||
"vue": "3",
|
"vue": "3",
|
||||||
"vue-router": "4"
|
"vue-router": "4",
|
||||||
|
"vue3-google-login": "^2.0.26"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@quasar/app-vite": "^1.9.1",
|
"@quasar/app-vite": "^1.9.1",
|
||||||
|
|||||||
@@ -48,12 +48,12 @@ module.exports = configure(function (/* ctx */) {
|
|||||||
|
|
||||||
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#build
|
// Full list of options: https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#build
|
||||||
build: {
|
build: {
|
||||||
env: require('dotenv').config({ path: '.env.local' }).parsed,
|
env: require('dotenv').config().parsed,
|
||||||
target: {
|
target: {
|
||||||
browser: ['es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1'],
|
browser: ['es2019', 'edge88', 'firefox78', 'chrome87', 'safari13.1'],
|
||||||
node: 'node16',
|
node: 'node16',
|
||||||
},
|
},
|
||||||
vueRouterMode: 'hash', // available values: 'hash', 'history'
|
vueRouterMode: 'history', // available values: 'hash', 'history'
|
||||||
// vueRouterBase,
|
// vueRouterBase,
|
||||||
// vueDevtools,
|
// vueDevtools,
|
||||||
// vueOptionsAPI: false,
|
// vueOptionsAPI: false,
|
||||||
|
|||||||
@@ -1,40 +1,74 @@
|
|||||||
import { boot } from 'quasar/wrappers';
|
import { boot } from 'quasar/wrappers';
|
||||||
import { Client, Account, Databases, Functions, ID } from 'appwrite';
|
import {
|
||||||
|
Client,
|
||||||
|
Account,
|
||||||
|
Databases,
|
||||||
|
Functions,
|
||||||
|
ID,
|
||||||
|
AppwriteException,
|
||||||
|
Teams,
|
||||||
|
} from 'appwrite';
|
||||||
import { useAuthStore } from 'src/stores/auth';
|
import { useAuthStore } from 'src/stores/auth';
|
||||||
import { Dialog, Notify } from 'quasar';
|
import { Dialog, Notify } from 'quasar';
|
||||||
import type { Router } from 'vue-router';
|
import type { Router } from 'vue-router';
|
||||||
|
|
||||||
const client = new Client();
|
const client = new Client();
|
||||||
|
|
||||||
// appwrite.io SaaS
|
let APPWRITE_API_ENDPOINT, APPWRITE_API_PROJECT;
|
||||||
// client
|
|
||||||
// .setEndpoint('https://api.bab.toal.ca/v1')
|
|
||||||
// .setProject('653ef6f76baf06d68034');
|
|
||||||
// const appDatabaseId = '654ac5044d1c446feb71';
|
|
||||||
|
|
||||||
// Private self-hosted appwrite
|
// Private self-hosted appwrite
|
||||||
if (process.env.APPWRITE_API_ENDPOINT && process.env.APPWRITE_API_PROJECT)
|
if (process.env.APPWRITE_API_ENDPOINT && process.env.APPWRITE_API_PROJECT) {
|
||||||
client
|
APPWRITE_API_ENDPOINT = process.env.APPWRITE_API_ENDPOINT;
|
||||||
.setEndpoint(process.env.APPWRITE_API_ENDPOINT)
|
APPWRITE_API_PROJECT = process.env.APPWRITE_API_PROJECT;
|
||||||
.setProject(process.env.APPWRITE_API_PROJECT);
|
} else if (process.env.DEV) {
|
||||||
|
APPWRITE_API_ENDPOINT = 'http://localhost:4000/api/v1';
|
||||||
|
APPWRITE_API_PROJECT = '65ede55a213134f2b688';
|
||||||
|
} else {
|
||||||
|
APPWRITE_API_ENDPOINT = 'https://appwrite.oys.undock.ca/v1';
|
||||||
|
APPWRITE_API_PROJECT = 'bab';
|
||||||
|
}
|
||||||
|
client.setEndpoint(APPWRITE_API_ENDPOINT).setProject(APPWRITE_API_PROJECT);
|
||||||
|
|
||||||
//TODO move this to config file
|
const pwresetUrl = process.env.DEV
|
||||||
const AppwriteIds = {
|
? 'http://localhost:4000/pwreset'
|
||||||
databaseId: '65ee1cbf9c2493faf15f',
|
: 'https://oys.undock.ca/pwreset';
|
||||||
collection: {
|
|
||||||
boat: '66341910003e287cd71c',
|
const AppwriteIds = process.env.DEV
|
||||||
reservation: '663f8847000b8f5e29bb',
|
? {
|
||||||
skillTags: '66072582a74d94a4bd01',
|
databaseId: '65ee1cbf9c2493faf15f',
|
||||||
task: '65ee1cd5b550023fae4f',
|
collection: {
|
||||||
taskTags: '65ee21d72d5c8007c34c',
|
boat: '66341910003e287cd71c',
|
||||||
timeBlock: '66361869002883fb4c4b',
|
reservation: '663f8847000b8f5e29bb',
|
||||||
timeBlockTemplate: '66361f480007fdd639af',
|
skillTags: '66072582a74d94a4bd01',
|
||||||
},
|
task: '65ee1cd5b550023fae4f',
|
||||||
};
|
taskTags: '65ee21d72d5c8007c34c',
|
||||||
|
interval: '66361869002883fb4c4b',
|
||||||
|
intervalTemplate: '66361f480007fdd639af',
|
||||||
|
},
|
||||||
|
function: {
|
||||||
|
userinfo: 'userinfo',
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
databaseId: 'bab_prod',
|
||||||
|
collection: {
|
||||||
|
boat: 'boat',
|
||||||
|
reservation: 'reservation',
|
||||||
|
skillTags: 'skillTags',
|
||||||
|
task: 'task',
|
||||||
|
taskTags: 'taskTags',
|
||||||
|
interval: 'interval',
|
||||||
|
intervalTemplate: 'intervalTemplate',
|
||||||
|
},
|
||||||
|
function: {
|
||||||
|
userinfo: '664038294b5473ef0c8d',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const account = new Account(client);
|
const account = new Account(client);
|
||||||
const databases = new Databases(client);
|
const databases = new Databases(client);
|
||||||
const functions = new Functions(client);
|
const functions = new Functions(client);
|
||||||
|
const teams = new Teams(client);
|
||||||
|
|
||||||
let appRouter: Router;
|
let appRouter: Router;
|
||||||
|
|
||||||
@@ -65,7 +99,7 @@ async function logout() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function login(email: string, password: string) {
|
async function login(email: string, password: string) {
|
||||||
const notification = Notify.create({
|
const notification = Notify.create({
|
||||||
type: 'primary',
|
type: 'primary',
|
||||||
position: 'top',
|
position: 'top',
|
||||||
@@ -75,39 +109,57 @@ function login(email: string, password: string) {
|
|||||||
group: false,
|
group: false,
|
||||||
});
|
});
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
authStore
|
try {
|
||||||
.login(email, password)
|
await authStore.login(email, password);
|
||||||
.then(() => {
|
notification({
|
||||||
notification({
|
type: 'positive',
|
||||||
type: 'positive',
|
message: 'Logged in!',
|
||||||
message: 'Logged in!',
|
timeout: 2000,
|
||||||
timeout: 2000,
|
spinner: false,
|
||||||
spinner: false,
|
icon: 'check_circle',
|
||||||
icon: 'check_circle',
|
});
|
||||||
});
|
console.log('Redirecting to index page');
|
||||||
console.log('Redirecting to index page');
|
appRouter.replace({ name: 'index' });
|
||||||
appRouter.replace({ name: 'index' });
|
} catch (error: unknown) {
|
||||||
})
|
if (error instanceof AppwriteException) {
|
||||||
.catch(function (reason: Error) {
|
if (error.type === 'user_session_already_exists') {
|
||||||
notification({
|
appRouter.replace({ name: 'index' });
|
||||||
type: 'negative',
|
notification({
|
||||||
message: 'Login failed.',
|
type: 'positive',
|
||||||
timeout: 1,
|
message: 'Already Logged in!',
|
||||||
});
|
timeout: 2000,
|
||||||
|
spinner: false,
|
||||||
|
icon: 'check_circle',
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
Dialog.create({
|
Dialog.create({
|
||||||
title: 'Login Error!',
|
title: 'Login Error!',
|
||||||
message: reason.message,
|
message: error.message,
|
||||||
persistent: true,
|
persistent: true,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
notification({
|
||||||
|
type: 'negative',
|
||||||
|
message: 'Login failed.',
|
||||||
|
timeout: 2000,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function resetPassword(email: string) {
|
||||||
|
await account.createRecovery(email, pwresetUrl);
|
||||||
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
client,
|
client,
|
||||||
account,
|
account,
|
||||||
|
teams,
|
||||||
databases,
|
databases,
|
||||||
functions,
|
functions,
|
||||||
ID,
|
ID,
|
||||||
AppwriteIds,
|
AppwriteIds,
|
||||||
login,
|
login,
|
||||||
logout,
|
logout,
|
||||||
|
resetPassword,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,37 +4,49 @@
|
|||||||
show-if-above
|
show-if-above
|
||||||
:width="200"
|
:width="200"
|
||||||
:breakpoint="1024"
|
:breakpoint="1024"
|
||||||
@update:model-value="$emit('drawer-toggle')"
|
@update:model-value="$emit('drawer-toggle')">
|
||||||
>
|
|
||||||
<q-scroll-area class="fit">
|
<q-scroll-area class="fit">
|
||||||
<q-list padding class="menu-list">
|
<q-list
|
||||||
<template v-for="link in enabledLinks" :key="link.name">
|
padding
|
||||||
<!-- TODO: Template this to be DRY --><q-item
|
class="menu-list">
|
||||||
|
<template
|
||||||
|
v-for="link in enabledLinks"
|
||||||
|
:key="link.name">
|
||||||
|
<!-- TODO: Template this to be DRY -->
|
||||||
|
<q-item
|
||||||
clickable
|
clickable
|
||||||
v-ripple
|
v-ripple
|
||||||
:to="link.to"
|
:to="link.to">
|
||||||
>
|
|
||||||
<q-item-section avatar>
|
<q-item-section avatar>
|
||||||
<q-icon :name="link.icon" />
|
<q-icon :name="link.icon" />
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
|
|
||||||
<q-item-section> {{ link.name }} </q-item-section>
|
<q-item-section>{{ link.name }}</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
<q-list v-if="link.sublinks">
|
<q-list v-if="link.sublinks">
|
||||||
<div v-for="sublink in link.sublinks" :key="sublink.name">
|
<div
|
||||||
<q-item clickable v-ripple :to="sublink.to" class="q-ml-md">
|
v-for="sublink in link.sublinks"
|
||||||
|
:key="sublink.name">
|
||||||
|
<q-item
|
||||||
|
clickable
|
||||||
|
v-ripple
|
||||||
|
:to="sublink.to"
|
||||||
|
class="q-ml-md">
|
||||||
<q-item-section avatar>
|
<q-item-section avatar>
|
||||||
<q-icon :name="sublink.icon" />
|
<q-icon :name="sublink.icon" />
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
|
|
||||||
<q-item-section> {{ sublink.name }} </q-item-section>
|
<q-item-section>{{ sublink.name }}</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
</div></q-list
|
</div>
|
||||||
>
|
</q-list>
|
||||||
</template>
|
</template>
|
||||||
<q-item clickable v-ripple @click="logout()">
|
<q-item
|
||||||
<q-item-section avatar><q-icon name="logout" /></q-item-section
|
clickable
|
||||||
><q-item-section>Logout</q-item-section>
|
v-ripple
|
||||||
|
@click="logout()">
|
||||||
|
<q-item-section avatar><q-icon name="logout" /></q-item-section>
|
||||||
|
<q-item-section>Logout</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
</q-list>
|
</q-list>
|
||||||
</q-scroll-area>
|
</q-scroll-area>
|
||||||
|
|||||||
@@ -1,8 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div v-if="boats">
|
<div v-if="boats">
|
||||||
<q-card v-for="boat in boats" :key="boat.id" flat class="mobile-card">
|
<q-card
|
||||||
|
v-for="boat in boats"
|
||||||
|
:key="boat.id"
|
||||||
|
class="mobile-card q-ma-sm">
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<q-img :src="boat.imgSrc" :fit="'scale-down'">
|
<q-img
|
||||||
|
:src="boat.imgSrc"
|
||||||
|
:fit="'scale-down'">
|
||||||
<div class="row absolute-top">
|
<div class="row absolute-top">
|
||||||
<div class="col text-h6 text-left">{{ boat.name }}</div>
|
<div class="col text-h6 text-left">{{ boat.name }}</div>
|
||||||
<div class="col text-right">{{ boat.class }}</div>
|
<div class="col text-right">{{ boat.class }}</div>
|
||||||
|
|||||||
@@ -113,12 +113,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {
|
import { useScheduleStore } from 'src/stores/schedule';
|
||||||
copyIntervalTemplate,
|
|
||||||
timeTuplesOverlapped,
|
|
||||||
useScheduleStore,
|
|
||||||
} from 'src/stores/schedule';
|
|
||||||
import { IntervalTemplate } from 'src/stores/schedule.types';
|
import { IntervalTemplate } from 'src/stores/schedule.types';
|
||||||
|
import { copyIntervalTemplate, timeTuplesOverlapped } from 'src/utils/schedule';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
const alert = ref(false);
|
const alert = ref(false);
|
||||||
const overlapped = ref();
|
const overlapped = ref();
|
||||||
|
|||||||
@@ -1,63 +1,83 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div>
|
||||||
<CalendarHeaderComponent v-model="selectedDate" />
|
<q-card>
|
||||||
<div class="boat-schedule-table-component">
|
<q-toolbar>
|
||||||
<QCalendarDay
|
<q-toolbar-title>Select a Boat and Time</q-toolbar-title>
|
||||||
ref="calendar"
|
<q-btn
|
||||||
class="q-pa-xs"
|
icon="close"
|
||||||
flat
|
flat
|
||||||
animated
|
round
|
||||||
dense
|
dense
|
||||||
:disabled-before="disabledBefore"
|
v-close-popup />
|
||||||
interval-height="24"
|
</q-toolbar>
|
||||||
interval-count="18"
|
<q-separator />
|
||||||
interval-start="06:00"
|
<CalendarHeaderComponent v-model="selectedDate" />
|
||||||
:short-interval-label="true"
|
<div class="boat-schedule-table-component">
|
||||||
v-model="selectedDate"
|
<QCalendarDay
|
||||||
:column-count="boats.length"
|
ref="calendar"
|
||||||
v-touch-swipe.left.right="handleSwipe"
|
class="q-pa-xs"
|
||||||
>
|
flat
|
||||||
<template #head-day="{ scope }">
|
animated
|
||||||
<div style="text-align: center; font-weight: 800">
|
dense
|
||||||
{{ getBoatDisplayName(scope) }}
|
:disabled-before="disabledBefore"
|
||||||
</div>
|
interval-height="24"
|
||||||
</template>
|
interval-count="18"
|
||||||
|
interval-start="06:00"
|
||||||
|
:short-interval-label="true"
|
||||||
|
v-model="selectedDate"
|
||||||
|
:column-count="boats.length"
|
||||||
|
v-touch-swipe.left.right="handleSwipe">
|
||||||
|
<template #head-day="{ scope }">
|
||||||
|
<div style="text-align: center; font-weight: 800">
|
||||||
|
{{ getBoatDisplayName(scope) }}
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template #day-body="{ scope }">
|
<template #day-body="{ scope }">
|
||||||
<div v-for="block in getBoatBlocks(scope)" :key="block.$id">
|
|
||||||
<div
|
<div
|
||||||
class="timeblock"
|
v-for="block in getBoatBlocks(scope)"
|
||||||
:class="selectedBlock?.$id === block.$id ? 'selected' : ''"
|
:key="block.$id">
|
||||||
:style="
|
<div
|
||||||
blockStyles(block, scope.timeStartPos, scope.timeDurationHeight)
|
class="timeblock"
|
||||||
"
|
:class="selectedBlock?.$id === block.$id ? 'selected' : ''"
|
||||||
:id="block.id"
|
:style="
|
||||||
@click="selectBlock($event, scope, block)"
|
blockStyles(
|
||||||
>
|
block,
|
||||||
{{ boats[scope.columnIndex].name }}<br />
|
scope.timeStartPos,
|
||||||
{{ selectedBlock?.$id === block.$id ? 'Selected' : 'Available' }}
|
scope.timeDurationHeight
|
||||||
|
)
|
||||||
|
"
|
||||||
|
:id="block.id"
|
||||||
|
@click="selectBlock($event, scope, block)"
|
||||||
|
v-close-popup>
|
||||||
|
{{ boats[scope.columnIndex].name }}
|
||||||
|
<br />
|
||||||
|
{{
|
||||||
|
selectedBlock?.$id === block.$id ? 'Selected' : 'Available'
|
||||||
|
}}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
v-for="reservation in getBoatReservations(scope)"
|
|
||||||
:key="reservation.$id"
|
|
||||||
>
|
|
||||||
<div
|
<div
|
||||||
class="reservation"
|
v-for="reservation in getBoatReservations(scope)"
|
||||||
:style="
|
:key="reservation.$id">
|
||||||
reservationStyles(
|
<div
|
||||||
reservation,
|
class="reservation column"
|
||||||
scope.timeStartPos,
|
:style="
|
||||||
scope.timeDurationHeight
|
reservationStyles(
|
||||||
)
|
reservation,
|
||||||
"
|
scope.timeStartPos,
|
||||||
>
|
scope.timeDurationHeight
|
||||||
{{ getUserName(reservation.user) || 'loading...' }}
|
)
|
||||||
|
">
|
||||||
|
{{ getUserName(reservation.user) || 'loading...' }}
|
||||||
|
<br />
|
||||||
|
<q-chip class="gt-md">{{ reservation.reason }}</q-chip>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</template>
|
||||||
</template>
|
</QCalendarDay>
|
||||||
</QCalendarDay>
|
</div>
|
||||||
</div>
|
</q-card>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -91,7 +111,6 @@ const calendar = ref<QCalendarDay | null>(null);
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await useBoatStore().fetchBoats();
|
await useBoatStore().fetchBoats();
|
||||||
await scheduleStore.fetchIntervals();
|
|
||||||
await scheduleStore.fetchIntervalTemplates();
|
await scheduleStore.fetchIntervalTemplates();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -169,6 +188,7 @@ interface DayBodyScope {
|
|||||||
|
|
||||||
function selectBlock(event: MouseEvent, scope: DayBodyScope, block: Interval) {
|
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
|
||||||
|
if (scope.timestamp.disabled) return false;
|
||||||
selectedBlock.value === block
|
selectedBlock.value === block
|
||||||
? (selectedBlock.value = null)
|
? (selectedBlock.value = null)
|
||||||
: (selectedBlock.value = block);
|
: (selectedBlock.value = block);
|
||||||
@@ -176,7 +196,7 @@ function selectBlock(event: MouseEvent, scope: DayBodyScope, block: Interval) {
|
|||||||
|
|
||||||
const boatBlocks = computed((): Record<string, Interval[]> => {
|
const boatBlocks = computed((): Record<string, Interval[]> => {
|
||||||
return scheduleStore
|
return scheduleStore
|
||||||
.getIntervalsForDate(selectedDate.value)
|
.getIntervals(selectedDate.value)
|
||||||
.reduce((result, interval) => {
|
.reduce((result, interval) => {
|
||||||
if (!result[interval.boatId]) result[interval.boatId] = [];
|
if (!result[interval.boatId]) result[interval.boatId] = [];
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -3,48 +3,55 @@
|
|||||||
<q-page-container>
|
<q-page-container>
|
||||||
<q-page class="flex bg-image flex-center">
|
<q-page class="flex bg-image flex-center">
|
||||||
<q-card
|
<q-card
|
||||||
v-bind:style="$q.screen.lt.sm ? { width: '80%' } : { width: '30%' }"
|
v-bind:style="$q.screen.lt.sm ? { width: '80%' } : { width: '30%' }">
|
||||||
>
|
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<q-img fit="scale-down" src="~assets/oysqn_logo.png" />
|
<q-img
|
||||||
|
fit="scale-down"
|
||||||
|
src="~assets/oysqn_logo.png" />
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section>
|
<q-card-section>
|
||||||
<div class="text-center q-pt-sm">
|
<div class="text-center q-pt-sm">
|
||||||
<div class="col text-h6">Log in</div>
|
<div class="col text-h6">Log in</div>
|
||||||
</div>
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section>
|
<q-form>
|
||||||
<q-form class="q-gutter-md">
|
<q-card-section class="q-gutter-md">
|
||||||
<q-input
|
<q-input
|
||||||
v-model="email"
|
v-model="email"
|
||||||
label="E-Mail"
|
label="E-Mail"
|
||||||
type="email"
|
type="email"
|
||||||
color="darkblue"
|
color="darkblue"
|
||||||
filled
|
filled></q-input>
|
||||||
></q-input>
|
|
||||||
<q-input
|
<q-input
|
||||||
v-model="password"
|
v-model="password"
|
||||||
label="Password"
|
label="Password"
|
||||||
type="password"
|
type="password"
|
||||||
color="darkblue"
|
color="darkblue"
|
||||||
filled
|
filled></q-input>
|
||||||
></q-input>
|
<q-card-actions>
|
||||||
<q-btn
|
<q-btn
|
||||||
type="submit"
|
type="button"
|
||||||
@click="login(email, password)"
|
@click="doLogin"
|
||||||
label="Login"
|
label="Login"
|
||||||
color="primary"
|
color="primary"></q-btn>
|
||||||
></q-btn>
|
<q-space />
|
||||||
<!-- <q-btn
|
<q-btn
|
||||||
|
flat
|
||||||
|
color="secondary"
|
||||||
|
to="/pwreset">
|
||||||
|
Reset password
|
||||||
|
</q-btn>
|
||||||
|
<!-- <q-btn
|
||||||
type="button"
|
type="button"
|
||||||
@click="register"
|
@click="register"
|
||||||
color="secondary"
|
color="secondary"
|
||||||
label="Register"
|
label="Register"
|
||||||
flat
|
flat
|
||||||
></q-btn> -->
|
></q-btn> -->
|
||||||
</q-form>
|
</q-card-actions>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
<q-card-section><GoogleOauthComponent /></q-card-section>
|
</q-form>
|
||||||
|
<!-- <q-card-section><GoogleOauthComponent /></q-card-section> -->
|
||||||
</q-card>
|
</q-card>
|
||||||
</q-page>
|
</q-page>
|
||||||
</q-page-container>
|
</q-page-container>
|
||||||
@@ -69,8 +76,12 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import { login } from 'boot/appwrite';
|
import { login } from 'boot/appwrite';
|
||||||
import GoogleOauthComponent from 'src/components/GoogleOauthComponent.vue';
|
// import GoogleOauthComponent from 'src/components/GoogleOauthComponent.vue';
|
||||||
|
|
||||||
const email = ref('');
|
const email = ref('');
|
||||||
const password = ref('');
|
const password = ref('');
|
||||||
|
|
||||||
|
const doLogin = async () => {
|
||||||
|
login(email.value, password.value);
|
||||||
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
190
src/pages/ResetPassword.vue
Normal file
190
src/pages/ResetPassword.vue
Normal file
@@ -0,0 +1,190 @@
|
|||||||
|
<template>
|
||||||
|
<q-layout>
|
||||||
|
<q-page-container>
|
||||||
|
<q-page class="flex bg-image flex-center">
|
||||||
|
<q-card
|
||||||
|
v-bind:style="$q.screen.lt.sm ? { width: '80%' } : { width: '30%' }">
|
||||||
|
<q-card-section>
|
||||||
|
<q-img
|
||||||
|
fit="scale-down"
|
||||||
|
src="~assets/oysqn_logo.png" />
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section>
|
||||||
|
<div class="text-center q-pt-sm">
|
||||||
|
<div class="col text-h6">Reset Password</div>
|
||||||
|
</div>
|
||||||
|
</q-card-section>
|
||||||
|
<q-form v-if="!isPasswordResetLink()">
|
||||||
|
<q-card-section class="q-ma-sm">
|
||||||
|
<q-input
|
||||||
|
v-model="email"
|
||||||
|
label="E-Mail"
|
||||||
|
type="email"
|
||||||
|
color="darkblue"
|
||||||
|
@keydown.enter.prevent="resetPw"
|
||||||
|
filled></q-input>
|
||||||
|
<div class="text-caption q-py-md">
|
||||||
|
Enter your e-mail address. If we have an account with that
|
||||||
|
address on file, you will be e-mailed a link to reset your
|
||||||
|
password.
|
||||||
|
</div>
|
||||||
|
<q-card-actions>
|
||||||
|
<q-btn
|
||||||
|
type="button"
|
||||||
|
@click="resetPw"
|
||||||
|
label="Send Reset Link"
|
||||||
|
color="primary"></q-btn>
|
||||||
|
<!-- <q-btn
|
||||||
|
type="button"
|
||||||
|
@click="register"
|
||||||
|
color="secondary"
|
||||||
|
label="Register"
|
||||||
|
flat
|
||||||
|
></q-btn> -->
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card-section>
|
||||||
|
</q-form>
|
||||||
|
<q-form
|
||||||
|
@submit="submitNewPw"
|
||||||
|
v-else-if="validResetLink()">
|
||||||
|
<q-card-section class="q-ma-sm">
|
||||||
|
<q-input
|
||||||
|
v-model="password"
|
||||||
|
label="New Password"
|
||||||
|
type="password"
|
||||||
|
color="darkblue"
|
||||||
|
:rules="[validatePasswordStrength]"
|
||||||
|
lazy-rules
|
||||||
|
filled></q-input>
|
||||||
|
<q-input
|
||||||
|
v-model="confirmPassword"
|
||||||
|
label="Confirm New Password"
|
||||||
|
type="password"
|
||||||
|
color="darkblue"
|
||||||
|
:rules="[validatePasswordStrength]"
|
||||||
|
lazy-rules
|
||||||
|
filled></q-input>
|
||||||
|
<div class="text-caption q-py-md">Enter a new password.</div>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-actions>
|
||||||
|
<q-btn
|
||||||
|
type="submit"
|
||||||
|
label="Reset Password"
|
||||||
|
color="primary"></q-btn>
|
||||||
|
<!-- <q-btn
|
||||||
|
type="button"
|
||||||
|
@click="register"
|
||||||
|
color="secondary"
|
||||||
|
label="Register"
|
||||||
|
flat
|
||||||
|
></q-btn> -->
|
||||||
|
</q-card-actions>
|
||||||
|
</q-form>
|
||||||
|
<q-card
|
||||||
|
v-else
|
||||||
|
class="text-center">
|
||||||
|
<span class="text-h5">Invalid reset link.</span>
|
||||||
|
</q-card>
|
||||||
|
<!-- <q-card-section><GoogleOauthComponent /></q-card-section> -->
|
||||||
|
</q-card>
|
||||||
|
</q-page>
|
||||||
|
</q-page-container>
|
||||||
|
</q-layout>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.bg-image {
|
||||||
|
background-image: url('/src/assets/oys_lighthouse.jpg');
|
||||||
|
background-repeat: no-repeat;
|
||||||
|
background-position-x: center;
|
||||||
|
background-size: cover;
|
||||||
|
/* background-image: linear-gradient(
|
||||||
|
135deg,
|
||||||
|
#ed232a 0%,
|
||||||
|
#ffffff 75%,
|
||||||
|
#14539a 100%
|
||||||
|
); */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import { account, resetPassword } from 'boot/appwrite';
|
||||||
|
import { useRouter } from 'vue-router';
|
||||||
|
import { Dialog } from 'quasar';
|
||||||
|
// import GoogleOauthComponent from 'src/components/GoogleOauthComponent.vue';
|
||||||
|
|
||||||
|
const email = ref('');
|
||||||
|
const router = useRouter();
|
||||||
|
const password = ref('');
|
||||||
|
const confirmPassword = ref('');
|
||||||
|
|
||||||
|
const validatePasswordStrength = (val: string) => {
|
||||||
|
const hasUpperCase = /[A-Z]/.test(val);
|
||||||
|
const hasLowerCase = /[a-z]/.test(val);
|
||||||
|
const hasNumbers = /[0-9]/.test(val);
|
||||||
|
const hasNonAlphas = /[\W_]/.test(val);
|
||||||
|
const isValidLength = val.length >= 8;
|
||||||
|
|
||||||
|
return (
|
||||||
|
(hasUpperCase &&
|
||||||
|
hasLowerCase &&
|
||||||
|
hasNumbers &&
|
||||||
|
hasNonAlphas &&
|
||||||
|
isValidLength) ||
|
||||||
|
'Password must be at least 8 characters long and include uppercase, lowercase, number, and special character.'
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const validatePasswordsMatch = (val: string) => {
|
||||||
|
return val === password.value || 'Passwords do not match.';
|
||||||
|
};
|
||||||
|
|
||||||
|
function isPasswordResetLink() {
|
||||||
|
const query = router.currentRoute.value.query;
|
||||||
|
return query && query.secret && query.userId && query.expire;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validResetLink(): boolean {
|
||||||
|
const query = router.currentRoute.value.query;
|
||||||
|
const expire = query.expire ? new Date(query.expire + 'Z') : null;
|
||||||
|
return Boolean(
|
||||||
|
query && expire && query.secret && query.userId && new Date() < expire
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function submitNewPw() {
|
||||||
|
const query = router.currentRoute.value.query;
|
||||||
|
if (
|
||||||
|
validatePasswordStrength(password.value) === true &&
|
||||||
|
validatePasswordsMatch(confirmPassword.value) === true
|
||||||
|
) {
|
||||||
|
account
|
||||||
|
.updateRecovery(
|
||||||
|
query.userId as string,
|
||||||
|
query.secret as string,
|
||||||
|
password.value
|
||||||
|
)
|
||||||
|
.then(() => {
|
||||||
|
Dialog.create({ message: 'Password Changed!' });
|
||||||
|
router.replace('/login');
|
||||||
|
})
|
||||||
|
.catch((e) =>
|
||||||
|
Dialog.create({
|
||||||
|
message: 'Password change failed! Error: ' + e.message,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function resetPw() {
|
||||||
|
resetPassword(email.value)
|
||||||
|
.then(() => router.replace('/login'))
|
||||||
|
.finally(() =>
|
||||||
|
Dialog.create({
|
||||||
|
message:
|
||||||
|
'If your address is in our system, you should receive an e-mail shortly.',
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -1,109 +1,131 @@
|
|||||||
<template>
|
<template>
|
||||||
<q-page>
|
<div class="q-pa-xs row q-gutter-xs">
|
||||||
<q-list>
|
<q-card
|
||||||
<q-form @submit="onSubmit" @reset="onReset" class="q-gutter-sm">
|
flat
|
||||||
<q-item>
|
class="col-lg-4 col-md-6 col-sm-8 col-xs-12">
|
||||||
<q-item-section :avatar="true">
|
<q-card-section>
|
||||||
<q-icon name="person"
|
<div class="text-h5 q-mt-none q-mb-xs">New Booking</div>
|
||||||
/></q-item-section>
|
<div class="text-caption text-grey-8">for: {{ bookingForm.name }}</div>
|
||||||
|
</q-card-section>
|
||||||
|
<q-list class="q-px-xs">
|
||||||
|
<q-separator />
|
||||||
|
<q-item
|
||||||
|
class="q-px-none"
|
||||||
|
clickable
|
||||||
|
@click="boatSelect = true">
|
||||||
<q-item-section>
|
<q-item-section>
|
||||||
<q-item-label> Name: {{ bookingForm.name }} </q-item-label>
|
<q-card
|
||||||
|
v-if="bookingForm.boat"
|
||||||
|
flat>
|
||||||
|
<q-card-section>
|
||||||
|
<q-img
|
||||||
|
:src="bookingForm.boat?.imgSrc"
|
||||||
|
:fit="'scale-down'">
|
||||||
|
<div class="row absolute-top">
|
||||||
|
<div class="col text-h7 text-left">
|
||||||
|
{{ bookingForm.boat?.name }}
|
||||||
|
</div>
|
||||||
|
<div class="col text-right text-caption">
|
||||||
|
{{ bookingForm.boat?.class }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</q-img>
|
||||||
|
</q-card-section>
|
||||||
|
<q-separator />
|
||||||
|
<q-card-section horizontal>
|
||||||
|
<q-card-section>
|
||||||
|
<q-list
|
||||||
|
dense
|
||||||
|
class="row">
|
||||||
|
<q-item>
|
||||||
|
<q-item-section avatar>
|
||||||
|
<q-badge
|
||||||
|
color="primary"
|
||||||
|
label="Start" />
|
||||||
|
</q-item-section>
|
||||||
|
<q-item-section class="text-body2">
|
||||||
|
{{ formatDate(bookingForm.startDate) }}
|
||||||
|
</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
<q-item class="q-ma-none">
|
||||||
|
<q-item-section avatar>
|
||||||
|
<q-badge
|
||||||
|
color="primary"
|
||||||
|
label="End" />
|
||||||
|
</q-item-section>
|
||||||
|
<q-item-section class="text-body2">
|
||||||
|
{{ formatDate(bookingForm.endDate) }}
|
||||||
|
</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
</q-list>
|
||||||
|
</q-card-section>
|
||||||
|
<q-separator vertical />
|
||||||
|
<q-card-section class="col-3 flex flex-center bg-grey-4">
|
||||||
|
{{ bookingDuration.hours }} hours
|
||||||
|
<div v-if="bookingDuration.minutes">
|
||||||
|
<q-separator />
|
||||||
|
{{ bookingDuration.minutes }} mins
|
||||||
|
</div>
|
||||||
|
</q-card-section>
|
||||||
|
</q-card-section>
|
||||||
|
</q-card>
|
||||||
|
<q-field
|
||||||
|
readonly
|
||||||
|
filled
|
||||||
|
v-else>
|
||||||
|
Tap to Select a Boat / Time
|
||||||
|
</q-field>
|
||||||
</q-item-section>
|
</q-item-section>
|
||||||
</q-item>
|
</q-item>
|
||||||
<q-expansion-item
|
<q-item class="q-px-none">
|
||||||
expand-separator
|
<q-item-section>
|
||||||
v-model="resourceView"
|
<q-select
|
||||||
icon="calendar_month"
|
filled
|
||||||
label="Boat and Time"
|
v-model="bookingForm.reason"
|
||||||
default-opened
|
:options="reason_options"
|
||||||
class="q-mt-none"
|
label="Reason for sail" />
|
||||||
:caption="bookingSummary"
|
</q-item-section>
|
||||||
>
|
</q-item>
|
||||||
<q-separator />
|
<q-item class="q-px-none">
|
||||||
<q-banner :class="$q.dark.isActive ? 'bg-grey-9' : 'bg-grey-3'">
|
<q-item-section>
|
||||||
Use the calendar to pick a date. Select an available boat and
|
<q-input
|
||||||
timeslot below.
|
v-model="bookingForm.comment"
|
||||||
</q-banner>
|
clearable
|
||||||
<BoatScheduleTableComponent v-model="interval" />
|
autogrow
|
||||||
|
filled
|
||||||
<q-banner
|
label="Additional Comments (optional)" />
|
||||||
rounded
|
</q-item-section>
|
||||||
class="bg-warning text-grey-10"
|
</q-item>
|
||||||
style="max-width: 95vw; margin: auto"
|
</q-list>
|
||||||
v-if="bookingForm.boat && bookingForm.boat.defects.length > 0"
|
<q-card-actions align="right">
|
||||||
>
|
<q-btn
|
||||||
<template v-slot:avatar>
|
label="Reset"
|
||||||
<q-icon name="warning" color="grey-10" />
|
@click="onReset"
|
||||||
</template>
|
color="secondary"
|
||||||
{{ bookingForm.boat.name }} currently has the following notices:
|
size="md" />
|
||||||
<ol>
|
<q-btn
|
||||||
<li
|
label="Submit"
|
||||||
v-for="defect in bookingForm.boat.defects"
|
@click="onSubmit"
|
||||||
:key="defect.description"
|
color="primary" />
|
||||||
>
|
</q-card-actions>
|
||||||
{{ defect.description }}
|
</q-card>
|
||||||
</li>
|
<q-dialog
|
||||||
</ol>
|
v-model="boatSelect"
|
||||||
</q-banner>
|
full-width>
|
||||||
<!-- <q-card-section>
|
<BoatScheduleTableComponent v-model="interval" />
|
||||||
<q-btn
|
</q-dialog>
|
||||||
color="primary"
|
</div>
|
||||||
class="full-width"
|
|
||||||
icon="keyboard_arrow_down"
|
|
||||||
icon-right="keyboard_arrow_down"
|
|
||||||
label="Next: Crew & Passengers"
|
|
||||||
@click="resourceView = false"
|
|
||||||
/></q-card-section> -->
|
|
||||||
</q-expansion-item>
|
|
||||||
<!-- <q-expansion-item
|
|
||||||
expand-separator
|
|
||||||
icon="people"
|
|
||||||
label="Crew and Passengers"
|
|
||||||
default-opened
|
|
||||||
><q-banner v-if="bookingForm.boat"
|
|
||||||
>Passengers:
|
|
||||||
{{ bookingForm.members.length + bookingForm.guests.length }} /
|
|
||||||
{{ bookingForm.boat.maxPassengers }}</q-banner
|
|
||||||
>
|
|
||||||
<q-item
|
|
||||||
class="q-my-sm"
|
|
||||||
v-for="passenger in [...bookingForm.members, ...bookingForm.guests]"
|
|
||||||
:key="passenger.name"
|
|
||||||
>
|
|
||||||
<q-item-section avatar>
|
|
||||||
<q-avatar color="primary" text-color="white" size="sm">
|
|
||||||
{{
|
|
||||||
passenger.name
|
|
||||||
.split(' ')
|
|
||||||
.map((i) => i.charAt(0))
|
|
||||||
.join('')
|
|
||||||
.toUpperCase()
|
|
||||||
}}
|
|
||||||
</q-avatar>
|
|
||||||
</q-item-section>
|
|
||||||
<q-item-section>{{ passenger.name }}</q-item-section>
|
|
||||||
<q-item-section side>
|
|
||||||
<q-btn color="negative" flat dense round icon="cancel" />
|
|
||||||
</q-item-section>
|
|
||||||
</q-item>
|
|
||||||
<q-separator />
|
|
||||||
</q-expansion-item> -->
|
|
||||||
|
|
||||||
<q-item-section>
|
|
||||||
<q-btn label="Submit" type="submit" color="primary" />
|
|
||||||
</q-item-section> </q-form
|
|
||||||
></q-list>
|
|
||||||
</q-page>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, computed, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
import { useAuthStore } from 'src/stores/auth';
|
import { useAuthStore } from 'src/stores/auth';
|
||||||
import { Boat, useBoatStore } from 'src/stores/boat';
|
import { Boat, useBoatStore } from 'src/stores/boat';
|
||||||
import { date, useQuasar } from 'quasar';
|
import { useQuasar } from 'quasar';
|
||||||
import { Interval, Reservation } from 'src/stores/schedule.types';
|
import { Interval, Reservation } from 'src/stores/schedule.types';
|
||||||
import BoatScheduleTableComponent from 'src/components/scheduling/boat/BoatScheduleTableComponent.vue';
|
import BoatScheduleTableComponent from 'src/components/scheduling/boat/BoatScheduleTableComponent.vue';
|
||||||
import { getNewId } from 'src/utils/misc';
|
import { getNewId } from 'src/utils/misc';
|
||||||
|
import { formatDate } from 'src/utils/schedule';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
import { useReservationStore } from 'src/stores/reservation';
|
import { useReservationStore } from 'src/stores/reservation';
|
||||||
|
|
||||||
@@ -113,42 +135,57 @@ interface BookingForm {
|
|||||||
boat?: Boat;
|
boat?: Boat;
|
||||||
startDate?: string;
|
startDate?: string;
|
||||||
endDate?: string;
|
endDate?: string;
|
||||||
|
reason: string;
|
||||||
members: { name: string }[];
|
members: { name: string }[];
|
||||||
guests: { name: string }[];
|
guests: { name: string }[];
|
||||||
|
comment?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const reason_options = ['Open Sail', 'Private Sail', 'Racing', 'Other'];
|
||||||
|
|
||||||
const auth = useAuthStore();
|
const auth = useAuthStore();
|
||||||
const dateFormat = 'MMM D, YYYY h:mm A';
|
|
||||||
const resourceView = ref(true);
|
|
||||||
const interval = ref<Interval>();
|
const interval = ref<Interval>();
|
||||||
const bookingForm = ref<BookingForm>({
|
const newForm = {
|
||||||
bookingId: getNewId(),
|
bookingId: getNewId(),
|
||||||
name: auth.currentUser?.name,
|
name: auth.currentUser?.name,
|
||||||
boat: <Boat | undefined>undefined,
|
boat: <Boat | undefined>undefined,
|
||||||
startDate: date.formatDate(new Date(), dateFormat),
|
startDate: '',
|
||||||
endDate: date.formatDate(new Date(), dateFormat),
|
endDate: '',
|
||||||
members: [{ name: 'Karen Henrikso' }, { name: "Rich O'hare" }],
|
reason: 'Open Sail',
|
||||||
guests: [{ name: 'Bob Barker' }, { name: 'Taylor Swift' }],
|
members: [],
|
||||||
});
|
guests: [],
|
||||||
|
comment: '',
|
||||||
|
};
|
||||||
|
const bookingForm = ref<BookingForm>({ ...newForm });
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const reservationStore = useReservationStore();
|
const reservationStore = useReservationStore();
|
||||||
const $q = useQuasar();
|
const $q = useQuasar();
|
||||||
|
const boatSelect = ref(false);
|
||||||
|
|
||||||
watch(interval, (new_interval) => {
|
watch(interval, (new_interval) => {
|
||||||
bookingForm.value.boat = useBoatStore().boats.find(
|
bookingForm.value.boat = useBoatStore().boats.find(
|
||||||
(b) => b.$id === new_interval?.boatId
|
(b) => b.$id === new_interval?.boatId
|
||||||
);
|
);
|
||||||
bookingForm.value.startDate = date.formatDate(
|
bookingForm.value.startDate = new_interval?.start;
|
||||||
new_interval?.start,
|
bookingForm.value.endDate = new_interval?.end;
|
||||||
dateFormat
|
});
|
||||||
);
|
|
||||||
bookingForm.value.endDate = date.formatDate(new_interval?.end, dateFormat);
|
const bookingDuration = computed((): { hours: number; minutes: number } => {
|
||||||
|
if (bookingForm.value.startDate && bookingForm.value.endDate) {
|
||||||
|
const start = new Date(bookingForm.value.startDate).getTime();
|
||||||
|
const end = new Date(bookingForm.value.endDate).getTime();
|
||||||
|
const delta = Math.abs(end - start) / 1000;
|
||||||
|
const hours = Math.floor(delta / 3600) % 24;
|
||||||
|
const minutes = Math.floor(delta - hours * 3600) % 60;
|
||||||
|
return { hours: hours, minutes: minutes };
|
||||||
|
}
|
||||||
|
return { hours: 0, minutes: 0 };
|
||||||
});
|
});
|
||||||
|
|
||||||
const onReset = () => {
|
const onReset = () => {
|
||||||
// TODO
|
interval.value = undefined;
|
||||||
|
bookingForm.value = { ...newForm };
|
||||||
};
|
};
|
||||||
|
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
const booking = bookingForm.value;
|
const booking = bookingForm.value;
|
||||||
if (
|
if (
|
||||||
@@ -163,9 +200,12 @@ const onSubmit = () => {
|
|||||||
end: booking.endDate,
|
end: booking.endDate,
|
||||||
user: auth.currentUser.$id,
|
user: auth.currentUser.$id,
|
||||||
status: 'confirmed',
|
status: 'confirmed',
|
||||||
|
reason: booking.reason,
|
||||||
|
comment: booking.comment,
|
||||||
};
|
};
|
||||||
|
console.log(reservation);
|
||||||
// TODO: Fix this. It will always look successful
|
// TODO: Fix this. It will always look successful
|
||||||
reservationStore.createReservation(reservation);
|
reservationStore.createReservation(reservation); // Probably should pass the notify as a callback to the reservation creation.
|
||||||
$q.notify({
|
$q.notify({
|
||||||
color: 'green-4',
|
color: 'green-4',
|
||||||
textColor: 'white',
|
textColor: 'white',
|
||||||
@@ -174,28 +214,4 @@ const onSubmit = () => {
|
|||||||
});
|
});
|
||||||
router.go(-1);
|
router.go(-1);
|
||||||
};
|
};
|
||||||
|
|
||||||
const bookingDuration = computed(() => {
|
|
||||||
if (bookingForm.value.endDate && bookingForm.value.startDate) {
|
|
||||||
const diff = date.getDateDiff(
|
|
||||||
bookingForm.value.endDate,
|
|
||||||
bookingForm.value.startDate,
|
|
||||||
'minutes'
|
|
||||||
);
|
|
||||||
return diff <= 0
|
|
||||||
? 'Invalid'
|
|
||||||
: (diff > 60 ? Math.trunc(diff / 60) + ' hours' : '') +
|
|
||||||
(diff % 60 > 0 ? ' ' + (diff % 60) + ' minutes' : '');
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const bookingSummary = computed(() => {
|
|
||||||
return bookingForm.value.boat &&
|
|
||||||
bookingForm.value.startDate &&
|
|
||||||
bookingForm.value.endDate
|
|
||||||
? `${bookingForm.value.boat.name} @ ${bookingForm.value.startDate} for ${bookingDuration.value}`
|
|
||||||
: '';
|
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,44 +1,46 @@
|
|||||||
<template>
|
<template>
|
||||||
<q-page padding>
|
<q-page padding>
|
||||||
<div class="subcontent">
|
<q-card class="subcontent">
|
||||||
<navigation-bar @today="onToday" @prev="onPrev" @next="onNext" />
|
<navigation-bar
|
||||||
<div class="row justify-center">
|
@today="onToday"
|
||||||
<q-calendar-scheduler
|
@prev="onPrev"
|
||||||
ref="calendar"
|
@next="onNext" />
|
||||||
v-model="selectedDate"
|
<q-calendar-scheduler
|
||||||
v-model:model-resources="boatStore.boats"
|
ref="calendar"
|
||||||
resource-key="$id"
|
v-model="selectedDate"
|
||||||
resource-label="displayName"
|
v-model:model-resources="boatStore.boats"
|
||||||
:weekdays="[1, 2, 3, 4, 5, 6, 0]"
|
resource-key="$id"
|
||||||
view="week"
|
resource-label="displayName"
|
||||||
bordered
|
:weekdays="[1, 2, 3, 4, 5, 6, 0]"
|
||||||
animated
|
:view="$q.screen.gt.md ? 'week' : 'day'"
|
||||||
cell-width="150px"
|
bordered
|
||||||
day-min-height="50px"
|
animated
|
||||||
@change="onChange"
|
day-min-height="50px"
|
||||||
@moved="onMoved"
|
@change="onChange"
|
||||||
@click-date="onClickDate"
|
@moved="onMoved"
|
||||||
@click-time="onClickTime"
|
@click-date="onClickDate"
|
||||||
@click-interval="onClickInterval"
|
@click-time="onClickTime"
|
||||||
@click-head-day="onClickHeadDay"
|
@click-interval="onClickInterval"
|
||||||
>
|
@click-head-day="onClickHeadDay">
|
||||||
<template #day="{ scope }">
|
<template #day="{ scope }">
|
||||||
<div v-for="event in boatReservationEvents(scope)" :key="event.id">
|
<div
|
||||||
<div v-if="event.start !== undefined" class="booking-event">
|
v-for="event in boatReservationEvents(scope)"
|
||||||
<span class="title q-calendar__ellipsis">
|
:key="event.id">
|
||||||
{{ useAuthStore().getUserNameById(event.user) }}
|
<div
|
||||||
<q-tooltip>{{
|
v-if="event.start !== undefined"
|
||||||
event.start +
|
class="booking-event">
|
||||||
' - ' +
|
<span class="title q-calendar__ellipsis">
|
||||||
boatStore.getBoatById(event.resource)?.name
|
{{ useAuthStore().getUserNameById(event.user) }} @
|
||||||
}}</q-tooltip>
|
{{ renderTime(event.start) }}
|
||||||
</span>
|
<q-tooltip>
|
||||||
</div>
|
{{ renderTime(event.start) + ' - ' + renderTime(event.end) }}
|
||||||
|
</q-tooltip>
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</div>
|
||||||
</q-calendar-scheduler>
|
</template>
|
||||||
</div>
|
</q-calendar-scheduler>
|
||||||
</div>
|
</q-card>
|
||||||
</q-page>
|
</q-page>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -53,10 +55,12 @@ import { QCalendarScheduler } from '@quasar/quasar-ui-qcalendar';
|
|||||||
import { Timestamp } from '@quasar/quasar-ui-qcalendar';
|
import { Timestamp } from '@quasar/quasar-ui-qcalendar';
|
||||||
import { Boat, useBoatStore } from 'src/stores/boat';
|
import { Boat, useBoatStore } from 'src/stores/boat';
|
||||||
import NavigationBar from 'src/components/scheduling/NavigationBar.vue';
|
import NavigationBar from 'src/components/scheduling/NavigationBar.vue';
|
||||||
|
import { useQuasar } from 'quasar';
|
||||||
|
|
||||||
const selectedDate = ref(today());
|
const selectedDate = ref(today());
|
||||||
const boatStore = useBoatStore();
|
const boatStore = useBoatStore();
|
||||||
const calendar = ref();
|
const calendar = ref();
|
||||||
|
const $q = useQuasar();
|
||||||
|
|
||||||
interface DayScope {
|
interface DayScope {
|
||||||
timestamp: Timestamp;
|
timestamp: Timestamp;
|
||||||
@@ -68,6 +72,10 @@ interface DayScope {
|
|||||||
droppable: boolean;
|
droppable: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const renderTime = (dateString: string) => {
|
||||||
|
const date = new Date(dateString);
|
||||||
|
return date.toLocaleTimeString();
|
||||||
|
};
|
||||||
onMounted(() => boatStore.fetchBoats());
|
onMounted(() => boatStore.fetchBoats());
|
||||||
// Method declarations
|
// Method declarations
|
||||||
|
|
||||||
|
|||||||
179
src/pages/schedule/ListBookingsPage.vue
Normal file
179
src/pages/schedule/ListBookingsPage.vue
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
<template>
|
||||||
|
<q-card
|
||||||
|
clas="q-ma-md"
|
||||||
|
bordered
|
||||||
|
v-if="!reservations">
|
||||||
|
<q-card-section>
|
||||||
|
<div class="text-h6">You don't have any bookings!</div>
|
||||||
|
<div class="text-h8">Why don't you go make one?</div>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-actions>
|
||||||
|
<q-btn
|
||||||
|
color="primary"
|
||||||
|
icon="event"
|
||||||
|
:size="`1.25em`"
|
||||||
|
label="Book Now"
|
||||||
|
rounded
|
||||||
|
class="full-width"
|
||||||
|
:align="'left'"
|
||||||
|
to="/schedule/book" />
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card>
|
||||||
|
<template
|
||||||
|
v-else
|
||||||
|
v-for="(reservation, index) in sortedBookings"
|
||||||
|
:key="reservation.$id">
|
||||||
|
<q-toolbar
|
||||||
|
class="bg-secondary glossy text-white"
|
||||||
|
v-if="showMarker(index, sortedBookings)">
|
||||||
|
Past
|
||||||
|
</q-toolbar>
|
||||||
|
<q-card
|
||||||
|
bordered
|
||||||
|
:class="isPast(reservation.end) ? 'text-blue-grey-6' : ''"
|
||||||
|
class="q-ma-md">
|
||||||
|
<q-card-section>
|
||||||
|
<div class="row items-center no-wrap">
|
||||||
|
<div class="col">
|
||||||
|
<div class="text-h6">
|
||||||
|
{{ boatStore.getBoatById(reservation.resource)?.name }}
|
||||||
|
</div>
|
||||||
|
<div class="text-subtitle2">
|
||||||
|
<p>
|
||||||
|
Start: {{ formatDate(reservation.start) }}
|
||||||
|
<br />
|
||||||
|
End: {{ formatDate(reservation.end) }}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<!-- <div class="col-auto">
|
||||||
|
<q-btn
|
||||||
|
color="grey-7"
|
||||||
|
round
|
||||||
|
flat
|
||||||
|
icon="more_vert">
|
||||||
|
<q-menu
|
||||||
|
cover
|
||||||
|
auto-close>
|
||||||
|
<q-list>
|
||||||
|
<q-item clickable>
|
||||||
|
<q-item-section>remove card</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
<q-item clickable>
|
||||||
|
<q-item-section>send feedback</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
<q-item clickable>
|
||||||
|
<q-item-section>share</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
</q-list>
|
||||||
|
</q-menu>
|
||||||
|
</q-btn>
|
||||||
|
</div> -->
|
||||||
|
</div>
|
||||||
|
</q-card-section>
|
||||||
|
|
||||||
|
<!-- <q-card-section>Some more information here...</q-card-section> -->
|
||||||
|
|
||||||
|
<q-separator />
|
||||||
|
|
||||||
|
<q-card-actions v-if="!isPast(reservation.end)">
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
@click="modifyReservation(reservation)">
|
||||||
|
Modify
|
||||||
|
</q-btn>
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
@click="cancelReservation(reservation)">
|
||||||
|
Cancel
|
||||||
|
</q-btn>
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card>
|
||||||
|
</template>
|
||||||
|
<q-dialog v-model="cancelDialog">
|
||||||
|
<q-card>
|
||||||
|
<q-card-section class="row items-center">
|
||||||
|
<q-avatar
|
||||||
|
icon="stop"
|
||||||
|
color="negative"
|
||||||
|
text-color="white" />
|
||||||
|
<span class="q-ml-sm">
|
||||||
|
This will delete your reservation for
|
||||||
|
{{ boatStore.getBoatById(currentReservation?.resource) }} on
|
||||||
|
{{ formatDate(currentReservation?.start) }}
|
||||||
|
</span>
|
||||||
|
</q-card-section>
|
||||||
|
|
||||||
|
<q-card-actions align="right">
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
label="Cancel"
|
||||||
|
color="primary"
|
||||||
|
v-close-popup />
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
label="Delete"
|
||||||
|
color="negative"
|
||||||
|
@click="reservationStore.deleteReservation(Reservation)"
|
||||||
|
v-close-popup />
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card>
|
||||||
|
</q-dialog>
|
||||||
|
</template>
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useBoatStore } from 'src/stores/boat';
|
||||||
|
import { useReservationStore } from 'src/stores/reservation';
|
||||||
|
import { Reservation } from 'src/stores/schedule.types';
|
||||||
|
import { formatDate } from 'src/utils/schedule';
|
||||||
|
import { computed, onMounted, ref } from 'vue';
|
||||||
|
|
||||||
|
const reservationStore = useReservationStore();
|
||||||
|
const reservations = reservationStore.getUserReservations();
|
||||||
|
const boatStore = useBoatStore();
|
||||||
|
const currentReservation = ref<Reservation>();
|
||||||
|
const cancelDialog = ref(false);
|
||||||
|
|
||||||
|
const sortedBookings = computed(() =>
|
||||||
|
reservations.value
|
||||||
|
?.slice()
|
||||||
|
.sort((a, b) => new Date(b.start).getTime() - new Date(a.start).getTime())
|
||||||
|
);
|
||||||
|
|
||||||
|
const isPast = (itemDate: Date | string): boolean => {
|
||||||
|
if (!(itemDate instanceof Date)) {
|
||||||
|
itemDate = new Date(itemDate);
|
||||||
|
}
|
||||||
|
console.log(itemDate);
|
||||||
|
const currentDate = new Date();
|
||||||
|
return itemDate < currentDate;
|
||||||
|
};
|
||||||
|
|
||||||
|
const showMarker = (
|
||||||
|
index: number,
|
||||||
|
items: Reservation[] | undefined
|
||||||
|
): boolean => {
|
||||||
|
if (!items) return false;
|
||||||
|
|
||||||
|
const currentItemDate = new Date(items[index].start);
|
||||||
|
const nextItemDate = index > 0 ? new Date(items[index - 1].start) : null;
|
||||||
|
|
||||||
|
// Show marker if current item is past and the next item is future or vice versa
|
||||||
|
return (
|
||||||
|
isPast(currentItemDate) && (nextItemDate === null || !isPast(nextItemDate))
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const cancelReservation = (reservation: Reservation) => {
|
||||||
|
currentReservation.value = reservation;
|
||||||
|
cancelDialog.value = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const modifyReservation = (reservation: Reservation) => {
|
||||||
|
return reservation;
|
||||||
|
};
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
boatStore.fetchBoats();
|
||||||
|
reservationStore.fetchUserReservations();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@@ -113,7 +113,7 @@
|
|||||||
/></q-item>
|
/></q-item>
|
||||||
<q-separator spaced />
|
<q-separator spaced />
|
||||||
<IntervalTemplateComponent
|
<IntervalTemplateComponent
|
||||||
v-for="template in timeblockTemplates"
|
v-for="template in intervalTemplates"
|
||||||
:key="template.$id"
|
:key="template.$id"
|
||||||
:model-value="template"
|
:model-value="template"
|
||||||
/>
|
/>
|
||||||
@@ -146,11 +146,7 @@ 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 { useScheduleStore } from 'src/stores/schedule';
|
||||||
blocksOverlapped,
|
|
||||||
buildInterval,
|
|
||||||
useScheduleStore,
|
|
||||||
} from 'src/stores/schedule';
|
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import type {
|
import type {
|
||||||
Interval,
|
Interval,
|
||||||
@@ -161,12 +157,13 @@ import { date } from 'quasar';
|
|||||||
import IntervalTemplateComponent from 'src/components/scheduling/IntervalTemplateComponent.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';
|
||||||
|
import { buildInterval, intervalsOverlapped } from 'src/utils/schedule';
|
||||||
|
|
||||||
const selectedDate = ref(today());
|
const selectedDate = ref(today());
|
||||||
const { fetchBoats } = useBoatStore();
|
const { fetchBoats } = useBoatStore();
|
||||||
const scheduleStore = useScheduleStore();
|
const scheduleStore = useScheduleStore();
|
||||||
const { boats } = storeToRefs(useBoatStore());
|
const { boats } = storeToRefs(useBoatStore());
|
||||||
const { timeblockTemplates } = storeToRefs(useScheduleStore());
|
const intervalTemplates = scheduleStore.getIntervalTemplates();
|
||||||
const calendar = ref();
|
const calendar = ref();
|
||||||
const overlapped = ref();
|
const overlapped = ref();
|
||||||
const alert = ref(false);
|
const alert = ref(false);
|
||||||
@@ -185,12 +182,11 @@ const newTemplate = ref<IntervalTemplate>({
|
|||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await fetchBoats();
|
await fetchBoats();
|
||||||
await scheduleStore.fetchIntervals();
|
|
||||||
await scheduleStore.fetchIntervalTemplates();
|
await scheduleStore.fetchIntervalTemplates();
|
||||||
});
|
});
|
||||||
|
|
||||||
const filteredIntervals = (date: Timestamp, boat: Boat) => {
|
const filteredIntervals = (date: Timestamp, boat: Boat) => {
|
||||||
return scheduleStore.getIntervals(date, boat).value;
|
return scheduleStore.getIntervals(date, boat);
|
||||||
};
|
};
|
||||||
|
|
||||||
const sortedIntervals = (date: Timestamp, boat: Boat) => {
|
const sortedIntervals = (date: Timestamp, boat: Boat) => {
|
||||||
@@ -210,7 +206,7 @@ function createTemplate() {
|
|||||||
newTemplate.value.$id = 'unsaved';
|
newTemplate.value.$id = 'unsaved';
|
||||||
}
|
}
|
||||||
function createIntervals(boat: Boat, templateId: string, date: string) {
|
function createIntervals(boat: Boat, templateId: string, date: string) {
|
||||||
const intervals = timeBlocksFromTemplate(boat, templateId, date);
|
const intervals = intervalsFromTemplate(boat, templateId, date);
|
||||||
intervals.forEach((interval) => scheduleStore.createInterval(interval));
|
intervals.forEach((interval) => scheduleStore.createInterval(interval));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -218,12 +214,14 @@ function getIntervals(date: Timestamp, boat: Boat) {
|
|||||||
return scheduleStore.getIntervals(date, boat);
|
return scheduleStore.getIntervals(date, boat);
|
||||||
}
|
}
|
||||||
|
|
||||||
function timeBlocksFromTemplate(
|
function intervalsFromTemplate(
|
||||||
boat: Boat,
|
boat: Boat,
|
||||||
templateId: string,
|
templateId: string,
|
||||||
date: string
|
date: string
|
||||||
): Interval[] {
|
): Interval[] {
|
||||||
const template = timeblockTemplates.value.find((t) => t.$id === templateId);
|
const template = scheduleStore
|
||||||
|
.getIntervalTemplates()
|
||||||
|
.value.find((t) => t.$id === templateId);
|
||||||
return template
|
return template
|
||||||
? template.timeTuples.map((timeTuple: TimeTuple) =>
|
? template.timeTuples.map((timeTuple: TimeTuple) =>
|
||||||
buildInterval(boat, timeTuple, date)
|
buildInterval(boat, timeTuple, date)
|
||||||
@@ -280,13 +278,13 @@ function onDrop(
|
|||||||
const templateId = e.dataTransfer.getData('ID');
|
const templateId = e.dataTransfer.getData('ID');
|
||||||
const date = scope.timestamp.date;
|
const date = scope.timestamp.date;
|
||||||
const resource = scope.resource;
|
const resource = scope.resource;
|
||||||
const existingIntervals = getIntervals(scope.timestamp, resource).value;
|
const existingIntervals = getIntervals(scope.timestamp, resource);
|
||||||
const boatsToApply = type === 'head-day' ? boats.value : [resource];
|
const boatsToApply = type === 'head-day' ? boats.value : [resource];
|
||||||
overlapped.value = boatsToApply
|
overlapped.value = boatsToApply
|
||||||
.map((boat) =>
|
.map((boat) =>
|
||||||
blocksOverlapped(
|
intervalsOverlapped(
|
||||||
existingIntervals.concat(
|
existingIntervals.concat(
|
||||||
timeBlocksFromTemplate(boat, templateId, date)
|
intervalsFromTemplate(boat, templateId, date)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -9,6 +9,10 @@ import {
|
|||||||
import routes from './routes';
|
import routes from './routes';
|
||||||
import { useAuthStore } from 'src/stores/auth';
|
import { useAuthStore } from 'src/stores/auth';
|
||||||
|
|
||||||
|
const publicRoutes = routes
|
||||||
|
.filter((route) => route.meta?.publicRoute)
|
||||||
|
.map((r) => r.path);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If not building with SSR mode, you can
|
* If not building with SSR mode, you can
|
||||||
* directly export the Router instantiation;
|
* directly export the Router instantiation;
|
||||||
@@ -35,14 +39,33 @@ export default route(function (/* { store, ssrContext } */) {
|
|||||||
history: createHistory(process.env.VUE_ROUTER_BASE),
|
history: createHistory(process.env.VUE_ROUTER_BASE),
|
||||||
});
|
});
|
||||||
|
|
||||||
Router.beforeEach((to) => {
|
Router.beforeEach(async (to, from, next) => {
|
||||||
const auth = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
|
const currentUser = authStore.currentUser;
|
||||||
|
const authRequired = !publicRoutes.includes(to.path);
|
||||||
|
const requiredRoles = to.meta?.requiredRoles as string[];
|
||||||
|
|
||||||
if (auth.currentUser) {
|
if (authRequired && !currentUser) {
|
||||||
return to.meta.accountRoute ? { name: 'index' } : true;
|
return next('/login');
|
||||||
} else {
|
|
||||||
return to.name == 'login' ? true : { name: 'login' };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (requiredRoles) {
|
||||||
|
if (!currentUser) {
|
||||||
|
return next('/login');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const hasRole = authStore.hasRequiredRole(requiredRoles);
|
||||||
|
if (!hasRole) {
|
||||||
|
return next(from);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch user teams:', error);
|
||||||
|
return next('/error'); // Redirect to an error page or handle it as needed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
return Router;
|
return Router;
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { useAuthStore } from 'src/stores/auth';
|
||||||
|
|
||||||
export const links = [
|
export const links = [
|
||||||
{
|
{
|
||||||
name: 'Home',
|
name: 'Home',
|
||||||
@@ -27,6 +29,13 @@ export const links = [
|
|||||||
front_links: true,
|
front_links: true,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
sublinks: [
|
sublinks: [
|
||||||
|
{
|
||||||
|
name: 'List',
|
||||||
|
to: '/schedule/list',
|
||||||
|
icon: 'list',
|
||||||
|
front_links: false,
|
||||||
|
enabled: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: 'Book',
|
name: 'Book',
|
||||||
to: '/schedule/book',
|
to: '/schedule/book',
|
||||||
@@ -47,6 +56,7 @@ export const links = [
|
|||||||
icon: 'edit_calendar',
|
icon: 'edit_calendar',
|
||||||
front_links: false,
|
front_links: false,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
|
requiredRoles: ['Schedule Admins'],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -80,11 +90,20 @@ export const links = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
|
function hasRole(roles: string[] | undefined) {
|
||||||
|
if (roles === undefined) return true;
|
||||||
|
const hasRole = authStore.hasRequiredRole(roles);
|
||||||
|
return hasRole;
|
||||||
|
}
|
||||||
export const enabledLinks = links
|
export const enabledLinks = links
|
||||||
.filter((link) => link.enabled)
|
.filter((link) => link.enabled)
|
||||||
.map((link) => {
|
.map((link) => {
|
||||||
if (link.sublinks) {
|
if (link.sublinks) {
|
||||||
link.sublinks = link.sublinks.filter((sublink) => sublink.enabled);
|
link.sublinks = link.sublinks.filter(
|
||||||
|
(sublink) => sublink.enabled && hasRole(sublink.requiredRoles)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return link;
|
return link;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -40,11 +40,16 @@ const routes: RouteRecordRaw[] = [
|
|||||||
component: () => import('src/pages/schedule/BoatScheduleView.vue'),
|
component: () => import('src/pages/schedule/BoatScheduleView.vue'),
|
||||||
name: 'boat-schedule',
|
name: 'boat-schedule',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: 'list',
|
||||||
|
component: () => import('src/pages/schedule/ListBookingsPage.vue'),
|
||||||
|
name: 'list-bookings',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: 'manage',
|
path: 'manage',
|
||||||
component: () => import('src/pages/schedule/ManageCalendar.vue'),
|
component: () => import('src/pages/schedule/ManageCalendar.vue'),
|
||||||
name: 'manage-schedule',
|
name: 'manage-schedule',
|
||||||
meta: { requiresScheduleAdmin: true },
|
meta: { requiredRoles: ['Schedule Admins'] },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -102,7 +107,7 @@ const routes: RouteRecordRaw[] = [
|
|||||||
{
|
{
|
||||||
path: '/admin',
|
path: '/admin',
|
||||||
component: () => import('layouts/AdminLayout.vue'),
|
component: () => import('layouts/AdminLayout.vue'),
|
||||||
meta: { requiresAdmin: true },
|
meta: { requiredRoles: ['admin'] },
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: '/user',
|
path: '/user',
|
||||||
@@ -124,6 +129,22 @@ const routes: RouteRecordRaw[] = [
|
|||||||
publicRoute: true,
|
publicRoute: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/pwreset',
|
||||||
|
component: () => import('pages/ResetPassword.vue'),
|
||||||
|
name: 'pwreset',
|
||||||
|
meta: {
|
||||||
|
publicRoute: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/login',
|
||||||
|
component: () => import('pages/LoginPage.vue'),
|
||||||
|
name: 'login',
|
||||||
|
meta: {
|
||||||
|
publicRoute: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/terms-of-service',
|
path: '/terms-of-service',
|
||||||
component: () => import('pages/TermsOfServicePage.vue'),
|
component: () => import('pages/TermsOfServicePage.vue'),
|
||||||
|
|||||||
@@ -1,28 +1,46 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { ID, account, functions } from 'boot/appwrite';
|
import { ID, account, functions, teams } from 'boot/appwrite';
|
||||||
import { ExecutionMethod, OAuthProvider, type Models } from 'appwrite';
|
import { ExecutionMethod, OAuthProvider, type Models } from 'appwrite';
|
||||||
import { ref } from 'vue';
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', () => {
|
export const useAuthStore = defineStore('auth', () => {
|
||||||
const currentUser = ref<Models.User<Models.Preferences> | null>(null);
|
const currentUser = ref<Models.User<Models.Preferences> | null>(null);
|
||||||
|
const currentUserTeams = ref<Models.TeamList<Models.Preferences> | null>(
|
||||||
|
null
|
||||||
|
);
|
||||||
const userNames = ref<Record<string, string>>({});
|
const userNames = ref<Record<string, string>>({});
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
try {
|
try {
|
||||||
currentUser.value = await account.get();
|
currentUser.value = await account.get();
|
||||||
|
currentUserTeams.value = await teams.list();
|
||||||
} catch {
|
} catch {
|
||||||
currentUser.value = null;
|
currentUser.value = null;
|
||||||
|
currentUserTeams.value = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currentUserTeamNames = computed(() =>
|
||||||
|
currentUserTeams.value
|
||||||
|
? currentUserTeams.value.teams.map((team) => team.name)
|
||||||
|
: []
|
||||||
|
);
|
||||||
|
|
||||||
|
const hasRequiredRole = (requiredRoles: string[]): boolean => {
|
||||||
|
return requiredRoles.some((role) =>
|
||||||
|
currentUserTeamNames.value.includes(role)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
async function register(email: string, password: string) {
|
async function register(email: string, password: string) {
|
||||||
await account.create(ID.unique(), email, password);
|
await account.create(ID.unique(), email, password);
|
||||||
return await login(email, password);
|
return await login(email, password);
|
||||||
}
|
}
|
||||||
async function login(email: string, password: string) {
|
async function login(email: string, password: string) {
|
||||||
await account.createEmailPasswordSession(email, password);
|
await account.createEmailPasswordSession(email, password);
|
||||||
currentUser.value = await account.get();
|
await init();
|
||||||
}
|
}
|
||||||
|
|
||||||
async function googleLogin() {
|
async function googleLogin() {
|
||||||
account.createOAuth2Session(
|
account.createOAuth2Session(
|
||||||
OAuthProvider.Google,
|
OAuthProvider.Google,
|
||||||
@@ -38,7 +56,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
userNames.value[id] = '';
|
userNames.value[id] = '';
|
||||||
functions
|
functions
|
||||||
.createExecution(
|
.createExecution(
|
||||||
'664038294b5473ef0c8d',
|
'userinfo',
|
||||||
'',
|
'',
|
||||||
false,
|
false,
|
||||||
'/userinfo/' + id,
|
'/userinfo/' + id,
|
||||||
@@ -65,6 +83,7 @@ export const useAuthStore = defineStore('auth', () => {
|
|||||||
return {
|
return {
|
||||||
currentUser,
|
currentUser,
|
||||||
getUserNameById,
|
getUserNameById,
|
||||||
|
hasRequiredRole,
|
||||||
register,
|
register,
|
||||||
login,
|
login,
|
||||||
googleLogin,
|
googleLogin,
|
||||||
|
|||||||
@@ -39,8 +39,9 @@ export const useBoatStore = defineStore('boat', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getBoatById = (id: string): Boat | null => {
|
const getBoatById = (id: string | null | undefined): Boat | null => {
|
||||||
return boats.value.find((b) => b.$id === id) || null;
|
if (!id) return null;
|
||||||
|
return boats.value?.find((b) => b.$id === id) || null;
|
||||||
};
|
};
|
||||||
|
|
||||||
return { boats, fetchBoats, getBoatById };
|
return { boats, fetchBoats, getBoatById };
|
||||||
|
|||||||
@@ -5,11 +5,14 @@ import { AppwriteIds, databases } from 'src/boot/appwrite';
|
|||||||
import { ID, Query } from 'appwrite';
|
import { ID, Query } from 'appwrite';
|
||||||
import { date } from 'quasar';
|
import { date } from 'quasar';
|
||||||
import { Timestamp, parseDate, today } from '@quasar/quasar-ui-qcalendar';
|
import { Timestamp, parseDate, today } from '@quasar/quasar-ui-qcalendar';
|
||||||
|
import { LoadingTypes } from 'src/utils/misc';
|
||||||
|
import { useAuthStore } from './auth';
|
||||||
|
|
||||||
export const useReservationStore = defineStore('reservation', () => {
|
export const useReservationStore = defineStore('reservation', () => {
|
||||||
type LoadingTypes = 'loaded' | 'pending' | undefined;
|
|
||||||
const reservations = ref<Map<string, Reservation>>(new Map());
|
const reservations = ref<Map<string, Reservation>>(new Map());
|
||||||
const datesLoaded = ref<Record<string, LoadingTypes>>({});
|
const datesLoaded = ref<Record<string, LoadingTypes>>({});
|
||||||
|
const userReservations = ref<Reservation[]>();
|
||||||
|
const authStore = useAuthStore();
|
||||||
|
|
||||||
// Fetch reservations for a specific date range
|
// Fetch reservations for a specific date range
|
||||||
const fetchReservationsForDateRange = async (
|
const fetchReservationsForDateRange = async (
|
||||||
@@ -39,7 +42,7 @@ export const useReservationStore = defineStore('reservation', () => {
|
|||||||
setDateLoaded(startDate, endDate, 'loaded');
|
setDateLoaded(startDate, endDate, 'loaded');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch reservations', error);
|
console.error('Failed to fetch reservations', error);
|
||||||
setDateLoaded(startDate, endDate, undefined);
|
setDateLoaded(startDate, endDate, 'error');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const createReservation = async (reservation: Reservation) => {
|
const createReservation = async (reservation: Reservation) => {
|
||||||
@@ -51,11 +54,38 @@ export const useReservationStore = defineStore('reservation', () => {
|
|||||||
reservation
|
reservation
|
||||||
);
|
);
|
||||||
reservations.value.set(response.$id, response as Reservation);
|
reservations.value.set(response.$id, response as Reservation);
|
||||||
|
console.info('Reservation booked: ', response);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error creating Reservation: ' + e);
|
console.error('Error creating Reservation: ' + e);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const deleteReservation = async (
|
||||||
|
reservation: string | Reservation | null | undefined
|
||||||
|
) => {
|
||||||
|
if (!reservation) return false;
|
||||||
|
let id;
|
||||||
|
if (typeof reservation === 'string') {
|
||||||
|
id = reservation;
|
||||||
|
} else if ('$id' in reservation && typeof reservation.$id === 'string') {
|
||||||
|
id = reservation.$id;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await databases.deleteDocument(
|
||||||
|
AppwriteIds.databaseId,
|
||||||
|
AppwriteIds.collection.interval,
|
||||||
|
id
|
||||||
|
);
|
||||||
|
reservations.value.delete(id);
|
||||||
|
console.info(`Deleted reservation: ${id}`);
|
||||||
|
} catch (e) {
|
||||||
|
console.error('Error deleting reservation: ' + e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Set the loading state for dates
|
// Set the loading state for dates
|
||||||
const setDateLoaded = (start: Date, end: Date, state: LoadingTypes) => {
|
const setDateLoaded = (start: Date, end: Date, state: LoadingTypes) => {
|
||||||
if (start > end) return [];
|
if (start > end) return [];
|
||||||
@@ -135,12 +165,33 @@ export const useReservationStore = defineStore('reservation', () => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getUserReservations = () => {
|
||||||
|
return userReservations;
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchUserReservations = async () => {
|
||||||
|
if (!authStore.currentUser) return;
|
||||||
|
try {
|
||||||
|
const response = await databases.listDocuments(
|
||||||
|
AppwriteIds.databaseId,
|
||||||
|
AppwriteIds.collection.reservation,
|
||||||
|
[Query.equal('user', authStore.currentUser.$id)]
|
||||||
|
);
|
||||||
|
userReservations.value = response.documents as Reservation[];
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to fetch reservations for user: ', error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getReservationsByDate,
|
getReservationsByDate,
|
||||||
createReservation,
|
createReservation,
|
||||||
|
deleteReservation,
|
||||||
fetchReservationsForDateRange,
|
fetchReservationsForDateRange,
|
||||||
isReservationOverlapped,
|
isReservationOverlapped,
|
||||||
isResourceTimeOverlapped,
|
isResourceTimeOverlapped,
|
||||||
getConflictingReservations,
|
getConflictingReservations,
|
||||||
|
fetchUserReservations,
|
||||||
|
getUserReservations,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ export function getSampleReservations(): Reservation[] {
|
|||||||
end: '10:00',
|
end: '10:00',
|
||||||
boat: '66359729003825946ae1',
|
boat: '66359729003825946ae1',
|
||||||
status: 'confirmed',
|
status: 'confirmed',
|
||||||
|
reason: 'Open Sail',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '2',
|
id: '2',
|
||||||
@@ -79,6 +80,7 @@ export function getSampleReservations(): Reservation[] {
|
|||||||
end: '19:00',
|
end: '19:00',
|
||||||
boat: '66359729003825946ae1',
|
boat: '66359729003825946ae1',
|
||||||
status: 'confirmed',
|
status: 'confirmed',
|
||||||
|
reason: 'Open Sail',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '3',
|
id: '3',
|
||||||
@@ -87,6 +89,7 @@ export function getSampleReservations(): Reservation[] {
|
|||||||
end: '13:00',
|
end: '13:00',
|
||||||
boat: '663597030029b71c7a9b',
|
boat: '663597030029b71c7a9b',
|
||||||
status: 'tentative',
|
status: 'tentative',
|
||||||
|
reason: 'Open Sail',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '4',
|
id: '4',
|
||||||
@@ -95,6 +98,7 @@ export function getSampleReservations(): Reservation[] {
|
|||||||
end: '13:00',
|
end: '13:00',
|
||||||
boat: '663597030029b71c7a9b',
|
boat: '663597030029b71c7a9b',
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
|
reason: 'Open Sail',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '5',
|
id: '5',
|
||||||
@@ -103,6 +107,7 @@ export function getSampleReservations(): Reservation[] {
|
|||||||
end: '19:00',
|
end: '19:00',
|
||||||
boat: '663596b9000235ffea55',
|
boat: '663596b9000235ffea55',
|
||||||
status: 'confirmed',
|
status: 'confirmed',
|
||||||
|
reason: 'Private Sail',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '6',
|
id: '6',
|
||||||
@@ -110,6 +115,7 @@ export function getSampleReservations(): Reservation[] {
|
|||||||
start: '13:00',
|
start: '13:00',
|
||||||
end: '16:00',
|
end: '16:00',
|
||||||
boat: '663596b9000235ffea55',
|
boat: '663596b9000235ffea55',
|
||||||
|
reason: 'Open Sail',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
const boatStore = useBoatStore();
|
const boatStore = useBoatStore();
|
||||||
@@ -137,7 +143,9 @@ export function getSampleReservations(): Reservation[] {
|
|||||||
end: date.adjustDate(now, makeOpts(splitTime(entry.end))).toISOString(),
|
end: date.adjustDate(now, makeOpts(splitTime(entry.end))).toISOString(),
|
||||||
resource: boat.$id,
|
resource: boat.$id,
|
||||||
reservationDate: now,
|
reservationDate: now,
|
||||||
|
reason: entry.reason,
|
||||||
status: entry.status as StatusTypes,
|
status: entry.status as StatusTypes,
|
||||||
|
comment: '',
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,127 +1,78 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { ComputedRef, computed, ref } from 'vue';
|
import { Ref, computed, ref } from 'vue';
|
||||||
import { Boat } from './boat';
|
import { Boat } from './boat';
|
||||||
import {
|
import { Timestamp } from '@quasar/quasar-ui-qcalendar';
|
||||||
Timestamp,
|
|
||||||
parseDate,
|
|
||||||
parsed,
|
|
||||||
compareDate,
|
|
||||||
} from '@quasar/quasar-ui-qcalendar';
|
|
||||||
|
|
||||||
import { IntervalTemplate, TimeTuple, Interval } from './schedule.types';
|
import { IntervalTemplate, Interval, IntervalRecord } 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, Query } from 'appwrite';
|
||||||
|
import { arrayToTimeTuples } from 'src/utils/schedule';
|
||||||
export function arrayToTimeTuples(arr: string[]) {
|
|
||||||
const timeTuples: TimeTuple[] = [];
|
|
||||||
for (let i = 0; i < arr.length; i += 2) {
|
|
||||||
timeTuples.push([arr[i], arr[i + 1]]);
|
|
||||||
}
|
|
||||||
return timeTuples;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function timeTuplesOverlapped(tuples: TimeTuple[]): Interval[] {
|
|
||||||
return blocksOverlapped(
|
|
||||||
tuples.map((tuples) => {
|
|
||||||
return {
|
|
||||||
boatId: '',
|
|
||||||
start: '01/01/2001 ' + tuples[0],
|
|
||||||
end: '01/01/2001 ' + tuples[1],
|
|
||||||
};
|
|
||||||
})
|
|
||||||
).map((t) => {
|
|
||||||
return { ...t, start: t.start.split(' ')[1], end: t.end.split(' ')[1] };
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
export function blocksOverlapped(blocks: Interval[] | Interval[]): Interval[] {
|
|
||||||
return Array.from(
|
|
||||||
new Set(
|
|
||||||
blocks
|
|
||||||
.sort((a, b) => Date.parse(a.start) - Date.parse(b.start))
|
|
||||||
.reduce((acc: Interval[], block, i, arr) => {
|
|
||||||
if (i > 0 && block.start < arr[i - 1].end)
|
|
||||||
acc.push(arr[i - 1], block);
|
|
||||||
return acc;
|
|
||||||
}, [])
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export function copyTimeTuples(tuples: TimeTuple[]): TimeTuple[] {
|
|
||||||
return tuples.map((t) => Object.assign([], t));
|
|
||||||
}
|
|
||||||
export function copyIntervalTemplate(
|
|
||||||
template: IntervalTemplate
|
|
||||||
): IntervalTemplate {
|
|
||||||
return {
|
|
||||||
...template,
|
|
||||||
timeTuples: copyTimeTuples(template.timeTuples || []),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export function buildInterval(
|
|
||||||
resource: Boat,
|
|
||||||
time: TimeTuple,
|
|
||||||
blockDate: string
|
|
||||||
): Interval {
|
|
||||||
/* 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. */
|
|
||||||
const result = {
|
|
||||||
boatId: resource.$id,
|
|
||||||
start: new Date(blockDate + 'T' + time[0]).toISOString(),
|
|
||||||
end: new Date(blockDate + 'T' + time[1]).toISOString(),
|
|
||||||
};
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
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 intervals = ref<Interval[]>([]);
|
const intervals = ref<Map<string, Interval>>(new Map());
|
||||||
|
const intervalDates = ref<IntervalRecord>({});
|
||||||
const intervalTemplates = ref<IntervalTemplate[]>([]);
|
const intervalTemplates = ref<IntervalTemplate[]>([]);
|
||||||
|
|
||||||
const getIntervals = (
|
const getIntervals = (date: Timestamp | string, boat?: Boat): Interval[] => {
|
||||||
date: Timestamp,
|
const searchDate = typeof date === 'string' ? date : date.date;
|
||||||
boat: Boat
|
const dayStart = new Date(searchDate + 'T00:00');
|
||||||
): ComputedRef<Interval[]> => {
|
const dayEnd = new Date(searchDate + 'T23:59');
|
||||||
return computed(() =>
|
if (!intervalDates.value[searchDate]) {
|
||||||
intervals.value.filter((block) => {
|
intervalDates.value[searchDate] = 'pending';
|
||||||
return (
|
fetchIntervals(searchDate);
|
||||||
compareDate(parseDate(new Date(block.start)) as Timestamp, date) &&
|
}
|
||||||
block.boatId === boat.$id
|
return computed(() => {
|
||||||
);
|
return Array.from(intervals.value.values()).filter((interval) => {
|
||||||
})
|
const intervalStart = new Date(interval.start);
|
||||||
);
|
const intervalEnd = new Date(interval.end);
|
||||||
|
|
||||||
|
const isWithinDay = intervalStart < dayEnd && intervalEnd > dayStart;
|
||||||
|
const matchesBoat = boat ? boat.$id === interval.boatId : true;
|
||||||
|
return isWithinDay && matchesBoat;
|
||||||
|
});
|
||||||
|
}).value;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getIntervalsForDate = (date: string): Interval[] => {
|
async function fetchIntervals(dateString: string) {
|
||||||
// TODO: This needs to actually make sure we have the dates we need, stay in sync, etc.
|
|
||||||
|
|
||||||
return intervals.value.filter((b) => {
|
|
||||||
return compareDate(
|
|
||||||
parseDate(new Date(b.start)) as Timestamp,
|
|
||||||
parsed(date) as Timestamp
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
async function fetchIntervals() {
|
|
||||||
try {
|
try {
|
||||||
const response = await databases.listDocuments(
|
const response = await databases.listDocuments(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlock
|
AppwriteIds.collection.interval,
|
||||||
|
[
|
||||||
|
Query.greaterThanEqual(
|
||||||
|
'end',
|
||||||
|
new Date(dateString + 'T00:00').toISOString()
|
||||||
|
),
|
||||||
|
Query.lessThanEqual(
|
||||||
|
'start',
|
||||||
|
new Date(dateString + 'T23:59').toISOString()
|
||||||
|
),
|
||||||
|
Query.limit(50), // We are asuming that we won't have more than 50 intervals per day.
|
||||||
|
]
|
||||||
);
|
);
|
||||||
intervals.value = response.documents as Interval[];
|
response.documents.forEach((d) =>
|
||||||
|
intervals.value.set(d.$id, d as Interval)
|
||||||
|
);
|
||||||
|
intervalDates.value[dateString] = 'loaded';
|
||||||
|
console.info(`Loaded ${response.documents.length} intervals from server`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to fetch timeblocks', error);
|
console.error('Failed to fetch intervals', error);
|
||||||
|
intervalDates.value[dateString] = 'error';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getIntervalTemplates = (): Ref<IntervalTemplate[]> => {
|
||||||
|
// Should subscribe to get new intervaltemplates when they are created
|
||||||
|
if (!intervalTemplates.value) fetchIntervalTemplates();
|
||||||
|
return intervalTemplates;
|
||||||
|
};
|
||||||
|
|
||||||
async function fetchIntervalTemplates() {
|
async function fetchIntervalTemplates() {
|
||||||
try {
|
try {
|
||||||
const response = await databases.listDocuments(
|
const response = await databases.listDocuments(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlockTemplate
|
AppwriteIds.collection.intervalTemplate
|
||||||
);
|
);
|
||||||
intervalTemplates.value = response.documents.map(
|
intervalTemplates.value = response.documents.map(
|
||||||
(d: Models.Document): IntervalTemplate => {
|
(d: Models.Document): IntervalTemplate => {
|
||||||
@@ -140,11 +91,11 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
try {
|
try {
|
||||||
const response = await databases.createDocument(
|
const response = await databases.createDocument(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlock,
|
AppwriteIds.collection.interval,
|
||||||
ID.unique(),
|
ID.unique(),
|
||||||
interval
|
interval
|
||||||
);
|
);
|
||||||
intervals.value.push(response as Interval);
|
intervals.value.set(response.$id, response as Interval);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error creating Interval: ' + e);
|
console.error('Error creating Interval: ' + e);
|
||||||
}
|
}
|
||||||
@@ -154,12 +105,12 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
if (interval.$id) {
|
if (interval.$id) {
|
||||||
const response = await databases.updateDocument(
|
const response = await databases.updateDocument(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlock,
|
AppwriteIds.collection.interval,
|
||||||
interval.$id,
|
interval.$id,
|
||||||
{ ...interval, $id: undefined }
|
{ ...interval, $id: undefined }
|
||||||
);
|
);
|
||||||
intervals.value.push(response as Interval);
|
intervals.value.set(response.$id, response as Interval);
|
||||||
console.log(`Saved Interval: ${interval.$id}`);
|
console.info(`Saved Interval: ${interval.$id}`);
|
||||||
} else {
|
} else {
|
||||||
console.error('Update interval called without an ID');
|
console.error('Update interval called without an ID');
|
||||||
}
|
}
|
||||||
@@ -171,10 +122,11 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
try {
|
try {
|
||||||
await databases.deleteDocument(
|
await databases.deleteDocument(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlock,
|
AppwriteIds.collection.interval,
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
intervals.value = intervals.value.filter((block) => block.$id !== id);
|
intervals.value.delete(id);
|
||||||
|
console.info(`Deleted interval: ${id}`);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error deleting Interval: ' + e);
|
console.error('Error deleting Interval: ' + e);
|
||||||
}
|
}
|
||||||
@@ -183,7 +135,7 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
try {
|
try {
|
||||||
const response = await databases.createDocument(
|
const response = await databases.createDocument(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlockTemplate,
|
AppwriteIds.collection.intervalTemplate,
|
||||||
ID.unique(),
|
ID.unique(),
|
||||||
{ name: template.name, timeTuple: template.timeTuples.flat(2) }
|
{ name: template.name, timeTuple: template.timeTuples.flat(2) }
|
||||||
);
|
);
|
||||||
@@ -196,7 +148,7 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
try {
|
try {
|
||||||
await databases.deleteDocument(
|
await databases.deleteDocument(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlockTemplate,
|
AppwriteIds.collection.intervalTemplate,
|
||||||
id
|
id
|
||||||
);
|
);
|
||||||
intervalTemplates.value = intervalTemplates.value.filter(
|
intervalTemplates.value = intervalTemplates.value.filter(
|
||||||
@@ -213,7 +165,7 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
try {
|
try {
|
||||||
const response = await databases.updateDocument(
|
const response = await databases.updateDocument(
|
||||||
AppwriteIds.databaseId,
|
AppwriteIds.databaseId,
|
||||||
AppwriteIds.collection.timeBlockTemplate,
|
AppwriteIds.collection.intervalTemplate,
|
||||||
id,
|
id,
|
||||||
{
|
{
|
||||||
name: template.name,
|
name: template.name,
|
||||||
@@ -234,10 +186,8 @@ export const useScheduleStore = defineStore('schedule', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
timeblocks: intervals,
|
|
||||||
timeblockTemplates: intervalTemplates,
|
|
||||||
getIntervalsForDate,
|
|
||||||
getIntervals,
|
getIntervals,
|
||||||
|
getIntervalTemplates,
|
||||||
fetchIntervals,
|
fetchIntervals,
|
||||||
fetchIntervalTemplates,
|
fetchIntervalTemplates,
|
||||||
createInterval,
|
createInterval,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Models } from 'appwrite';
|
import { Models } from 'appwrite';
|
||||||
|
import { LoadingTypes } from 'src/utils/misc';
|
||||||
|
|
||||||
export type StatusTypes = 'tentative' | 'confirmed' | 'pending' | undefined;
|
export type StatusTypes = 'tentative' | 'confirmed' | 'pending' | undefined;
|
||||||
export type Reservation = Partial<Models.Document> & {
|
export type Reservation = Partial<Models.Document> & {
|
||||||
@@ -7,6 +8,8 @@ export type Reservation = Partial<Models.Document> & {
|
|||||||
end: string;
|
end: string;
|
||||||
resource: string; // Boat ID
|
resource: string; // Boat ID
|
||||||
status?: StatusTypes;
|
status?: StatusTypes;
|
||||||
|
reason: string;
|
||||||
|
comment: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 24 hrs in advance only 2 weekday, and 1 weekend slot
|
// 24 hrs in advance only 2 weekday, and 1 weekend slot
|
||||||
@@ -27,3 +30,7 @@ export type IntervalTemplate = Partial<Models.Document> & {
|
|||||||
name: string;
|
name: string;
|
||||||
timeTuples: TimeTuple[];
|
timeTuples: TimeTuple[];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface IntervalRecord {
|
||||||
|
[key: string]: LoadingTypes;
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,3 +5,5 @@ export function getNewId(): string {
|
|||||||
// Trivial placeholder
|
// Trivial placeholder
|
||||||
//return Math.max(...reservations.value.map((item) => item.id)) + 1;
|
//return Math.max(...reservations.value.map((item) => item.id)) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type LoadingTypes = 'loaded' | 'pending' | 'error' | undefined;
|
||||||
|
|||||||
77
src/utils/schedule.ts
Normal file
77
src/utils/schedule.ts
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import { date } from 'quasar';
|
||||||
|
import { Boat } from 'src/stores/boat';
|
||||||
|
import {
|
||||||
|
Interval,
|
||||||
|
IntervalTemplate,
|
||||||
|
TimeTuple,
|
||||||
|
} from 'src/stores/schedule.types';
|
||||||
|
|
||||||
|
export function arrayToTimeTuples(arr: string[]) {
|
||||||
|
const timeTuples: TimeTuple[] = [];
|
||||||
|
for (let i = 0; i < arr.length; i += 2) {
|
||||||
|
timeTuples.push([arr[i], arr[i + 1]]);
|
||||||
|
}
|
||||||
|
return timeTuples;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function timeTuplesOverlapped(tuples: TimeTuple[]): Interval[] {
|
||||||
|
return intervalsOverlapped(
|
||||||
|
tuples.map((tuples) => {
|
||||||
|
return {
|
||||||
|
boatId: '',
|
||||||
|
start: '01/01/2001 ' + tuples[0],
|
||||||
|
end: '01/01/2001 ' + tuples[1],
|
||||||
|
};
|
||||||
|
})
|
||||||
|
).map((t) => {
|
||||||
|
return { ...t, start: t.start.split(' ')[1], end: t.end.split(' ')[1] };
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function intervalsOverlapped(
|
||||||
|
blocks: Interval[] | Interval[]
|
||||||
|
): Interval[] {
|
||||||
|
return Array.from(
|
||||||
|
new Set(
|
||||||
|
blocks
|
||||||
|
.sort((a, b) => Date.parse(a.start) - Date.parse(b.start))
|
||||||
|
.reduce((acc: Interval[], block, i, arr) => {
|
||||||
|
if (i > 0 && block.start < arr[i - 1].end)
|
||||||
|
acc.push(arr[i - 1], block);
|
||||||
|
return acc;
|
||||||
|
}, [])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function copyTimeTuples(tuples: TimeTuple[]): TimeTuple[] {
|
||||||
|
return tuples.map((t) => Object.assign([], t));
|
||||||
|
}
|
||||||
|
export function copyIntervalTemplate(
|
||||||
|
template: IntervalTemplate
|
||||||
|
): IntervalTemplate {
|
||||||
|
return {
|
||||||
|
...template,
|
||||||
|
timeTuples: copyTimeTuples(template.timeTuples || []),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildInterval(
|
||||||
|
resource: Boat,
|
||||||
|
time: TimeTuple,
|
||||||
|
blockDate: string
|
||||||
|
): Interval {
|
||||||
|
/* 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. */
|
||||||
|
const result = {
|
||||||
|
boatId: resource.$id,
|
||||||
|
start: new Date(blockDate + 'T' + time[0]).toISOString(),
|
||||||
|
end: new Date(blockDate + 'T' + time[1]).toISOString(),
|
||||||
|
};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function formatDate(inputDate: string | undefined): string {
|
||||||
|
if (!inputDate) return '';
|
||||||
|
return date.formatDate(new Date(inputDate), 'ddd MMM Do hh:mm A');
|
||||||
|
}
|
||||||
@@ -5278,6 +5278,11 @@ vue-tsc@^1.8.22:
|
|||||||
"@vue/language-core" "1.8.27"
|
"@vue/language-core" "1.8.27"
|
||||||
semver "^7.5.4"
|
semver "^7.5.4"
|
||||||
|
|
||||||
|
vue3-google-login@^2.0.26:
|
||||||
|
version "2.0.26"
|
||||||
|
resolved "https://registry.yarnpkg.com/vue3-google-login/-/vue3-google-login-2.0.26.tgz#0e55dbb3c6cbb78872dee0de800624c749d07882"
|
||||||
|
integrity sha512-BuTSIeSjINNHNPs+BDF4COnjWvff27IfCBDxK6JPRqvm57lF8iK4B3+zcG8ud6BXfZdyuiDlxletbEDgg4/RFA==
|
||||||
|
|
||||||
vue@3:
|
vue@3:
|
||||||
version "3.4.25"
|
version "3.4.25"
|
||||||
resolved "https://registry.yarnpkg.com/vue/-/vue-3.4.25.tgz#e59d4ed36389647b52ff2fd7aa84bb6691f4205b"
|
resolved "https://registry.yarnpkg.com/vue/-/vue-3.4.25.tgz#e59d4ed36389647b52ff2fd7aa84bb6691f4205b"
|
||||||
|
|||||||
Reference in New Issue
Block a user