wrbapp/frontend/pages/wedstrijd/alltimes.vue

264 lines
11 KiB
Vue
Raw Normal View History

2023-02-10 13:55:18 +01:00
<template>
<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="submitModalForm" 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">Tijd {{ modelData.eventName }}</h1>
2023-02-13 16:01:42 +01:00
<label class="font-bold">Locatie</label>
2023-03-20 11:23:46 +01:00
<input :disabled="!userStore.userData.wedstrijdAdmin" v-model="modelData.contest.location" type="text" class="input dark:bg-neutral-700 bg-neutral-300 mb-5" />
2023-02-10 13:55:18 +01:00
<label class="font-bold">Type zwembad</label>
2023-03-20 11:23:46 +01:00
<select :disabled="!userStore.userData.wedstrijdAdmin" v-model="modelData.contest.type" required="true" class="input dark:bg-neutral-700 bg-neutral-300 mb-5">
2023-02-10 13:55:18 +01:00
<option value="50m">50 Meter</option>
<option value="25m">25 Meter</option>
</select>
2023-02-13 16:01:42 +01:00
<label class="font-bold">Datum</label>
2023-03-20 11:23:46 +01:00
<input :disabled="!userStore.userData.wedstrijdAdmin" :value="dateToYYYYMMDD(modelData.contest.date)" @input="modelData.contest.date = $event.target.valueAsDate" required="true" class="input dark:bg-neutral-700 bg-neutral-300 w-min hover:cursor-pointer pr-0 mb-5 " type="date">
2023-02-13 16:01:42 +01:00
2023-02-10 13:55:18 +01:00
<label class="font-bold">Tijd</label>
<div class="mb-1">
2023-03-20 11:23:46 +01:00
<input :disabled="!userStore.userData.wedstrijdAdmin" 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" />
2023-02-10 13:55:18 +01:00
<span class="text-default text-xl font-bold mx-1">:</span>
2023-03-20 11:23:46 +01:00
<input :disabled="!userStore.userData.wedstrijdAdmin" 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" />
2023-02-10 13:55:18 +01:00
<span class="text-default text-xl font-bold mx-1">:</span>
2023-03-20 11:23:46 +01:00
<input :disabled="!userStore.userData.wedstrijdAdmin" 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" />
2023-02-10 13:55:18 +01:00
</div>
<div class="flex items-center mb-5">
2023-03-20 11:23:46 +01:00
<input :disabled="!userStore.userData.wedstrijdAdmin" type="checkbox" v-model="modelData.dsq" class="mr-1 checkbox">
2023-02-10 13:55:18 +01:00
<span class="text-default">Diskwalificatie</span>
</div>
<label class="font-bold">Info </label>
2023-03-20 11:23:46 +01:00
<input :disabled="!userStore.userData.wedstrijdAdmin" v-model="modelData.info" type="text" placeholder="Bijv. Een diskwalificatie" class="input dark:bg-neutral-700 bg-neutral-300 mb-10" />
2023-02-10 13:55:18 +01:00
2023-03-20 11:23:46 +01:00
<input v-if="userStore.userData.wedstrijdAdmin" :disabled="disableButtons" type="submit" class="btn" value="Bewerken" />
2023-02-10 13:55:18 +01:00
</form>
</div>
2023-03-20 11:23:46 +01:00
<div v-if="contestStore.timings[0]" class="flex flex-col justify-center items-center gap-y-3 px-2 overflow-hidden">
2023-02-13 12:46:59 +01:00
<div class="flex gap-x-5">
<div class="relative">
<button @click.stop="showDeelnemersDropdown = !showDeelnemersDropdown" class="btn">Deelnemers <Icon size="1.2em" name="ion:arrow-down-b" /></button>
<div v-if="showDeelnemersDropdown" v-on-click-outside.bubble="handleDeelnemersDropdown" class="w-48 mt-2 container absolute rounded-lg shadow p-3">
<ul class="space-y-2 text-default">
2023-03-20 11:23:46 +01:00
<li v-for="competitor in contestStore.competitors" @click="competitor.checked = !competitor.checked" class="flex gap-x-1 items-center hover:cursor-pointer">
2023-02-13 12:46:59 +01:00
<input v-model="competitor.checked" type="checkbox" class="checkbox">
<label class="hover:cursor-pointer">{{ competitor.name }}</label>
</li>
</ul>
</div>
</div>
<div class="relative">
<button @click.stop="showPropertiesDropdown = !showPropertiesDropdown" class="btn">Eigenschappen <Icon size="1.2em" name="ion:arrow-down-b" /></button>
<div v-if="showPropertiesDropdown" v-on-click-outside.bubble="handlePropertiesDropdown" class="w-48 mt-2 container absolute rounded-lg shadow p-3">
<ul class="space-y-2 text-default">
<li v-for="property in Object.values(properties)" @click="property.enabled = !property.enabled" class="flex gap-x-1 items-center hover:cursor-pointer">
<input v-model="property.enabled" type="checkbox" class="checkbox">
<label class="hover:cursor-pointer">{{ property.name }}</label>
</li>
</ul>
</div>
2023-02-10 13:55:18 +01:00
</div>
</div>
2023-02-13 16:01:42 +01:00
<div v-for="event in events" class="container w-full max-w-3xl py-2 px-4">
2023-02-10 13:55:18 +01:00
<div @click="event.open = !event.open" class="flex hover:cursor-pointer">
2023-02-13 16:01:42 +01:00
<h2 class="font-bold mr-auto">{{ event.name }}</h2>
2023-03-20 11:23:46 +01:00
<span v-if="contestStore.filteredTimings.filter(a => a.event === event.id).length > 0" class="">
<span>
{{ contestStore.filteredTimings.filter(a => a.event === event.id)[0].time.minutes }}:{{ contestStore.filteredTimings.filter(a => a.event === event.id)[0].time.seconds }}:{{ contestStore.filteredTimings.filter(a => a.event === event.id)[0].time.milliseconds }} |
</span>
2023-02-13 16:01:42 +01:00
<span class="hidden md:inline-block mr-1">
{{ contestStore.filteredTimings.filter(a => a.event === event.id)[0].contest.type }}
2023-03-20 11:23:46 +01:00
{{ contestStore.filteredTimings.filter(a => a.event === event.id)[0].contest.date.toLocaleDateString('nl-NL') }} |
{{ contestStore.filteredTimings.filter(a => a.event === event.id)[0].contest.location }} |
2023-02-13 16:01:42 +01:00
</span>
</span>
2023-02-13 16:01:42 +01:00
<span v-else class="">Geen tijd</span>
2023-02-10 13:55:18 +01:00
<Icon size="1.2em" name="ion:arrow-down-b" class="my-auto ml-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>
2023-02-13 12:46:59 +01:00
<th v-for="property in Object.values(properties).filter(a => a.enabled === true)">{{ property.name }}</th>
2023-02-10 13:55:18 +01:00
</tr>
</thead>
<tbody>
2023-03-20 11:23:46 +01:00
<tr @click="handleModel(time, event, index)" v-for="(time, index) in contestStore.filteredTimings.filter(a => a.event === event.id)" class="even:dark:bg-neutral-700 even:bg-neutral-300 hover:cursor-pointer">
2023-02-13 12:46:59 +01:00
<td v-if="properties.time.enabled" class="pl-1" :class="time.dsq ? 'line-through' : ''">{{ time.time.minutes }}:{{ time.time.seconds }}:{{ time.time.milliseconds}}</td>
2023-02-13 16:01:42 +01:00
<td v-if="properties.date.enabled">{{ time.contest.date.toLocaleDateString('nl-NL') }}</td>
2023-03-20 11:23:46 +01:00
<td v-if="properties.name.enabled" class="overflow-hidden whitespace-nowrap truncate">{{ contestStore.competitors.filter(a => a.relatiecode === time.relatiecode)[0].name.split(', ')[1] + ' ' + contestStore.competitors.filter(a => a.relatiecode === time.relatiecode)[0].name.split(', ')[0] }}</td>
2023-02-13 12:46:59 +01:00
<td v-if="properties.type.enabled">{{ time.contest.type }}</td>
2023-02-13 16:01:42 +01:00
<td v-if="properties.location.enabled">{{ time.contest.location }}</td>
2023-02-10 13:55:18 +01:00
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<script setup>
2023-02-13 16:01:42 +01:00
import { collection, query, getDocs, doc, updateDoc } from "firebase/firestore";
2023-02-10 13:55:18 +01:00
import { useToast } from 'vue-toastification'
import { vOnClickOutside} from '@vueuse/components'
definePageMeta({
2023-02-13 12:46:59 +01:00
title: 'Brigade Tijden',
2023-02-10 13:55:18 +01:00
key: 'back'
})
const toast = useToast()
2023-03-20 11:23:46 +01:00
const userStore = useUserStore()
const contestStore = useContestStore()
2023-02-10 13:55:18 +01:00
const showModel = ref(false)
const disableButtons = ref(false)
2023-02-13 12:46:59 +01:00
const showDeelnemersDropdown = ref(false)
const showPropertiesDropdown = ref(false)
const handleDeelnemersDropdown = () => {
showDeelnemersDropdown.value = false
}
2023-02-10 13:55:18 +01:00
2023-02-13 12:46:59 +01:00
const handlePropertiesDropdown = () => {
showPropertiesDropdown.value = false
2023-02-10 13:55:18 +01:00
}
const modelData = ref({
time: {
minutes: null,
seconds: null,
milliseconds: null,
},
dsq: false,
info: '',
contest: {
type: '',
2023-02-13 16:01:42 +01:00
location: '',
date: Date,
2023-02-10 13:55:18 +01:00
}
})
2023-02-13 12:46:59 +01:00
const properties = ref({
time: {
enabled: true,
id: 'time',
name: 'Tijd',
},
date: {
enabled: true,
id: 'date',
name: 'Datum',
},
name: {
enabled: true,
id: 'name',
name: 'Naam',
},
type: {
enabled: false,
id: 'type',
name: 'Type zwembad',
},
2023-02-13 16:01:42 +01:00
location: {
2023-02-13 12:46:59 +01:00
enabled: false,
2023-02-13 16:01:42 +01:00
id: 'location',
name: 'Locatie',
2023-02-13 12:46:59 +01:00
},
})
2023-02-10 13:55:18 +01:00
const events = ref({
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: [],
},
manikinTowWithFins: {
open: false,
name: '100m Manikin Tow with Fins',
id: 'manikinTowWithFins',
competitors: [],
},
superLifesaver: {
open: false,
name: '200m Super Lifesaver',
id: 'superLifesaver',
competitors: [],
},
})
onMounted(async () => {
2023-03-20 11:23:46 +01:00
await contestStore.getCompetitors()
await contestStore.getTimings()
2023-02-10 13:55:18 +01:00
2023-03-20 11:23:46 +01:00
contestStore.selectCompetitors('all')
2023-02-10 13:55:18 +01:00
})
2023-02-13 16:01:42 +01:00
const dateToYYYYMMDD = (d) => {
return d && new Date(d.getTime()-(d.getTimezoneOffset()*60*1000)).toISOString().split('T')[0]
}
2023-02-10 13:55:18 +01:00
const handleModel = (competitor, e, index) => {
modelData.value = competitor
modelData.value.index = index
modelData.value.eventId = e.id
showModel.value = true
}
const submitModalForm = async () => {
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 id = modelData.value.id
delete modelData.value.index
delete modelData.value.eventId
delete modelData.value.id
disableButtons.value = true
const combinedTime = modelData.value.time.minutes.toString().padStart(2, '0') + modelData.value.time.seconds.toString().padStart(2, '0') + modelData.value.time.milliseconds.toString().padStart(2, '0')
modelData.value.time.combinedTime = combinedTime
const docRef = doc(db, "timings", id);
await updateDoc(docRef, modelData.value);
toast.success('Tijd is bewerkt')
showModel.value = false
disableButtons.value = false
}
</script>
<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>