feat(frontend): download responsable history csv
This commit is contained in:
@@ -4,6 +4,7 @@ import "package:google_fonts/google_fonts.dart";
|
||||
import "../demo_identity.dart";
|
||||
import "../services/responsable_service.dart";
|
||||
import "../theme/ensup_colors.dart";
|
||||
import "../utils/file_download.dart";
|
||||
|
||||
const _workspaceBackground = Color(0xFFF3F6F9);
|
||||
const _orange = Color(0xFFD97706);
|
||||
@@ -19,6 +20,7 @@ class _ResponsableScreenState extends State<ResponsableScreen> {
|
||||
late Future<_ResponsableData> _future = _charger();
|
||||
int _onglet = 0;
|
||||
bool _transitionEnCours = false;
|
||||
bool _exportEnCours = false;
|
||||
|
||||
Future<_ResponsableData> _charger() async {
|
||||
final dashboard = await ResponsableService.dashboard();
|
||||
@@ -79,6 +81,33 @@ class _ResponsableScreenState extends State<ResponsableScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _exporterHistorique() async {
|
||||
if (_exportEnCours) return;
|
||||
|
||||
setState(() => _exportEnCours = true);
|
||||
try {
|
||||
final file = await ResponsableService.exporterHistorique();
|
||||
downloadFile(
|
||||
bytes: file.bytes,
|
||||
fileName: file.fileName,
|
||||
contentType: file.contentType,
|
||||
);
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(const SnackBar(content: Text("Export CSV téléchargé.")));
|
||||
} catch (error) {
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(
|
||||
context,
|
||||
).showSnackBar(SnackBar(content: Text(error.toString())));
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() => _exportEnCours = false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String? _prochainStatut(String? statut) {
|
||||
return switch (statut) {
|
||||
"DETECTEE" => "EN_COURS_TRAITEMENT",
|
||||
@@ -195,17 +224,15 @@ class _ResponsableScreenState extends State<ResponsableScreen> {
|
||||
items: data.historique,
|
||||
builder: _historiqueTile,
|
||||
action: OutlinedButton.icon(
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text(
|
||||
"Export disponible via /api/responsable/historique/export.csv",
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.download_outlined, size: 16),
|
||||
label: const Text("Export CSV"),
|
||||
onPressed: _exportEnCours ? null : _exporterHistorique,
|
||||
icon: _exportEnCours
|
||||
? const SizedBox(
|
||||
width: 16,
|
||||
height: 16,
|
||||
child: CircularProgressIndicator(strokeWidth: 2),
|
||||
)
|
||||
: const Icon(Icons.download_outlined, size: 16),
|
||||
label: Text(_exportEnCours ? "Export en cours" : "Export CSV"),
|
||||
),
|
||||
searchableText: (item) => "${item["action"]} ${item["description"]}",
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user