Files
FEDEO/frontend/components/displayRunningWorkingTime.vue

90 lines
2.6 KiB
Vue

<script setup>
import dayjs from "dayjs";
import { useNow } from "@vueuse/core";
import { workingMinutes } from "~/utils/staffTimeSpans";
const profileStore = useProfileStore();
const toast = useToast()
const staffTime = useStaffTime()
const runningTimeInfo = ref({})
const clock = useNow({ interval: 1000 })
const workingDuration = computed(() => {
const minutes = workingMinutes(runningTimeInfo.value, clock.value.getTime())
return `${Math.floor(minutes / 60)}:${String(minutes % 60).padStart(2, '0')} h`
})
const setupPage = async () => {
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()
/*if(dataStore.workingtimes.find(time => time.profile === profileStore.activeProfile.id && !time.endDate)) {
runningTimeInfo.value = dataStore.workingtimes.find(time => time.profile === profileStore.activeProfile.id && !time.end)
}*/
const startTime = async () => {
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:"error"})
}
}
const stopStartedTime = async () => {
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:"error"})
}
}
</script>
<template>
<div v-if="runningTimeInfo.started_at">
<p>Start: {{dayjs(runningTimeInfo.started_at).format("HH:mm")}}</p>
<p>Arbeitszeit: {{ workingDuration }}</p>
<p v-if="runningTimeInfo.paused">In Pause</p>
<UButton v-if="runningTimeInfo.model === 'spans-v2'" class="mt-2" variant="soft" :to="{ path: '/v2/time', query: { user_id: runningTimeInfo.user_id } }">Anwesenheit bearbeiten</UButton>
<UFormField
v-if="runningTimeInfo.model !== 'spans-v2'"
class="mt-2"
label="Notizen:"
>
<UTextarea
v-model="runningTimeInfo.notes"
/>
</UFormField>
<UButton
class="mt-3"
@click="stopStartedTime"
:disabled="!runningTimeInfo.id"
>
Stop
</UButton>
</div>
<div v-else>
<p>Keine Anwesenheit gestartet</p>
<UButton
class="mt-3"
@click="startTime"
>Starten</UButton>
</div>
</template>
<style scoped>
</style>