|
@@ -15,15 +15,14 @@
|
|
|
categoryList.innerHTML = '';
|
|
categoryList.innerHTML = '';
|
|
|
categories.forEach(category => {
|
|
categories.forEach(category => {
|
|
|
const listItem = document.createElement('li');
|
|
const listItem = document.createElement('li');
|
|
|
- listItem.textContent = category.name;
|
|
|
|
|
- listItem.onclick = () => fetchTableData(category.table_name);
|
|
|
|
|
|
|
+ listItem.textContent = category.categoryName;
|
|
|
|
|
+ listItem.onclick = () => fetchTableData(category.categoryName);
|
|
|
categoryList.appendChild(listItem);
|
|
categoryList.appendChild(listItem);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // Fetch table data when a category is clicked
|
|
|
|
|
async function fetchTableData(tableName) {
|
|
async function fetchTableData(tableName) {
|
|
|
- const response = await fetch(`/table-data?table=${tableName}`); // Backend endpoint for table data
|
|
|
|
|
|
|
+ const response = await fetch(`/category-data?categoryName=${tableName}`); // Backend endpoint for table data
|
|
|
const tableData = await response.json();
|
|
const tableData = await response.json();
|
|
|
const tableBody = document.getElementById('table-body');
|
|
const tableBody = document.getElementById('table-body');
|
|
|
|
|
|
|
@@ -31,15 +30,56 @@
|
|
|
tableBody.innerHTML = '';
|
|
tableBody.innerHTML = '';
|
|
|
tableData.forEach(row => {
|
|
tableData.forEach(row => {
|
|
|
const tableRow = document.createElement('tr');
|
|
const tableRow = document.createElement('tr');
|
|
|
- Object.values(row).forEach(value => {
|
|
|
|
|
|
|
+ Object.values(row).forEach((value) => {
|
|
|
const cell = document.createElement('td');
|
|
const cell = document.createElement('td');
|
|
|
cell.textContent = value;
|
|
cell.textContent = value;
|
|
|
tableRow.appendChild(cell);
|
|
tableRow.appendChild(cell);
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
|
|
+ // Add the download button in the last column
|
|
|
|
|
+ const downloadCell = document.createElement('td');
|
|
|
|
|
+ const downloadButton = document.createElement('button');
|
|
|
|
|
+
|
|
|
|
|
+ downloadButton.textContent = 'Download';
|
|
|
|
|
+ downloadButton.onclick = () => downloadFile(row.categoryName); // Assuming row[1] is the filename
|
|
|
|
|
+ downloadCell.appendChild(downloadButton);
|
|
|
|
|
+ tableRow.appendChild(downloadCell);
|
|
|
|
|
+
|
|
|
tableBody.appendChild(tableRow);
|
|
tableBody.appendChild(tableRow);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ async function downloadFile(filename) {
|
|
|
|
|
+ const response = await fetch(`/download/${filename}`, {
|
|
|
|
|
+ method: 'GET',
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ 'Content-Type': 'application/json'
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ if (response.ok) {
|
|
|
|
|
+ // Create a blob from the response
|
|
|
|
|
+ const blob = await response.blob();
|
|
|
|
|
+
|
|
|
|
|
+ // Create a link element
|
|
|
|
|
+ const link = document.createElement('a');
|
|
|
|
|
+ link.href = URL.createObjectURL(blob);
|
|
|
|
|
+ link.download = filename;
|
|
|
|
|
+
|
|
|
|
|
+ // Append the link to the body (it needs to be in the DOM to work)
|
|
|
|
|
+ document.body.appendChild(link);
|
|
|
|
|
+
|
|
|
|
|
+ // Programmatically trigger the download
|
|
|
|
|
+ link.click();
|
|
|
|
|
+
|
|
|
|
|
+ // Clean up the DOM
|
|
|
|
|
+ document.body.removeChild(link);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ console.error('Failed to download the file');
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
// Initial load
|
|
// Initial load
|
|
|
document.addEventListener('DOMContentLoaded', fetchCategories);
|
|
document.addEventListener('DOMContentLoaded', fetchCategories);
|
|
|
</script>
|
|
</script>
|