55 lines
1.6 KiB
JavaScript
55 lines
1.6 KiB
JavaScript
document.addEventListener('DOMContentLoaded', function() {
|
|
fetchRoutes();
|
|
});
|
|
|
|
async function fetchRoutes() {
|
|
try {
|
|
const response = await fetch('/api/v1/admin/routes');
|
|
const routes = await response.json();
|
|
populateTable(routes);
|
|
} catch (error) {
|
|
console.error('Error fetching routes:', error);
|
|
}
|
|
}
|
|
|
|
const deleteRoute = async (id) => {
|
|
// Confirm deletion
|
|
if (!confirm('Are you sure you want to delete this route?')) {
|
|
return;
|
|
}
|
|
try {
|
|
const response = await fetch(`/api/v1/admin/route/${id}`, {
|
|
method: 'DELETE'
|
|
});
|
|
if (response.status === 200) {
|
|
fetchRoutes();
|
|
}
|
|
} catch (error) {
|
|
console.error('Error deleting route:', error);
|
|
}
|
|
}
|
|
|
|
function populateTable(routes) {
|
|
const tableBody = document.querySelector('#adminTable tbody');
|
|
if (!tableBody) return;
|
|
|
|
tableBody.innerHTML = '';
|
|
|
|
routes.forEach(route => {
|
|
const row = document.createElement('tr');
|
|
row.className = 'table-dark';
|
|
row.innerHTML = `
|
|
<td class="text-light">${route.id || ''}</td>
|
|
<td class="text-light">${route.server}:${route.port || ''}</td>
|
|
<td class="text-light">${route.auth || ''}</td>
|
|
<td class="text-light">${route.secret || ''}</td>
|
|
<td class="text-light">${route.block_start || ''} - ${route.block_start + route.block_length || ''}</td>
|
|
<td class="text-light">${route.apiKey || ''}</td>
|
|
<td>
|
|
<button class="btn btn-sm btn-outline-primary edit-btn" onclick="window.location.href = '/admin/route/${route.id}'" data-id="${route.id}">Edit</button>
|
|
<button class="btn btn-sm btn-outline-danger delete-btn" onclick="deleteRoute(${route.id})" data-id="${route.id}">Delete</button>
|
|
</td>
|
|
`;
|
|
tableBody.appendChild(row);
|
|
});
|
|
} |