Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a36e9ef176 | ||
|
|
5d36b0f4c1 | ||
|
|
ad48ab28cc | ||
|
|
342686f4e0 | ||
|
|
d42927297d | ||
|
|
1d3ec0b759 | ||
|
|
608e62d662 | ||
|
|
dc491470db | ||
|
|
5a73da898b | ||
|
|
0c736f5605 | ||
|
|
6c8ef32a11 | ||
|
|
f3b2da4b4d | ||
|
|
edab253296 | ||
|
|
d61e34a1e6 | ||
|
|
484fb9a3e5 |
@@ -5,6 +5,7 @@ import {
|
|||||||
JoinColumn,
|
JoinColumn,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
PrimaryGeneratedColumn,
|
PrimaryGeneratedColumn,
|
||||||
|
RelationId,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { CardInstance } from './card_instances.entity';
|
import { CardInstance } from './card_instances.entity';
|
||||||
import { Users } from './users.entity';
|
import { Users } from './users.entity';
|
||||||
@@ -20,20 +21,21 @@ export class CardResponse {
|
|||||||
@PrimaryGeneratedColumn('uuid')
|
@PrimaryGeneratedColumn('uuid')
|
||||||
id: string;
|
id: string;
|
||||||
|
|
||||||
@Column({ name: 'id_card', type: 'uuid' })
|
/** FK carte — une seule source de vérité via @JoinColumn (pas de @Column doublon). */
|
||||||
id_card: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => CardInstance, (c) => c.responses, { onDelete: 'CASCADE' })
|
@ManyToOne(() => CardInstance, (c) => c.responses, { onDelete: 'CASCADE' })
|
||||||
@JoinColumn({ name: 'id_card', referencedColumnName: 'id' })
|
@JoinColumn({ name: 'id_card', referencedColumnName: 'id' })
|
||||||
card: CardInstance;
|
card: CardInstance;
|
||||||
|
|
||||||
@Column({ name: 'id_utilisateur', type: 'uuid' })
|
@RelationId((r: CardResponse) => r.card)
|
||||||
id_utilisateur: string;
|
id_card: string;
|
||||||
|
|
||||||
@ManyToOne(() => Users, { onDelete: 'CASCADE' })
|
@ManyToOne(() => Users, { onDelete: 'CASCADE' })
|
||||||
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
@JoinColumn({ name: 'id_utilisateur', referencedColumnName: 'id' })
|
||||||
user: Users;
|
user: Users;
|
||||||
|
|
||||||
|
@RelationId((r: CardResponse) => r.user)
|
||||||
|
id_utilisateur: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: 'enum',
|
type: 'enum',
|
||||||
enum: CardResponseActionType,
|
enum: CardResponseActionType,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ describe('CardsService (#194)', () => {
|
|||||||
const cardsRepo = {
|
const cardsRepo = {
|
||||||
create: jest.fn((x) => x),
|
create: jest.fn((x) => x),
|
||||||
save: jest.fn(async (x) => ({ ...x, id: x.id ?? 'card-1', cree_le: new Date(), modifie_le: new Date() })),
|
save: jest.fn(async (x) => ({ ...x, id: x.id ?? 'card-1', cree_le: new Date(), modifie_le: new Date() })),
|
||||||
|
update: jest.fn(async () => ({ affected: 1 })),
|
||||||
findOne: jest.fn(),
|
findOne: jest.fn(),
|
||||||
delete: jest.fn(),
|
delete: jest.fn(),
|
||||||
createQueryBuilder: jest.fn(),
|
createQueryBuilder: jest.fn(),
|
||||||
@@ -37,7 +38,8 @@ describe('CardsService (#194)', () => {
|
|||||||
};
|
};
|
||||||
const responsesRepo = {
|
const responsesRepo = {
|
||||||
create: jest.fn((x) => x),
|
create: jest.fn((x) => x),
|
||||||
save: jest.fn(),
|
save: jest.fn(async (x) => x),
|
||||||
|
insert: jest.fn(),
|
||||||
};
|
};
|
||||||
const amChildrenRepo = { findOne: jest.fn() };
|
const amChildrenRepo = { findOne: jest.fn() };
|
||||||
const parentsChildrenRepo = { find: jest.fn(), findOne: jest.fn() };
|
const parentsChildrenRepo = { find: jest.fn(), findOne: jest.fn() };
|
||||||
@@ -110,7 +112,6 @@ describe('CardsService (#194)', () => {
|
|||||||
modifie_le: new Date(),
|
modifie_le: new Date(),
|
||||||
type: {
|
type: {
|
||||||
titre: 'Congé AM',
|
titre: 'Congé AM',
|
||||||
couleur: 'lavender',
|
|
||||||
response_mode: CardResponseModeType.ACCEPT_REFUSE,
|
response_mode: CardResponseModeType.ACCEPT_REFUSE,
|
||||||
retention_days: 14,
|
retention_days: 14,
|
||||||
},
|
},
|
||||||
@@ -156,4 +157,128 @@ describe('CardsService (#194)', () => {
|
|||||||
}),
|
}),
|
||||||
).rejects.toBeInstanceOf(ForbiddenException);
|
).rejects.toBeInstanceOf(ForbiddenException);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('parent crée absence_enfant → audience AM + co-parent', async () => {
|
||||||
|
typesRepo.findOne.mockResolvedValue({
|
||||||
|
code: 'absence_enfant',
|
||||||
|
system: true,
|
||||||
|
titre: 'Absence enfant',
|
||||||
|
emitter_roles: [RoleType.PARENT],
|
||||||
|
recipient_roles: [RoleType.ASSISTANTE_MATERNELLE],
|
||||||
|
audience_resolver: 'couple_am',
|
||||||
|
response_mode: CardResponseModeType.NONE,
|
||||||
|
retention_days: 7,
|
||||||
|
});
|
||||||
|
amChildrenRepo.findOne.mockResolvedValue({
|
||||||
|
id: 'pl-1',
|
||||||
|
amId: 'am-1',
|
||||||
|
enfantId: 'e-1',
|
||||||
|
date_fin: null,
|
||||||
|
});
|
||||||
|
parentsChildrenRepo.findOne.mockResolvedValue({
|
||||||
|
parentId: 'p-1',
|
||||||
|
enfantId: 'e-1',
|
||||||
|
});
|
||||||
|
parentsChildrenRepo.find.mockResolvedValue([
|
||||||
|
{ parentId: 'p-1', enfantId: 'e-1' },
|
||||||
|
{ parentId: 'p-2', enfantId: 'e-1' },
|
||||||
|
]);
|
||||||
|
evenementsService.creer.mockResolvedValue({
|
||||||
|
id: 'abs-1',
|
||||||
|
type: TypeEvenementAgendaType.ABSENCE_ENFANT,
|
||||||
|
statut: StatutEvenementAgendaType.ACCEPTE,
|
||||||
|
});
|
||||||
|
cardsRepo.findOne.mockResolvedValue({
|
||||||
|
id: 'card-abs',
|
||||||
|
type_code: 'absence_enfant',
|
||||||
|
id_placement: 'pl-1',
|
||||||
|
id_evenement: 'abs-1',
|
||||||
|
cree_par: 'p-1',
|
||||||
|
operation: CardOperationType.CREATE,
|
||||||
|
statut: CardInstanceStatutType.OUVERTE,
|
||||||
|
payload: { date_debut: '2026-10-28', date_fin: '2026-10-29' },
|
||||||
|
purge_at: new Date(),
|
||||||
|
cree_le: new Date(),
|
||||||
|
modifie_le: new Date(),
|
||||||
|
type: {
|
||||||
|
titre: 'Absence enfant',
|
||||||
|
response_mode: CardResponseModeType.NONE,
|
||||||
|
retention_days: 7,
|
||||||
|
},
|
||||||
|
responses: [],
|
||||||
|
audience: [
|
||||||
|
{ id_utilisateur: 'p-1' },
|
||||||
|
{ id_utilisateur: 'am-1' },
|
||||||
|
{ id_utilisateur: 'p-2' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
|
||||||
|
await service.creer('p-1', RoleType.PARENT, {
|
||||||
|
type_code: 'absence_enfant',
|
||||||
|
id_placement: 'pl-1',
|
||||||
|
date_debut: '2026-10-28',
|
||||||
|
date_fin: '2026-10-29',
|
||||||
|
});
|
||||||
|
|
||||||
|
const saved = audienceRepo.save.mock.calls[0][0] as Array<{
|
||||||
|
id_utilisateur: string;
|
||||||
|
is_creator: boolean;
|
||||||
|
}>;
|
||||||
|
const ids = saved.map((m) => m.id_utilisateur).sort();
|
||||||
|
expect(ids).toEqual(['am-1', 'p-1', 'p-2']);
|
||||||
|
expect(saved.find((m) => m.id_utilisateur === 'p-2')?.is_creator).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('parent accepte conge_am → response via relation + carte traitee', async () => {
|
||||||
|
cardsRepo.findOne.mockResolvedValue({
|
||||||
|
id: 'card-1',
|
||||||
|
type_code: 'conge_am',
|
||||||
|
id_placement: 'pl-1',
|
||||||
|
id_evenement: 'ev-1',
|
||||||
|
cree_par: 'am-1',
|
||||||
|
operation: CardOperationType.CREATE,
|
||||||
|
statut: CardInstanceStatutType.OUVERTE,
|
||||||
|
payload: { date_debut: '2026-10-27', date_fin: '2026-10-31' },
|
||||||
|
purge_at: new Date(),
|
||||||
|
cree_le: new Date(),
|
||||||
|
modifie_le: new Date(),
|
||||||
|
type: {
|
||||||
|
titre: 'Congé AM',
|
||||||
|
response_mode: CardResponseModeType.ACCEPT_REFUSE,
|
||||||
|
retention_days: 14,
|
||||||
|
},
|
||||||
|
responses: [],
|
||||||
|
audience: [
|
||||||
|
{ id_utilisateur: 'am-1' },
|
||||||
|
{ id_utilisateur: 'p-1' },
|
||||||
|
{ id_utilisateur: 'p-2' },
|
||||||
|
],
|
||||||
|
});
|
||||||
|
audienceRepo.findOne.mockResolvedValue({ id_card: 'card-1', id_utilisateur: 'p-1' });
|
||||||
|
evenementsService.maj.mockResolvedValue({});
|
||||||
|
|
||||||
|
const res = await service.repondre('p-1', RoleType.PARENT, 'card-1', {
|
||||||
|
action: 'accept' as never,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(responsesRepo.create).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
card: { id: 'card-1' },
|
||||||
|
user: { id: 'p-1' },
|
||||||
|
action: 'accept',
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(responsesRepo.save).toHaveBeenCalled();
|
||||||
|
expect(evenementsService.maj).toHaveBeenCalledWith(
|
||||||
|
'p-1',
|
||||||
|
RoleType.PARENT,
|
||||||
|
'ev-1',
|
||||||
|
expect.objectContaining({ statut: StatutEvenementAgendaType.ACCEPTE }),
|
||||||
|
);
|
||||||
|
expect(cardsRepo.update).toHaveBeenCalledWith(
|
||||||
|
{ id: 'card-1' },
|
||||||
|
expect.objectContaining({ statut: CardInstanceStatutType.TRAITEE }),
|
||||||
|
);
|
||||||
|
expect(res.statut).toBe(CardInstanceStatutType.TRAITEE);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -227,12 +227,14 @@ export class CardsService {
|
|||||||
throw new BadRequestException('Motivation obligatoire en cas de refus');
|
throw new BadRequestException('Motivation obligatoire en cas de refus');
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.responsesRepo.insert({
|
await this.responsesRepo.save(
|
||||||
id_card: card.id,
|
this.responsesRepo.create({
|
||||||
id_utilisateur: userId,
|
card: { id: card.id },
|
||||||
action: dto.action,
|
user: { id: userId },
|
||||||
comment: dto.comment?.trim() || undefined,
|
action: dto.action,
|
||||||
});
|
comment: dto.comment?.trim() || undefined,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
if (card.id_evenement) {
|
if (card.id_evenement) {
|
||||||
if (dto.action === CardResponseActionType.ACCEPT || dto.action === CardResponseActionType.ACK) {
|
if (dto.action === CardResponseActionType.ACCEPT || dto.action === CardResponseActionType.ACK) {
|
||||||
@@ -252,7 +254,12 @@ export class CardsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
card.purge_at = this.purgeAt(card.type.retention_days, card.statut);
|
card.purge_at = this.purgeAt(card.type.retention_days, card.statut);
|
||||||
await this.cardsRepo.save(card);
|
// Ne pas cardsRepo.save(card) avec relations chargées : TypeORM peut
|
||||||
|
// resynchroniser les FK enfants (UPDATE … SET id_card=null).
|
||||||
|
await this.cardsRepo.update(
|
||||||
|
{ id: card.id },
|
||||||
|
{ statut: card.statut, purge_at: card.purge_at },
|
||||||
|
);
|
||||||
const full = await this.loadCard(cardId);
|
const full = await this.loadCard(cardId);
|
||||||
const dtoOut = this.toDto(full, userId);
|
const dtoOut = this.toDto(full, userId);
|
||||||
this.emitAudience(full, 'response.added', {
|
this.emitAudience(full, 'response.added', {
|
||||||
@@ -304,7 +311,12 @@ export class CardsService {
|
|||||||
};
|
};
|
||||||
card.statut = CardInstanceStatutType.OUVERTE;
|
card.statut = CardInstanceStatutType.OUVERTE;
|
||||||
card.purge_at = this.purgeAt(card.type.retention_days, card.statut);
|
card.purge_at = this.purgeAt(card.type.retention_days, card.statut);
|
||||||
await this.cardsRepo.save(card);
|
await this.cardsRepo.manager.query(
|
||||||
|
`UPDATE card_instances
|
||||||
|
SET statut = $1, purge_at = $2, payload = $3::jsonb, modifie_le = now()
|
||||||
|
WHERE id = $4`,
|
||||||
|
[card.statut, card.purge_at, JSON.stringify(card.payload), card.id],
|
||||||
|
);
|
||||||
const full = await this.loadCard(cardId);
|
const full = await this.loadCard(cardId);
|
||||||
const dtoOut = this.toDto(full, userId);
|
const dtoOut = this.toDto(full, userId);
|
||||||
this.emitAudience(full, 'card.updated', dtoOut);
|
this.emitAudience(full, 'card.updated', dtoOut);
|
||||||
@@ -395,12 +407,25 @@ export class CardsService {
|
|||||||
];
|
];
|
||||||
|
|
||||||
if (type.audience_resolver === 'couple_am') {
|
if (type.audience_resolver === 'couple_am') {
|
||||||
|
// Destinataire métier = AM + miroir foyer : tous les co-parents de l’enfant
|
||||||
members.push({
|
members.push({
|
||||||
id_card: card.id,
|
id_card: card.id,
|
||||||
id_utilisateur: placement.amId,
|
id_utilisateur: placement.amId,
|
||||||
role_snapshot: RoleType.ASSISTANTE_MATERNELLE,
|
role_snapshot: RoleType.ASSISTANTE_MATERNELLE,
|
||||||
is_creator: false,
|
is_creator: false,
|
||||||
});
|
});
|
||||||
|
const liensAm = await this.parentsChildrenRepo.find({
|
||||||
|
where: { enfantId: placement.enfantId },
|
||||||
|
});
|
||||||
|
for (const l of liensAm) {
|
||||||
|
if (l.parentId === creatorId) continue;
|
||||||
|
members.push({
|
||||||
|
id_card: card.id,
|
||||||
|
id_utilisateur: l.parentId,
|
||||||
|
role_snapshot: RoleType.PARENT,
|
||||||
|
is_creator: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
} else if (type.audience_resolver === 'couple_parents') {
|
} else if (type.audience_resolver === 'couple_parents') {
|
||||||
const liens = await this.parentsChildrenRepo.find({
|
const liens = await this.parentsChildrenRepo.find({
|
||||||
where: { enfantId: placement.enfantId },
|
where: { enfantId: placement.enfantId },
|
||||||
|
|||||||
@@ -587,6 +587,12 @@ POST /repos/jmartin/petitspas/pulls/{index}/merge
|
|||||||
|
|
||||||
**Flux V1** : BDD agenda → API liste/CRUD → module Cartes SYSTEM → front bulles (séparé).
|
**Flux V1** : BDD agenda → API liste/CRUD → module Cartes SYSTEM → front bulles (séparé).
|
||||||
|
|
||||||
|
**V1 cartes (réponses)** :
|
||||||
|
- `absence_enfant` → info (`none`) — pas d’ack AM ; audience **AM + tous les parents du foyer** (co-parent inclus)
|
||||||
|
- `arret_maladie_am` → ack parent (« Bien reçu »)
|
||||||
|
- `conge_am` → accept / refuse (+ motivation refus)
|
||||||
|
- **Modifs d’absence** → via **agenda / calendrier**, pas via bulle `absence_enfant_modif` (reporté au ticket calendrier)
|
||||||
|
|
||||||
**Réf. détail** : `docs/32_MINI-SPEC-BULLES-CARTES.md`
|
**Réf. détail** : `docs/32_MINI-SPEC-BULLES-CARTES.md`
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|||||||
@@ -41,9 +41,11 @@ Endpoint principal : `GET /api/v1/cards` (filtre couple / placement).
|
|||||||
| `payload.date_debut` / `date_fin` | Période (agenda) |
|
| `payload.date_debut` / `date_fin` | Période (agenda) |
|
||||||
| `payload.motif` | Texte libre / détail |
|
| `payload.motif` | Texte libre / détail |
|
||||||
| `last_refuse_comment` | Si `refusee` |
|
| `last_refuse_comment` | Si `refusee` |
|
||||||
| `id_absence` | Lien métier agenda (si applicable) |
|
| `id_evenement` | Lien métier agenda (`evenements_agenda`, si applicable) — ex-`id_absence` (#205) |
|
||||||
| `purge_at` | Péremption de la bulle dans la file |
|
| `purge_at` | Péremption de la bulle dans la file |
|
||||||
|
|
||||||
|
> **Front** : parser `id_evenement` (fallback éventuel `id_absence` uniquement pour anciennes fixtures / caches). Ne plus documenter ni dépendre de `id_absence` comme contrat.
|
||||||
|
|
||||||
**Pas de champ `couleur` dans l’API.**
|
**Pas de champ `couleur` dans l’API.**
|
||||||
La teinte pastel est **100 % front** : table de mapping `type_code` → asset (`card_*_h.png`). Le back ne gère pas la charte graphique.
|
La teinte pastel est **100 % front** : table de mapping `type_code` → asset (`card_*_h.png`). Le back ne gère pas la charte graphique.
|
||||||
|
|
||||||
@@ -61,7 +63,7 @@ La teinte pastel est **100 % front** : table de mapping `type_code` → asset (`
|
|||||||
- Libellés UI :
|
- Libellés UI :
|
||||||
- `conge_am` → « Demande de congés »
|
- `conge_am` → « Demande de congés »
|
||||||
- `arret_maladie_am` → « Arrêt maladie »
|
- `arret_maladie_am` → « Arrêt maladie »
|
||||||
- `absence_enfant` (+ `_modif`) → « Notification d’absence »
|
- `absence_enfant` → « Notification d’absence »
|
||||||
|
|
||||||
### 3.2 Carte **congés** (`conge_am`)
|
### 3.2 Carte **congés** (`conge_am`)
|
||||||
|
|
||||||
@@ -93,10 +95,13 @@ Clé = **choix front**, pas une valeur API.
|
|||||||
|------------|---------|--------|
|
|------------|---------|--------|
|
||||||
| **`aqua`** | Congés AM | `conge_am` |
|
| **`aqua`** | Congés AM | `conge_am` |
|
||||||
| **`blue`** | Arrêt maladie AM | `arret_maladie_am` |
|
| **`blue`** | Arrêt maladie AM | `arret_maladie_am` |
|
||||||
| **`peach`** | Absence enfant / info pratique | `absence_enfant`, `absence_enfant_modif` |
|
| **`peach`** | Absence enfant / info pratique | `absence_enfant` |
|
||||||
| **`pink`** | Soins / bobo / problème **enfant** (AM → parents) | `soin_enfant` *(nouveau — voir §5)* |
|
| **`pink`** | Soins / bobo / problème **enfant** (AM → parents) | `soin_enfant` *(nouveau — voir §5)* |
|
||||||
| **`lavender`** | Admin / divers | futurs types admin |
|
| **`lavender`** | Admin / divers | futurs types admin |
|
||||||
|
|
||||||
|
**Hors scope V1 cartes** : `absence_enfant_modif` (ack AM sur modif).
|
||||||
|
Les **modifications d’absence** se font via l’**agenda / calendrier**, pas via une bulle dédiée. On rebranchera une notif éventuelle quand le calendrier sera implémenté.
|
||||||
|
|
||||||
**Principes**
|
**Principes**
|
||||||
|
|
||||||
- Couleur = famille visuelle (lisible sans tout lire).
|
- Couleur = famille visuelle (lisible sans tout lire).
|
||||||
@@ -138,6 +143,7 @@ Pourquoi **pas seulement la messagerie** ?
|
|||||||
| Famille | Couleur UI | Exemples | `response_mode` |
|
| Famille | Couleur UI | Exemples | `response_mode` |
|
||||||
|---------|------------|----------|-----------------|
|
|---------|------------|----------|-----------------|
|
||||||
| Soins (détail) | `pink` | `soin_temperature`, `soin_medicament`, `soin_bobo` — ou sous-types dans payload | `ack` |
|
| Soins (détail) | `pink` | `soin_temperature`, `soin_medicament`, `soin_bobo` — ou sous-types dans payload | `ack` |
|
||||||
|
| Modif absence | `peach` | `absence_enfant_modif` — **via calendrier** d’abord ; bulle ack AM éventuelle ensuite | `ack` |
|
||||||
| Sortie | `peach` / `lavender` | `sortie_a_valider` | `accept_refuse` |
|
| Sortie | `peach` / `lavender` | `sortie_a_valider` | `accept_refuse` |
|
||||||
| Admin | `lavender` | `info_admin`, `document_a_fournir` | `ack` / `none` |
|
| Admin | `lavender` | `info_admin`, `document_a_fournir` | `ack` / `none` |
|
||||||
|
|
||||||
@@ -150,7 +156,9 @@ Variante soins : un seul fond rose ; l’icône / sous-type change.
|
|||||||
- Créateur : pas de boutons réponse ; éventuel « En attente de réponse ».
|
- Créateur : pas de boutons réponse ; éventuel « En attente de réponse ».
|
||||||
- Refus : afficher `last_refuse_comment`.
|
- Refus : afficher `last_refuse_comment`.
|
||||||
- Congé : `accept_refuse` côté destinataire.
|
- Congé : `accept_refuse` côté destinataire.
|
||||||
- Absence enfant : info / ack — pas de veto AM en V1.
|
- Absence enfant : **info seule** (`response_mode: none`) — pas de veto ni ack AM en V1.
|
||||||
|
- Absence enfant : audience = **AM + tous les parents du foyer** (créateur + co-parent), pas seulement le déclarant.
|
||||||
|
- Modif / édition d’absence : **agenda**, pas les cartes (V1).
|
||||||
- File courte : `purge_at` ; l’**agenda** conserve l’historique métier.
|
- File courte : `purge_at` ; l’**agenda** conserve l’historique métier.
|
||||||
|
|
||||||
---
|
---
|
||||||
@@ -167,11 +175,14 @@ Variante soins : un seul fond rose ; l’icône / sous-type change.
|
|||||||
## 9. Recettes
|
## 9. Recettes
|
||||||
|
|
||||||
- [ ] API cartes **sans** champ `couleur` (ni feed ni `/types`).
|
- [ ] API cartes **sans** champ `couleur` (ni feed ni `/types`).
|
||||||
- [ ] Front mappe `conge_am` → aqua, `arret_maladie_am` → blue, `absence_*` → peach.
|
- [ ] Contrat lien agenda : champ API `id_evenement` (plus `id_absence`).
|
||||||
|
- [ ] Front mappe `conge_am` → aqua, `arret_maladie_am` → blue, `absence_enfant` → peach.
|
||||||
- [ ] Accept / refuse congé OK.
|
- [ ] Accept / refuse congé OK.
|
||||||
- [ ] Arrêt traité + période en cours → reste visible.
|
- [ ] Arrêt : ack parent « Bien reçu » ; traité + période en cours → reste visible.
|
||||||
|
- [ ] Absence enfant : pas de bouton (info).
|
||||||
- [ ] Filtre couple / placement.
|
- [ ] Filtre couple / placement.
|
||||||
- [ ] (Plus tard) `soin_enfant` rose AM → parents + ligne agenda.
|
- [ ] (Plus tard) `soin_enfant` rose AM → parents + ligne agenda.
|
||||||
|
- [ ] (Plus tard / calendrier) modifs d’absence + éventuel `absence_enfant_modif`.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
|
After Width: | Height: | Size: 310 KiB |
|
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 1.8 KiB |
|
Before Width: | Height: | Size: 591 KiB |
|
Before Width: | Height: | Size: 683 KiB |
|
Before Width: | Height: | Size: 1.2 MiB |
|
Before Width: | Height: | Size: 1.1 MiB |
|
After Width: | Height: | Size: 289 KiB |
|
After Width: | Height: | Size: 291 KiB |
@@ -49,7 +49,6 @@ class CarteBulle {
|
|||||||
final String id;
|
final String id;
|
||||||
final String typeCode;
|
final String typeCode;
|
||||||
final String titre;
|
final String titre;
|
||||||
final String? couleur;
|
|
||||||
final String idPlacement;
|
final String idPlacement;
|
||||||
final String? idAbsence;
|
final String? idAbsence;
|
||||||
final String operation;
|
final String operation;
|
||||||
@@ -67,7 +66,6 @@ class CarteBulle {
|
|||||||
required this.id,
|
required this.id,
|
||||||
required this.typeCode,
|
required this.typeCode,
|
||||||
required this.titre,
|
required this.titre,
|
||||||
this.couleur,
|
|
||||||
required this.idPlacement,
|
required this.idPlacement,
|
||||||
this.idAbsence,
|
this.idAbsence,
|
||||||
this.operation = 'create',
|
this.operation = 'create',
|
||||||
@@ -82,10 +80,45 @@ class CarteBulle {
|
|||||||
this.modifieLe,
|
this.modifieLe,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
CarteBulle copyWith({
|
||||||
|
CarteStatut? statut,
|
||||||
|
bool? isCreator,
|
||||||
|
String? lastRefuseComment,
|
||||||
|
DateTime? modifieLe,
|
||||||
|
Map<String, dynamic>? payload,
|
||||||
|
}) {
|
||||||
|
return CarteBulle(
|
||||||
|
id: id,
|
||||||
|
typeCode: typeCode,
|
||||||
|
titre: titre,
|
||||||
|
idPlacement: idPlacement,
|
||||||
|
idAbsence: idAbsence,
|
||||||
|
operation: operation,
|
||||||
|
statut: statut ?? this.statut,
|
||||||
|
payload: payload ?? this.payload,
|
||||||
|
purgeAt: purgeAt,
|
||||||
|
creePar: creePar,
|
||||||
|
isCreator: isCreator ?? this.isCreator,
|
||||||
|
responseMode: responseMode,
|
||||||
|
lastRefuseComment: lastRefuseComment ?? this.lastRefuseComment,
|
||||||
|
creeLe: creeLe,
|
||||||
|
modifieLe: modifieLe ?? this.modifieLe,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
String? get dateDebut => payload['date_debut']?.toString();
|
String? get dateDebut => payload['date_debut']?.toString();
|
||||||
String? get dateFin => payload['date_fin']?.toString();
|
String? get dateFin => payload['date_fin']?.toString();
|
||||||
String? get motif => payload['motif']?.toString();
|
String? get motif => payload['motif']?.toString();
|
||||||
|
|
||||||
|
/// Motif de refus : réponse API, sinon motif payload (co-parent / reload).
|
||||||
|
String? get motifRefus {
|
||||||
|
final fromResponse = lastRefuseComment?.trim();
|
||||||
|
if (fromResponse != null && fromResponse.isNotEmpty) return fromResponse;
|
||||||
|
final fromPayload = motif?.trim();
|
||||||
|
if (fromPayload != null && fromPayload.isNotEmpty) return fromPayload;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/// Libellé UI (sémantique produit) — pas le titre brut API.
|
/// Libellé UI (sémantique produit) — pas le titre brut API.
|
||||||
String get titreAffiche {
|
String get titreAffiche {
|
||||||
switch (typeCode) {
|
switch (typeCode) {
|
||||||
@@ -96,6 +129,8 @@ class CarteBulle {
|
|||||||
case 'absence_enfant':
|
case 'absence_enfant':
|
||||||
case 'absence_enfant_modif':
|
case 'absence_enfant_modif':
|
||||||
return 'Notification d’absence';
|
return 'Notification d’absence';
|
||||||
|
case 'soin_enfant':
|
||||||
|
return 'Soin / bobo';
|
||||||
default:
|
default:
|
||||||
return titre;
|
return titre;
|
||||||
}
|
}
|
||||||
@@ -103,6 +138,22 @@ class CarteBulle {
|
|||||||
|
|
||||||
bool get isArretMaladie => typeCode == 'arret_maladie_am';
|
bool get isArretMaladie => typeCode == 'arret_maladie_am';
|
||||||
bool get isCongeAm => typeCode == 'conge_am';
|
bool get isCongeAm => typeCode == 'conge_am';
|
||||||
|
bool get isSoinEnfant => typeCode == 'soin_enfant';
|
||||||
|
bool get isAbsenceEnfant =>
|
||||||
|
typeCode == 'absence_enfant' || typeCode == 'absence_enfant_modif';
|
||||||
|
|
||||||
|
/// Info seule (`response_mode: none`) : créée déjà `traitee`, mais reste
|
||||||
|
/// pertinente dans la file tant que la période n’est pas finie.
|
||||||
|
bool get restePleineDansFile {
|
||||||
|
if (statut == CarteStatut.ouverte) return true;
|
||||||
|
if (statut != CarteStatut.traitee) return false;
|
||||||
|
if (!periodeEncoreActive) return false;
|
||||||
|
// Arrêt maladie ack : opaque jusqu’à date_fin.
|
||||||
|
if (isArretMaladie) return true;
|
||||||
|
// Absence (et autres infos) : pas d’atténuation tant que période active.
|
||||||
|
if (responseMode == CarteResponseMode.none) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Icône dessin (haut droite) selon le type de bulle.
|
/// Icône dessin (haut droite) selon le type de bulle.
|
||||||
String? get iconAsset {
|
String? get iconAsset {
|
||||||
@@ -110,10 +161,11 @@ class CarteBulle {
|
|||||||
case 'conge_am':
|
case 'conge_am':
|
||||||
return 'assets/images/valise.png';
|
return 'assets/images/valise.png';
|
||||||
case 'arret_maladie_am':
|
case 'arret_maladie_am':
|
||||||
return 'assets/images/cartes/icon_carte_maladie.png';
|
return 'assets/images/thermo_croix.png';
|
||||||
case 'absence_enfant':
|
case 'absence_enfant':
|
||||||
case 'absence_enfant_modif':
|
case 'absence_enfant_modif':
|
||||||
return 'assets/images/cartes/icon_carte_absence.png';
|
return 'assets/images/sac_lapin.png';
|
||||||
|
// soin_enfant : icône selon sous-type payload — à brancher plus tard
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -137,35 +189,27 @@ class CarteBulle {
|
|||||||
return !todayDay.isAfter(fin);
|
return !todayDay.isAfter(fin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Asset horizontal pastel (palette `assets/cards/` uniquement).
|
/// Teinte pastel UI dérivée du `type_code` (pas de `couleur` API).
|
||||||
String get backgroundAsset {
|
/// Voir `docs/32_MINI-SPEC-BULLES-CARTES.md` §4.
|
||||||
// Congés : aqua (le lavande API ne convient pas au design).
|
CardColorHorizontal get colorFamily {
|
||||||
if (typeCode == 'conge_am') {
|
switch (typeCode) {
|
||||||
return CardColorHorizontal.aqua.path;
|
case 'conge_am':
|
||||||
}
|
return CardColorHorizontal.aqua;
|
||||||
final key = (couleur ?? '').trim().toLowerCase();
|
case 'arret_maladie_am':
|
||||||
switch (key) {
|
return CardColorHorizontal.blue;
|
||||||
case 'red':
|
case 'absence_enfant':
|
||||||
return CardColorHorizontal.red.path;
|
case 'absence_enfant_modif':
|
||||||
case 'pink':
|
return CardColorHorizontal.peach;
|
||||||
return CardColorHorizontal.pink.path;
|
case 'soin_enfant':
|
||||||
case 'peach':
|
return CardColorHorizontal.pink;
|
||||||
return CardColorHorizontal.peach.path;
|
|
||||||
case 'lime':
|
|
||||||
return CardColorHorizontal.lime.path;
|
|
||||||
case 'lavender':
|
|
||||||
return CardColorHorizontal.lavender.path;
|
|
||||||
case 'green':
|
|
||||||
return CardColorHorizontal.green.path;
|
|
||||||
case 'blue':
|
|
||||||
return CardColorHorizontal.blue.path;
|
|
||||||
case 'aqua':
|
|
||||||
return CardColorHorizontal.aqua.path;
|
|
||||||
default:
|
default:
|
||||||
return CardColorHorizontal.peach.path;
|
return CardColorHorizontal.lavender;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Asset horizontal pastel (palette `assets/cards/` uniquement).
|
||||||
|
String get backgroundAsset => colorFamily.path;
|
||||||
|
|
||||||
/// Le destinataire peut répondre (pas le créateur, carte ouverte).
|
/// Le destinataire peut répondre (pas le créateur, carte ouverte).
|
||||||
bool get peutRepondre =>
|
bool get peutRepondre =>
|
||||||
!isCreator &&
|
!isCreator &&
|
||||||
@@ -178,7 +222,6 @@ class CarteBulle {
|
|||||||
id: (json['id'] ?? '').toString(),
|
id: (json['id'] ?? '').toString(),
|
||||||
typeCode: (json['type_code'] ?? '').toString(),
|
typeCode: (json['type_code'] ?? '').toString(),
|
||||||
titre: (json['titre'] ?? json['type_code'] ?? 'Carte').toString(),
|
titre: (json['titre'] ?? json['type_code'] ?? 'Carte').toString(),
|
||||||
couleur: json['couleur']?.toString(),
|
|
||||||
idPlacement: (json['id_placement'] ?? '').toString(),
|
idPlacement: (json['id_placement'] ?? '').toString(),
|
||||||
idAbsence: json['id_absence']?.toString(),
|
idAbsence: json['id_absence']?.toString(),
|
||||||
operation: (json['operation'] ?? 'create').toString(),
|
operation: (json['operation'] ?? 'create').toString(),
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
/// Configuration UI d'un type de carte — catalogue front (#175).
|
||||||
|
/// Les types émissibles viennent de l'API ; ce fichier affine libellés / hints.
|
||||||
|
enum CartePeriodeMode {
|
||||||
|
/// Plage date_debut → date_fin.
|
||||||
|
range,
|
||||||
|
|
||||||
|
/// Une seule date (début = fin).
|
||||||
|
singleDay,
|
||||||
|
}
|
||||||
|
|
||||||
|
class CarteSousTypeUi {
|
||||||
|
final String code;
|
||||||
|
final String label;
|
||||||
|
|
||||||
|
const CarteSousTypeUi({required this.code, required this.label});
|
||||||
|
}
|
||||||
|
|
||||||
|
class CarteTypeUi {
|
||||||
|
final String typeCode;
|
||||||
|
final String label;
|
||||||
|
final String motifHint;
|
||||||
|
final bool motifRequired;
|
||||||
|
final CartePeriodeMode periodeMode;
|
||||||
|
final List<CarteSousTypeUi> sousTypes;
|
||||||
|
|
||||||
|
const CarteTypeUi({
|
||||||
|
required this.typeCode,
|
||||||
|
required this.label,
|
||||||
|
this.motifHint = 'Motif (optionnel)',
|
||||||
|
this.motifRequired = false,
|
||||||
|
this.periodeMode = CartePeriodeMode.range,
|
||||||
|
this.sousTypes = const [],
|
||||||
|
});
|
||||||
|
|
||||||
|
static const _catalog = <String, CarteTypeUi>{
|
||||||
|
'absence_enfant': CarteTypeUi(
|
||||||
|
typeCode: 'absence_enfant',
|
||||||
|
label: 'Notification d’absence',
|
||||||
|
motifHint: 'Motif de l’absence (optionnel)',
|
||||||
|
),
|
||||||
|
// absence_enfant_modif : hors scope cartes — via agenda uniquement.
|
||||||
|
'conge_am': CarteTypeUi(
|
||||||
|
typeCode: 'conge_am',
|
||||||
|
label: 'Demande de congés',
|
||||||
|
motifHint: 'Précisions (optionnel)',
|
||||||
|
),
|
||||||
|
'arret_maladie_am': CarteTypeUi(
|
||||||
|
typeCode: 'arret_maladie_am',
|
||||||
|
label: 'Arrêt maladie',
|
||||||
|
motifHint: 'Précisions (optionnel)',
|
||||||
|
),
|
||||||
|
// Point d’extension #soins — visible dès que le back l’émet.
|
||||||
|
'soin_enfant': CarteTypeUi(
|
||||||
|
typeCode: 'soin_enfant',
|
||||||
|
label: 'Soin / bobo',
|
||||||
|
motifHint: 'Décrivez le soin ou le bobo',
|
||||||
|
motifRequired: true,
|
||||||
|
periodeMode: CartePeriodeMode.singleDay,
|
||||||
|
sousTypes: [
|
||||||
|
CarteSousTypeUi(code: 'temperature', label: 'Température'),
|
||||||
|
CarteSousTypeUi(code: 'bobo', label: 'Bobo'),
|
||||||
|
CarteSousTypeUi(code: 'medicament', label: 'Médicament'),
|
||||||
|
CarteSousTypeUi(code: 'autre', label: 'Autre'),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
/// Fusionne un type API avec le catalogue ; fallback générique sinon.
|
||||||
|
static CarteTypeUi resolve({
|
||||||
|
required String typeCode,
|
||||||
|
String? apiTitre,
|
||||||
|
}) {
|
||||||
|
final known = _catalog[typeCode];
|
||||||
|
if (known != null) return known;
|
||||||
|
final titre = (apiTitre ?? '').trim();
|
||||||
|
return CarteTypeUi(
|
||||||
|
typeCode: typeCode,
|
||||||
|
label: titre.isNotEmpty ? titre : typeCode,
|
||||||
|
motifHint: 'Motif (optionnel)',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Type SYSTEM émissible renvoyé par GET /cards/types.
|
||||||
|
class CarteTypeEmissible {
|
||||||
|
final String code;
|
||||||
|
final String titre;
|
||||||
|
final String? responseMode;
|
||||||
|
final CarteTypeUi ui;
|
||||||
|
|
||||||
|
const CarteTypeEmissible({
|
||||||
|
required this.code,
|
||||||
|
required this.titre,
|
||||||
|
this.responseMode,
|
||||||
|
required this.ui,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory CarteTypeEmissible.fromJson(Map<String, dynamic> json) {
|
||||||
|
final code = (json['code'] ?? '').toString();
|
||||||
|
final titre = (json['titre'] ?? code).toString();
|
||||||
|
return CarteTypeEmissible(
|
||||||
|
code: code,
|
||||||
|
titre: titre,
|
||||||
|
responseMode: json['response_mode']?.toString(),
|
||||||
|
ui: CarteTypeUi.resolve(typeCode: code, apiTitre: titre),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String get label => ui.label;
|
||||||
|
}
|
||||||
@@ -3,14 +3,15 @@ import 'package:p_tits_pas/models/couple_garde.dart';
|
|||||||
import 'package:p_tits_pas/models/user.dart';
|
import 'package:p_tits_pas/models/user.dart';
|
||||||
import 'package:p_tits_pas/services/auth_service.dart';
|
import 'package:p_tits_pas/services/auth_service.dart';
|
||||||
import 'package:p_tits_pas/services/couple_garde_service.dart';
|
import 'package:p_tits_pas/services/couple_garde_service.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/quotidien/cartes_feed.dart';
|
||||||
import 'package:p_tits_pas/widgets/quotidien/couple_selector_bandeau.dart';
|
import 'package:p_tits_pas/widgets/quotidien/couple_selector_bandeau.dart';
|
||||||
import 'package:p_tits_pas/widgets/quotidien/quotidien_shell.dart';
|
import 'package:p_tits_pas/widgets/quotidien/quotidien_shell.dart';
|
||||||
import 'package:p_tits_pas/widgets/quotidien/quotidien_theme.dart';
|
import 'package:p_tits_pas/widgets/quotidien/quotidien_theme.dart';
|
||||||
import 'package:p_tits_pas/screens/home/parent_screen/agenda_absences_stub.dart';
|
import 'package:p_tits_pas/screens/home/parent_screen/agenda_absences_stub.dart';
|
||||||
|
|
||||||
/// Dashboard assistante maternelle – coquille 3 colonnes quotidien (#169).
|
/// Dashboard assistante maternelle – coquille 3 colonnes quotidien (#169).
|
||||||
/// Colonne gauche : sélecteur de couple enfant–parent(s) (#170).
|
/// Colonne gauche : sélecteur couple (#170) + feed bulles (#174).
|
||||||
/// Métier cartes / blog / messagerie : tickets C/D/E.
|
/// Création « Ajouter une carte » : modale générique (#175, réutilisée #176).
|
||||||
class AmDashboardScreen extends StatefulWidget {
|
class AmDashboardScreen extends StatefulWidget {
|
||||||
const AmDashboardScreen({super.key});
|
const AmDashboardScreen({super.key});
|
||||||
|
|
||||||
@@ -138,6 +139,7 @@ class _AmDashboardScreenState extends State<AmDashboardScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Colonne gauche : bandeau couple AM (#170) puis flux de cartes (#174 / #175).
|
||||||
class _LeftColumn extends StatelessWidget {
|
class _LeftColumn extends StatelessWidget {
|
||||||
final List<CoupleGarde> couples;
|
final List<CoupleGarde> couples;
|
||||||
final String? selectedCoupleId;
|
final String? selectedCoupleId;
|
||||||
@@ -172,12 +174,9 @@ class _LeftColumn extends StatelessWidget {
|
|||||||
onCoupleSelected: onCoupleSelected,
|
onCoupleSelected: onCoupleSelected,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 14),
|
const SizedBox(height: 14),
|
||||||
const Expanded(
|
Expanded(
|
||||||
child: QuotidienColumnPlaceholder(
|
child: CartesFeed(
|
||||||
title: 'Cartes',
|
placementId: selectedCoupleId,
|
||||||
subtitle:
|
|
||||||
'Absences, congés AM, sorties à valider\n(à brancher — ticket #174).',
|
|
||||||
icon: Icons.style_outlined,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -115,7 +115,6 @@ class _ParentDashboardScreenState extends State<ParentDashboardScreen> {
|
|||||||
error: _couplesError,
|
error: _couplesError,
|
||||||
onRetry: _loadCouples,
|
onRetry: _loadCouples,
|
||||||
onCoupleSelected: _selectCouple,
|
onCoupleSelected: _selectCouple,
|
||||||
onAjouterBulle: () => _soon('Ajouter une bulle'),
|
|
||||||
),
|
),
|
||||||
centerColumn: const QuotidienColumnPlaceholder(
|
centerColumn: const QuotidienColumnPlaceholder(
|
||||||
title: 'Blog',
|
title: 'Blog',
|
||||||
@@ -138,7 +137,7 @@ class _ParentDashboardScreenState extends State<ParentDashboardScreen> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Colonne gauche : bandeau couple (#167) puis flux de cartes (#173).
|
/// Colonne gauche : bandeau couple (#167) puis flux de cartes (#173 / #175).
|
||||||
class _LeftColumn extends StatelessWidget {
|
class _LeftColumn extends StatelessWidget {
|
||||||
final List<CoupleGarde> couples;
|
final List<CoupleGarde> couples;
|
||||||
final String? selectedCoupleId;
|
final String? selectedCoupleId;
|
||||||
@@ -146,7 +145,6 @@ class _LeftColumn extends StatelessWidget {
|
|||||||
final String? error;
|
final String? error;
|
||||||
final VoidCallback onRetry;
|
final VoidCallback onRetry;
|
||||||
final ValueChanged<CoupleGarde> onCoupleSelected;
|
final ValueChanged<CoupleGarde> onCoupleSelected;
|
||||||
final VoidCallback onAjouterBulle;
|
|
||||||
|
|
||||||
const _LeftColumn({
|
const _LeftColumn({
|
||||||
required this.couples,
|
required this.couples,
|
||||||
@@ -155,7 +153,6 @@ class _LeftColumn extends StatelessWidget {
|
|||||||
required this.error,
|
required this.error,
|
||||||
required this.onRetry,
|
required this.onRetry,
|
||||||
required this.onCoupleSelected,
|
required this.onCoupleSelected,
|
||||||
required this.onAjouterBulle,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -177,7 +174,6 @@ class _LeftColumn extends StatelessWidget {
|
|||||||
Expanded(
|
Expanded(
|
||||||
child: CartesFeed(
|
child: CartesFeed(
|
||||||
placementId: selectedCoupleId,
|
placementId: selectedCoupleId,
|
||||||
onAjouterBulle: onAjouterBulle,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -2,11 +2,14 @@ import 'dart:convert';
|
|||||||
|
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
import 'package:p_tits_pas/models/carte_bulle.dart';
|
import 'package:p_tits_pas/models/carte_bulle.dart';
|
||||||
|
import 'package:p_tits_pas/models/carte_type_ui.dart';
|
||||||
import 'package:p_tits_pas/services/api/api_config.dart';
|
import 'package:p_tits_pas/services/api/api_config.dart';
|
||||||
import 'package:p_tits_pas/services/api/tokenService.dart';
|
import 'package:p_tits_pas/services/api/tokenService.dart';
|
||||||
|
|
||||||
/// Accès API Cartes (file d'attention) — tickets #173 / #194.
|
/// Accès API Cartes (file d'attention) — tickets #173 / #175 / #194.
|
||||||
/// - GET /cards?placementId=
|
/// - GET /cards?placementId=
|
||||||
|
/// - GET /cards/types
|
||||||
|
/// - POST /cards
|
||||||
/// - POST /cards/:id/respond
|
/// - POST /cards/:id/respond
|
||||||
class CardsService {
|
class CardsService {
|
||||||
static Future<Map<String, String>> _headers() async {
|
static Future<Map<String, String>> _headers() async {
|
||||||
@@ -57,6 +60,60 @@ class CardsService {
|
|||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Types SYSTEM émissibles pour le rôle connecté.
|
||||||
|
static Future<List<CarteTypeEmissible>> listerTypes() async {
|
||||||
|
final response = await http.get(
|
||||||
|
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.cards}/types'),
|
||||||
|
headers: await _headers(),
|
||||||
|
);
|
||||||
|
if (response.statusCode != 200) {
|
||||||
|
throw Exception(
|
||||||
|
_extractError(response.body, 'Erreur chargement des types de cartes'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
final decoded = jsonDecode(response.body);
|
||||||
|
final list = decoded is List
|
||||||
|
? decoded
|
||||||
|
: (decoded is Map ? decoded['items'] as List? : null) ?? const [];
|
||||||
|
return list
|
||||||
|
.whereType<Map>()
|
||||||
|
.map((e) => CarteTypeEmissible.fromJson(Map<String, dynamic>.from(e)))
|
||||||
|
.where((t) => t.code.isNotEmpty)
|
||||||
|
// Modif d’absence = agenda, pas la modale cartes (#175).
|
||||||
|
.where((t) => t.code != 'absence_enfant_modif')
|
||||||
|
.toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Créer une bulle (+ événement agenda côté back).
|
||||||
|
static Future<CarteBulle> creer({
|
||||||
|
required String typeCode,
|
||||||
|
required String idPlacement,
|
||||||
|
required String dateDebut,
|
||||||
|
required String dateFin,
|
||||||
|
String? motif,
|
||||||
|
}) async {
|
||||||
|
final response = await http.post(
|
||||||
|
Uri.parse('${ApiConfig.baseUrl}${ApiConfig.cards}'),
|
||||||
|
headers: await _headers(),
|
||||||
|
body: jsonEncode({
|
||||||
|
'type_code': typeCode,
|
||||||
|
'id_placement': idPlacement,
|
||||||
|
'date_debut': dateDebut,
|
||||||
|
'date_fin': dateFin,
|
||||||
|
if (motif != null && motif.trim().isNotEmpty) 'motif': motif.trim(),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (response.statusCode != 201 && response.statusCode != 200) {
|
||||||
|
throw Exception(
|
||||||
|
_extractError(response.body, 'Erreur lors de la création'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
final decoded = jsonDecode(response.body);
|
||||||
|
return CarteBulle.fromJson(Map<String, dynamic>.from(decoded as Map));
|
||||||
|
}
|
||||||
|
|
||||||
/// Répondre : accept | refuse | ack.
|
/// Répondre : accept | refuse | ack.
|
||||||
static Future<CarteBulle> repondre({
|
static Future<CarteBulle> repondre({
|
||||||
required String cardId,
|
required String cardId,
|
||||||
@@ -75,7 +132,7 @@ class CardsService {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (response.statusCode != 200) {
|
if (response.statusCode != 200 && response.statusCode != 201) {
|
||||||
throw Exception(
|
throw Exception(
|
||||||
_extractError(response.body, 'Erreur lors de la réponse'),
|
_extractError(response.body, 'Erreur lors de la réponse'),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,154 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:p_tits_pas/models/carte_bulle.dart';
|
||||||
|
import 'package:p_tits_pas/services/api/api_config.dart';
|
||||||
|
import 'package:p_tits_pas/services/api/tokenService.dart';
|
||||||
|
|
||||||
|
import 'cards_stream_connector_stub.dart'
|
||||||
|
if (dart.library.html) 'cards_stream_connector_web.dart'
|
||||||
|
if (dart.library.io) 'cards_stream_connector_io.dart';
|
||||||
|
|
||||||
|
/// Événement temps réel file d'attention — ticket #195.
|
||||||
|
class CardsStreamEvent {
|
||||||
|
final String type;
|
||||||
|
final String? cardId;
|
||||||
|
final CarteBulle? card;
|
||||||
|
|
||||||
|
const CardsStreamEvent({
|
||||||
|
required this.type,
|
||||||
|
this.cardId,
|
||||||
|
this.card,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Client SSE `GET /cards/stream` avec reconnexion.
|
||||||
|
class CardsStreamClient {
|
||||||
|
final void Function(CardsStreamEvent event) onEvent;
|
||||||
|
final VoidCallback? onReconnectSync;
|
||||||
|
|
||||||
|
CardsStreamClient({
|
||||||
|
required this.onEvent,
|
||||||
|
this.onReconnectSync,
|
||||||
|
});
|
||||||
|
|
||||||
|
final CardsStreamConnector _connector = CardsStreamConnector();
|
||||||
|
bool _started = false;
|
||||||
|
bool _stopRequested = false;
|
||||||
|
int _attempt = 0;
|
||||||
|
Timer? _retryTimer;
|
||||||
|
bool _hadConnection = false;
|
||||||
|
|
||||||
|
void start() {
|
||||||
|
if (_started) return;
|
||||||
|
_started = true;
|
||||||
|
_stopRequested = false;
|
||||||
|
_attempt = 0;
|
||||||
|
unawaited(_connect());
|
||||||
|
}
|
||||||
|
|
||||||
|
void stop() {
|
||||||
|
_stopRequested = true;
|
||||||
|
_started = false;
|
||||||
|
_retryTimer?.cancel();
|
||||||
|
_retryTimer = null;
|
||||||
|
_connector.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _connect() async {
|
||||||
|
if (_stopRequested) return;
|
||||||
|
|
||||||
|
final token = await TokenService.getToken();
|
||||||
|
if (token == null || token.isEmpty) {
|
||||||
|
_scheduleRetry();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final base =
|
||||||
|
'${ApiConfig.baseUrl}${ApiConfig.cardsStream}'.replaceAll(
|
||||||
|
RegExp(r'/+$'),
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
|
||||||
|
// Web (EventSource) : token en query. IO : Bearer dans le connecteur.
|
||||||
|
final url = kIsWeb
|
||||||
|
? Uri.parse(base).replace(
|
||||||
|
queryParameters: {'access_token': token},
|
||||||
|
).toString()
|
||||||
|
: base;
|
||||||
|
|
||||||
|
await _connector.connect(
|
||||||
|
url: url,
|
||||||
|
bearerToken: kIsWeb ? null : token,
|
||||||
|
onEvent: _handleRaw,
|
||||||
|
onError: (_) {
|
||||||
|
if (_stopRequested) return;
|
||||||
|
_connector.close();
|
||||||
|
_scheduleRetry();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _handleRaw(String eventType, String data) {
|
||||||
|
if (_stopRequested) return;
|
||||||
|
|
||||||
|
// Premier événement (souvent heartbeat) = connexion OK.
|
||||||
|
if (!_hadConnection) {
|
||||||
|
_hadConnection = true;
|
||||||
|
_attempt = 0;
|
||||||
|
} else if (eventType == 'heartbeat') {
|
||||||
|
_attempt = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (eventType == 'heartbeat') return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final decoded = jsonDecode(data);
|
||||||
|
if (decoded is! Map) return;
|
||||||
|
final map = Map<String, dynamic>.from(decoded);
|
||||||
|
final type = (map['event']?.toString().isNotEmpty == true)
|
||||||
|
? map['event'].toString()
|
||||||
|
: eventType;
|
||||||
|
final cardId = map['card_id']?.toString();
|
||||||
|
final payload = map['data'];
|
||||||
|
|
||||||
|
CarteBulle? card;
|
||||||
|
if (type == 'response.added' && payload is Map) {
|
||||||
|
final nested = payload['card'];
|
||||||
|
if (nested is Map) {
|
||||||
|
card = CarteBulle.fromJson(Map<String, dynamic>.from(nested));
|
||||||
|
}
|
||||||
|
} else if ((type == 'card.created' || type == 'card.updated') &&
|
||||||
|
payload is Map) {
|
||||||
|
card = CarteBulle.fromJson(Map<String, dynamic>.from(payload));
|
||||||
|
}
|
||||||
|
|
||||||
|
onEvent(
|
||||||
|
CardsStreamEvent(
|
||||||
|
type: type,
|
||||||
|
cardId: cardId ?? card?.id,
|
||||||
|
card: card,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
} catch (_) {
|
||||||
|
// Événement mal formé : ignorer.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _scheduleRetry() {
|
||||||
|
if (_stopRequested) return;
|
||||||
|
_retryTimer?.cancel();
|
||||||
|
final delaySec = (1 << _attempt.clamp(0, 4)).clamp(1, 30);
|
||||||
|
_attempt++;
|
||||||
|
_retryTimer = Timer(Duration(seconds: delaySec), () {
|
||||||
|
if (_stopRequested) return;
|
||||||
|
if (_hadConnection) {
|
||||||
|
// Resync REST après coupure pour ne pas manquer d'événements.
|
||||||
|
onReconnectSync?.call();
|
||||||
|
}
|
||||||
|
unawaited(_connect());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
|
||||||
|
/// Connecteur SSE via HTTP stream (IO / mobile) — ticket #195.
|
||||||
|
class CardsStreamConnector {
|
||||||
|
http.Client? _client;
|
||||||
|
StreamSubscription<List<int>>? _sub;
|
||||||
|
bool _closed = false;
|
||||||
|
|
||||||
|
Future<void> connect({
|
||||||
|
required String url,
|
||||||
|
String? bearerToken,
|
||||||
|
required void Function(String eventType, String data) onEvent,
|
||||||
|
required void Function(Object error) onError,
|
||||||
|
}) async {
|
||||||
|
close();
|
||||||
|
_closed = false;
|
||||||
|
final client = http.Client();
|
||||||
|
_client = client;
|
||||||
|
|
||||||
|
try {
|
||||||
|
final request = http.Request('GET', Uri.parse(url));
|
||||||
|
request.headers['Accept'] = 'text/event-stream';
|
||||||
|
request.headers['Cache-Control'] = 'no-cache';
|
||||||
|
if (bearerToken != null && bearerToken.isNotEmpty) {
|
||||||
|
request.headers['Authorization'] = 'Bearer $bearerToken';
|
||||||
|
}
|
||||||
|
|
||||||
|
final response = await client.send(request);
|
||||||
|
if (response.statusCode != 200) {
|
||||||
|
onError(
|
||||||
|
StateError('SSE cards HTTP ${response.statusCode}'),
|
||||||
|
);
|
||||||
|
close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String? eventType;
|
||||||
|
final dataBuf = StringBuffer();
|
||||||
|
final lineBuf = StringBuffer();
|
||||||
|
|
||||||
|
void flushEvent() {
|
||||||
|
if (dataBuf.isEmpty) {
|
||||||
|
eventType = null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onEvent(eventType ?? 'message', dataBuf.toString());
|
||||||
|
dataBuf.clear();
|
||||||
|
eventType = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleLine(String line) {
|
||||||
|
if (line.isEmpty) {
|
||||||
|
flushEvent();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (line.startsWith(':')) return;
|
||||||
|
if (line.startsWith('event:')) {
|
||||||
|
eventType = line.substring(6).trim();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (line.startsWith('data:')) {
|
||||||
|
final payload = line.length > 5 ? line.substring(5) : '';
|
||||||
|
final trimmed = payload.startsWith(' ')
|
||||||
|
? payload.substring(1)
|
||||||
|
: payload;
|
||||||
|
if (dataBuf.isNotEmpty) dataBuf.write('\n');
|
||||||
|
dataBuf.write(trimmed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_sub = response.stream.listen(
|
||||||
|
(chunk) {
|
||||||
|
if (_closed) return;
|
||||||
|
lineBuf.write(utf8.decode(chunk, allowMalformed: true));
|
||||||
|
var content = lineBuf.toString();
|
||||||
|
var idx = content.indexOf('\n');
|
||||||
|
while (idx >= 0) {
|
||||||
|
var line = content.substring(0, idx);
|
||||||
|
if (line.endsWith('\r')) {
|
||||||
|
line = line.substring(0, line.length - 1);
|
||||||
|
}
|
||||||
|
handleLine(line);
|
||||||
|
content = content.substring(idx + 1);
|
||||||
|
idx = content.indexOf('\n');
|
||||||
|
}
|
||||||
|
lineBuf
|
||||||
|
..clear()
|
||||||
|
..write(content);
|
||||||
|
},
|
||||||
|
onError: (Object e) {
|
||||||
|
if (!_closed) onError(e);
|
||||||
|
},
|
||||||
|
onDone: () {
|
||||||
|
if (!_closed) onError(StateError('SSE cards fermé'));
|
||||||
|
},
|
||||||
|
cancelOnError: true,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
if (!_closed) onError(e);
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void close() {
|
||||||
|
_closed = true;
|
||||||
|
_sub?.cancel();
|
||||||
|
_sub = null;
|
||||||
|
_client?.close();
|
||||||
|
_client = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
/// Connecteur SSE — stub (tests / plateformes sans impl).
|
||||||
|
class CardsStreamConnector {
|
||||||
|
Future<void> connect({
|
||||||
|
required String url,
|
||||||
|
String? bearerToken,
|
||||||
|
required void Function(String eventType, String data) onEvent,
|
||||||
|
required void Function(Object error) onError,
|
||||||
|
}) async {}
|
||||||
|
|
||||||
|
void close() {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
// Connecteur web uniquement (import conditionnel).
|
||||||
|
// ignore_for_file: avoid_web_libraries_in_flutter, deprecated_member_use
|
||||||
|
|
||||||
|
import 'dart:html' as html;
|
||||||
|
|
||||||
|
/// Connecteur SSE navigateur (EventSource) — ticket #195.
|
||||||
|
/// Auth via `?access_token=` (EventSource ne permet pas Authorization).
|
||||||
|
class CardsStreamConnector {
|
||||||
|
html.EventSource? _source;
|
||||||
|
final Map<String, html.EventListener> _listeners = {};
|
||||||
|
|
||||||
|
Future<void> connect({
|
||||||
|
required String url,
|
||||||
|
String? bearerToken,
|
||||||
|
required void Function(String eventType, String data) onEvent,
|
||||||
|
required void Function(Object error) onError,
|
||||||
|
}) async {
|
||||||
|
close();
|
||||||
|
final source = html.EventSource(url);
|
||||||
|
_source = source;
|
||||||
|
|
||||||
|
const names = [
|
||||||
|
'card.created',
|
||||||
|
'card.updated',
|
||||||
|
'card.deleted',
|
||||||
|
'response.added',
|
||||||
|
'heartbeat',
|
||||||
|
];
|
||||||
|
for (final name in names) {
|
||||||
|
void listener(html.Event raw) {
|
||||||
|
final msg = raw as html.MessageEvent;
|
||||||
|
final data = msg.data?.toString() ?? '';
|
||||||
|
if (data.isEmpty) return;
|
||||||
|
onEvent(name, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
_listeners[name] = listener;
|
||||||
|
source.addEventListener(name, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void onErr(html.Event _) {
|
||||||
|
onError(StateError('SSE cards déconnecté'));
|
||||||
|
}
|
||||||
|
|
||||||
|
_listeners['error'] = onErr;
|
||||||
|
source.addEventListener('error', onErr);
|
||||||
|
}
|
||||||
|
|
||||||
|
void close() {
|
||||||
|
final source = _source;
|
||||||
|
if (source != null) {
|
||||||
|
_listeners.forEach((name, listener) {
|
||||||
|
source.removeEventListener(name, listener);
|
||||||
|
});
|
||||||
|
source.close();
|
||||||
|
}
|
||||||
|
_listeners.clear();
|
||||||
|
_source = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,408 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
import 'package:p_tits_pas/models/carte_bulle.dart';
|
||||||
|
import 'package:p_tits_pas/models/carte_type_ui.dart';
|
||||||
|
import 'package:p_tits_pas/services/api/cards_service.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/quotidien/quotidien_theme.dart';
|
||||||
|
|
||||||
|
/// Ouvre la modale Material générique « Ajouter une carte » (#175).
|
||||||
|
/// Retourne la bulle créée, ou `null` si annulé.
|
||||||
|
Future<CarteBulle?> showAjouterCarteModal(
|
||||||
|
BuildContext context, {
|
||||||
|
required String placementId,
|
||||||
|
}) {
|
||||||
|
return showDialog<CarteBulle>(
|
||||||
|
context: context,
|
||||||
|
barrierDismissible: false,
|
||||||
|
builder: (ctx) => AjouterCarteModal(placementId: placementId),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Modale générique : types API + catalogue UI, période (pas de motif V1).
|
||||||
|
class AjouterCarteModal extends StatefulWidget {
|
||||||
|
final String placementId;
|
||||||
|
|
||||||
|
const AjouterCarteModal({super.key, required this.placementId});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AjouterCarteModal> createState() => _AjouterCarteModalState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AjouterCarteModalState extends State<AjouterCarteModal> {
|
||||||
|
List<CarteTypeEmissible> _types = const [];
|
||||||
|
CarteTypeEmissible? _selected;
|
||||||
|
String? _sousTypeCode;
|
||||||
|
DateTime _dateDebut = DateTime.now();
|
||||||
|
DateTime _dateFin = DateTime.now();
|
||||||
|
bool _loadingTypes = true;
|
||||||
|
bool _submitting = false;
|
||||||
|
String? _error;
|
||||||
|
|
||||||
|
CarteTypeUi get _ui =>
|
||||||
|
_selected?.ui ??
|
||||||
|
CarteTypeUi.resolve(typeCode: _selected?.code ?? 'inconnu');
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
final now = DateTime.now();
|
||||||
|
_dateDebut = DateTime(now.year, now.month, now.day);
|
||||||
|
_dateFin = _dateDebut;
|
||||||
|
_loadTypes();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadTypes() async {
|
||||||
|
setState(() {
|
||||||
|
_loadingTypes = true;
|
||||||
|
_error = null;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
final types = await CardsService.listerTypes();
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_types = types;
|
||||||
|
_selected = types.isNotEmpty ? types.first : null;
|
||||||
|
_sousTypeCode = null;
|
||||||
|
_loadingTypes = false;
|
||||||
|
if (types.isEmpty) {
|
||||||
|
_error = 'Aucun type de carte disponible pour votre rôle.';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_loadingTypes = false;
|
||||||
|
_error = e.toString().replaceFirst('Exception: ', '');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String _fmtIso(DateTime d) {
|
||||||
|
final y = d.year.toString().padLeft(4, '0');
|
||||||
|
final m = d.month.toString().padLeft(2, '0');
|
||||||
|
final day = d.day.toString().padLeft(2, '0');
|
||||||
|
return '$y-$m-$day';
|
||||||
|
}
|
||||||
|
|
||||||
|
String _fmtUi(DateTime d) {
|
||||||
|
final day = d.day.toString().padLeft(2, '0');
|
||||||
|
final m = d.month.toString().padLeft(2, '0');
|
||||||
|
return '$day/$m/${d.year}';
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _pickSingleDay() async {
|
||||||
|
final picked = await showDatePicker(
|
||||||
|
context: context,
|
||||||
|
useRootNavigator: true,
|
||||||
|
initialDate: _dateDebut,
|
||||||
|
firstDate: DateTime(2020),
|
||||||
|
lastDate: DateTime(2040),
|
||||||
|
helpText: 'Date',
|
||||||
|
cancelText: 'Annuler',
|
||||||
|
confirmText: 'Valider',
|
||||||
|
);
|
||||||
|
if (picked == null || !mounted) return;
|
||||||
|
final day = DateTime(picked.year, picked.month, picked.day);
|
||||||
|
setState(() {
|
||||||
|
_dateDebut = day;
|
||||||
|
_dateFin = day;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Plage Material (jours surlignés), en boîte compacte — pas plein écran.
|
||||||
|
/// Astuce : le mode calendrier de [DateRangePickerDialog] prend
|
||||||
|
/// `MediaQuery.size` comme taille de dialog ; on la bride.
|
||||||
|
Future<void> _pickDateRange() async {
|
||||||
|
final initialEnd =
|
||||||
|
_dateFin.isBefore(_dateDebut) ? _dateDebut : _dateFin;
|
||||||
|
final picked = await showDialog<DateTimeRange>(
|
||||||
|
context: context,
|
||||||
|
useRootNavigator: true,
|
||||||
|
barrierDismissible: true,
|
||||||
|
builder: (dialogContext) {
|
||||||
|
final base = MediaQuery.of(dialogContext);
|
||||||
|
final theme = Theme.of(dialogContext);
|
||||||
|
return MediaQuery(
|
||||||
|
data: base.copyWith(size: const Size(420, 560)),
|
||||||
|
child: Theme(
|
||||||
|
data: theme.copyWith(
|
||||||
|
datePickerTheme: theme.datePickerTheme.copyWith(
|
||||||
|
rangePickerShape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
dialogTheme: theme.dialogTheme.copyWith(
|
||||||
|
shape: RoundedRectangleBorder(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
child: DateRangePickerDialog(
|
||||||
|
initialDateRange: DateTimeRange(
|
||||||
|
start: _dateDebut,
|
||||||
|
end: initialEnd,
|
||||||
|
),
|
||||||
|
firstDate: DateTime(2020),
|
||||||
|
lastDate: DateTime(2040),
|
||||||
|
currentDate: DateTime.now(),
|
||||||
|
helpText: 'Début, puis fin (même jour : 2×)',
|
||||||
|
saveText: 'Valider',
|
||||||
|
cancelText: 'Annuler',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
if (picked == null || !mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_dateDebut = DateTime(
|
||||||
|
picked.start.year,
|
||||||
|
picked.start.month,
|
||||||
|
picked.start.day,
|
||||||
|
);
|
||||||
|
_dateFin = DateTime(
|
||||||
|
picked.end.year,
|
||||||
|
picked.end.month,
|
||||||
|
picked.end.day,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
String? _sousTypeLabel() {
|
||||||
|
final sous = _sousTypeCode;
|
||||||
|
if (sous == null) return null;
|
||||||
|
for (final s in _ui.sousTypes) {
|
||||||
|
if (s.code == sous) return s.label;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// V1 : pas de texte libre ; seul un sous-type catalogue peut alimenter motif.
|
||||||
|
String? _motifOptionnel() => _sousTypeLabel();
|
||||||
|
|
||||||
|
Future<void> _submit() async {
|
||||||
|
if (_selected == null) return;
|
||||||
|
if (_dateFin.isBefore(_dateDebut)) {
|
||||||
|
setState(() => _error = 'La date de fin doit être après la date de début.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
_submitting = true;
|
||||||
|
_error = null;
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
final created = await CardsService.creer(
|
||||||
|
typeCode: _selected!.code,
|
||||||
|
idPlacement: widget.placementId,
|
||||||
|
dateDebut: _fmtIso(_dateDebut),
|
||||||
|
dateFin: _fmtIso(
|
||||||
|
_ui.periodeMode == CartePeriodeMode.singleDay
|
||||||
|
? _dateDebut
|
||||||
|
: _dateFin,
|
||||||
|
),
|
||||||
|
motif: _motifOptionnel(),
|
||||||
|
);
|
||||||
|
if (!mounted) return;
|
||||||
|
Navigator.of(context).pop(created);
|
||||||
|
} catch (e) {
|
||||||
|
if (!mounted) return;
|
||||||
|
setState(() {
|
||||||
|
_submitting = false;
|
||||||
|
_error = e.toString().replaceFirst('Exception: ', '');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(
|
||||||
|
'Ajouter une carte',
|
||||||
|
style: GoogleFonts.merienda(fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
content: SizedBox(
|
||||||
|
width: 420,
|
||||||
|
child: _loadingTypes
|
||||||
|
? const Padding(
|
||||||
|
padding: EdgeInsets.symmetric(vertical: 24),
|
||||||
|
child: Center(
|
||||||
|
child: SizedBox(
|
||||||
|
width: 28,
|
||||||
|
height: 28,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: SingleChildScrollView(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
if (_error != null) ...[
|
||||||
|
Text(
|
||||||
|
_error!,
|
||||||
|
style: GoogleFonts.merriweather(
|
||||||
|
fontSize: 13,
|
||||||
|
color: Theme.of(context).colorScheme.error,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
],
|
||||||
|
_buildTypeSelector(),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
if (_ui.periodeMode == CartePeriodeMode.singleDay)
|
||||||
|
_DateField(
|
||||||
|
label: 'Date',
|
||||||
|
value: _fmtUi(_dateDebut),
|
||||||
|
onTap: _submitting ? null : _pickSingleDay,
|
||||||
|
)
|
||||||
|
else
|
||||||
|
_DateField(
|
||||||
|
label: 'Période',
|
||||||
|
value: _dateDebut == _dateFin
|
||||||
|
? _fmtUi(_dateDebut)
|
||||||
|
: '${_fmtUi(_dateDebut)} → ${_fmtUi(_dateFin)}',
|
||||||
|
onTap: _submitting ? null : _pickDateRange,
|
||||||
|
),
|
||||||
|
if (_ui.sousTypes.isNotEmpty) ...[
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
'Sous-type',
|
||||||
|
style: GoogleFonts.merriweather(
|
||||||
|
fontSize: 13,
|
||||||
|
color: QuotidienTheme.ink,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 8,
|
||||||
|
children: [
|
||||||
|
for (final s in _ui.sousTypes)
|
||||||
|
ChoiceChip(
|
||||||
|
label: Text(s.label),
|
||||||
|
selected: _sousTypeCode == s.code,
|
||||||
|
onSelected: _submitting
|
||||||
|
? null
|
||||||
|
: (sel) {
|
||||||
|
setState(() {
|
||||||
|
_sousTypeCode = sel ? s.code : null;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: _submitting ? null : () => Navigator.pop(context),
|
||||||
|
child: const Text('Annuler'),
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: (_submitting ||
|
||||||
|
_loadingTypes ||
|
||||||
|
_selected == null ||
|
||||||
|
_types.isEmpty)
|
||||||
|
? null
|
||||||
|
: _submit,
|
||||||
|
child: _submitting
|
||||||
|
? const SizedBox(
|
||||||
|
width: 18,
|
||||||
|
height: 18,
|
||||||
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
|
)
|
||||||
|
: const Text('Envoyer'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildTypeSelector() {
|
||||||
|
if (_types.isEmpty) {
|
||||||
|
return Text(
|
||||||
|
'Aucun type disponible.',
|
||||||
|
style: GoogleFonts.merriweather(fontSize: 13),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (_types.length == 1) {
|
||||||
|
return Text(
|
||||||
|
_types.first.label,
|
||||||
|
style: GoogleFonts.merienda(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
color: QuotidienTheme.ink,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return DropdownButtonFormField<String>(
|
||||||
|
value: _selected?.code,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
labelText: 'Type de carte',
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
items: [
|
||||||
|
for (final t in _types)
|
||||||
|
DropdownMenuItem(value: t.code, child: Text(t.label)),
|
||||||
|
],
|
||||||
|
onChanged: _submitting
|
||||||
|
? null
|
||||||
|
: (code) {
|
||||||
|
if (code == null) return;
|
||||||
|
CarteTypeEmissible? next;
|
||||||
|
for (final t in _types) {
|
||||||
|
if (t.code == code) {
|
||||||
|
next = t;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (next == null) return;
|
||||||
|
setState(() {
|
||||||
|
_selected = next;
|
||||||
|
_sousTypeCode = null;
|
||||||
|
if (next!.ui.periodeMode == CartePeriodeMode.singleDay) {
|
||||||
|
_dateFin = _dateDebut;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DateField extends StatelessWidget {
|
||||||
|
final String label;
|
||||||
|
final String value;
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
|
||||||
|
const _DateField({
|
||||||
|
required this.label,
|
||||||
|
required this.value,
|
||||||
|
required this.onTap,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
borderRadius: BorderRadius.circular(8),
|
||||||
|
child: InputDecorator(
|
||||||
|
decoration: InputDecoration(
|
||||||
|
labelText: label,
|
||||||
|
border: const OutlineInputBorder(),
|
||||||
|
suffixIcon: const Icon(Icons.calendar_today_outlined, size: 18),
|
||||||
|
),
|
||||||
|
child: Text(
|
||||||
|
value,
|
||||||
|
style: GoogleFonts.merriweather(fontSize: 14),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,14 +1,22 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
import 'package:p_tits_pas/models/card_assets.dart';
|
||||||
import 'package:p_tits_pas/models/carte_bulle.dart';
|
import 'package:p_tits_pas/models/carte_bulle.dart';
|
||||||
import 'package:p_tits_pas/services/api/cards_service.dart';
|
import 'package:p_tits_pas/services/api/cards_service.dart';
|
||||||
|
import 'package:p_tits_pas/services/api/cards_stream_client.dart';
|
||||||
|
import 'package:p_tits_pas/services/auth_service.dart';
|
||||||
|
import 'package:p_tits_pas/widgets/quotidien/ajouter_carte_modal.dart';
|
||||||
import 'package:p_tits_pas/widgets/quotidien/carte.dart';
|
import 'package:p_tits_pas/widgets/quotidien/carte.dart';
|
||||||
import 'package:p_tits_pas/widgets/quotidien/quotidien_theme.dart';
|
import 'package:p_tits_pas/widgets/quotidien/quotidien_theme.dart';
|
||||||
|
|
||||||
/// Feed de bulles (file d'attention) — ticket #173.
|
/// Feed de bulles (file d'attention) — tickets #173 (parent) / #174 (AM).
|
||||||
/// Widget partagé parent / AM ; les actions dépendent du rôle + payload API.
|
/// Widget partagé ; les actions dépendent du rôle + payload API.
|
||||||
class CartesFeed extends StatefulWidget {
|
class CartesFeed extends StatefulWidget {
|
||||||
final String? placementId;
|
final String? placementId;
|
||||||
|
|
||||||
|
/// Conservé pour override éventuel ; sinon le CTA ouvre [showAjouterCarteModal].
|
||||||
final VoidCallback? onAjouterBulle;
|
final VoidCallback? onAjouterBulle;
|
||||||
|
|
||||||
const CartesFeed({
|
const CartesFeed({
|
||||||
@@ -34,15 +42,28 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
bool _fadeTop = false;
|
bool _fadeTop = false;
|
||||||
bool _fadeBottom = false;
|
bool _fadeBottom = false;
|
||||||
|
|
||||||
|
CardsStreamClient? _stream;
|
||||||
|
String? _userId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
_scrollController.addListener(_syncScrollFades);
|
_scrollController.addListener(_syncScrollFades);
|
||||||
|
unawaited(_loadUserId());
|
||||||
_load();
|
_load();
|
||||||
|
_startStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _loadUserId() async {
|
||||||
|
final user = await AuthService.getCurrentUser();
|
||||||
|
if (!mounted) return;
|
||||||
|
_userId = user?.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
|
_stream?.stop();
|
||||||
|
_stream = null;
|
||||||
_scrollController.removeListener(_syncScrollFades);
|
_scrollController.removeListener(_syncScrollFades);
|
||||||
_scrollController.dispose();
|
_scrollController.dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
@@ -56,6 +77,84 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _startStream() {
|
||||||
|
_stream?.stop();
|
||||||
|
_stream = CardsStreamClient(
|
||||||
|
onEvent: _onStreamEvent,
|
||||||
|
onReconnectSync: () {
|
||||||
|
if (mounted) _load();
|
||||||
|
},
|
||||||
|
)..start();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// SSE diffuse le DTO du répondant / créateur : recalcule `is_creator` local.
|
||||||
|
CarteBulle _avecIsCreatorLocal(CarteBulle incoming, {CarteBulle? previous}) {
|
||||||
|
if (previous != null) {
|
||||||
|
return incoming.copyWith(isCreator: previous.isCreator);
|
||||||
|
}
|
||||||
|
final uid = _userId;
|
||||||
|
if (uid != null &&
|
||||||
|
incoming.creePar != null &&
|
||||||
|
incoming.creePar!.isNotEmpty) {
|
||||||
|
return incoming.copyWith(isCreator: incoming.creePar == uid);
|
||||||
|
}
|
||||||
|
return incoming;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _onStreamEvent(CardsStreamEvent event) {
|
||||||
|
if (!mounted) return;
|
||||||
|
if (event.type == 'heartbeat') return;
|
||||||
|
// `response.added` puis `card.updated` : on ne traite que l’update carte.
|
||||||
|
if (event.type == 'response.added') return;
|
||||||
|
|
||||||
|
if (event.type == 'card.deleted') {
|
||||||
|
final id = event.cardId;
|
||||||
|
if (id == null || id.isEmpty) return;
|
||||||
|
setState(() {
|
||||||
|
_items = _trier([
|
||||||
|
for (final c in _items)
|
||||||
|
if (c.id != id) c,
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) => _syncScrollFades());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final raw = event.card;
|
||||||
|
if (raw == null) return;
|
||||||
|
|
||||||
|
final filter = widget.placementId;
|
||||||
|
final matchesFilter = filter == null ||
|
||||||
|
filter.isEmpty ||
|
||||||
|
raw.idPlacement == filter;
|
||||||
|
|
||||||
|
setState(() {
|
||||||
|
if (!matchesFilter) {
|
||||||
|
_items = _trier([
|
||||||
|
for (final c in _items)
|
||||||
|
if (c.id != raw.id) c,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
CarteBulle? previous;
|
||||||
|
for (final c in _items) {
|
||||||
|
if (c.id == raw.id) {
|
||||||
|
previous = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final card = _avecIsCreatorLocal(raw, previous: previous);
|
||||||
|
if (previous != null) {
|
||||||
|
_items = _trier([
|
||||||
|
for (final c in _items) if (c.id == card.id) card else c,
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
_items = _trier([..._items, card]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) => _syncScrollFades());
|
||||||
|
}
|
||||||
|
|
||||||
void _syncScrollFades() {
|
void _syncScrollFades() {
|
||||||
if (!_scrollController.hasClients) return;
|
if (!_scrollController.hasClients) return;
|
||||||
final position = _scrollController.position;
|
final position = _scrollController.position;
|
||||||
@@ -75,6 +174,35 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Tri stable partagé : refusées → encore actives (ouvertes / infos
|
||||||
|
/// période en cours) → traitées passées, puis `cree_le` DESC + `id`.
|
||||||
|
static List<CarteBulle> _trier(List<CarteBulle> items) {
|
||||||
|
int rang(CarteBulle c) {
|
||||||
|
switch (c.statut) {
|
||||||
|
case CarteStatut.refusee:
|
||||||
|
return 0;
|
||||||
|
case CarteStatut.ouverte:
|
||||||
|
return 1;
|
||||||
|
case CarteStatut.traitee:
|
||||||
|
// Absence info / arrêt encore dans la période : même rang que
|
||||||
|
// ouverte (sinon elles tombent en bas dès la création).
|
||||||
|
return c.restePleineDansFile ? 1 : 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final out = List<CarteBulle>.from(items);
|
||||||
|
out.sort((a, b) {
|
||||||
|
final byStatut = rang(a).compareTo(rang(b));
|
||||||
|
if (byStatut != 0) return byStatut;
|
||||||
|
final ac = a.creeLe?.millisecondsSinceEpoch ?? 0;
|
||||||
|
final bc = b.creeLe?.millisecondsSinceEpoch ?? 0;
|
||||||
|
final byCree = bc.compareTo(ac); // DESC
|
||||||
|
if (byCree != 0) return byCree;
|
||||||
|
return a.id.compareTo(b.id);
|
||||||
|
});
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> _load() async {
|
Future<void> _load() async {
|
||||||
setState(() {
|
setState(() {
|
||||||
_loading = true;
|
_loading = true;
|
||||||
@@ -86,7 +214,7 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
);
|
);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_items = items;
|
_items = _trier(items);
|
||||||
_loading = false;
|
_loading = false;
|
||||||
});
|
});
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) => _syncScrollFades());
|
WidgetsBinding.instance.addPostFrameCallback((_) => _syncScrollFades());
|
||||||
@@ -113,9 +241,9 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
);
|
);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
setState(() {
|
setState(() {
|
||||||
_items = [
|
_items = _trier([
|
||||||
for (final c in _items) if (c.id == updated.id) updated else c,
|
for (final c in _items) if (c.id == updated.id) updated else c,
|
||||||
];
|
]);
|
||||||
_busyCardId = null;
|
_busyCardId = null;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -138,8 +266,10 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
style: GoogleFonts.merienda(fontWeight: FontWeight.w600),
|
style: GoogleFonts.merienda(fontWeight: FontWeight.w600),
|
||||||
),
|
),
|
||||||
content: Text(
|
content: Text(
|
||||||
'Confirmez-vous l’acceptation de « ${card.titreAffiche} » '
|
card.isCongeAm
|
||||||
'(${_periodeCourte(card)}) ?',
|
? 'Confirmez-vous les congés ${_periodeDuAu(card)} ?'
|
||||||
|
: 'Confirmez-vous l’acceptation de « ${card.titreAffiche} » '
|
||||||
|
'(${_periodeCourte(card)}) ?',
|
||||||
style: GoogleFonts.merriweather(fontSize: 14, height: 1.4),
|
style: GoogleFonts.merriweather(fontSize: 14, height: 1.4),
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
@@ -159,89 +289,39 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onAck(CarteBulle card) async {
|
/// Ack immédiat (arrêt maladie, etc.) — pas de modale : un clic = bien reçu.
|
||||||
final ok = await showDialog<bool>(
|
Future<void> _onAck(CarteBulle card) => _respond(card, action: 'ack');
|
||||||
|
|
||||||
|
Future<void> _onRefuse(CarteBulle card) async {
|
||||||
|
final comment = await showDialog<String>(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (ctx) => AlertDialog(
|
builder: (ctx) => _RefuseDialog(
|
||||||
title: Text(
|
title: card.isCongeAm ? 'Refuser les congés ?' : 'Refuser la demande',
|
||||||
'Prise en compte',
|
message: card.isCongeAm
|
||||||
style: GoogleFonts.merienda(fontWeight: FontWeight.w600),
|
? 'Indiquez le motif du refus des congés '
|
||||||
),
|
'${_periodeDuAu(card)}.'
|
||||||
content: Text(
|
: 'Indiquez le motif du refus pour « ${card.titreAffiche} ».',
|
||||||
'Confirmez-vous avoir bien reçu cet arrêt maladie '
|
|
||||||
'(${_periodeCourte(card)}) ?',
|
|
||||||
style: GoogleFonts.merriweather(fontSize: 14, height: 1.4),
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(ctx, false),
|
|
||||||
child: const Text('Annuler'),
|
|
||||||
),
|
|
||||||
FilledButton(
|
|
||||||
onPressed: () => Navigator.pop(ctx, true),
|
|
||||||
child: const Text('Bien reçu'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (ok == true) {
|
if (comment != null && comment.isNotEmpty) {
|
||||||
await _respond(card, action: 'ack');
|
await _respond(card, action: 'refuse', comment: comment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _onRefuse(CarteBulle card) async {
|
static const _mois = [
|
||||||
final controller = TextEditingController();
|
'janvier',
|
||||||
final ok = await showDialog<bool>(
|
'février',
|
||||||
context: context,
|
'mars',
|
||||||
builder: (ctx) => AlertDialog(
|
'avril',
|
||||||
title: Text(
|
'mai',
|
||||||
'Refuser la demande',
|
'juin',
|
||||||
style: GoogleFonts.merienda(fontWeight: FontWeight.w600),
|
'juillet',
|
||||||
),
|
'août',
|
||||||
content: Column(
|
'septembre',
|
||||||
mainAxisSize: MainAxisSize.min,
|
'octobre',
|
||||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
'novembre',
|
||||||
children: [
|
'décembre',
|
||||||
Text(
|
];
|
||||||
'Indiquez le motif du refus pour « ${card.titreAffiche} ».',
|
|
||||||
style: GoogleFonts.merriweather(fontSize: 14, height: 1.4),
|
|
||||||
),
|
|
||||||
const SizedBox(height: 12),
|
|
||||||
TextField(
|
|
||||||
controller: controller,
|
|
||||||
maxLines: 3,
|
|
||||||
autofocus: true,
|
|
||||||
decoration: const InputDecoration(
|
|
||||||
hintText: 'Motif du refus…',
|
|
||||||
border: OutlineInputBorder(),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(ctx, false),
|
|
||||||
child: const Text('Annuler'),
|
|
||||||
),
|
|
||||||
FilledButton(
|
|
||||||
onPressed: () {
|
|
||||||
if (controller.text.trim().isEmpty) return;
|
|
||||||
Navigator.pop(ctx, true);
|
|
||||||
},
|
|
||||||
child: const Text('Refuser'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
);
|
|
||||||
if (ok == true && controller.text.trim().isNotEmpty) {
|
|
||||||
await _respond(
|
|
||||||
card,
|
|
||||||
action: 'refuse',
|
|
||||||
comment: controller.text.trim(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
controller.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
static String _periodeCourte(CarteBulle card) {
|
static String _periodeCourte(CarteBulle card) {
|
||||||
final d = card.dateDebut;
|
final d = card.dateDebut;
|
||||||
@@ -258,6 +338,23 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
return '${fmt(d)} → ${fmt(f)}';
|
return '${fmt(d)} → ${fmt(f)}';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// « du 04 novembre 2026 au 06 novembre 2026 »
|
||||||
|
static String _periodeDuAu(CarteBulle card) {
|
||||||
|
String fmtLong(String? iso) {
|
||||||
|
if (iso == null || iso.isEmpty) return '…';
|
||||||
|
final dt = DateTime.tryParse(iso);
|
||||||
|
if (dt == null) return iso;
|
||||||
|
final jj = dt.day.toString().padLeft(2, '0');
|
||||||
|
return '$jj ${_mois[dt.month - 1]} ${dt.year}';
|
||||||
|
}
|
||||||
|
|
||||||
|
final d = card.dateDebut;
|
||||||
|
final f = card.dateFin;
|
||||||
|
if (d == null && f == null) return 'pour une période non précisée';
|
||||||
|
if (d != null && (f == null || d == f)) return 'du ${fmtLong(d)}';
|
||||||
|
return 'du ${fmtLong(d)} au ${fmtLong(f)}';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
return Column(
|
||||||
@@ -279,23 +376,42 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
color: QuotidienTheme.ink,
|
color: QuotidienTheme.ink,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
const Spacer(),
|
|
||||||
TextButton.icon(
|
|
||||||
onPressed: widget.onAjouterBulle,
|
|
||||||
icon: const Icon(Icons.add, size: 18),
|
|
||||||
label: Text(
|
|
||||||
'Ajouter',
|
|
||||||
style: GoogleFonts.merriweather(fontSize: 13),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Expanded(child: _buildBody()),
|
Expanded(child: _buildBody()),
|
||||||
|
_AjouterCarteCta(onTap: _onAjouterCarte),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> _onAjouterCarte() async {
|
||||||
|
if (widget.onAjouterBulle != null) {
|
||||||
|
widget.onAjouterBulle!();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final placementId = widget.placementId;
|
||||||
|
if (placementId == null || placementId.isEmpty) {
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
const SnackBar(
|
||||||
|
content: Text(
|
||||||
|
'Sélectionnez un couple de garde pour ajouter une carte.',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final created = await showAjouterCarteModal(
|
||||||
|
context,
|
||||||
|
placementId: placementId,
|
||||||
|
);
|
||||||
|
if (created != null && mounted) {
|
||||||
|
// SSE peut précéder ; refresh pour garantir la cohérence locale.
|
||||||
|
await _load();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Widget _buildBody() {
|
Widget _buildBody() {
|
||||||
if (_loading) {
|
if (_loading) {
|
||||||
return const Center(
|
return const Center(
|
||||||
@@ -384,7 +500,7 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
onRefresh: _load,
|
onRefresh: _load,
|
||||||
child: ListView.separated(
|
child: ListView.separated(
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
padding: const EdgeInsets.only(top: 4, bottom: 8),
|
padding: const EdgeInsets.only(top: 4, bottom: 4),
|
||||||
itemCount: _items.length,
|
itemCount: _items.length,
|
||||||
separatorBuilder: (_, __) => const SizedBox(height: 10),
|
separatorBuilder: (_, __) => const SizedBox(height: 10),
|
||||||
itemBuilder: (context, index) {
|
itemBuilder: (context, index) {
|
||||||
@@ -404,14 +520,60 @@ class _CartesFeedState extends State<CartesFeed> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _BulleTile extends StatelessWidget {
|
/// Encre (titre / date / lien) accordée à la teinte de fond de la bulle.
|
||||||
/// Encre aqua foncé — harmonisée fond aqua / valise (pas le violet).
|
class _Encre {
|
||||||
static const Color _aquaInk = Color(0xFF315F63);
|
final Color ink;
|
||||||
/// Date : même famille, ~12 % plus claire.
|
final Color date;
|
||||||
static const Color _aquaDate = Color(0xFF4A7276);
|
final Color link;
|
||||||
/// Lien agenda : légère dérive bleue.
|
const _Encre(this.ink, this.date, this.link);
|
||||||
static const Color _aquaLink = Color(0xFF2B5868);
|
|
||||||
|
|
||||||
|
/// Aqua → pétrole désaturé ; pêche → brun chaud ; bleu → marine doux ;
|
||||||
|
/// rose → bois de rose ; lavande → prune.
|
||||||
|
static _Encre pour(CardColorHorizontal c) {
|
||||||
|
switch (c) {
|
||||||
|
case CardColorHorizontal.aqua:
|
||||||
|
return const _Encre(
|
||||||
|
Color(0xFF315F63),
|
||||||
|
Color(0xFF4A7276),
|
||||||
|
Color(0xFF2B5868),
|
||||||
|
);
|
||||||
|
case CardColorHorizontal.peach:
|
||||||
|
return const _Encre(
|
||||||
|
Color(0xFF7A4A2E),
|
||||||
|
Color(0xFF8F6248),
|
||||||
|
Color(0xFF6E4530),
|
||||||
|
);
|
||||||
|
case CardColorHorizontal.blue:
|
||||||
|
return const _Encre(
|
||||||
|
Color(0xFF2F4A6E),
|
||||||
|
Color(0xFF486083),
|
||||||
|
Color(0xFF2A4670),
|
||||||
|
);
|
||||||
|
case CardColorHorizontal.pink:
|
||||||
|
return const _Encre(
|
||||||
|
Color(0xFF7A3E52),
|
||||||
|
Color(0xFF8E5668),
|
||||||
|
Color(0xFF6E3A50),
|
||||||
|
);
|
||||||
|
case CardColorHorizontal.lavender:
|
||||||
|
return const _Encre(
|
||||||
|
Color(0xFF5C3D5C),
|
||||||
|
Color(0xFF70536F),
|
||||||
|
Color(0xFF553A60),
|
||||||
|
);
|
||||||
|
case CardColorHorizontal.red:
|
||||||
|
case CardColorHorizontal.lime:
|
||||||
|
case CardColorHorizontal.green:
|
||||||
|
return const _Encre(
|
||||||
|
Color(0xFF2F2F2F),
|
||||||
|
Color(0xFF6B6B6B),
|
||||||
|
Color(0xFF3A3A3A),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _BulleTile extends StatelessWidget {
|
||||||
final CarteBulle card;
|
final CarteBulle card;
|
||||||
final bool busy;
|
final bool busy;
|
||||||
final VoidCallback onAccept;
|
final VoidCallback onAccept;
|
||||||
@@ -473,20 +635,42 @@ class _BulleTile extends StatelessWidget {
|
|||||||
'au $j2 ${_mois[b.month - 1]} ${b.year}';
|
'au $j2 ${_mois[b.month - 1]} ${b.year}';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Arrêt maladie : reste opaque tant que la période n’est pas finie.
|
/// Arrêt / absence info : reste opaque tant que la période n’est pas finie
|
||||||
|
/// (même si `traitee` — absence = info seule dès la création).
|
||||||
bool get _attenuee {
|
bool get _attenuee {
|
||||||
if (card.isArretMaladie && card.periodeEncoreActive) return false;
|
if (card.restePleineDansFile) return false;
|
||||||
return card.statut == CarteStatut.traitee;
|
return card.statut == CarteStatut.traitee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Statut bas de carte (centré) : Validée / Refusée / En attente / Vu / Bien reçu.
|
||||||
|
bool get _montreStatutReponse {
|
||||||
|
if (card.peutRepondre) return false;
|
||||||
|
if (card.isCongeAm) {
|
||||||
|
if (card.statut == CarteStatut.ouverte) return card.isCreator;
|
||||||
|
return card.statut == CarteStatut.traitee ||
|
||||||
|
card.statut == CarteStatut.refusee;
|
||||||
|
}
|
||||||
|
// Arrêt (ack) : AM créateur → « Vu » seulement après ack parent.
|
||||||
|
// Destinataire → « Bien reçu » une fois traité.
|
||||||
|
return card.responseMode == CarteResponseMode.ack &&
|
||||||
|
card.statut == CarteStatut.traitee;
|
||||||
|
}
|
||||||
|
|
||||||
|
String get _libelleStatutReponse {
|
||||||
|
if (card.responseMode == CarteResponseMode.ack) {
|
||||||
|
return card.isCreator ? 'Vu' : 'Bien reçu';
|
||||||
|
}
|
||||||
|
if (card.isCongeAm && card.statut == CarteStatut.ouverte) {
|
||||||
|
return 'En attente de validation';
|
||||||
|
}
|
||||||
|
// Accordé à « Demande de congés ».
|
||||||
|
return card.statut == CarteStatut.refusee ? 'Refusée' : 'Validée';
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
if (card.isCongeAm) return _buildConge(context);
|
|
||||||
return _buildGeneric(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget _buildConge(BuildContext context) {
|
|
||||||
final periode = _fmtPeriodeUneLigne();
|
final periode = _fmtPeriodeUneLigne();
|
||||||
|
final encre = _Encre.pour(card.colorFamily);
|
||||||
|
|
||||||
return Opacity(
|
return Opacity(
|
||||||
opacity: _attenuee ? 0.55 : 1,
|
opacity: _attenuee ? 0.55 : 1,
|
||||||
@@ -511,7 +695,7 @@ class _BulleTile extends StatelessWidget {
|
|||||||
style: GoogleFonts.merienda(
|
style: GoogleFonts.merienda(
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontWeight: FontWeight.w700,
|
fontWeight: FontWeight.w700,
|
||||||
color: _aquaInk,
|
color: encre.ink,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (periode.isNotEmpty) ...[
|
if (periode.isNotEmpty) ...[
|
||||||
@@ -525,6 +709,8 @@ class _BulleTile extends StatelessWidget {
|
|||||||
height: 28,
|
height: 28,
|
||||||
fit: BoxFit.contain,
|
fit: BoxFit.contain,
|
||||||
filterQuality: FilterQuality.high,
|
filterQuality: FilterQuality.high,
|
||||||
|
color: encre.ink,
|
||||||
|
colorBlendMode: BlendMode.srcIn,
|
||||||
),
|
),
|
||||||
const SizedBox(width: 8),
|
const SizedBox(width: 8),
|
||||||
Expanded(
|
Expanded(
|
||||||
@@ -535,7 +721,7 @@ class _BulleTile extends StatelessWidget {
|
|||||||
style: GoogleFonts.merienda(
|
style: GoogleFonts.merienda(
|
||||||
fontSize: 15,
|
fontSize: 15,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: _aquaDate,
|
color: encre.date,
|
||||||
height: 1.25,
|
height: 1.25,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -543,29 +729,19 @@ class _BulleTile extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
if (card.statut == CarteStatut.refusee) ...[
|
if (card.isCongeAm &&
|
||||||
|
card.statut == CarteStatut.refusee &&
|
||||||
|
card.motifRefus != null) ...[
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
Text(
|
Text(
|
||||||
card.lastRefuseComment != null &&
|
'Motif : ${card.motifRefus}',
|
||||||
card.lastRefuseComment!.trim().isNotEmpty
|
maxLines: 4,
|
||||||
? 'Refusé — ${card.lastRefuseComment}'
|
|
||||||
: 'Refusé',
|
|
||||||
maxLines: 2,
|
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
style: GoogleFonts.merriweather(
|
style: GoogleFonts.merriweather(
|
||||||
fontSize: 12,
|
fontSize: 13,
|
||||||
fontStyle: FontStyle.italic,
|
fontStyle: FontStyle.italic,
|
||||||
color: _aquaInk,
|
height: 1.3,
|
||||||
),
|
color: encre.ink,
|
||||||
),
|
|
||||||
] else if (card.statut == CarteStatut.ouverte &&
|
|
||||||
card.isCreator) ...[
|
|
||||||
const SizedBox(height: 8),
|
|
||||||
Text(
|
|
||||||
'En attente de réponse',
|
|
||||||
style: GoogleFonts.merriweather(
|
|
||||||
fontSize: 12,
|
|
||||||
color: QuotidienTheme.muted,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@@ -595,25 +771,46 @@ class _BulleTile extends StatelessWidget {
|
|||||||
height: 28,
|
height: 28,
|
||||||
child: CircularProgressIndicator(strokeWidth: 2),
|
child: CircularProgressIndicator(strokeWidth: 2),
|
||||||
)
|
)
|
||||||
: Row(
|
: card.responseMode == CarteResponseMode.ack
|
||||||
mainAxisSize: MainAxisSize.min,
|
? _PilulePeinteButton(
|
||||||
children: [
|
|
||||||
_PilulePeinteButton(
|
|
||||||
asset:
|
asset:
|
||||||
'assets/images/cartes/btn_coche_pilule.png',
|
'assets/images/cartes/btn_coche_pilule.png',
|
||||||
tooltip: 'Accepter',
|
tooltip: 'Bien reçu',
|
||||||
onTap: onAccept,
|
onTap: onAck,
|
||||||
),
|
)
|
||||||
const SizedBox(width: 10),
|
: Row(
|
||||||
_PilulePeinteButton(
|
mainAxisSize: MainAxisSize.min,
|
||||||
asset:
|
children: [
|
||||||
'assets/images/cartes/btn_croix_pilule.png',
|
_PilulePeinteButton(
|
||||||
tooltip: 'Refuser',
|
asset:
|
||||||
onTap: onRefuse,
|
'assets/images/cartes/btn_coche_pilule.png',
|
||||||
),
|
tooltip: 'Accepter',
|
||||||
],
|
onTap: onAccept,
|
||||||
),
|
),
|
||||||
const Spacer(),
|
const SizedBox(width: 10),
|
||||||
|
_PilulePeinteButton(
|
||||||
|
asset:
|
||||||
|
'assets/images/cartes/btn_croix_pilule.png',
|
||||||
|
tooltip: 'Refuser',
|
||||||
|
onTap: onRefuse,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
else if (_montreStatutReponse)
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
_libelleStatutReponse,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: GoogleFonts.merienda(
|
||||||
|
fontSize: 16,
|
||||||
|
fontWeight: FontWeight.w600,
|
||||||
|
fontStyle: FontStyle.italic,
|
||||||
|
color: encre.ink.withValues(alpha: 0.75),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
if (card.peutRepondre) const SizedBox(width: 8),
|
||||||
|
if (!_montreStatutReponse) const Spacer(),
|
||||||
InkWell(
|
InkWell(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
@@ -631,12 +828,15 @@ class _BulleTile extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
child: Text(
|
child: Text(
|
||||||
'Ouvrir dans l’agenda ↗',
|
'Ouvrir dans l’agenda ↗',
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
textAlign: TextAlign.right,
|
||||||
style: GoogleFonts.merienda(
|
style: GoogleFonts.merienda(
|
||||||
fontSize: 13,
|
fontSize: 13,
|
||||||
fontWeight: FontWeight.w600,
|
fontWeight: FontWeight.w600,
|
||||||
color: _aquaLink,
|
color: encre.link,
|
||||||
decoration: TextDecoration.underline,
|
decoration: TextDecoration.underline,
|
||||||
decorationColor: _aquaLink,
|
decorationColor: encre.link,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -807,6 +1007,119 @@ class _BulleTile extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Modale de refus : le controller vit avec le State (Échap / Annuler OK).
|
||||||
|
class _RefuseDialog extends StatefulWidget {
|
||||||
|
final String title;
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
const _RefuseDialog({
|
||||||
|
required this.title,
|
||||||
|
required this.message,
|
||||||
|
});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_RefuseDialog> createState() => _RefuseDialogState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _RefuseDialogState extends State<_RefuseDialog> {
|
||||||
|
late final TextEditingController _controller;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_controller = TextEditingController();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text(
|
||||||
|
widget.title,
|
||||||
|
style: GoogleFonts.merienda(fontWeight: FontWeight.w600),
|
||||||
|
),
|
||||||
|
content: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
widget.message,
|
||||||
|
style: GoogleFonts.merriweather(fontSize: 14, height: 1.4),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 12),
|
||||||
|
TextField(
|
||||||
|
controller: _controller,
|
||||||
|
maxLines: 3,
|
||||||
|
autofocus: true,
|
||||||
|
decoration: const InputDecoration(
|
||||||
|
hintText: 'Motif du refus…',
|
||||||
|
border: OutlineInputBorder(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: const Text('Annuler'),
|
||||||
|
),
|
||||||
|
FilledButton(
|
||||||
|
onPressed: () {
|
||||||
|
final text = _controller.text.trim();
|
||||||
|
if (text.isEmpty) return;
|
||||||
|
Navigator.pop(context, text);
|
||||||
|
},
|
||||||
|
child: const Text('Refuser'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// CTA « Ajouter une carte » — pilule aquarelle en bas du feed (#175).
|
||||||
|
class _AjouterCarteCta extends StatelessWidget {
|
||||||
|
final VoidCallback onTap;
|
||||||
|
|
||||||
|
const _AjouterCarteCta({required this.onTap});
|
||||||
|
|
||||||
|
static const _asset =
|
||||||
|
'assets/images/cartes/btn_ajouter_carte_pilule.png';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(4, 12, 4, 14),
|
||||||
|
child: Center(
|
||||||
|
child: Tooltip(
|
||||||
|
message: 'Ajouter une carte',
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
child: InkWell(
|
||||||
|
onTap: onTap,
|
||||||
|
borderRadius: BorderRadius.circular(28),
|
||||||
|
child: Semantics(
|
||||||
|
button: true,
|
||||||
|
label: 'Ajouter une carte',
|
||||||
|
child: Image.asset(
|
||||||
|
_asset,
|
||||||
|
height: 48,
|
||||||
|
fit: BoxFit.contain,
|
||||||
|
filterQuality: FilterQuality.high,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Bouton pilule peinte (coche / croix intégrées) — carte congés.
|
/// Bouton pilule peinte (coche / croix intégrées) — carte congés.
|
||||||
class _PilulePeinteButton extends StatelessWidget {
|
class _PilulePeinteButton extends StatelessWidget {
|
||||||
final String asset;
|
final String asset;
|
||||||
|
|||||||