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);
|
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
|
private function getTimeline($type, $campaign_ids, $gemeinde_ids) { //TODO: fix gemeinde
|
||||||
$timeline = [];
|
$timeline = [];
|
||||||
$baseParams = ["preordercampaign_id" => $campaign_ids, "gemeinde_id" => $gemeinde_ids];
|
$baseParams = ["preordercampaign_id" => $campaign_ids, "gemeinde_id" => $gemeinde_ids];
|
||||||
|
|||||||
@@ -675,21 +675,35 @@ Vue.component('dashboard-new', {
|
|||||||
},
|
},
|
||||||
async csvExport() {
|
async csvExport() {
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
|
let objectUrl = null;
|
||||||
try {
|
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 headers = Object.keys(data[0]);
|
||||||
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 csvContent = [
|
||||||
const encodedUri = "\uFEFF" + encodeURI(csvContent);
|
headers.join(';'),
|
||||||
const link = document.createElement("a");
|
...data.map(row => headers.map(header => {
|
||||||
link.setAttribute("href", encodedUri);
|
const cell = String(row[header] ?? ''); // Ensure value is a string, default to empty
|
||||||
link.setAttribute("download", `Statistik_${new Date().toISOString()}.csv`);
|
return /[";\n]/.test(cell) ? `"${cell.replace(/"/g, '""')}"` : cell;
|
||||||
document.body.appendChild(link); // Required for FF
|
}).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.click();
|
||||||
|
link.remove(); // More modern than removeChild(link)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error exporting CSV:', error);
|
console.error('Error exporting CSV:', error);
|
||||||
} finally {
|
} finally {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
|
if (objectUrl) URL.revokeObjectURL(objectUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user