Merge branch 'Dashboard/fix-export' into 'master'
fixed export of dashboard See merge request fronk/thetool!1825
This commit is contained in:
@@ -459,16 +459,6 @@ class DashboardNewController extends mfBaseController {
|
||||
self::returnJson($export_data);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//Installationsfortschritt Provider
|
||||
//
|
||||
|
||||
|
||||
// jasmin wegkommt
|
||||
// psc raaba 0316 67 33 00 zollweg michael (
|
||||
// zollweg michael
|
||||
|
||||
private function getTimeline($type, $campaign_ids, $gemeinde_ids) { //TODO: fix gemeinde
|
||||
$timeline = [];
|
||||
$baseParams = ["preordercampaign_id" => $campaign_ids, "gemeinde_id" => $gemeinde_ids];
|
||||
|
||||
@@ -675,21 +675,35 @@ Vue.component('dashboard-new', {
|
||||
},
|
||||
async csvExport() {
|
||||
this.isLoading = true;
|
||||
let objectUrl = null;
|
||||
try {
|
||||
const response = await axios.get(`${window.TT_CONFIG['BASE_URL']}/export`);
|
||||
const { data } = await axios.get(`${window.TT_CONFIG['BASE_URL']}/export`);
|
||||
if (!data?.length) return console.warn('No data available to export.');
|
||||
|
||||
const csvData = response.data;
|
||||
const csvContent = "data:text/csv;charset=utf-8," + [Object.keys(csvData[0]), ...csvData.map(obj => Object.keys(csvData[0]).map(header => obj[header]))].map(e => e.join(";")).join("\n");
|
||||
const encodedUri = "\uFEFF" + encodeURI(csvContent);
|
||||
const link = document.createElement("a");
|
||||
link.setAttribute("href", encodedUri);
|
||||
link.setAttribute("download", `Statistik_${new Date().toISOString()}.csv`);
|
||||
document.body.appendChild(link); // Required for FF
|
||||
const headers = Object.keys(data[0]);
|
||||
const csvContent = [
|
||||
headers.join(';'),
|
||||
...data.map(row => headers.map(header => {
|
||||
const cell = String(row[header] ?? ''); // Ensure value is a string, default to empty
|
||||
return /[";\n]/.test(cell) ? `"${cell.replace(/"/g, '""')}"` : cell;
|
||||
}).join(';'))
|
||||
].join('\n');
|
||||
|
||||
const blob = new Blob(['\uFEFF' + csvContent], { type: 'text/csv;charset=utf-8;' });
|
||||
objectUrl = URL.createObjectURL(blob);
|
||||
const link = Object.assign(document.createElement('a'), {
|
||||
href: objectUrl,
|
||||
download: `Statistik_${new Date().toISOString().slice(0, 10)}.csv`
|
||||
});
|
||||
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
link.remove(); // More modern than removeChild(link)
|
||||
} catch (error) {
|
||||
console.error('Error exporting CSV:', error);
|
||||
} finally {
|
||||
this.isLoading = false;
|
||||
if (objectUrl) URL.revokeObjectURL(objectUrl);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user