Spaces:
Paused
Paused
File size: 5,014 Bytes
5a81b95 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | import { Download, FileText, FileJson, FileSpreadsheet } from 'lucide-react';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { exportToCSV, exportToJSON, exportToPDF, generateReportData } from '@/lib/exportUtils';
import { toast } from '@/hooks/use-toast';
interface ExportMenuProps {
elementId?: string;
filename?: string;
}
const ExportMenu = ({ elementId = 'export-content', filename = 'cyber-report' }: ExportMenuProps) => {
const handleExportCSV = () => {
const data = generateReportData();
exportToCSV(data.threats, `${filename}-threats`);
toast({ title: "CSV eksporteret", description: "Threats data er downloadet" });
};
const handleExportJSON = () => {
const data = generateReportData();
exportToJSON(data, filename);
toast({ title: "JSON eksporteret", description: "Fuld rapport er downloadet" });
};
const handleExportPDF = () => {
exportToPDF(elementId, filename);
toast({ title: "PDF eksporteret", description: "Print dialog åbnet" });
};
const handleExportFullReport = () => {
const data = generateReportData();
// Create a comprehensive report
const reportHTML = `
<div id="full-report">
<h2>Sikkerhedsoversigt</h2>
<div style="display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin: 20px 0;">
<div class="metric">
<div class="metric-value">${data.summary.totalThreats}</div>
<div class="metric-label">Total Trusler</div>
</div>
<div class="metric">
<div class="metric-value">${data.summary.criticalAlerts}</div>
<div class="metric-label">Kritiske Alerts</div>
</div>
<div class="metric">
<div class="metric-value">${data.summary.resolvedIncidents}</div>
<div class="metric-label">Løste Incidents</div>
</div>
<div class="metric">
<div class="metric-value">${data.summary.activeMonitors}</div>
<div class="metric-label">Aktive Monitors</div>
</div>
</div>
<h2>Seneste Trusler</h2>
<table>
<thead>
<tr>
<th>ID</th>
<th>Navn</th>
<th>Severity</th>
<th>Status</th>
<th>Tidspunkt</th>
</tr>
</thead>
<tbody>
${data.threats.map(t => `
<tr>
<td>${t.id}</td>
<td>${t.name}</td>
<td>${t.severity}</td>
<td>${t.status}</td>
<td>${new Date(t.timestamp).toLocaleString('da-DK')}</td>
</tr>
`).join('')}
</tbody>
</table>
<h2>Regional Oversigt</h2>
<table>
<thead>
<tr>
<th>Region</th>
<th>Trusler</th>
<th>Incidents</th>
</tr>
</thead>
<tbody>
${data.regions.map(r => `
<tr>
<td>${r.region}</td>
<td>${r.threats}</td>
<td>${r.incidents}</td>
</tr>
`).join('')}
</tbody>
</table>
</div>
`;
// Create temp element for PDF export
const tempDiv = document.createElement('div');
tempDiv.id = 'temp-export-content';
tempDiv.innerHTML = reportHTML;
tempDiv.style.position = 'absolute';
tempDiv.style.left = '-9999px';
document.body.appendChild(tempDiv);
exportToPDF('temp-export-content', `${filename}-full`);
setTimeout(() => {
document.body.removeChild(tempDiv);
}, 1000);
};
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="sm">
<Download className="w-4 h-4 mr-2" />
Eksporter
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="bg-card border-border">
<DropdownMenuItem onClick={handleExportCSV} className="cursor-pointer">
<FileSpreadsheet className="w-4 h-4 mr-2" />
Eksporter CSV
</DropdownMenuItem>
<DropdownMenuItem onClick={handleExportJSON} className="cursor-pointer">
<FileJson className="w-4 h-4 mr-2" />
Eksporter JSON
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={handleExportPDF} className="cursor-pointer">
<FileText className="w-4 h-4 mr-2" />
Eksporter PDF (denne side)
</DropdownMenuItem>
<DropdownMenuItem onClick={handleExportFullReport} className="cursor-pointer">
<FileText className="w-4 h-4 mr-2" />
Fuld rapport (PDF)
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
};
export default ExportMenu;
|