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:
@@ -19,7 +19,10 @@
|
||||
v-for="(item, index) in paginatedItems"
|
||||
:key="item.id ?? index"
|
||||
class="grid gap-6 px-4 py-3 text-sm border-t border-slate-200"
|
||||
:class="rowClickable ? 'hover:bg-slate-50 cursor-pointer' : ''"
|
||||
:class="[
|
||||
rowClickable ? 'hover:bg-slate-50 cursor-pointer' : '',
|
||||
rowClass ? rowClass(item) : ''
|
||||
]"
|
||||
:style="{ gridTemplateColumns: gridCols }"
|
||||
:role="rowClickable ? 'button' : undefined"
|
||||
:tabindex="rowClickable ? 0 : undefined"
|
||||
@@ -83,12 +86,12 @@
|
||||
<nav aria-label="Pagination" class="flex items-center gap-1">
|
||||
<button
|
||||
type="button"
|
||||
class="h-10 px-3 text-sm text-primary-500 hover:underline disabled:cursor-not-allowed disabled:text-slate-400 disabled:no-underline"
|
||||
class="h-10 rounded border border-primary-500 bg-white px-3 text-sm text-primary-500 hover:bg-primary-500 hover:text-white disabled:cursor-not-allowed disabled:border-slate-300 disabled:text-slate-400 disabled:hover:bg-white disabled:hover:text-slate-400"
|
||||
:disabled="currentPage <= 1"
|
||||
aria-label="Page précédente"
|
||||
@click="goToPage(currentPage - 1)"
|
||||
>
|
||||
Prev
|
||||
Précédent
|
||||
</button>
|
||||
|
||||
<template v-for="(entry, i) in visiblePages" :key="`${typeof entry}-${entry}-${i}`">
|
||||
@@ -113,12 +116,12 @@
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="h-10 px-3 text-sm text-primary-500 hover:underline disabled:cursor-not-allowed disabled:text-slate-400 disabled:no-underline"
|
||||
class="h-10 rounded border border-primary-500 bg-white px-3 text-sm text-primary-500 hover:bg-primary-500 hover:text-white disabled:cursor-not-allowed disabled:border-slate-300 disabled:text-slate-400 disabled:hover:bg-white disabled:hover:text-slate-400"
|
||||
:disabled="currentPage >= totalPages"
|
||||
aria-label="Page suivante"
|
||||
@click="goToPage(currentPage + 1)"
|
||||
>
|
||||
Next
|
||||
Suivant
|
||||
</button>
|
||||
</nav>
|
||||
</div>
|
||||
@@ -145,6 +148,7 @@ const props = withDefaults(defineProps<{
|
||||
showActions?: boolean
|
||||
emptyMessage?: string
|
||||
loading?: boolean
|
||||
rowClass?: (item: T) => string | undefined
|
||||
}>(), {
|
||||
totalItems: undefined,
|
||||
page: 1,
|
||||
@@ -153,7 +157,8 @@ const props = withDefaults(defineProps<{
|
||||
rowClickable: false,
|
||||
showActions: false,
|
||||
emptyMessage: 'Aucune donnée',
|
||||
loading: false
|
||||
loading: false,
|
||||
rowClass: undefined
|
||||
})
|
||||
|
||||
const emit = defineEmits<{
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -15,6 +15,7 @@ export interface BovineData {
|
||||
birthDate: string | null
|
||||
breedCode: string | null
|
||||
sex: string | null
|
||||
ageMonths: number | null
|
||||
exitedAt: string | null
|
||||
}
|
||||
|
||||
|
||||
10
frontend/utils/bovine-age.ts
Normal file
10
frontend/utils/bovine-age.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
export const formatAgeLabel = (months: number | null | undefined): string => {
|
||||
if (months === null || months === undefined) return '—'
|
||||
const years = Math.floor(months / 12)
|
||||
const remaining = months % 12
|
||||
let label = ''
|
||||
if (years > 0) label = `${years} an${years > 1 ? 's' : ''}`
|
||||
if (remaining > 0) label += `${label ? ' ' : ''}${remaining} mois`
|
||||
if (!label) label = '< 1 mois'
|
||||
return label
|
||||
}
|
||||
31
migrations/Version20260424074454.php
Normal file
31
migrations/Version20260424074454.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace DoctrineMigrations;
|
||||
|
||||
use Doctrine\DBAL\Schema\Schema;
|
||||
use Doctrine\Migrations\AbstractMigration;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your needs!
|
||||
*/
|
||||
final class Version20260424074454 extends AbstractMigration
|
||||
{
|
||||
public function getDescription(): string
|
||||
{
|
||||
return '';
|
||||
}
|
||||
|
||||
public function up(Schema $schema): void
|
||||
{
|
||||
// this up() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE bovine ADD age_months INT DEFAULT NULL');
|
||||
}
|
||||
|
||||
public function down(Schema $schema): void
|
||||
{
|
||||
// this down() migration is auto-generated, please modify it to your needs
|
||||
$this->addSql('ALTER TABLE bovine DROP age_months');
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
||||
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
|
||||
|
||||
#[ORM\Entity]
|
||||
#[ORM\HasLifecycleCallbacks]
|
||||
#[ORM\Table(name: 'bovine')]
|
||||
#[ORM\UniqueConstraint(name: 'uniq_bovine_national_number', columns: ['national_number'])]
|
||||
#[ApiFilter(SearchFilter::class, properties: [
|
||||
@@ -106,6 +107,10 @@ class Bovine
|
||||
#[Groups(['bovine:read', 'building_case:read'])]
|
||||
private ?string $sex = null;
|
||||
|
||||
#[ORM\Column(type: 'integer', nullable: true)]
|
||||
#[Groups(['bovine:read', 'building_case:read'])]
|
||||
private ?int $ageMonths = null;
|
||||
|
||||
#[ORM\Column(type: 'date_immutable', nullable: true)]
|
||||
#[Groups(['bovine:read', 'building_case:read'])]
|
||||
#[Context([DateTimeNormalizer::FORMAT_KEY => 'Y-m-d'])]
|
||||
@@ -252,4 +257,30 @@ class Bovine
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getAgeMonths(): ?int
|
||||
{
|
||||
return $this->ageMonths;
|
||||
}
|
||||
|
||||
public function setAgeMonths(?int $ageMonths): static
|
||||
{
|
||||
$this->ageMonths = $ageMonths;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
#[ORM\PrePersist]
|
||||
#[ORM\PreUpdate]
|
||||
public function refreshAgeMonths(): void
|
||||
{
|
||||
if (null === $this->birthDate) {
|
||||
$this->ageMonths = null;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$diff = $this->birthDate->diff(new DateTimeImmutable());
|
||||
$this->ageMonths = ($diff->y * 12) + $diff->m;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,5 +100,6 @@ final class BovineSyncInventoryProcessor implements ProcessorInterface
|
||||
}
|
||||
$bovine->setArrivalDate($latestEntry);
|
||||
$bovine->setExitDate($latestExit);
|
||||
$bovine->refreshAgeMonths();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user