Skip to content

Commit

Permalink
code refact
Browse files Browse the repository at this point in the history
  • Loading branch information
EdiWang committed Sep 14, 2023
1 parent 16e4698 commit fe43265
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
25 changes: 1 addition & 24 deletions src/Moonglade.Web/Pages/Admin/Category.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
}

@section scripts{
<script src="~/js/app/dataexport.js"></script>
<script>
var editCanvas = new bootstrap.Offcanvas(document.getElementById('editCatCanvas'));
var catId = window.emptyGuid;
Expand Down Expand Up @@ -89,30 +90,6 @@
return csvRows.join('\n');
}
function downloadCSV(csvData, filename) {
const blob = new Blob([csvData], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.setAttribute('hidden', '');
a.setAttribute('href', url);
a.setAttribute('download', filename);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}
function exportCSV(api, filename) {
fetch(api)
.then(response => response.json())
.then(data => {
const csvData = convertJSONtoCSV(data);
downloadCSV(csvData, filename);
})
.catch(error => {
console.error('Error:', error);
});
}
</script>
}

Expand Down
23 changes: 23 additions & 0 deletions src/Moonglade.Web/wwwroot/js/app/dataexport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function downloadCSV(csvData, filename) {
const blob = new Blob([csvData], { type: 'text/csv' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.setAttribute('hidden', '');
a.setAttribute('href', url);
a.setAttribute('download', filename);
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
}

function exportCSV(api, filename) {
fetch(api)
.then(response => response.json())
.then(data => {
const csvData = convertJSONtoCSV(data);
downloadCSV(csvData, filename);
})
.catch(error => {
console.error('Error:', error);
});
}

0 comments on commit fe43265

Please sign in to comment.