This commit is contained in:
2024-04-07 19:10:17 +02:00
parent e0750e755f
commit 895f508c29

View File

@@ -4,9 +4,6 @@ import customParseFormat from "dayjs/plugin/customParseFormat"
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
definePageMeta({ definePageMeta({
middleware: "auth" middleware: "auth"
}) })
@@ -32,7 +29,9 @@ const filteredRows = computed(() => {
let times = dataStore.workingtimes let times = dataStore.workingtimes
if(dataStore.hasRight('viewTimes')) { times = times.filter(i => i.profile === filterUser.value)
/*if(dataStore.hasRight('viewTimes')) {
if(filterUser.value !== "") { if(filterUser.value !== "") {
times = times.filter(i => i.profile === filterUser.value) times = times.filter(i => i.profile === filterUser.value)
} }
@@ -40,7 +39,7 @@ const filteredRows = computed(() => {
times = times.filter(i => i.profile === dataStore.getOwnProfile.id) times = times.filter(i => i.profile === dataStore.getOwnProfile.id)
} else { } else {
times = [] times = []
} }*/
return times return times
@@ -73,12 +72,12 @@ const columns = [
sortable:true sortable:true
}, },
{ {
key:"start", key:"startDate",
label:"Start", label:"Start",
sortable:true sortable:true
}, },
{ {
key: "end", key: "endDate",
label: "Ende", label: "Ende",
sortable:true sortable:true
}, },
@@ -95,16 +94,12 @@ const columns = [
] ]
const runningTimeInfo = ref({}) const runningTimeInfo = ref({})
const configTimeMode = ref("create")
const startTime = async () => { const startTime = async () => {
console.log("started") console.log("started")
timeInfo.value = { timeInfo.value = {
profile: dataStore.activeProfile.id, profile: dataStore.activeProfile.id,
start: dayjs().format("HH:mm:ss"), startDate: dayjs(),
date: dayjs().format("YYYY-MM-DD"),
tenant: dataStore.currentTenant, tenant: dataStore.currentTenant,
state: "Im Web gestartet" state: "Im Web gestartet"
} }
@@ -113,28 +108,19 @@ const startTime = async () => {
.from("workingtimes") .from("workingtimes")
.insert([timeInfo.value]) .insert([timeInfo.value])
.select() .select()
if(error) { if(error) {
console.log(error) console.log(error)
} else if(data) { } else if(data) {
//timeInfo.value = data[0] //timeInfo.value = data[0]
await dataStore.fetchWorkingTimes() await dataStore.fetchWorkingTimes()
runningTimeInfo.value = dataStore.times.find(time => time.profile === dataStore.activeProfile.id && !time.end) runningTimeInfo.value = timeInfo.value//dataStore.times.find(time => time.profile === dataStore.activeProfile.id && !time.endDate)
} }
} }
const stopStartedTime = async () => { const stopStartedTime = async () => {
//console.log(runningTimeInfo.value) runningTimeInfo.value.endDate = dayjs()
runningTimeInfo.value.end = dayjs().format("HH:mm:ssZ")
runningTimeInfo.value.state = "Im Web gestoppt" runningTimeInfo.value.state = "Im Web gestoppt"
/*const mapNumRange = (num, inMin, inMax, outMin, outMax) =>
((num - inMin) * (outMax - outMin)) / (inMax - inMin) + outMin;*/
//runningTimeInfo.value.duration = Math.round(mapNumRange(Math.abs(new Date(runningTimeInfo.value.end) - new Date(runningTimeInfo.value.start))/1000/60,0,60,0,1)*100)/100
const {data,error} = await supabase const {data,error} = await supabase
.from("workingtimes") .from("workingtimes")
.update(runningTimeInfo.value) .update(runningTimeInfo.value)
@@ -151,54 +137,10 @@ const stopStartedTime = async () => {
} }
} }
if(dataStore.workingtimes.find(time => time.profile === dataStore.activeProfile.id && !time.end)) { if(dataStore.workingtimes.find(time => time.profile === dataStore.activeProfile.id && !time.endDate)) {
runningTimeInfo.value = dataStore.workingtimes.find(time => time.profile === dataStore.activeProfile.id && !time.end) runningTimeInfo.value = dataStore.workingtimes.find(time => time.profile === dataStore.activeProfile.id && !time.end)
} }
const createTime = async () => {
const date = dayjs(itemInfo.value.start).format("YYYY-MM-DD")
const start = dayjs(itemInfo.value.start).format("HH:mm:ssZ")
const end = dayjs(itemInfo.value.end).format("HH:mm:ssZ")
const {data,error} = await supabase
.from("workingtimes")
.insert({...itemInfo.value, date,start,end, tenant: dataStore.currentTenant})
.select()
if(error) {
console.log(error)
} else if(data) {
itemInfo.value = {}
toast.add({title: "Zeit erfolgreich erstellt"})
await dataStore.fetchTimes()
}
}
const updateTime = async () => {
const {error} = await supabase
.from("workingTimes")
.update(itemInfo.value)
.eq('id',itemInfo.value.id)
if(error) {
console.log(error)
}
toast.add({title: "Zeit erfolgreich gespeichert"})
await dataStore.fetchTimes()
}
const format = (date) => {
let dateFormat = dayjs(date).format("DD.MM.YY HH:mm")
return `${dateFormat}`;
}
const getDuration = (time) => { const getDuration = (time) => {
const minutes = Math.floor(dayjs(time.endDate).diff(dayjs(time.startDate),'minutes',true)) const minutes = Math.floor(dayjs(time.endDate).diff(dayjs(time.startDate),'minutes',true))
const hours = Math.floor(minutes/60) const hours = Math.floor(minutes/60)
@@ -210,19 +152,11 @@ const getDuration = (time) => {
} }
} }
const setState = async (newState) => {
itemInfo.value.state = newState
await updateTime()
}
</script> </script>
<template> <template>
<UDashboardNavbar title="Zeiterfassung"> <UDashboardNavbar title="Anwesenheiten">
<template #right>
</UDashboardNavbar>
<UDashboardToolbar>
<template #left>
<UButton <UButton
@click="startTime" @click="startTime"
:disabled="runningTimeInfo.id " :disabled="runningTimeInfo.id "
@@ -234,6 +168,11 @@ const setState = async (newState) => {
> >
Erstellen Erstellen
</UButton> </UButton>
</template>
</UDashboardNavbar>
<UDashboardToolbar>
<template #left>
<USelectMenu <USelectMenu
v-if="dataStore.hasRight('viewTimes')" v-if="dataStore.hasRight('viewTimes')"
:options="dataStore.profiles" :options="dataStore.profiles"
@@ -249,13 +188,13 @@ const setState = async (newState) => {
</UDashboardToolbar> </UDashboardToolbar>
<div class="mx-3"> <div class="mx-3">
<UAlert <UAlert
v-if="runningTimeInfo.id" v-if="runningTimeInfo.startDate && !runningTimeInfo.endDate"
class="my-3" class="my-3"
title="Laufende Zeit:" title="Laufende Zeit:"
> >
<template #description> <template #description>
<p>Start: {{dayjs(runningTimeInfo.start, "HH:mm:ss").format("HH:mm")}}</p> <p>Start: {{dayjs(runningTimeInfo.startDate).format("HH:mm")}}</p>
<p>Dauer: {{dayjs().diff(dayjs(runningTimeInfo.start, "HH:mm:ss"),'minutes') > 59 ? `${Math.floor(dayjs().diff(dayjs(runningTimeInfo.start, "HH:mm:ss"),'minutes') / 60)}:${dayjs().diff(dayjs(runningTimeInfo.start, "HH:mm:ss"),'minutes') % 60} h` : dayjs().diff(dayjs(runningTimeInfo.start, "HH:mm:ss"),'minutes') + ' min' }}</p> <p>Dauer: {{dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') > 59 ? `${Math.floor(dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') / 60)}:${dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') % 60} h` : dayjs().diff(dayjs(runningTimeInfo.startDate),'minutes') + ' min' }}</p>
<UFormGroup <UFormGroup
class="mt-2" class="mt-2"
@@ -311,10 +250,10 @@ const setState = async (newState) => {
{{dayjs(row.startDate).format("DD.MM.YYYY")}} {{dayjs(row.startDate).format("DD.MM.YYYY")}}
</template> </template>
<template #start-data="{row}"> <template #startDate-data="{row}">
{{dayjs(row.startDate).format("HH:mm")}} Uhr {{dayjs(row.startDate).format("HH:mm")}} Uhr
</template> </template>
<template #end-data="{row}"> <template #endDate-data="{row}">
{{row.endDate ? dayjs(row.endDate).format("HH:mm") + " Uhr" : ""}} {{row.endDate ? dayjs(row.endDate).format("HH:mm") + " Uhr" : ""}}
</template> </template>
<template #duration-data="{row}"> <template #duration-data="{row}">