Supabase Removals Frontend
This commit is contained in:
@@ -2,14 +2,14 @@
|
||||
import dayjs from "dayjs";
|
||||
|
||||
const profileStore = useProfileStore();
|
||||
const supabase = useSupabaseClient()
|
||||
const toast = useToast()
|
||||
const staffTime = useStaffTime()
|
||||
|
||||
const runningTimeInfo = ref({})
|
||||
|
||||
const setupPage = async () => {
|
||||
runningTimeInfo.value = (await supabase.from("workingtimes").select().eq("profile", profileStore.activeProfile.id).is("endDate", null).single()).data || {}
|
||||
console.log(runningTimeInfo.value)
|
||||
const rows = await staffTime.list({ user_id: profileStore.activeProfile?.user_id || profileStore.activeProfile?.id })
|
||||
runningTimeInfo.value = rows.find((r) => !r.stopped_at && r.type === "work") || {}
|
||||
}
|
||||
|
||||
setupPage()
|
||||
@@ -19,47 +19,25 @@ setupPage()
|
||||
}*/
|
||||
|
||||
const startTime = async () => {
|
||||
console.log("started")
|
||||
runningTimeInfo.value = {
|
||||
profile: profileStore.activeProfile.id,
|
||||
startDate: dayjs(),
|
||||
tenant: profileStore.currentTenant,
|
||||
state: "Im Web gestartet",
|
||||
source: "Dashboard"
|
||||
}
|
||||
|
||||
const {data,error} = await supabase
|
||||
.from("workingtimes")
|
||||
.insert([runningTimeInfo.value])
|
||||
.select()
|
||||
if(error) {
|
||||
try {
|
||||
await staffTime.start("Arbeitszeit")
|
||||
toast.add({title: "Anwesenheit erfolgreich gestartet"})
|
||||
await setupPage()
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
toast.add({title: "Fehler beim starten der Zeit",color:"rose"})
|
||||
} else if(data) {
|
||||
toast.add({title: "Anwesenheit erfolgreich gestartet"})
|
||||
runningTimeInfo.value = data[0]
|
||||
console.log(runningTimeInfo.value)
|
||||
}
|
||||
}
|
||||
|
||||
const stopStartedTime = async () => {
|
||||
runningTimeInfo.value.endDate = dayjs()
|
||||
runningTimeInfo.value.state = "Im Web gestoppt"
|
||||
|
||||
const {error,status} = await supabase
|
||||
.from("workingtimes")
|
||||
.update(runningTimeInfo.value)
|
||||
.eq('id',runningTimeInfo.value.id)
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
let errorId = await useError().logError(`${status} - ${JSON.stringify(error)}`)
|
||||
toast.add({title: errorId ? `Fehler beim stoppen der Anwesenheit (Fehler ID: ${errorId})` : `Fehler beim stoppen der Anwesenheit`,color:"rose"})
|
||||
|
||||
|
||||
} else {
|
||||
try {
|
||||
await staffTime.stop()
|
||||
toast.add({title: "Anwesenheit erfolgreich gestoppt"})
|
||||
runningTimeInfo.value = {}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
let errorId = await useError().logError(`${JSON.stringify(error)}`)
|
||||
toast.add({title: errorId ? `Fehler beim stoppen der Anwesenheit (Fehler ID: ${errorId})` : `Fehler beim stoppen der Anwesenheit`,color:"rose"})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -67,9 +45,9 @@ const stopStartedTime = async () => {
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div v-if="runningTimeInfo.startDate">
|
||||
<p>Start: {{dayjs(runningTimeInfo.startDate).format("HH:mm")}}</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>
|
||||
<div v-if="runningTimeInfo.started_at">
|
||||
<p>Start: {{dayjs(runningTimeInfo.started_at).format("HH:mm")}}</p>
|
||||
<p>Dauer: {{dayjs().diff(dayjs(runningTimeInfo.started_at),'minutes') > 59 ? `${Math.floor(dayjs().diff(dayjs(runningTimeInfo.started_at),'minutes') / 60)}:${dayjs().diff(dayjs(runningTimeInfo.started_at),'minutes') % 60} h` : dayjs().diff(dayjs(runningTimeInfo.started_at),'minutes') + ' min' }}</p>
|
||||
|
||||
<UFormGroup
|
||||
class="mt-2"
|
||||
@@ -98,4 +76,4 @@ const stopStartedTime = async () => {
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user