This commit is contained in:
pika 2025-03-30 21:52:20 +02:00
parent f939933a7c
commit be6f7cfcbb
35 changed files with 1897 additions and 733 deletions

View file

@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ title if title else 'Network Documentation' }}</title>
<title>{{ title|default('Network Infrastructure Management') }}</title>
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- Tabler Icons -->
@ -15,6 +15,12 @@
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<!-- Custom CSS -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/app.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/tabler.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='libs/tabler-icons/tabler-icons.min.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/custom.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/markdown.css') }}">
<!-- Favicon -->
<link rel="icon" type="image/png" href="{{ url_for('static', filename='img/favicon.png') }}">
{% block styles %}{% endblock %}
<script>
// Check for saved theme preference or respect OS preference
@ -31,6 +37,71 @@
// Run before page load to prevent flash
initTheme();
</script>
<style>
.sidebar-item-parent {
position: relative;
}
.sidebar-submenu {
display: none;
padding-left: 20px;
font-size: 0.9em;
}
.sidebar-item-parent.expanded .sidebar-submenu {
display: block;
}
.sidebar-item-parent.expanded .toggle-icon {
transform: rotate(180deg);
}
.subnet-item,
.server-item {
padding: 5px 10px;
margin: 2px 0;
border-radius: 4px;
cursor: pointer;
display: flex;
align-items: center;
text-decoration: none;
color: inherit;
}
.subnet-item:hover,
.server-item:hover {
background-color: rgba(0, 0, 0, 0.05);
}
.subnet-item.active,
.server-item.active {
background-color: rgba(0, 0, 0, 0.1);
}
.subnet-servers {
margin-left: 15px;
display: none;
}
.subnet-item-expanded .subnet-servers {
display: block;
}
.subnet-item-expanded .subnet-toggle-icon {
transform: rotate(90deg);
}
.subnet-toggle-icon {
transition: transform 0.2s ease;
margin-right: 5px;
}
.loading-placeholder {
color: #888;
font-style: italic;
padding: 5px 15px;
}
</style>
</head>
<body class="{{ 'auth-page' if not current_user.is_authenticated else '' }}">
@ -55,10 +126,25 @@
class="sidebar-item {{ 'active' if request.endpoint and request.endpoint.startswith('dashboard.server') }}">
<span class="ti ti-server me-2"></span> Servers
</a>
<a href="{{ url_for('ipam.ipam_home') }}"
class="sidebar-item {{ 'active' if request.endpoint and request.endpoint.startswith('ipam.') }}">
<span class="ti ti-network me-2"></span> IPAM
</a>
<!-- IPAM with Subnet Tree -->
<div class="sidebar-item-parent">
<a href="{{ url_for('ipam.ipam_home') }}"
class="sidebar-item {{ 'active' if request.endpoint and request.endpoint.startswith('ipam.') }}">
<span class="ti ti-network me-2"></span> IPAM
<span class="ti ti-chevron-down ms-auto toggle-icon"></span>
</a>
<div class="sidebar-submenu">
<div id="subnet-tree-container">
<!-- Subnets will be loaded here -->
<div class="text-center py-2 d-none" id="subnet-loader">
<div class="spinner-border spinner-border-sm" role="status">
<span class="visually-hidden">Loading...</span>
</div>
</div>
</div>
</div>
</div>
<div class="sidebar-heading">Management</div>
<a href="{{ url_for('dashboard.server_new') }}" class="sidebar-item">
@ -69,6 +155,10 @@
</a>
<div class="sidebar-heading">User</div>
<a href="{{ url_for('dashboard.settings') }}"
class="sidebar-item {{ 'active' if request.endpoint == 'dashboard.settings' }}">
<span class="ti ti-settings me-2"></span> Settings
</a>
<a href="{{ url_for('auth.logout') }}" class="sidebar-item">
<span class="ti ti-logout me-2"></span> Logout
</a>
@ -162,6 +252,130 @@
});
}
</script>
<script>
document.addEventListener('DOMContentLoaded', function () {
// Toggle sidebar submenus
document.querySelectorAll('.sidebar-item-parent > a').forEach(item => {
item.addEventListener('click', function (e) {
e.preventDefault();
const parent = this.parentElement;
parent.classList.toggle('expanded');
// Load subnet data when IPAM is expanded
if (parent.classList.contains('expanded') && this.textContent.includes('IPAM')) {
loadSubnets();
}
});
});
function loadSubnets() {
const subnetContainer = document.getElementById('subnet-tree-container');
const loader = document.getElementById('subnet-loader');
if (!loader || !subnetContainer) return;
// Show loader
loader.classList.remove('d-none');
// Fetch subnets
fetch('/api/subnets')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(subnets => {
loader.classList.add('d-none');
if (subnets.length === 0) {
subnetContainer.innerHTML = '<div class="text-muted px-3 py-2">No subnets found</div>';
return;
}
let html = '';
subnets.forEach(subnet => {
html += `
<div class="subnet-item-container">
<div class="subnet-item" data-subnet-id="${subnet.id}">
<span class="ti ti-chevron-right subnet-toggle-icon me-1"></span>
<a href="/ipam/subnet/${subnet.id}" class="text-reset text-decoration-none flex-grow-1">
${subnet.cidr} (${subnet.location})
</a>
</div>
<div class="subnet-servers d-none" id="subnet-servers-${subnet.id}">
<div class="text-muted px-3 py-2">Loading servers...</div>
</div>
</div>
`;
});
subnetContainer.innerHTML = html;
// Add click handlers to subnet items
document.querySelectorAll('.subnet-item').forEach(item => {
item.querySelector('.subnet-toggle-icon').addEventListener('click', function (e) {
e.preventDefault();
e.stopPropagation();
const subnetId = item.dataset.subnetId;
const serversContainer = document.getElementById(`subnet-servers-${subnetId}`);
serversContainer.classList.toggle('d-none');
if (!serversContainer.classList.contains('d-none') &&
serversContainer.querySelector('.text-muted')) {
loadServersForSubnet(subnetId);
}
// Toggle icon
this.classList.toggle('ti-chevron-right');
this.classList.toggle('ti-chevron-down');
});
});
})
.catch(error => {
console.error('Error loading subnets:', error);
loader.classList.add('d-none');
subnetContainer.innerHTML = '<div class="text-danger px-3 py-2">Error loading subnets</div>';
});
}
function loadServersForSubnet(subnetId) {
const serversContainer = document.getElementById(`subnet-servers-${subnetId}`);
// Fetch servers for this subnet
fetch(`/api/subnets/${subnetId}/servers`)
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(servers => {
if (servers.length === 0) {
serversContainer.innerHTML = '<div class="text-muted px-3 py-2">No servers in this subnet</div>';
return;
}
let html = '';
servers.forEach(server => {
html += `
<a href="/dashboard/server/${server.id}" class="server-item d-block ps-4 py-1">
<span class="ti ti-server me-1 small"></span>
${server.hostname} (${server.ip_address})
</a>
`;
});
serversContainer.innerHTML = html;
})
.catch(error => {
console.error('Error loading servers:', error);
serversContainer.innerHTML = '<div class="text-danger px-3 py-2">Error loading servers</div>';
});
}
});
</script>
{% block scripts %}{% endblock %}
</body>