|
|
@@ -22,34 +22,43 @@
|
|
|
}
|
|
|
|
|
|
async function fetchTableData(tableName) {
|
|
|
- const response = await fetch(`/category-data?categoryName=${tableName}`); // Backend endpoint for table data
|
|
|
- const tableData = await response.json();
|
|
|
- const tableBody = document.getElementById('table-body');
|
|
|
-
|
|
|
- // Populate the right-side table with data
|
|
|
- tableBody.innerHTML = '';
|
|
|
- tableData.forEach(row => {
|
|
|
- const tableRow = document.createElement('tr');
|
|
|
- // 显示 id 和 categoryName
|
|
|
- const cells = [row.id, row.categoryName];
|
|
|
- cells.forEach(value => {
|
|
|
- const cell = document.createElement('td');
|
|
|
- cell.textContent = value;
|
|
|
- tableRow.appendChild(cell);
|
|
|
- });
|
|
|
+ const response = await fetch(`/category-data?categoryName=${tableName}`);
|
|
|
+ const tableData = await response.json();
|
|
|
+ const tableBody = document.getElementById('table-body');
|
|
|
|
|
|
- // Add the download button in the last column
|
|
|
- const downloadCell = document.createElement('td');
|
|
|
- const downloadButton = document.createElement('button');
|
|
|
+ // Populate the right-side table with data
|
|
|
+ tableBody.innerHTML = '';
|
|
|
+ tableData.forEach(row => {
|
|
|
+ const tableRow = document.createElement('tr');
|
|
|
|
|
|
- downloadButton.textContent = 'Download';
|
|
|
- downloadButton.onclick = () => downloadFile(row.categoryName); // Assuming row[1] is the filename
|
|
|
- downloadCell.appendChild(downloadButton);
|
|
|
- tableRow.appendChild(downloadCell);
|
|
|
+ // Display id and categoryName
|
|
|
+ const cells = [row.id, row.categoryName];
|
|
|
+ cells.forEach(value => {
|
|
|
+ const cell = document.createElement('td');
|
|
|
+ cell.textContent = value;
|
|
|
+ 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);
|
|
|
+ downloadCell.appendChild(downloadButton);
|
|
|
+
|
|
|
+ // Add the delete button in the last column
|
|
|
+ const deleteCell = document.createElement('td');
|
|
|
+ const deleteButton = document.createElement('button');
|
|
|
+ deleteButton.textContent = 'Delete';
|
|
|
+ deleteButton.onclick = () => deleteRow(tableName, row.id); // Pass the table name and row id
|
|
|
+ deleteCell.appendChild(deleteButton);
|
|
|
+
|
|
|
+ tableRow.appendChild(downloadCell);
|
|
|
+ tableRow.appendChild(deleteCell);
|
|
|
+ tableBody.appendChild(tableRow);
|
|
|
+ });
|
|
|
+}
|
|
|
|
|
|
- tableBody.appendChild(tableRow);
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
async function downloadFile(filename) {
|
|
|
const response = await fetch(`/download/${filename}`, {
|
|
|
@@ -105,6 +114,24 @@
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Function to handle file deletion
|
|
|
+ // Function to handle delete
|
|
|
+ async function deleteRow(tableName, rowId) {
|
|
|
+ const confirmation = confirm('Are you sure you want to delete this row?');
|
|
|
+ if (confirmation) {
|
|
|
+ const response = await fetch(`/delete_files?tableName=${tableName}&rowId=${rowId}`, {
|
|
|
+ method: 'DELETE',
|
|
|
+ });
|
|
|
+
|
|
|
+ if (response.ok) {
|
|
|
+ alert('Row deleted successfully!');
|
|
|
+ fetchTableData(tableName); // Reload the table data after deletion
|
|
|
+ } else {
|
|
|
+ alert('Failed to delete the row');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// Initial load
|
|
|
document.addEventListener('DOMContentLoaded', fetchCategories);
|
|
|
</script>
|
|
|
@@ -219,8 +246,9 @@
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<th>ID</th>
|
|
|
- <th>Category Name</th>
|
|
|
+ <th>文件名</th>
|
|
|
<th>操作</th>
|
|
|
+ <th>删除</th> <!-- Added Delete column -->
|
|
|
</tr>
|
|
|
</thead>
|
|
|
<tbody id="table-body">
|