feat : calcul de l'âge en mois côté back + colonne Age et alertes visuelles

- Champ ageMonths (int) ajouté à Bovine avec migration
- Lifecycle PrePersist/PreUpdate pour maintenir la cohérence
- Sync processor recalcule explicitement ageMonths à chaque passage (cron-friendly)
- Colonne Age + rowClass côté front : rouge >= 24 mois, orange 22-24 mois
- Util formatAgeLabel remplace le calcul client
- Boutons pagination Prev/Next en français avec style bouton bordure primary
- Colonnes Sexe/N° Travail réduites au profit de Bâtiment

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-24 09:50:39 +02:00
parent 9d3cfd10db
commit c0c6c81e74
7 changed files with 104 additions and 9 deletions

View File

@@ -30,6 +30,7 @@
:items="items"
:total-items="totalItems"
:loading="loading"
:row-class="rowClass"
>
<template #header-nationalNumber>
<UiTextInput
@@ -72,9 +73,15 @@
<template #header-buildingCase.caseNumber>
<UiTextInput :model-value="''" placeholder="Case" size="compact" disabled />
</template>
<template #header-age>
<UiTextInput :model-value="''" placeholder="Age" size="compact" disabled />
</template>
<template #cell-birthDate="{ item }">
{{ formatDate(item.birthDate) }}
</template>
<template #cell-age="{ item }">
{{ formatAgeLabel(item.ageMonths) }}
</template>
<template #cell-arrivalDate="{ item }">
{{ formatDate(item.arrivalDate) }}
</template>
@@ -94,6 +101,7 @@
import type { BovineData } from '~/services/dto/bovine-data'
import { useAuthStore } from '~/stores/auth'
import { useDataTableServerState } from '~/composables/useDataTableServerState'
import { formatAgeLabel } from '~/utils/bovine-age'
const router = useRouter()
const auth = useAuthStore()
@@ -177,11 +185,12 @@ const birthDateFilter = singleDateFilter('birthDate[after]', 'birthDate[strictly
const columns = [
{ key: 'nationalNumber', label: 'N° National', width: '160px' },
{ key: 'workNumber', label: 'N° Travail', width: '110px' },
{ key: 'sex', label: 'Sexe', width: '90px' },
{ key: 'workNumber', label: 'N° Travail', width: '85px' },
{ key: 'sex', label: 'Sexe', width: '70px' },
{ key: 'birthDate', label: 'Né le', width: '120px' },
{ key: 'age', label: 'Age', width: '110px' },
{ key: 'breedCode', label: 'Race' },
{ key: 'buildingCase.building.label', label: 'Bâtiment' },
{ key: 'buildingCase.building.label', label: 'Bâtiment', width: '1.5fr' },
{ key: 'buildingCase.caseNumber', label: 'Case', width: '80px' },
{ key: 'arrivalDate', label: 'Entrée le', width: '120px' }
]
@@ -197,5 +206,12 @@ const formatDate = (date: string | null) => {
})
}
const rowClass = (item: BovineData): string => {
if (item.ageMonths === null || item.ageMonths === undefined) return ''
if (item.ageMonths >= 24) return 'bg-red-100 hover:bg-red-200'
if (item.ageMonths >= 22) return 'bg-orange-100 hover:bg-orange-200'
return ''
}
onMounted(reload)
</script>