Change for Agrar
All checks were successful
Build and Push Docker Images / build-backend (push) Successful in 31s
Build and Push Docker Images / build-frontend (push) Successful in 1m8s

This commit is contained in:
2026-01-27 08:58:44 +01:00
parent 2aed851224
commit 01ef3c5a42
2 changed files with 61 additions and 33 deletions

View File

@@ -1,4 +1,6 @@
<script setup>
import dayjs from 'dayjs'
const props = defineProps({
context: { type: Object, required: true },
token: { type: String, required: true },
@@ -12,8 +14,9 @@ const toast = useToast()
const config = computed(() => props.context.config)
const data = computed(() => props.context.data)
// Initiale Werte setzen (Quantity statt Start/EndDate)
// Initiale Werte setzen
const form = ref({
deliveryDate: dayjs().format('YYYY-MM-DD'), // Standard: Heute
profile: props.context.meta?.defaultProfileId || null,
project: null,
service: config.value?.defaults?.serviceId || null,
@@ -25,11 +28,17 @@ const form = ref({
const isSubmitting = ref(false)
const errors = ref({})
// Validierung basierend auf JSON Config & neuen Anforderungen
const validate = () => {
errors.value = {}
let isValid = true
const validationRules = config.value.validation || {}
if (!form.value.deliveryDate) {
errors.value.deliveryDate = 'Datum erforderlich'
isValid = false
}
if (!form.value.project && data.value.projects?.length > 0) {
errors.value.project = 'Pflichtfeld'
isValid = false
@@ -45,6 +54,13 @@ const validate = () => {
isValid = false
}
// Profil nur validieren, wenn Auswahl nötig und möglich ist
if (!form.value.profile && data.value.profiles?.length > 0 && !props.context.meta.defaultProfileId) {
errors.value.profile = 'Bitte Mitarbeiter wählen'
isValid = false
}
// Feature: Agriculture Diesel
if (config.value.features?.agriculture?.showDieselUsage && validationRules.requireDiesel) {
if (!form.value.dieselUsage || form.value.dieselUsage <= 0) {
errors.value.diesel = 'Dieselverbrauch erforderlich'
@@ -61,6 +77,7 @@ const submit = async () => {
isSubmitting.value = true
try {
const payload = { ...form.value }
const headers = {}
if (props.pin) headers['x-public-pin'] = props.pin
@@ -73,11 +90,18 @@ const submit = async () => {
emit('success')
} catch (e) {
console.error(e)
toast.add({ title: 'Fehler beim Speichern', color: 'red' })
toast.add({ title: 'Fehler beim Speichern', color: 'red', icon: 'i-heroicons-exclamation-triangle' })
} finally {
isSubmitting.value = false
}
}
// Hilfsfunktion für die dynamische Einheiten-Anzeige
const currentUnit = computed(() => {
if (!form.value.service) return data.value?.units?.[0]?.symbol || 'h'
const selectedService = data.value.services?.find(s => s.id === form.value.service)
return selectedService?.unitSymbol || data.value?.units?.[0]?.symbol || 'h'
})
</script>
<template>
@@ -90,6 +114,20 @@ const submit = async () => {
</template>
<div class="space-y-5">
<UFormGroup
label="Datum der Ausführung"
:error="errors.deliveryDate"
required
>
<UInput
v-model="form.deliveryDate"
type="date"
size="lg"
icon="i-heroicons-calendar-days"
/>
</UFormGroup>
<UFormGroup
v-if="!context?.meta?.defaultProfileId && data?.profiles?.length > 0"
label="Mitarbeiter"
@@ -103,12 +141,13 @@ const submit = async () => {
value-attribute="id"
placeholder="Name auswählen..."
searchable
size="lg"
/>
</UFormGroup>
<UFormGroup
v-if="data?.projects?.length > 0"
:label="config.ui?.labels?.project || 'Projekt'"
:label="config.ui?.labels?.project || 'Projekt / Auftrag'"
:error="errors.project"
required
>
@@ -119,12 +158,13 @@ const submit = async () => {
value-attribute="id"
placeholder="Wählen..."
searchable
size="lg"
/>
</UFormGroup>
<UFormGroup
v-if="data?.services?.length > 0"
:label="config?.ui?.labels?.service || 'Leistung'"
:label="config?.ui?.labels?.service || 'Tätigkeit'"
:error="errors.service"
required
>
@@ -135,11 +175,11 @@ const submit = async () => {
value-attribute="id"
placeholder="Wählen..."
searchable
size="lg"
/>
</UFormGroup>
<UFormGroup
v-if="config?.features?.timeTracking?.allowManualTime"
label="Menge / Dauer"
:error="errors.quantity"
required
@@ -152,9 +192,7 @@ const submit = async () => {
placeholder="0.00"
>
<template #trailing>
<span class="text-gray-500 text-sm pr-2">
{{ data?.units?.[0]?.symbol || 'h' }}
</span>
<span class="text-gray-500 text-sm pr-2">{{ currentUnit }}</span>
</template>
</UInput>
</UFormGroup>
@@ -165,16 +203,17 @@ const submit = async () => {
:error="errors.diesel"
:required="config?.validation?.requireDiesel"
>
<UInput v-model="form.dieselUsage" type="number" step="0.1" placeholder="0.0">
<UInput v-model="form.dieselUsage" type="number" step="0.1" placeholder="0.0" size="lg">
<template #trailing>
<span class="text-gray-500 text-xs">Liter</span>
</template>
</UInput>
</UFormGroup>
<UFormGroup :label="config?.ui?.labels?.description || 'Notiz'">
<UTextarea v-model="form.description" :rows="3" />
<UFormGroup :label="config?.ui?.labels?.description || 'Notiz / Vorkommnisse'">
<UTextarea v-model="form.description" :rows="3" placeholder="Optional..." />
</UFormGroup>
</div>
<template #footer>