Restructured Workingtimes without date to start and end
Added Page to Edit Workingtimes
This commit is contained in:
122
spaces/pages/workingtimes/[mode]/[[id]].vue
Normal file
122
spaces/pages/workingtimes/[mode]/[[id]].vue
Normal file
@@ -0,0 +1,122 @@
|
||||
<script setup>
|
||||
import dayjs from "dayjs";
|
||||
|
||||
|
||||
const dataStore = useDataStore()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
const toast = useToast()
|
||||
const id = ref(route.params.id ? route.params.id : null )
|
||||
|
||||
const mode = ref(route.params.mode || "show")
|
||||
const itemInfo = ref({
|
||||
startDate: new Date(),
|
||||
endDate: new Date(),
|
||||
profile: dataStore.activeProfile.id
|
||||
})
|
||||
const oldItemInfo = ref({})
|
||||
|
||||
const setupPage = () => {
|
||||
if(route.params.id && mode.value === 'edit') {
|
||||
itemInfo.value = dataStore.getWorkingTimeById(Number(route.params.id))
|
||||
//setStartEnd()
|
||||
}
|
||||
oldItemInfo.value = itemInfo.value
|
||||
}
|
||||
|
||||
/*const setStartEnd = () => {
|
||||
console.log("test")
|
||||
console.log(String(itemInfo.value.date).split("T")[0])
|
||||
itemInfo.value.date = String(itemInfo.value.date).split("T")[0]
|
||||
itemInfo.value.start = new Date(itemInfo.value.date + "T" + itemInfo.value.start)
|
||||
itemInfo.value.end = new Date(itemInfo.value.date + "T" + itemInfo.value.end)
|
||||
}*/
|
||||
|
||||
setupPage()
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UDashboardNavbar
|
||||
:title="mode === 'show' ? `Anwesenheit: ${itemInfo.profile}` : (itemInfo.id ? 'Anwesenheit bearbeiten' :'Anwesenheit erstellen')"
|
||||
>
|
||||
<template #right>
|
||||
<UButton
|
||||
color="rose"
|
||||
v-if="mode === 'edit'"
|
||||
@click="router.push('/workingtimes')"
|
||||
>
|
||||
Abbrechen
|
||||
</UButton>
|
||||
<UButton
|
||||
v-if="mode === 'edit' && itemInfo.id"
|
||||
@click="dataStore.updateItem('workingtimes',itemInfo)"
|
||||
>
|
||||
Speichern
|
||||
</UButton>
|
||||
<UButton
|
||||
v-else-if="mode === 'edit' && !itemInfo.id"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
</template>
|
||||
</UDashboardNavbar>
|
||||
|
||||
<UForm class="p-5">
|
||||
<UFormGroup
|
||||
label="Mitarbeiter:"
|
||||
>
|
||||
<USelectMenu
|
||||
:options="dataStore.profiles"
|
||||
v-model="itemInfo.profile"
|
||||
option-attribute="fullName"
|
||||
value-attribute="id"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup label="Start:">
|
||||
<UPopover :popper="{ placement: 'bottom-start' }">
|
||||
<UButton
|
||||
icon="i-heroicons-calendar-days-20-solid"
|
||||
:label="itemInfo.startDate ? dayjs(itemInfo.startDate).format('HH:mm') : 'Datum auswählen'"
|
||||
variant="outline"
|
||||
/>
|
||||
|
||||
<template #panel="{ close }">
|
||||
<LazyDatePicker v-model="itemInfo.startDate" @close="itemInfo.endDate = itemInfo.startDate" mode="dateTime"/>
|
||||
</template>
|
||||
</UPopover>
|
||||
</UFormGroup>
|
||||
|
||||
<UFormGroup label="Ende:">
|
||||
<UPopover :popper="{ placement: 'bottom-start' }">
|
||||
<UButton
|
||||
variant="outline"
|
||||
icon="i-heroicons-calendar-days-20-solid"
|
||||
:label="itemInfo.endDate ? dayjs(itemInfo.endDate).format('HH:mm') : 'Datum auswählen'"
|
||||
/>
|
||||
|
||||
<template #panel="{ close }">
|
||||
<LazyDatePicker v-model="itemInfo.endDate" @close="close" mode="time"/>
|
||||
</template>
|
||||
</UPopover>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="Genehmigt:"
|
||||
>
|
||||
<UCheckbox
|
||||
v-model="itemInfo.approved"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UFormGroup
|
||||
label="Notizen:"
|
||||
>
|
||||
<UTextarea
|
||||
v-model="itemInfo.notes"
|
||||
/>
|
||||
</UFormGroup>
|
||||
</UForm>
|
||||
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
328
spaces/pages/workingtimes/index.vue
Normal file
328
spaces/pages/workingtimes/index.vue
Normal file
@@ -0,0 +1,328 @@
|
||||
<script setup>
|
||||
import dayjs from "dayjs";
|
||||
import customParseFormat from "dayjs/plugin/customParseFormat"
|
||||
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
|
||||
|
||||
|
||||
definePageMeta({
|
||||
middleware: "auth"
|
||||
})
|
||||
|
||||
const dataStore = useDataStore()
|
||||
const supabase = useSupabaseClient()
|
||||
const user = useSupabaseUser()
|
||||
const toast = useToast()
|
||||
const router = useRouter()
|
||||
|
||||
|
||||
const timeInfo = ref({
|
||||
profile: "",
|
||||
start: "",
|
||||
end: null,
|
||||
notes: null,
|
||||
})
|
||||
|
||||
const filterUser = ref(dataStore.activeProfile.id || "")
|
||||
|
||||
|
||||
const filteredRows = computed(() => {
|
||||
|
||||
let times = dataStore.workingtimes
|
||||
|
||||
if(dataStore.hasRight('viewTimes')) {
|
||||
if(filterUser.value !== "") {
|
||||
times = times.filter(i => i.profile === filterUser.value)
|
||||
}
|
||||
} else if(dataStore.hasRight('viewOwnTimes')) {
|
||||
times = times.filter(i => i.profile === dataStore.getOwnProfile.id)
|
||||
} else {
|
||||
times = []
|
||||
}
|
||||
|
||||
return times
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
||||
const itemInfo = ref({
|
||||
profile: "",
|
||||
start: new Date(),
|
||||
end: "",
|
||||
notes: null,
|
||||
})
|
||||
|
||||
|
||||
const columns = [
|
||||
{
|
||||
key:"state",
|
||||
label: "Status",
|
||||
sortable:true
|
||||
},
|
||||
{
|
||||
key: "profile",
|
||||
label: "Mitarbeiter",
|
||||
sortable:true
|
||||
},
|
||||
{
|
||||
key: "date",
|
||||
label: "Datum",
|
||||
sortable:true
|
||||
},
|
||||
{
|
||||
key:"start",
|
||||
label:"Start",
|
||||
sortable:true
|
||||
},
|
||||
{
|
||||
key: "end",
|
||||
label: "Ende",
|
||||
sortable:true
|
||||
},
|
||||
{
|
||||
key: "duration",
|
||||
label: "Dauer",
|
||||
sortable:true
|
||||
},
|
||||
{
|
||||
key: "notes",
|
||||
label: "Notizen",
|
||||
sortable:true
|
||||
}
|
||||
]
|
||||
|
||||
const runningTimeInfo = ref({})
|
||||
const configTimeMode = ref("create")
|
||||
|
||||
|
||||
|
||||
const startTime = async () => {
|
||||
console.log("started")
|
||||
timeInfo.value = {
|
||||
profile: dataStore.activeProfile.id,
|
||||
start: dayjs().format("HH:mm:ss"),
|
||||
date: dayjs().format("YYYY-MM-DD"),
|
||||
tenant: dataStore.currentTenant,
|
||||
state: "Im Web gestartet"
|
||||
}
|
||||
|
||||
const {data,error} = await supabase
|
||||
.from("workingtimes")
|
||||
.insert([timeInfo.value])
|
||||
.select()
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else if(data) {
|
||||
//timeInfo.value = data[0]
|
||||
await dataStore.fetchWorkingTimes()
|
||||
runningTimeInfo.value = dataStore.times.find(time => time.profile === dataStore.activeProfile.id && !time.end)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
const stopStartedTime = async () => {
|
||||
//console.log(runningTimeInfo.value)
|
||||
|
||||
runningTimeInfo.value.end = dayjs().format("HH:mm:ssZ")
|
||||
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
|
||||
.from("workingtimes")
|
||||
.update(runningTimeInfo.value)
|
||||
.eq('id',runningTimeInfo.value.id)
|
||||
.select()
|
||||
console.log(data)
|
||||
|
||||
if(error) {
|
||||
console.log(error)
|
||||
} else {
|
||||
toast.add({title: "Zeit erfolgreich gestoppt"})
|
||||
runningTimeInfo.value = {}
|
||||
dataStore.fetchWorkingTimes()
|
||||
}
|
||||
}
|
||||
|
||||
if(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 minutes = Math.floor(dayjs(time.endDate).diff(dayjs(time.startDate),'minutes',true))
|
||||
const hours = Math.floor(minutes/60)
|
||||
return {
|
||||
//dezimal: dez,
|
||||
hours: hours,
|
||||
minutes: minutes,
|
||||
composed: `${hours}:${String(minutes % 60).padStart(2,"0")} h`
|
||||
}
|
||||
}
|
||||
|
||||
const setState = async (newState) => {
|
||||
itemInfo.value.state = newState
|
||||
await updateTime()
|
||||
}
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<UDashboardNavbar title="Zeiterfassung">
|
||||
|
||||
</UDashboardNavbar>
|
||||
<UDashboardToolbar>
|
||||
<template #left>
|
||||
<UButton
|
||||
@click="startTime"
|
||||
:disabled="runningTimeInfo.id "
|
||||
>
|
||||
Start
|
||||
</UButton>
|
||||
<UButton
|
||||
@click="router.push(`/workingtimes/edit`)"
|
||||
>
|
||||
Erstellen
|
||||
</UButton>
|
||||
<USelectMenu
|
||||
v-if="dataStore.hasRight('viewTimes')"
|
||||
:options="dataStore.profiles"
|
||||
option-attribute="fullName"
|
||||
value-attribute="id"
|
||||
v-model="filterUser"
|
||||
>
|
||||
<template #label>
|
||||
{{dataStore.getProfileById(filterUser) ? dataStore.getProfileById(filterUser).fullName : "Kein Benutzer ausgewählt"}}
|
||||
</template>
|
||||
</USelectMenu>
|
||||
</template>
|
||||
</UDashboardToolbar>
|
||||
<div class="mx-3">
|
||||
<UAlert
|
||||
v-if="runningTimeInfo.id"
|
||||
class="my-3"
|
||||
title="Laufende Zeit:"
|
||||
>
|
||||
<template #description>
|
||||
<p>Start: {{dayjs(runningTimeInfo.start, "HH:mm:ss").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>
|
||||
|
||||
<UFormGroup
|
||||
class="mt-2"
|
||||
label="Notizen:"
|
||||
>
|
||||
<UTextarea
|
||||
v-model="runningTimeInfo.notes"
|
||||
/>
|
||||
</UFormGroup>
|
||||
<UButton
|
||||
class="mt-3"
|
||||
@click="stopStartedTime"
|
||||
:disabled="!runningTimeInfo.id"
|
||||
>
|
||||
Stop
|
||||
</UButton>
|
||||
</template>
|
||||
</UAlert>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
<UTable
|
||||
class="mt-3"
|
||||
:columns="columns"
|
||||
:rows="filteredRows"
|
||||
:empty-state="{ icon: 'i-heroicons-circle-stack-20-solid', label: 'Noch keine Einträge' }"
|
||||
@select="(row) => {
|
||||
router.push(`/workingtimes/edit/${row.id}`)
|
||||
/*configTimeMode = 'edit';
|
||||
itemInfo = row;
|
||||
showConfigTimeModal = true*/}"
|
||||
>
|
||||
<!-- <template #state-data="{row}">
|
||||
<span
|
||||
v-if="row.state === 'Entwurf'"
|
||||
class="text-rose-500"
|
||||
>{{row.state}}</span>
|
||||
<span
|
||||
v-if="row.state === 'Eingereicht'"
|
||||
class="text-cyan-500"
|
||||
>{{row.state}}</span>
|
||||
<span
|
||||
v-if="row.state === 'Bestätigt'"
|
||||
class="text-primary-500"
|
||||
>{{row.state}}</span>
|
||||
</template>-->
|
||||
<template #profile-data="{row}">
|
||||
{{dataStore.profiles.find(profile => profile.id === row.profile) ? dataStore.profiles.find(profile => profile.id === row.profile).fullName : row.profile }}
|
||||
</template>
|
||||
<template #date-data="{row}">
|
||||
{{dayjs(row.startDate).format("DD.MM.YYYY")}}
|
||||
</template>
|
||||
|
||||
<template #start-data="{row}">
|
||||
{{dayjs(row.startDate).format("HH:mm")}} Uhr
|
||||
</template>
|
||||
<template #end-data="{row}">
|
||||
{{row.endDate ? dayjs(row.endDate).format("HH:mm") + " Uhr" : ""}}
|
||||
</template>
|
||||
<template #duration-data="{row}">
|
||||
{{row.endDate ? getDuration(row).composed : ""}}
|
||||
</template>
|
||||
</UTable>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
Reference in New Issue
Block a user