ajout de l'export des votes dans un fichier ODS avec toutes les données (anonymisées par défaut - réglable dans les paramètres)

This commit is contained in:
Yannick Le Duc
2025-08-27 18:38:20 +02:00
parent c94c8038f3
commit b7ce1145e3
10 changed files with 979 additions and 23 deletions

View File

@@ -0,0 +1,94 @@
'use client';
import { useState } from 'react';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Alert, AlertDescription } from '@/components/ui/alert';
import { Shield, User, UserCheck, AlertTriangle } from 'lucide-react';
export type AnonymizationLevel = 'full' | 'initials' | 'none';
interface ExportAnonymizationSelectProps {
value: AnonymizationLevel;
onValueChange: (value: AnonymizationLevel) => void;
}
const anonymizationOptions = [
{
value: 'full' as AnonymizationLevel,
label: 'Anonymisation complète',
description: 'Noms remplacés par "XXXX"',
icon: Shield,
color: 'text-green-600'
},
{
value: 'initials' as AnonymizationLevel,
label: 'Initiales uniquement',
description: 'Premières lettres des noms/prénoms',
icon: User,
color: 'text-blue-600'
},
{
value: 'none' as AnonymizationLevel,
label: 'Aucune anonymisation',
description: 'Noms et prénoms complets',
icon: UserCheck,
color: 'text-orange-600'
}
];
export function ExportAnonymizationSelect({ value, onValueChange }: ExportAnonymizationSelectProps) {
const [showWarning, setShowWarning] = useState(false);
const handleValueChange = (newValue: AnonymizationLevel) => {
if (newValue === 'none') {
setShowWarning(true);
} else {
setShowWarning(false);
}
onValueChange(newValue);
};
const selectedOption = anonymizationOptions.find(option => option.value === value);
return (
<div className="space-y-4">
<div>
<label className="text-sm font-medium text-slate-700 dark:text-slate-300 mb-2 block">
Niveau d'anonymisation des exports
</label>
<Select value={value} onValueChange={handleValueChange}>
<SelectTrigger className="w-full">
<SelectValue />
</SelectTrigger>
<SelectContent>
{anonymizationOptions.map((option) => {
const OptionIcon = option.icon;
return (
<SelectItem key={option.value} value={option.value} className="py-3">
<div className="flex items-center gap-3 w-full">
<OptionIcon className={`w-4 h-4 ${option.color}`} />
<div className="min-w-0 flex-1">
<div className="font-medium">{option.label}</div>
<div className="text-xs text-slate-500">{option.description}</div>
</div>
</div>
</SelectItem>
);
})}
</SelectContent>
</Select>
</div>
{showWarning && (
<Alert className="border-orange-200 bg-orange-50 dark:border-orange-800 dark:bg-orange-950">
<AlertTriangle className="h-4 w-4 text-orange-600" />
<AlertDescription className="text-orange-800 dark:text-orange-200">
<strong>Attention RGPD :</strong> L'export sans anonymisation contient des données personnelles.
Assurez-vous d'avoir le consentement des participants et de respecter les obligations légales
en matière de protection des données personnelles.
</AlertDescription>
</Alert>
)}
</div>
);
}

View File

@@ -0,0 +1,83 @@
'use client';
import { useState } from 'react';
import { Button } from '@/components/ui/button';
import { Download, FileSpreadsheet } from 'lucide-react';
import { generateVoteExportODS, downloadODS, formatFilename, ExportData, AnonymizationLevel } from '@/lib/export-utils';
import { settingsService } from '@/lib/services';
interface ExportStatsButtonProps {
campaignTitle: string;
propositions: any[];
participants: any[];
votes: any[];
budgetPerUser: number;
propositionStats?: any[];
disabled?: boolean;
}
export function ExportStatsButton({
campaignTitle,
propositions,
participants,
votes,
budgetPerUser,
propositionStats,
disabled = false
}: ExportStatsButtonProps) {
const [isExporting, setIsExporting] = useState(false);
const handleExport = async () => {
if (disabled || isExporting) return;
setIsExporting(true);
try {
// Récupérer le niveau d'anonymisation depuis les paramètres
const anonymizationLevel = await settingsService.getStringValue('export_anonymization', 'full') as AnonymizationLevel;
const exportData: ExportData = {
campaignTitle,
propositions,
participants,
votes,
budgetPerUser,
propositionStats,
anonymizationLevel
};
const odsData = generateVoteExportODS(exportData);
const filename = formatFilename(campaignTitle);
downloadODS(odsData, filename);
} catch (error) {
console.error('Erreur lors de l\'export:', error);
// Ici on pourrait ajouter une notification d'erreur
} finally {
setIsExporting(false);
}
};
return (
<Button
onClick={handleExport}
disabled={disabled || isExporting}
variant="outline"
className="gap-2"
>
{isExporting ? (
<>
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-current"></div>
Export en cours...
</>
) : (
<>
<FileSpreadsheet className="h-4 w-4" />
Exporter les votes (ODS)
</>
)}
</Button>
);
}