2022-12-04 10:29:11 +01:00
|
|
|
<template>
|
2023-01-19 15:31:22 +01:00
|
|
|
<div @click.self="showModel = false" v-if="showModel" class="fixed flex justify-center items-center h-screen w-full bg-black top-0 left-0 z-50 bg-opacity-50" >
|
|
|
|
<form @submit.prevent="submitModelForm" class="dark:bg-neutral-800 bg-neutral-200 p-10 rounded-xl flex flex-col w-full max-w-sm">
|
|
|
|
<h1 class="font-bold text-center text-lg mb-5">Deelnemer Toevoegen</h1>
|
|
|
|
|
|
|
|
<label class="font-bold text-default">Deelnemer</label>
|
|
|
|
<select :disabled="modelData.edit" required v-model="modelData.relatiecode" class="input dark:bg-neutral-700 bg-neutral-300 mb-5">
|
2023-03-20 11:23:46 +01:00
|
|
|
<option v-if="!modelData.edit" v-for="user in contestStore.competitors.filter(x => !contest.events[modelData.event].competitors.map(y => y.relatiecode).includes(x.relatiecode))" :value="user.relatiecode">{{ user.name}} ({{ user.relatiecode }})</option>
|
2023-01-19 15:31:22 +01:00
|
|
|
<option v-else v-for="user in competitors" :value="user.relatiecode">{{ user.name}} ({{ user.relatiecode }})</option>
|
|
|
|
</select>
|
|
|
|
|
|
|
|
<label class="font-bold text-default">Tijd</label>
|
|
|
|
<div class="mb-1">
|
|
|
|
<input v-model="modelData.time.minutes" type="number" step="1" min="0" max="99" placeholder="mm" class="input dark:bg-neutral-700 bg-neutral-300 w-10 text-center p-1" />
|
|
|
|
<span class="text-default text-xl font-bold mx-1">:</span>
|
|
|
|
<input v-model="modelData.time.seconds" type="number" step="1" min="0" max="99" placeholder="ss" class="input dark:bg-neutral-700 bg-neutral-300 w-10 text-center p-1" />
|
|
|
|
<span class="text-default text-xl font-bold mx-1">:</span>
|
|
|
|
<input v-model="modelData.time.milliseconds" type="number" step="1" min="0" max="99" placeholder="ms" class="input dark:bg-neutral-700 bg-neutral-300 w-10 text-center p-1" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex items-center mb-5">
|
|
|
|
<input type="checkbox" v-model="modelData.dsq" class="mr-1 checkbox">
|
|
|
|
<span class="text-default">Diskwalificatie</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<label class="font-bold">Info (Optioneel)</label>
|
|
|
|
<input v-model="modelData.info" type="text" placeholder="Bijv. Een diskwalificatie" class="input dark:bg-neutral-700 bg-neutral-300 mb-10" />
|
|
|
|
|
2023-01-27 19:09:09 +01:00
|
|
|
<input :disabled="disableButtons" type="submit" class="btn" :value="modelData.edit ? 'Bewerken' : 'Toevoegen'" />
|
2023-01-19 15:31:22 +01:00
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<div class="flex flex-col gap-5 mx-auto p-2 w-full max-w-md">
|
|
|
|
<form @submit.prevent="submitContestForm" class="flex flex-col">
|
2023-02-13 16:01:42 +01:00
|
|
|
<label class="font-bold">Locatie Wedstrijd</label>
|
|
|
|
<input v-model="contest.location" required="true" class="input mb-5 " type="text">
|
2023-01-19 15:31:22 +01:00
|
|
|
|
2023-02-10 13:55:18 +01:00
|
|
|
<label class="font-bold">Type Zwembad</label>
|
|
|
|
<select v-model="contest.type" required="true" class="input mb-5 " type="text">
|
|
|
|
<option value="50m">50 Meter</option>
|
|
|
|
<option value="25m">25 Meter</option>
|
|
|
|
</select>
|
|
|
|
|
2023-01-19 15:31:22 +01:00
|
|
|
<label class="font-bold">Datum</label>
|
|
|
|
<input v-model="contest.date" required="true" class="input w-min hover:cursor-pointer pr-0 mb-5 " type="date">
|
|
|
|
|
|
|
|
<label class="font-bold">Onderdelen</label>
|
2023-02-10 13:55:18 +01:00
|
|
|
<div class="flex flex-col gap-y-3">
|
2023-03-20 11:23:46 +01:00
|
|
|
<div v-if="contestStore.competitors[0]" v-for="event in contest.events" class="container p-2">
|
2023-01-19 15:31:22 +01:00
|
|
|
<div @click="event.open = !event.open" class="flex hover:cursor-pointer">
|
|
|
|
<h2 class="font-bold">{{ event.name }}</h2>
|
|
|
|
<Icon size="1.2em" name="ion:arrow-down-b" class="ml-auto my-auto mr-2 transition-all" :class="{'rotate-180' : event.open }" />
|
|
|
|
</div>
|
|
|
|
<div v-if="event.open" class="mt-2">
|
|
|
|
<table class="table-fixed text-left w-full even:bg-gray-500">
|
|
|
|
<thead class="font-bold">
|
|
|
|
<tr>
|
|
|
|
<th class="w-3/6">Naam</th>
|
|
|
|
<th class="w-2/6">Tijd</th>
|
|
|
|
<th class="w-1/6">DSQ</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr @click="handleModel(competitor, event.id, true, index)" v-for="(competitor, index) in event.competitors" class="even:dark:bg-neutral-700 even:bg-neutral-300 hover:cursor-pointer">
|
2023-03-20 11:23:46 +01:00
|
|
|
<td class="py-1 pl-1">{{ contestStore.competitors.find(x => x.relatiecode === competitor.relatiecode ).name }}</td>
|
2023-01-19 15:31:22 +01:00
|
|
|
<td>{{ competitor.time.minutes.toString().padStart(2, '0') }}:{{ competitor.time.seconds.toString().padStart(2, '0') }}:{{ competitor.time.milliseconds.toString().padStart(2, '0') }}</td>
|
|
|
|
<td>{{ competitor.dsq }}</td>
|
|
|
|
</tr>
|
2023-03-20 11:23:46 +01:00
|
|
|
<tr v-if="contestStore.competitors.filter(x => !event.competitors.map(y => y.relatiecode).includes(x.relatiecode)).length > 0" class="even:dark:bg-neutral-700 even:bg-neutral-300">
|
2023-01-19 15:31:22 +01:00
|
|
|
<td @click="handleModel(null, event.id)" class="hover:cursor-pointer py-1 pl-1">+ Deelnemer toevoegen</td>
|
|
|
|
<td></td>
|
|
|
|
<td></td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
</table>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-01-26 11:06:07 +01:00
|
|
|
<input :disabled="disableButtons" type="submit" class="btn mt-10 px-5 w-min mx-auto" value="Wedstrijd toevoegen" />
|
2023-01-19 15:31:22 +01:00
|
|
|
</form>
|
|
|
|
</div>
|
2022-12-04 10:29:11 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
2023-03-20 11:23:46 +01:00
|
|
|
import { getDocs, collection, writeBatch, doc, getFirestore } from "firebase/firestore"
|
2023-01-26 11:06:07 +01:00
|
|
|
import { useToast } from 'vue-toastification'
|
2022-12-04 10:29:11 +01:00
|
|
|
|
|
|
|
definePageMeta({
|
2023-01-19 15:31:22 +01:00
|
|
|
title: 'Wedstrijd Toevoegen',
|
|
|
|
key: 'back'
|
2022-12-04 10:29:11 +01:00
|
|
|
})
|
|
|
|
|
2023-01-26 11:06:07 +01:00
|
|
|
const toast = useToast()
|
|
|
|
|
2023-03-20 11:23:46 +01:00
|
|
|
const contestStore = useContestStore()
|
|
|
|
const userStore = useUserStore()
|
|
|
|
const db = getFirestore()
|
2022-12-04 10:29:11 +01:00
|
|
|
|
2023-01-19 15:31:22 +01:00
|
|
|
const showModel = ref(false)
|
2023-01-26 11:06:07 +01:00
|
|
|
const disableButtons = ref(false)
|
2023-01-19 15:31:22 +01:00
|
|
|
|
|
|
|
const modelData = ref({
|
|
|
|
relatiecode: '',
|
|
|
|
time: {
|
|
|
|
minutes: null,
|
|
|
|
seconds: null,
|
|
|
|
milliseconds: null,
|
|
|
|
},
|
|
|
|
dsq: false,
|
|
|
|
info: '',
|
|
|
|
})
|
2022-12-04 10:29:11 +01:00
|
|
|
|
|
|
|
const contest = ref({
|
2023-02-13 16:01:42 +01:00
|
|
|
location: '',
|
2023-02-10 13:55:18 +01:00
|
|
|
type: '',
|
2023-02-13 16:01:42 +01:00
|
|
|
date: Date,
|
2023-01-19 15:31:22 +01:00
|
|
|
events: {
|
|
|
|
obstacleSwim: {
|
|
|
|
open: false,
|
|
|
|
name: '200m Obstacle Swim',
|
|
|
|
id: 'obstacleSwim',
|
|
|
|
competitors: [],
|
|
|
|
},
|
|
|
|
manikinCarry: {
|
|
|
|
open: false,
|
|
|
|
name: '50m Manikin Carry',
|
|
|
|
id: 'manikinCarry',
|
|
|
|
competitors: [],
|
|
|
|
},
|
|
|
|
rescueMedley: {
|
|
|
|
open: false,
|
|
|
|
name: '100m Rescue Medley',
|
|
|
|
id: 'rescueMedley',
|
|
|
|
competitors: [],
|
|
|
|
},
|
|
|
|
manikinCarryWithFins: {
|
|
|
|
open: false,
|
|
|
|
name: '100m Manikin Carry with Fins',
|
|
|
|
id: 'manikinCarryWithFins',
|
|
|
|
competitors: [],
|
|
|
|
},
|
2023-02-10 13:55:18 +01:00
|
|
|
manikinTowWithFins: {
|
|
|
|
open: false,
|
|
|
|
name: '100m Manikin Tow with Fins',
|
|
|
|
id: 'manikinTowWithFins',
|
|
|
|
competitors: [],
|
|
|
|
},
|
2023-01-19 15:31:22 +01:00
|
|
|
superLifesaver: {
|
|
|
|
open: false,
|
|
|
|
name: '200m Super Lifesaver',
|
|
|
|
id: 'superLifesaver',
|
|
|
|
competitors: [],
|
|
|
|
},
|
|
|
|
}
|
2022-12-04 10:29:11 +01:00
|
|
|
})
|
|
|
|
|
2023-01-19 15:31:22 +01:00
|
|
|
const handleModel = (competitor, event, edit, index) => {
|
|
|
|
if(!competitor) competitor = {
|
|
|
|
relatiecode: '',
|
|
|
|
time: {
|
|
|
|
minutes: null,
|
|
|
|
seconds: null,
|
|
|
|
milliseconds: null,
|
|
|
|
},
|
|
|
|
dsq: false,
|
|
|
|
info: '',
|
|
|
|
}
|
|
|
|
|
|
|
|
modelData.value = competitor
|
|
|
|
modelData.value.event = event
|
|
|
|
modelData.value.edit = edit
|
|
|
|
modelData.value.index = index
|
|
|
|
showModel.value = true
|
2022-12-17 13:01:49 +01:00
|
|
|
}
|
|
|
|
|
2023-01-19 15:31:22 +01:00
|
|
|
const submitModelForm = () => {
|
|
|
|
if (!modelData.value.time.minutes) modelData.value.time.minutes = 0
|
|
|
|
if (!modelData.value.time.seconds) modelData.value.time.seconds = 0
|
|
|
|
if (!modelData.value.time.milliseconds) modelData.value.time.milliseconds = 0
|
|
|
|
const index = modelData.value.index
|
|
|
|
const edit = modelData.value.edit
|
|
|
|
|
|
|
|
delete modelData.value.index
|
|
|
|
delete modelData.value.edit
|
2023-03-20 11:23:46 +01:00
|
|
|
|
2023-01-19 15:31:22 +01:00
|
|
|
if (!edit) contest.value.events[modelData.value.event].competitors.push(modelData.value)
|
|
|
|
|
|
|
|
showModel.value = false
|
|
|
|
}
|
|
|
|
|
|
|
|
const submitContestForm = async () => {
|
2023-01-26 11:06:07 +01:00
|
|
|
disableButtons.value = true
|
|
|
|
|
2023-01-19 15:31:22 +01:00
|
|
|
const batch = writeBatch(db)
|
|
|
|
|
|
|
|
Object.values(contest.value.events).forEach(event => {
|
|
|
|
event.competitors.forEach(competitor => {
|
2023-01-26 11:06:07 +01:00
|
|
|
const combinedTime = competitor.time.minutes.toString().padStart(2, '0') + competitor.time.seconds.toString().padStart(2, '0') + competitor.time.milliseconds.toString().padStart(2, '0')
|
2023-01-19 15:31:22 +01:00
|
|
|
|
|
|
|
const docRef = doc(collection(db, 'timings'))
|
|
|
|
batch.set(docRef, {
|
|
|
|
relatiecode: competitor.relatiecode,
|
2023-03-20 11:23:46 +01:00
|
|
|
contest: { location: contest.value.location, date: new Date(contest.value.date), type: contest.value.type },
|
2023-01-19 15:31:22 +01:00
|
|
|
event: event.id,
|
2023-01-26 11:06:07 +01:00
|
|
|
time: { minutes: competitor.time.minutes.toString().padStart(2, '0'), seconds: competitor.time.seconds.toString().padStart(2, '0'), milliseconds: competitor.time.milliseconds.toString().padStart(2, '0'), combined: combinedTime },
|
2023-01-19 15:31:22 +01:00
|
|
|
dsq: competitor.dsq,
|
|
|
|
info: competitor.info || ''
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
await batch.commit()
|
2023-01-26 11:06:07 +01:00
|
|
|
disableButtons.value = false
|
|
|
|
|
|
|
|
toast.success('Wedstrijd is toegevoegd')
|
|
|
|
navigateTo('/wedstrijd')
|
2022-12-17 13:01:49 +01:00
|
|
|
}
|
|
|
|
|
2022-12-04 10:29:11 +01:00
|
|
|
onMounted(() => {
|
2023-03-20 11:23:46 +01:00
|
|
|
contestStore.getCompetitors()
|
2022-12-04 10:29:11 +01:00
|
|
|
})
|
|
|
|
</script>
|
2023-01-19 15:31:22 +01:00
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
input::-webkit-outer-spin-button,
|
|
|
|
input::-webkit-inner-spin-button {
|
|
|
|
-webkit-appearance: none;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
input[type=number] {
|
|
|
|
-moz-appearance: textfield;
|
|
|
|
appearance: textfield;
|
|
|
|
}
|
|
|
|
</style>
|