moved times/index

This commit is contained in:
2025-06-01 18:23:14 +02:00
parent 03231ab3f3
commit 4346fbffe5
2 changed files with 67 additions and 73 deletions

View File

@@ -126,7 +126,7 @@ const links = computed(() => {
children: [ children: [
... profileStore.ownTenant.features.timeTracking ? [{ ... profileStore.ownTenant.features.timeTracking ? [{
label: "Zeiterfassung", label: "Zeiterfassung",
to: "/employees/timetracking", to: "/times",
icon: "i-heroicons-clock" icon: "i-heroicons-clock"
}] : [], }] : [],
... profileStore.ownTenant.features.workingTimeTracking ? [{ ... profileStore.ownTenant.features.workingTimeTracking ? [{
@@ -319,6 +319,10 @@ const links = computed(() => {
label: "Projekttypen", label: "Projekttypen",
to: "/projecttypes", to: "/projecttypes",
icon: "i-heroicons-clipboard-document-list" icon: "i-heroicons-clipboard-document-list"
},{
label: "Export",
to: "/export",
icon: "i-heroicons-clipboard-document-list"
} }
] ]
} }

View File

@@ -15,7 +15,7 @@ const user = useSupabaseUser()
const toast = useToast() const toast = useToast()
const timeTypes = dataStore.getTimeTypes const timeTypes = profileStore.ownTenant.timeConfig.timeTypes
const timeInfo = ref({ const timeInfo = ref({
profile: "", profile: "",
startDate: "", startDate: "",
@@ -28,9 +28,21 @@ const timeInfo = ref({
const filterUser = ref(profileStore.activeProfile.id || "") const filterUser = ref(profileStore.activeProfile.id || "")
const times = ref([]) const times = ref([])
const runningTimeInfo = ref({})
const showConfigTimeModal = ref(false)
const configTimeMode = ref("create")
const setup = async () => { const setup = async () => {
times.value = await useSupabaseSelect("times","*, profile(*)") times.value = await useSupabaseSelect("times","*, profile(*), project(id, name)")
runningTimeInfo.value = (await supabase
.from("times")
.select()
.eq("tenant", profileStore.currentTenant)
.eq("profile", profileStore.activeProfile.id)
.is("endDate",null)
.single()).data
} }
setup() setup()
@@ -60,7 +72,7 @@ const itemInfo = ref({
start: new Date(), start: new Date(),
end: "", end: "",
notes: null, notes: null,
projectId: null, project: null,
type: null, type: null,
state: "Entwurf" state: "Entwurf"
}) })
@@ -87,10 +99,6 @@ const columns = [
key:"type", key:"type",
label:"Typ", label:"Typ",
}, },
{
key: "duration",
label: "Dauer",
},
{ {
key: "project", key: "project",
label: "Projekt", label: "Projekt",
@@ -101,16 +109,14 @@ const columns = [
} }
] ]
const runningTimeInfo = ref({})
const showConfigTimeModal = ref(false)
const configTimeMode = ref("create")
const startTime = async () => { const startTime = async () => {
console.log("started") console.log("started")
timeInfo.value.profile = profileStore.activeProfile.id timeInfo.value.profile = profileStore.activeProfile.id
timeInfo.value.start = new Date().toISOString() timeInfo.value.startDate = dayjs()
timeInfo.value.tenant = profileStore.currentTenant timeInfo.value.tenant = profileStore.currentTenant
const {data,error} = await supabase const {data,error} = await supabase
@@ -120,45 +126,34 @@ const startTime = async () => {
if(error) { if(error) {
console.log(error) console.log(error)
toast.add({title: "Fehler beim starten der Zeit",color:"rose"})
} else if(data) { } else if(data) {
//timeInfo.value = data[0] toast.add({title: "Zeit erfolgreich gestartet"})
await dataStore.fetchTimes() runningTimeInfo.value = data[0]
runningTimeInfo.value = dataStore.times.find(time => time.profile === profileStore.activeProfile.id && !time.end)
} }
} }
const stopStartedTime = async () => { const stopStartedTime = async () => {
console.log(runningTimeInfo.value) runningTimeInfo.value.endDate = dayjs()
runningTimeInfo.value.state = "Im Web gestoppt"
runningTimeInfo.value.end = new Date().toISOString()
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("times") .from("times")
.update(runningTimeInfo.value) .update(runningTimeInfo.value)
.eq('id',runningTimeInfo.value.id) .eq('id',runningTimeInfo.value.id)
.select() .select()
console.log(data)
if(error) { if(error) {
console.log(error) console.log(error)
} else { } else {
toast.add({title: "Zeit erfolgreich gestoppt"}) toast.add({title: "Zeit erfolgreich gestoppt"})
runningTimeInfo.value = {} runningTimeInfo.value = null
dataStore.fetchTimes() setup()
} }
} }
if(times.value.find(time => time.profile == profileStore.activeProfile.id && !time.end)) {
runningTimeInfo.value = times.value.find(time => time.profile == profileStore.activeProfile.id && !time.end)
}
const createTime = async () => { const createTime = async () => {
const {data,error} = await supabase const {data,error} = await supabase
.from("times") .from("times")
@@ -224,13 +219,13 @@ const setState = async (newState) => {
<template #left> <template #left>
<UButton <UButton
@click="startTime" @click="startTime"
:disabled="runningTimeInfo.id " :disabled="runningTimeInfo "
> >
Start Start
</UButton> </UButton>
<UButton <UButton
@click="stopStartedTime" @click="stopStartedTime"
:disabled="!runningTimeInfo.id" :disabled="!runningTimeInfo"
> >
Stop Stop
</UButton> </UButton>
@@ -251,9 +246,9 @@ const setState = async (newState) => {
</USelectMenu> </USelectMenu>
</template> </template>
</UDashboardToolbar> </UDashboardToolbar>
<div v-if="runningTimeInfo.id" class="m-3"> <div v-if="runningTimeInfo" class="m-3">
Start: {{dayjs(runningTimeInfo.start).format("DD.MM.YY HH:mm")}} Start: {{dayjs(runningTimeInfo.startDate).format("DD.MM.YY HH:mm")}}
<UFormGroup <UFormGroup
label="Notizen:" label="Notizen:"
@@ -270,10 +265,10 @@ const setState = async (newState) => {
:options="dataStore.projects" :options="dataStore.projects"
option-attribute="name" option-attribute="name"
value-attribute="id" value-attribute="id"
v-model="runningTimeInfo.projectId" v-model="runningTimeInfo.project"
> >
<template #label> <template #label>
{{ dataStore.projects.find(project => project.id === runningTimeInfo.projectId) ? dataStore.projects.find(project => project.id === runningTimeInfo.projectId).name : "Projekt auswählen" }} {{ dataStore.projects.find(project => project.id === runningTimeInfo.project) ? dataStore.projects.find(project => project.id === runningTimeInfo.project).name : "Projekt auswählen" }}
</template> </template>
</USelectMenu> </USelectMenu>
</UFormGroup> </UFormGroup>
@@ -305,34 +300,32 @@ const setState = async (newState) => {
<UFormGroup <UFormGroup
label="Start:" label="Start:"
> >
<VueDatePicker <UPopover :popper="{ placement: 'bottom-start' }">
v-model="itemInfo.start" <UButton
locale="de" icon="i-heroicons-calendar-days-20-solid"
cancel-text="Abbrechen" :label="itemInfo.startDate ? dayjs(itemInfo.startDate).format('DD.MM.YYYY') : 'Datum auswählen'"
select-text="Auswählen" variant="outline"
now-button-label="Jetzt" />
text-input="MM.dd.yyyy HH:mm"
:dark="useColorMode().value !== 'light'" <template #panel="{ close }">
:format="format" <LazyDatePicker v-model="itemInfo.startDate" @close="close" mode="dateTime" />
:preview-format="format" </template>
:disabled="configTimeMode === 'create' ? false : itemInfo.state !== 'Entwurf'" </UPopover>
/>
</UFormGroup> </UFormGroup>
<UFormGroup <UFormGroup
label="Ende:" label="Ende:"
> >
<VueDatePicker <UPopover :popper="{ placement: 'bottom-start' }">
v-model="itemInfo.end" <UButton
locale="de" icon="i-heroicons-calendar-days-20-solid"
cancel-text="Abbrechen" :label="itemInfo.endDate ? dayjs(itemInfo.endDate).format('DD.MM.YYYY') : 'Datum auswählen'"
select-text="Auswählen" variant="outline"
now-button-label="Jetzt" />
text-input="MM.dd.yyyy HH:mm"
:dark="useColorMode().value !== 'light'" <template #panel="{ close }">
:format="format" <LazyDatePicker v-model="itemInfo.endDate" @close="close" mode="dateTime" />
:preview-format="format" </template>
:disabled="configTimeMode === 'create' ? false : itemInfo.state !== 'Entwurf'" </UPopover>
/>
</UFormGroup> </UFormGroup>
<UFormGroup <UFormGroup
label="Benutzer:" label="Benutzer:"
@@ -342,7 +335,7 @@ const setState = async (newState) => {
v-model="itemInfo.user" v-model="itemInfo.user"
option-attribute="fullName" option-attribute="fullName"
value-attribute="id" value-attribute="id"
:disabled="(configTimeMode === 'create' ? false : itemInfo.state !== 'Entwurf') || (!dataStore.hasRight('createTime') || !dataStore.hasRight('createOwnTime'))" :disabled="(configTimeMode === 'create' ? false : itemInfo.state !== 'Entwurf') || (!dataStore.hasRight('createTime') || !useRole().hasRight('createOwnTime'))"
> >
<template #label> <template #label>
{{profileStore.profiles.find(profile => profile.id === itemInfo.user) ? profileStore.profiles.find(profile => profile.id === itemInfo.user).fullName : "Benutzer auswählen"}} {{profileStore.profiles.find(profile => profile.id === itemInfo.user) ? profileStore.profiles.find(profile => profile.id === itemInfo.user).fullName : "Benutzer auswählen"}}
@@ -354,7 +347,7 @@ const setState = async (newState) => {
> >
<USelectMenu <USelectMenu
:options="dataStore.projects" :options="dataStore.projects"
v-model="itemInfo.projectId" v-model="itemInfo.project"
option-attribute="name" option-attribute="name"
value-attribute="id" value-attribute="id"
searchable searchable
@@ -363,7 +356,7 @@ const setState = async (newState) => {
:disabled="configTimeMode === 'create' ? false : itemInfo.state !== 'Entwurf'" :disabled="configTimeMode === 'create' ? false : itemInfo.state !== 'Entwurf'"
> >
<template #label> <template #label>
{{dataStore.projects.find(project => project.id === itemInfo.projectId) ? dataStore.projects.find(project => project.id === itemInfo.projectId).name : "Projekt auswählen"}} {{dataStore.projects.find(project => project.id === itemInfo.project) ? dataStore.projects.find(project => project.id === itemInfo.project).name : "Projekt auswählen"}}
</template> </template>
</USelectMenu> </USelectMenu>
</UFormGroup> </UFormGroup>
@@ -443,20 +436,17 @@ const setState = async (newState) => {
>{{row.state}}</span> >{{row.state}}</span>
</template> </template>
<template #user-data="{row}"> <template #user-data="{row}">
{{profileStore.profiles.find(profile => profile.id === row.user) ? profileStore.profiles.find(profile => profile.id === row.user).fullName : row.user }} {{row.profile ? row.profile.fullName : "" }}
</template> </template>
<template #start-data="{row}"> <template #startDate-data="{row}">
{{dayjs(row.start).format("DD.MM.YY HH:mm")}} {{dayjs(row.startDate).format("DD.MM.YY HH:mm")}}
</template> </template>
<template #end-data="{row}"> <template #endDate-data="{row}">
{{dayjs(row.end).format("DD.MM.YY HH:mm")}} {{dayjs(row.endDate).format("DD.MM.YY HH:mm")}}
</template> </template>
<template #duration-data="{row}"> <template #project-data="{row}">
{{getDuration(row).composed}} {{row.project ? row.project.name : "" }}
</template>
<template #projectId-data="{row}">
{{dataStore.projects.find(project => project.id === row.projectId) ? dataStore.projects.find(project => project.id === row.projectId).name : ""}}
</template> </template>
</UTable> </UTable>
</template> </template>