wip
This commit is contained in:
parent
2b36992be1
commit
25087d055c
16 changed files with 1394 additions and 816 deletions
56
app/static/js/api-functions.js
Normal file
56
app/static/js/api-functions.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
// API Functions for reuse across the application
|
||||
const apiFunctions = {
|
||||
// Create a new location
|
||||
createLocation: function (name, description, csrfToken) {
|
||||
return fetch('/api/locations', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
body: JSON.stringify({
|
||||
name: name,
|
||||
description: description
|
||||
})
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to create location');
|
||||
}
|
||||
return response.json();
|
||||
});
|
||||
},
|
||||
|
||||
// Create a new subnet
|
||||
createSubnet: function (cidr, locationId, autoScan, csrfToken) {
|
||||
return fetch('/api/subnets', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRFToken': csrfToken
|
||||
},
|
||||
body: JSON.stringify({
|
||||
cidr: cidr,
|
||||
location_id: locationId,
|
||||
auto_scan: autoScan
|
||||
})
|
||||
})
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to create subnet');
|
||||
}
|
||||
return response.json();
|
||||
});
|
||||
},
|
||||
|
||||
// Get all subnets
|
||||
getSubnets: function () {
|
||||
return fetch('/api/subnets')
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to load subnets');
|
||||
}
|
||||
return response.json();
|
||||
});
|
||||
}
|
||||
};
|
53
app/static/js/sidebar.js
Normal file
53
app/static/js/sidebar.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
// Function to load subnets in the sidebar
|
||||
function loadSubnets() {
|
||||
fetch('/api/subnets')
|
||||
.then(response => {
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok');
|
||||
}
|
||||
return response.json();
|
||||
})
|
||||
.then(data => {
|
||||
// Update the sidebar with the fetched subnets
|
||||
const subnetList = document.getElementById('subnet-list');
|
||||
subnetList.innerHTML = ''; // Clear existing items
|
||||
|
||||
if (data.length === 0) {
|
||||
subnetList.innerHTML = '<div class="nav-item"><span class="nav-link">No subnets found</span></div>';
|
||||
return;
|
||||
}
|
||||
|
||||
data.forEach(site => {
|
||||
// Create site header if it has subnets
|
||||
if (site.subnets && site.subnets.length > 0) {
|
||||
const siteHeader = document.createElement('div');
|
||||
siteHeader.className = 'nav-item';
|
||||
siteHeader.innerHTML = `<span class="nav-link text-muted">${site.name || 'Unassigned'}</span>`;
|
||||
subnetList.appendChild(siteHeader);
|
||||
|
||||
// Add each subnet under this site
|
||||
site.subnets.forEach(subnet => {
|
||||
const subnetItem = document.createElement('div');
|
||||
subnetItem.className = 'nav-item';
|
||||
subnetItem.innerHTML = `
|
||||
<a href="/ipam/subnet/${subnet.id}" class="nav-link">
|
||||
<span class="nav-link-icon">
|
||||
<i class="ti ti-network"></i>
|
||||
</span>
|
||||
<span>${subnet.cidr}</span>
|
||||
</a>
|
||||
`;
|
||||
subnetList.appendChild(subnetItem);
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error loading subnets:', error);
|
||||
const subnetList = document.getElementById('subnet-list');
|
||||
subnetList.innerHTML = '<div class="nav-item text-danger">Error loading subnets</div>';
|
||||
});
|
||||
}
|
||||
|
||||
// Call this function when the page loads
|
||||
document.addEventListener('DOMContentLoaded', loadSubnets);
|
Loading…
Add table
Add a link
Reference in a new issue