Thomas Fransolet bb4d4fe2d5 Écran Statistiques refondu + Guide IA + onboarding (auth, abonnement) + i18n FR/EN/NL
Statistiques — refonte complète, aucun changement backend
  statistics_screen.dart réécrit (+1832) : barres horizontales monochromes à la place
  des barres verticales tronquées et des deux anneaux, barre de filtres unique avec les
  volumes par canal, règle mono-canal, 4 KPI portant chacun leur variation, bandeau
  « à retenir », courbe en aire avec bandes de week-end. La période précédente s'obtient
  en rappelant le même endpoint.
  statistics_report.dart : export PDF généré côté client (paquet pdf Dart), il partage
  les valeurs calculées de l'écran — un chiffre ne peut pas diverger entre l'écran et le
  document envoyé à la commune. Deux puces du sommaire promettaient des données
  inexistantes (parcours terminés, questions au guide IA), retirées.
  ⚠️ Jamais ouvert dans un navigateur. Cases de test : test-plan.md §8bis / §8ter.

Guide IA
  Screens/GuideIa/guide_ia_screen.dart — onglet Configuration. Menu conditionné à
  isAssistant, le même drapeau que la garde d'AiController. L'onglet « Ce que demandent
  vos visiteurs » n'est pas dans ce commit : le schéma backend est prêt, l'UI non.

Onboarding self-service
  Screens/Auth/ (mot de passe oublié, définition du mot de passe),
  Screens/Billing/subscription_screen.dart, ai_quota_hint.dart.
  ⚠️ Aucun parcours joué de bout en bout — test-plan.md §18.

Parcours guidés
  progression_mode.dart : 9 booléens sur 3 niveaux remplacés par 3 questions.
  Popups GuidedPath / GuidedStep / QuizQuestion mises à jour en conséquence.

Client API (manager_api_new) — édité À LA MAIN, ne pas relancer la génération
  onboarding_api.dart, authentication_api.dart (+80), instance_dto (champs Guide*),
  guided_step / quiz_question_guided_step (flags morts retirés).
  Le // @dart=2.18 manquant dans onboarding_api.dart cassait les 3 apps Flutter d'un
  coup — corrigé ici.

i18n : ~180 clés par langue (FR/EN/NL) + fichiers générés.
Tests : progression_mode_test, statistics_report_test (le second a attrapé deux
plantages qui seraient sortis au premier clic).

flutter build web . flutter analyze : 68 erreurs, toutes dans les fichiers modèle
orphelins de manager_api_new — dette connue, pas une régression, ces fichiers ne sont
pas dans le graphe de compilation.
2026-08-09 22:14:37 +02:00

298 lines
13 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:manager_api_new/api.dart';
import 'package:manager_app/constants.dart';
import 'package:manager_app/Screens/Configurations/Section/SubSection/Parcours/showNewOrUpdateGuidedPath.dart';
import 'package:provider/provider.dart';
import 'package:manager_app/app_context.dart';
import 'package:manager_app/l10n/app_localizations.dart';
import 'package:manager_app/Models/managerContext.dart';
import 'package:manager_app/Components/message_notification.dart';
class ParcoursConfig extends StatefulWidget {
final List<GuidedPathDTO> initialValue;
final String parentId;
final bool isEvent;
final bool isParcours;
/// Parcours géolocalisé (`ShowMap`) : conditionne l'affichage des champs de
/// position et de zone sur les étapes. Un parcours en salle n'en a pas besoin.
final bool isGeolocated;
final ValueChanged<List<GuidedPathDTO>> onChanged;
const ParcoursConfig({
Key? key,
required this.initialValue,
required this.parentId,
required this.isEvent,
this.isParcours = false,
this.isGeolocated = true,
required this.onChanged,
}) : super(key: key);
@override
_ParcoursConfigState createState() => _ParcoursConfigState();
}
class _ParcoursConfigState extends State<ParcoursConfig> {
late List<GuidedPathDTO> paths;
@override
void initState() {
super.initState();
paths = List.from(widget.initialValue);
paths.sort((a, b) => (a.order ?? 0).compareTo(b.order ?? 0));
WidgetsBinding.instance.addPostFrameCallback((_) => _loadFromApi());
}
Future<void> _loadFromApi() async {
final appContext = Provider.of<AppContext>(context, listen: false);
final clientAPI = (appContext.getContext() as ManagerAppContext).clientAPI!;
try {
final fetchedPaths = widget.isParcours
? await clientAPI.sectionParcoursApi!
.sectionParcoursGetAllGuidedPathFromSection(widget.parentId)
: await clientAPI.sectionMapApi!
.sectionMapGetAllGuidedPathFromSection(widget.parentId);
if (fetchedPaths == null || !mounted) return;
fetchedPaths.sort((a, b) => (a.order ?? 0).compareTo(b.order ?? 0));
setState(() {
paths = List.from(fetchedPaths);
});
} catch (e) {
// Silently keep initial value on error
}
}
@override
Widget build(BuildContext context) {
return Column(
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(AppLocalizations.of(context)!.guidedPathsLabel,
style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold)),
ElevatedButton.icon(
icon: Icon(Icons.add),
label: Text(AppLocalizations.of(context)!.addPath),
onPressed: () {
final appContext =
Provider.of<AppContext>(context, listen: false);
showNewOrUpdateGuidedPath(
context,
null,
widget.parentId,
widget.isEvent,
isGeolocated: widget.isGeolocated,
(newPath) async {
try {
newPath.order = paths.length;
newPath.instanceId =
(appContext.getContext() as ManagerAppContext)
.instanceId;
if (widget.isParcours) {
newPath.sectionParcoursId = widget.parentId;
} else if (widget.isEvent) {
newPath.sectionEventId = widget.parentId;
} else {
newPath.sectionMapId = widget.parentId;
}
final clientAPI = (appContext.getContext() as ManagerAppContext).clientAPI!;
final createdPath = widget.isParcours
? await clientAPI.sectionParcoursApi!
.sectionParcoursCreateGuidedPath(widget.parentId, newPath)
: await clientAPI.sectionMapApi!
.sectionMapCreateGuidedPath(widget.parentId, newPath);
if (createdPath != null) {
if (mounted) {
setState(() {
paths.add(createdPath);
widget.onChanged(paths);
});
}
showNotification(kSuccess, kWhite,
AppLocalizations.of(context)!.pathCreatedSuccess, context, null);
}
} catch (e) {
showNotification(
kError,
kWhite,
AppLocalizations.of(context)!.pathCreateError,
context,
null);
rethrow; // Important so showNewOrUpdateGuidedPath knows it failed
}
},
);
},
style: ElevatedButton.styleFrom(
backgroundColor: kSuccess, foregroundColor: kWhite),
),
],
),
),
Expanded(
child: paths.isEmpty
? Center(
child: Text(AppLocalizations.of(context)!.noPathConfigured,
style: TextStyle(fontStyle: FontStyle.italic)))
: ReorderableListView.builder(
buildDefaultDragHandles: false,
itemCount: paths.length,
onReorder: (oldIndex, newIndex) async {
if (newIndex > oldIndex) newIndex -= 1;
final item = paths.removeAt(oldIndex);
paths.insert(newIndex, item);
for (int i = 0; i < paths.length; i++) {
paths[i].order = i;
}
setState(() {});
widget.onChanged(paths);
final appContext =
Provider.of<AppContext>(context, listen: false);
final clientAPI = (appContext.getContext() as ManagerAppContext).clientAPI!;
try {
await Future.wait(widget.isParcours
? paths.map((p) => clientAPI.sectionParcoursApi!.sectionParcoursUpdateGuidedPath(p))
: paths.map((p) => clientAPI.sectionMapApi!.sectionMapUpdateGuidedPath(p)));
} catch (e) {
showNotification(
kError,
kWhite,
AppLocalizations.of(context)!.pathOrderUpdateError,
context,
null);
}
},
itemBuilder: (context, index) {
final path = paths[index];
return Card(
key: ValueKey(path.id ?? index.toString()),
margin: EdgeInsets.symmetric(horizontal: 10, vertical: 5),
child: ListTile(
leading: CircleAvatar(
child: Text("${index + 1}"),
backgroundColor: kPrimaryColor,
foregroundColor: kWhite),
title: path.title != null && path.title!.isNotEmpty
? HtmlWidget(
path.title!
.firstWhere((t) => t.language == 'FR',
orElse: () => path.title![0])
.value ??
AppLocalizations.of(context)!.pathNoTitle,
)
: Text(AppLocalizations.of(context)!.pathNoTitle),
subtitle: Text(AppLocalizations.of(context)!.stepsCount(path.steps?.length ?? 0)),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
IconButton(
icon: Icon(Icons.edit, color: kPrimaryColor),
onPressed: () {
final appContext = Provider.of<AppContext>(
context,
listen: false);
showNewOrUpdateGuidedPath(
context,
path,
widget.parentId,
widget.isEvent,
isGeolocated: widget.isGeolocated,
(updatedPath) async {
try {
final clientAPI = (appContext.getContext() as ManagerAppContext).clientAPI!;
final result = widget.isParcours
? await clientAPI.sectionParcoursApi!.sectionParcoursUpdateGuidedPath(updatedPath)
: await clientAPI.sectionMapApi!.sectionMapUpdateGuidedPath(updatedPath);
if (result != null) {
if (mounted) {
setState(() {
paths[index] = result;
widget.onChanged(paths);
});
}
showNotification(
kSuccess,
kWhite,
AppLocalizations.of(context)!.pathUpdatedSuccess,
context,
null);
}
} catch (e) {
showNotification(
kError,
kWhite,
AppLocalizations.of(context)!.pathUpdateError,
context,
null);
rethrow;
}
},
);
},
),
IconButton(
icon: Icon(Icons.delete, color: kError),
onPressed: () async {
final appContext = Provider.of<AppContext>(
context,
listen: false);
try {
if (path.id != null) {
final clientAPI = (appContext.getContext() as ManagerAppContext).clientAPI!;
if (widget.isParcours) {
await clientAPI.sectionParcoursApi!.sectionParcoursDeleteGuidedPath(path.id!);
} else {
await clientAPI.sectionMapApi!.sectionMapDeleteGuidedPath(path.id!);
}
}
setState(() {
paths.removeAt(index);
for (int i = 0; i < paths.length; i++) {
paths[i].order = i;
}
widget.onChanged(paths);
});
showNotification(
kSuccess,
kWhite,
AppLocalizations.of(context)!.pathDeletedSuccess,
context,
null);
} catch (e) {
showNotification(
kError,
kWhite,
AppLocalizations.of(context)!.pathDeleteError,
context,
null);
}
},
),
ReorderableDragStartListener(
index: index,
child: Icon(Icons.drag_handle),
),
],
),
),
);
},
),
),
],
);
}
}