109 lines
3.2 KiB
Vue
109 lines
3.2 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 projects = ref([])
|
|
const platform = ref("default")
|
|
|
|
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") || {}
|
|
projects.value = await useEntities("projects").select("*")
|
|
}
|
|
|
|
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: "Projektzeit erfolgreich gestartet"})
|
|
await setupPage()
|
|
} catch (error) {
|
|
console.log(error)
|
|
toast.add({title: "Fehler beim starten der Projektzeit",color:"error"})
|
|
}
|
|
}
|
|
|
|
const stopStartedTime = async () => {
|
|
try {
|
|
await staffTime.stop()
|
|
toast.add({title: "Projektzeit 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 Projektzeit (Fehler ID: ${errorId})` : `Fehler beim stoppen der Projektzeit`,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>
|
|
<UFormField
|
|
v-if="runningTimeInfo.model !== 'spans-v2'"
|
|
class="mt-2"
|
|
label="Projekt:"
|
|
>
|
|
<USelectMenu
|
|
v-model="runningTimeInfo.project"
|
|
:options="projects"
|
|
searchable
|
|
:search-attributes="['name','notes','customer']"
|
|
searchable-placeholder="Suche"
|
|
value-attribute="id"
|
|
option-attribute="name"
|
|
/>
|
|
</UFormField>
|
|
<UButton
|
|
class="mt-3"
|
|
@click="stopStartedTime"
|
|
:disabled="!runningTimeInfo.id"
|
|
>
|
|
Stop
|
|
</UButton>
|
|
</div>
|
|
<div v-else>
|
|
<p>Keine Projektzeit gestartet</p>
|
|
<UButton
|
|
class="mt-3"
|
|
@click="startTime"
|
|
>Starten</UButton>
|
|
</div>
|
|
</template>
|
|
|
|
<style scoped>
|
|
|
|
</style>
|