refactor: 🎨 js
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
function showAddSubnetModal() {
|
||||
document.getElementById('add-subnet-modal').classList.remove('hidden');
|
||||
document.getElementById('add-subnet-name').value = '';
|
||||
document.getElementById('add-subnet-cidr').value = '';
|
||||
document.getElementById('add-subnet-site').value = '';
|
||||
}
|
||||
|
||||
function closeAddSubnetModal() {
|
||||
document.getElementById('add-subnet-modal').classList.add('hidden');
|
||||
document.getElementById('cidr-error').classList.add('hidden');
|
||||
}
|
||||
|
||||
function editSubnet(subnetId, name, cidr, site) {
|
||||
document.getElementById('edit-subnet-id').value = subnetId;
|
||||
document.getElementById('edit-subnet-name').value = name;
|
||||
document.getElementById('edit-subnet-cidr').value = cidr;
|
||||
document.getElementById('edit-subnet-site').value = site;
|
||||
document.getElementById('edit-subnet-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeEditSubnetModal() {
|
||||
document.getElementById('edit-subnet-modal').classList.add('hidden');
|
||||
document.getElementById('edit-cidr-error').classList.add('hidden');
|
||||
}
|
||||
|
||||
function validateEditSubnetForm() {
|
||||
const cidrInput = document.getElementById('edit-subnet-cidr');
|
||||
const cidrError = document.getElementById('edit-cidr-error');
|
||||
const cidr = cidrInput.value.trim();
|
||||
|
||||
// Basic CIDR validation
|
||||
const cidrPattern = /^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/;
|
||||
if (!cidrPattern.test(cidr)) {
|
||||
cidrError.textContent = 'Invalid CIDR format. Use format like 192.168.1.0/24';
|
||||
cidrError.classList.remove('hidden');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check prefix length
|
||||
const parts = cidr.split('/');
|
||||
if (parts.length === 2) {
|
||||
const prefixLen = parseInt(parts[1]);
|
||||
if (prefixLen < 24 || prefixLen > 32) {
|
||||
cidrError.textContent = 'Subnet must be /24 or smaller (e.g., /24, /25, ... /32)';
|
||||
cidrError.classList.remove('hidden');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cidrError.classList.add('hidden');
|
||||
return true;
|
||||
}
|
||||
|
||||
// Close modals when clicking outside
|
||||
window.onclick = function(event) {
|
||||
const addModal = document.getElementById('add-subnet-modal');
|
||||
const editModal = document.getElementById('edit-subnet-modal');
|
||||
if (event.target === addModal) {
|
||||
closeAddSubnetModal();
|
||||
}
|
||||
if (event.target === editModal) {
|
||||
closeEditSubnetModal();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Filter toggle functionality
|
||||
const filterToggle = document.getElementById('filter-toggle');
|
||||
const filterForm = document.getElementById('audit-filter-form');
|
||||
const filterArrow = document.getElementById('filter-arrow');
|
||||
|
||||
if (filterToggle && filterForm && filterArrow) {
|
||||
filterToggle.addEventListener('click', function() {
|
||||
filterForm.classList.toggle('hidden');
|
||||
// Toggle rotation using inline style for better compatibility
|
||||
if (filterForm.classList.contains('hidden')) {
|
||||
filterArrow.style.transform = 'rotate(0deg)';
|
||||
} else {
|
||||
filterArrow.style.transform = 'rotate(180deg)';
|
||||
}
|
||||
});
|
||||
|
||||
// Set initial arrow rotation if form is visible (has active filters or expand_filters param)
|
||||
if (!filterForm.classList.contains('hidden')) {
|
||||
filterArrow.style.transform = 'rotate(180deg)';
|
||||
}
|
||||
}
|
||||
|
||||
// Format timestamps
|
||||
document.querySelectorAll('td[data-utc]').forEach(function(td) {
|
||||
const utc = td.getAttribute('data-utc');
|
||||
if (utc) {
|
||||
const date = new Date(utc + 'Z');
|
||||
td.textContent = date.toLocaleString();
|
||||
}
|
||||
});
|
||||
|
||||
// Parse and display visual diffs
|
||||
document.querySelectorAll('.diff-container').forEach(function(container) {
|
||||
const details = container.getAttribute('data-details');
|
||||
if (!details) return;
|
||||
|
||||
// Try to parse common change patterns
|
||||
let html = details;
|
||||
|
||||
// Pattern 1: "Changed X from 'old' to 'new'"
|
||||
html = html.replace(/Changed (.+?) from ['"](.+?)['"] to ['"](.+?)['"]/gi, function(match, field, oldVal, newVal) {
|
||||
return `Changed ${field} from <span class="diff-removed">${oldVal}</span> to <span class="diff-added">${newVal}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 2: "Renamed X to Y"
|
||||
html = html.replace(/Renamed (.+?) to ['"](.+?)['"]/gi, function(match, oldVal, newVal) {
|
||||
return `Renamed <span class="diff-removed">${oldVal}</span> to <span class="diff-added">${newVal}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 3: "Updated X: old -> new"
|
||||
html = html.replace(/Updated (.+?):\s*(.+?)\s*->\s*(.+?)(?:\s|$)/gi, function(match, field, oldVal, newVal) {
|
||||
return `Updated ${field}: <span class="diff-removed">${oldVal}</span> → <span class="diff-added">${newVal}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 4: "Set X to Y" (when it was previously something else, look for context)
|
||||
html = html.replace(/Set (.+?) to ['"](.+?)['"]/gi, function(match, field, newVal) {
|
||||
return `Set ${field} to <span class="diff-added">${newVal}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 5: "Removed X" or "Deleted X"
|
||||
html = html.replace(/(Removed|Deleted) ['"](.+?)['"]/gi, function(match, action, val) {
|
||||
return `${action} <span class="diff-removed">${val}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 6: "Added X"
|
||||
html = html.replace(/Added ['"](.+?)['"]/gi, function(match, val) {
|
||||
return `Added <span class="diff-added">${val}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 7: "Assigned X to Y" or "Unassigned X from Y"
|
||||
html = html.replace(/(Assigned|Unassigned) (.+?) (to|from) (.+?)(?:\s|$)/gi, function(match, action, item, prep, target) {
|
||||
const actionClass = action === 'Assigned' ? 'diff-added' : 'diff-removed';
|
||||
return `${action} <span class="${actionClass}">${item}</span> ${prep} ${target}`;
|
||||
});
|
||||
|
||||
// Pattern 8: Generic "from X to Y" pattern
|
||||
html = html.replace(/from ['"](.+?)['"] to ['"](.+?)['"]/gi, function(match, oldVal, newVal) {
|
||||
return `from <span class="diff-removed">${oldVal}</span> to <span class="diff-added">${newVal}</span>`;
|
||||
});
|
||||
|
||||
container.innerHTML = html || details;
|
||||
});
|
||||
|
||||
// Export button handler
|
||||
const exportBtn = document.getElementById('export-btn');
|
||||
if (exportBtn) {
|
||||
exportBtn.addEventListener('click', function() {
|
||||
const form = document.getElementById('audit-filter-form');
|
||||
const formData = new FormData(form);
|
||||
const params = new URLSearchParams();
|
||||
|
||||
// Add all form fields to params
|
||||
for (const [key, value] of formData.entries()) {
|
||||
if (value) {
|
||||
if (key === 'user_ids') {
|
||||
// Handle multiple user_ids
|
||||
params.append('user_ids', value);
|
||||
} else {
|
||||
params.append(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle multiple user_ids separately
|
||||
const userSelect = form.querySelector('select[name="user_ids"]');
|
||||
if (userSelect) {
|
||||
const selectedUsers = Array.from(userSelect.selectedOptions).map(opt => opt.value);
|
||||
params.delete('user_ids');
|
||||
selectedUsers.forEach(userId => {
|
||||
params.append('user_ids', userId);
|
||||
});
|
||||
}
|
||||
|
||||
// Redirect to export endpoint
|
||||
window.location.href = '/audit/export_csv?' + params.toString();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,175 @@
|
||||
function showTab(tabName) {
|
||||
// Hide all panels
|
||||
document.querySelectorAll('.tab-panel').forEach(panel => panel.classList.add('hidden'));
|
||||
// Remove active class from all tabs
|
||||
document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
|
||||
// Show selected panel
|
||||
document.getElementById('panel-' + tabName).classList.remove('hidden');
|
||||
// Add active class to selected tab
|
||||
document.getElementById('tab-' + tabName).classList.add('active');
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Update selected IP count
|
||||
document.getElementById('bulk-ip-select')?.addEventListener('change', function() {
|
||||
document.getElementById('selected-ip-count').textContent = this.selectedOptions.length;
|
||||
});
|
||||
|
||||
document.getElementById('bulk-tag-device-select')?.addEventListener('change', function() {
|
||||
document.getElementById('selected-tag-device-count').textContent = this.selectedOptions.length;
|
||||
});
|
||||
|
||||
// Load available IPs when subnet changes
|
||||
document.getElementById('bulk-subnet-select')?.addEventListener('change', function() {
|
||||
const subnetId = this.value;
|
||||
const ipSelect = document.getElementById('bulk-ip-select');
|
||||
if (!subnetId) {
|
||||
ipSelect.innerHTML = '<option value="" disabled>Select a subnet first...</option>';
|
||||
document.getElementById('selected-ip-count').textContent = '0';
|
||||
return;
|
||||
}
|
||||
ipSelect.innerHTML = '<option value="" disabled>Loading...</option>';
|
||||
fetch(`/get_available_ips?subnet_id=${subnetId}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
ipSelect.innerHTML = '';
|
||||
if (data.available_ips.length === 0) {
|
||||
ipSelect.innerHTML = '<option value="" disabled>No available IPs in this subnet</option>';
|
||||
} else {
|
||||
data.available_ips.forEach(ip => {
|
||||
const option = document.createElement('option');
|
||||
option.value = ip.id;
|
||||
option.textContent = ip.ip;
|
||||
ipSelect.appendChild(option);
|
||||
});
|
||||
}
|
||||
document.getElementById('selected-ip-count').textContent = '0';
|
||||
})
|
||||
.catch(() => {
|
||||
ipSelect.innerHTML = '<option value="" disabled>Error loading IPs</option>';
|
||||
});
|
||||
});
|
||||
|
||||
// Bulk IP Assignment
|
||||
document.getElementById('bulk-assign-ips-form')?.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const formData = new FormData(this);
|
||||
const resultDiv = document.getElementById('assign-ips-result');
|
||||
resultDiv.classList.remove('hidden');
|
||||
resultDiv.innerHTML = '<p class="text-blue-500">Processing...</p>';
|
||||
|
||||
fetch('/bulk/assign_ips', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
let html = '<div class="space-y-2">';
|
||||
if (data.success.length > 0) {
|
||||
html += `<div class="text-green-600 dark:text-green-400"><strong>Successfully assigned ${data.success.length} IP(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.success.forEach(item => {
|
||||
html += `<li>${item.ip}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
if (data.failed.length > 0) {
|
||||
html += `<div class="text-red-600 dark:text-red-400"><strong>Failed ${data.failed.length} assignment(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.failed.forEach(item => {
|
||||
const ipDisplay = item.ip ? ` (${item.ip})` : '';
|
||||
html += `<li>IP ID ${item.ip_id}${ipDisplay}: ${item.reason}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
html += '</div>';
|
||||
resultDiv.innerHTML = html;
|
||||
// Reload IP list if successful
|
||||
if (data.success.length > 0) {
|
||||
const subnetSelect = document.getElementById('bulk-subnet-select');
|
||||
if (subnetSelect.value) {
|
||||
subnetSelect.dispatchEvent(new Event('change'));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
resultDiv.innerHTML = `<p class="text-red-600">Error: ${error.message}</p>`;
|
||||
});
|
||||
});
|
||||
|
||||
// Bulk Device Creation
|
||||
document.getElementById('bulk-create-devices-form')?.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const formData = new FormData(this);
|
||||
const resultDiv = document.getElementById('create-devices-result');
|
||||
resultDiv.classList.remove('hidden');
|
||||
resultDiv.innerHTML = '<p class="text-blue-500">Processing...</p>';
|
||||
|
||||
fetch('/bulk/create_devices', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
let html = '<div class="space-y-2">';
|
||||
if (data.success.length > 0) {
|
||||
html += `<div class="text-green-600 dark:text-green-400"><strong>Successfully created ${data.success.length} device(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.success.forEach(item => {
|
||||
html += `<li>${item.name}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
if (data.failed.length > 0) {
|
||||
html += `<div class="text-red-600 dark:text-red-400"><strong>Failed ${data.failed.length} creation(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.failed.forEach(item => {
|
||||
html += `<li>${item.name}: ${item.reason}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
html += '</div>';
|
||||
resultDiv.innerHTML = html;
|
||||
if (data.success.length > 0) {
|
||||
setTimeout(() => window.location.reload(), 2000);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
resultDiv.innerHTML = `<p class="text-red-600">Error: ${error.message}</p>`;
|
||||
});
|
||||
});
|
||||
|
||||
// Bulk Tag Assignment
|
||||
document.getElementById('bulk-assign-tags-form')?.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const formData = new FormData(this);
|
||||
const resultDiv = document.getElementById('assign-tags-result');
|
||||
resultDiv.classList.remove('hidden');
|
||||
resultDiv.innerHTML = '<p class="text-blue-500">Processing...</p>';
|
||||
|
||||
fetch('/bulk/assign_tags', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
let html = '<div class="space-y-2">';
|
||||
if (data.success.length > 0) {
|
||||
html += `<div class="text-green-600 dark:text-green-400"><strong>Successfully assigned ${data.success.length} tag(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.success.forEach(item => {
|
||||
html += `<li>${item.device_name}: ${item.tag_name}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
if (data.failed.length > 0) {
|
||||
html += `<div class="text-red-600 dark:text-red-400"><strong>Failed ${data.failed.length} assignment(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.failed.forEach(item => {
|
||||
html += `<li>Device ID ${item.device_id}, Tag ID ${item.tag_id}: ${item.reason}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
html += '</div>';
|
||||
resultDiv.innerHTML = html;
|
||||
})
|
||||
.catch(error => {
|
||||
resultDiv.innerHTML = `<p class="text-red-600">Error: ${error.message}</p>`;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Export CSV button
|
||||
const exportBtn = document.getElementById('export-csv');
|
||||
if (exportBtn) {
|
||||
exportBtn.addEventListener('click', function() {
|
||||
const rackId = exportBtn.getAttribute('data-rack-id');
|
||||
if (rackId) {
|
||||
window.location = '/rack/' + rackId + '/export_csv';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Form toggle functionality
|
||||
function showBothAddButtons() {
|
||||
document.getElementById('show-add-device-form').classList.remove('hidden');
|
||||
document.getElementById('show-nonnet-form').classList.remove('hidden');
|
||||
}
|
||||
|
||||
showBothAddButtons();
|
||||
|
||||
document.getElementById('show-nonnet-form').onclick = function() {
|
||||
document.getElementById('nonnet-form').classList.remove('hidden');
|
||||
this.classList.add('hidden');
|
||||
};
|
||||
|
||||
document.getElementById('hide-nonnet-form').onclick = function() {
|
||||
document.getElementById('nonnet-form').classList.add('hidden');
|
||||
showBothAddButtons();
|
||||
};
|
||||
|
||||
document.getElementById('show-add-device-form').onclick = function() {
|
||||
document.getElementById('add-device-form').classList.remove('hidden');
|
||||
this.classList.add('hidden');
|
||||
};
|
||||
|
||||
document.getElementById('hide-add-device-form').onclick = function() {
|
||||
document.getElementById('add-device-form').classList.add('hidden');
|
||||
showBothAddButtons();
|
||||
};
|
||||
});
|
||||
|
||||
+44
-27
@@ -1,38 +1,55 @@
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const form = document.querySelector('form');
|
||||
if (form) {
|
||||
form.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
});
|
||||
|
||||
const searchInput = document.createElement('input');
|
||||
searchInput.type = 'text';
|
||||
searchInput.placeholder = 'Search by IP or Hostname';
|
||||
searchInput.className = 'p-2 w-full rounded-lg bg-gray-200 dark:bg-zinc-800 border border-gray-600 focus:outline-none focus:border-blue-400 mb-4 text-center';
|
||||
form.insertAdjacentElement('beforebegin', searchInput);
|
||||
|
||||
searchInput.addEventListener('keypress', (event) => {
|
||||
if (event.key === 'Enter') {
|
||||
// Check if search input already exists to prevent duplicates
|
||||
if (!document.querySelector('input[placeholder="Search by IP or Hostname"]')) {
|
||||
form.addEventListener('submit', (event) => {
|
||||
event.preventDefault();
|
||||
const searchTerm = searchInput.value.toLowerCase();
|
||||
const rows = document.querySelectorAll('tbody tr');
|
||||
});
|
||||
|
||||
rows.forEach(row => {
|
||||
const ipCell = row.querySelector('td:nth-child(1)').textContent.toLowerCase();
|
||||
const hostnameCell = row.querySelector('td:nth-child(2)').textContent.toLowerCase();
|
||||
const searchInput = document.createElement('input');
|
||||
searchInput.type = 'text';
|
||||
searchInput.placeholder = 'Search by IP or Hostname';
|
||||
searchInput.className = 'p-2 w-full rounded-lg bg-gray-200 dark:bg-zinc-800 border border-gray-600 focus:outline-none focus:border-blue-400 mb-4 text-center';
|
||||
form.insertAdjacentElement('beforebegin', searchInput);
|
||||
|
||||
if (ipCell.includes(searchTerm) || hostnameCell.includes(searchTerm)) {
|
||||
row.style.backgroundColor = 'rgba(59, 130, 246, 0.5)';
|
||||
row.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
searchInput.addEventListener('keypress', (event) => {
|
||||
if (event.key === 'Enter') {
|
||||
event.preventDefault();
|
||||
const searchTerm = searchInput.value.toLowerCase();
|
||||
const rows = document.querySelectorAll('tbody tr');
|
||||
|
||||
setTimeout(() => {
|
||||
rows.forEach(row => {
|
||||
const ipCell = row.querySelector('td:nth-child(1)').textContent.toLowerCase();
|
||||
const hostnameCell = row.querySelector('td:nth-child(2)').textContent.toLowerCase();
|
||||
|
||||
if (ipCell.includes(searchTerm) || hostnameCell.includes(searchTerm)) {
|
||||
row.style.backgroundColor = 'rgba(59, 130, 246, 0.5)';
|
||||
row.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
||||
|
||||
setTimeout(() => {
|
||||
row.style.backgroundColor = '';
|
||||
}, 3000);
|
||||
} else {
|
||||
row.style.backgroundColor = '';
|
||||
}, 3000);
|
||||
} else {
|
||||
row.style.backgroundColor = '';
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Description toggle functionality
|
||||
const toggleBtn = document.getElementById('toggle-desc');
|
||||
const descCols = document.querySelectorAll('.desc-col');
|
||||
const descHeader = document.getElementById('desc-col-header');
|
||||
let shown = false;
|
||||
if (toggleBtn) {
|
||||
toggleBtn.addEventListener('click', function() {
|
||||
shown = !shown;
|
||||
descCols.forEach(col => col.classList.toggle('hidden', !shown));
|
||||
if (descHeader) descHeader.classList.toggle('hidden', !shown);
|
||||
toggleBtn.textContent = shown ? 'Hide Descriptions' : 'Show Descriptions';
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Check if toast was dismissed in this session
|
||||
const toastDismissed = sessionStorage.getItem('update-toast-dismissed');
|
||||
if (toastDismissed) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for updates
|
||||
fetch('/check_update')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.update_available) {
|
||||
const toast = document.getElementById('update-toast');
|
||||
const currentVersionEl = document.getElementById('toast-current-version');
|
||||
const latestVersionEl = document.getElementById('toast-latest-version');
|
||||
const compareLink = document.getElementById('toast-compare-link');
|
||||
const closeBtn = document.getElementById('toast-close');
|
||||
|
||||
// Set versions
|
||||
currentVersionEl.textContent = 'v' + data.current_version;
|
||||
latestVersionEl.textContent = 'v' + data.latest_version;
|
||||
|
||||
// Set compare link (current version to latest version)
|
||||
compareLink.href = `https://github.com/JDB-NET/ipam/compare/v${data.current_version}...v${data.latest_version}`;
|
||||
|
||||
// Show toast
|
||||
toast.classList.remove('hidden');
|
||||
|
||||
// Close button handler
|
||||
closeBtn.addEventListener('click', function() {
|
||||
toast.classList.add('hidden');
|
||||
sessionStorage.setItem('update-toast-dismissed', 'true');
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error checking for updates:', error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
// These variables are set inline in the template from server data
|
||||
// permissions and rolePermissions are passed from the template
|
||||
|
||||
function showTab(tab) {
|
||||
document.getElementById('users-tab').classList.add('hidden');
|
||||
document.getElementById('roles-tab').classList.add('hidden');
|
||||
document.getElementById('tab-users').classList.remove('border-blue-500', 'text-blue-600', 'dark:text-blue-400');
|
||||
document.getElementById('tab-users').classList.add('border-transparent', 'text-gray-600', 'dark:text-gray-400');
|
||||
document.getElementById('tab-roles').classList.remove('border-blue-500', 'text-blue-600', 'dark:text-blue-400');
|
||||
document.getElementById('tab-roles').classList.add('border-transparent', 'text-gray-600', 'dark:text-gray-400');
|
||||
|
||||
if (tab === 'users') {
|
||||
document.getElementById('users-tab').classList.remove('hidden');
|
||||
document.getElementById('tab-users').classList.remove('border-transparent', 'text-gray-600', 'dark:text-gray-400');
|
||||
document.getElementById('tab-users').classList.add('border-blue-500', 'text-blue-600', 'dark:text-blue-400');
|
||||
} else {
|
||||
document.getElementById('roles-tab').classList.remove('hidden');
|
||||
document.getElementById('tab-roles').classList.remove('border-transparent', 'text-gray-600', 'dark:text-gray-400');
|
||||
document.getElementById('tab-roles').classList.add('border-blue-500', 'text-blue-600', 'dark:text-blue-400');
|
||||
}
|
||||
}
|
||||
|
||||
function editUser(userId, name, email, roleId, apiKey) {
|
||||
document.getElementById('edit-user-id').value = userId;
|
||||
document.getElementById('edit-user-name').value = name;
|
||||
document.getElementById('edit-user-email').value = email;
|
||||
document.getElementById('edit-user-password').value = '';
|
||||
document.getElementById('edit-user-role').value = (roleId === null || roleId === 'null') ? '' : roleId;
|
||||
document.getElementById('edit-user-api-key').textContent = apiKey || 'No API Key';
|
||||
document.getElementById('edit-user-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeEditUserModal() {
|
||||
document.getElementById('edit-user-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
function showAddRoleModal() {
|
||||
// Make sure edit modal is closed first
|
||||
document.getElementById('edit-role-modal').classList.add('hidden');
|
||||
// Clear any form data
|
||||
const addForm = document.querySelector('#add-role-modal form');
|
||||
if (addForm) {
|
||||
addForm.reset();
|
||||
}
|
||||
// Show add modal
|
||||
document.getElementById('add-role-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeAddRoleModal() {
|
||||
document.getElementById('add-role-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
function editRole(roleId, roleName, roleDescription) {
|
||||
// Make sure add modal is closed first
|
||||
document.getElementById('add-role-modal').classList.add('hidden');
|
||||
document.getElementById('edit-role-id').value = roleId;
|
||||
document.getElementById('edit-role-name').value = roleName;
|
||||
document.getElementById('edit-role-description').value = roleDescription || '';
|
||||
|
||||
const permissionsDiv = document.getElementById('edit-role-permissions');
|
||||
permissionsDiv.innerHTML = '';
|
||||
|
||||
const rolePerms = rolePermissions[roleId] || [];
|
||||
|
||||
// Group permissions by merged categories
|
||||
const viewPerms = permissions.filter(p => p[3] === 'View');
|
||||
const devicePerms = permissions.filter(p => p[3] === 'Device');
|
||||
const deviceTypePerms = permissions.filter(p => p[3] === 'Device Type');
|
||||
const subnetPerms = permissions.filter(p => p[3] === 'Subnet');
|
||||
const dhcpPerms = permissions.filter(p => p[3] === 'DHCP');
|
||||
const rackPerms = permissions.filter(p => p[3] === 'Rack');
|
||||
const adminPerms = permissions.filter(p => p[3] === 'Admin');
|
||||
|
||||
let html = '';
|
||||
|
||||
// View Permissions
|
||||
html += ' <!-- View Permissions -->\n';
|
||||
html += ' <div class="col-span-full">\n';
|
||||
html += ' <h4 class="font-semibold text-base mb-2 border-b border-gray-500 pb-1">View Permissions</h4>\n';
|
||||
html += ' <div class="grid grid-cols-1 md:grid-cols-2 gap-2">\n';
|
||||
viewPerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
html += ' </div>\n';
|
||||
html += ' </div>\n';
|
||||
html += ' \n';
|
||||
|
||||
// Device Management
|
||||
html += ' <!-- Device Management -->\n';
|
||||
html += ' <div>\n';
|
||||
html += ' <h4 class="font-semibold text-base mb-2 border-b border-gray-500 pb-1">Device Management</h4>\n';
|
||||
devicePerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
deviceTypePerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
html += ' </div>\n';
|
||||
html += ' \n';
|
||||
|
||||
// Network Management
|
||||
html += ' <!-- Network Management -->\n';
|
||||
html += ' <div>\n';
|
||||
html += ' <h4 class="font-semibold text-base mb-2 border-b border-gray-500 pb-1">Network Management</h4>\n';
|
||||
subnetPerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
dhcpPerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
html += ' </div>\n';
|
||||
html += ' \n';
|
||||
|
||||
// Rack Management
|
||||
html += ' <!-- Rack Management -->\n';
|
||||
html += ' <div>\n';
|
||||
html += ' <h4 class="font-semibold text-base mb-2 border-b border-gray-500 pb-1">Rack Management</h4>\n';
|
||||
rackPerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
html += ' </div>\n';
|
||||
html += ' \n';
|
||||
|
||||
// Admin
|
||||
html += ' <!-- Admin -->\n';
|
||||
html += ' <div>\n';
|
||||
html += ' <h4 class="font-semibold text-base mb-2 border-b border-gray-500 pb-1">Administration</h4>\n';
|
||||
adminPerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
html += ' </div>\n';
|
||||
|
||||
permissionsDiv.innerHTML = html;
|
||||
|
||||
document.getElementById('edit-role-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeEditRoleModal() {
|
||||
document.getElementById('edit-role-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
function deleteRole(roleId, roleName) {
|
||||
if (confirm(`Are you sure you want to delete the role "${roleName}"?`)) {
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = '/users';
|
||||
form.innerHTML = `
|
||||
<input type="hidden" name="action" value="delete_role">
|
||||
<input type="hidden" name="role_id" value="${roleId}">
|
||||
`;
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
}
|
||||
}
|
||||
|
||||
// Close modals when clicking outside
|
||||
window.onclick = function(event) {
|
||||
const editUserModal = document.getElementById('edit-user-modal');
|
||||
const editRoleModal = document.getElementById('edit-role-modal');
|
||||
const addRoleModal = document.getElementById('add-role-modal');
|
||||
if (event.target === editUserModal) {
|
||||
closeEditUserModal();
|
||||
}
|
||||
if (event.target === editRoleModal) {
|
||||
closeEditRoleModal();
|
||||
}
|
||||
if (event.target === addRoleModal) {
|
||||
closeAddRoleModal();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-66
@@ -190,71 +190,6 @@
|
||||
</div>
|
||||
|
||||
<script src="/static/js/add_subnet.js"></script>
|
||||
<script>
|
||||
function showAddSubnetModal() {
|
||||
document.getElementById('add-subnet-modal').classList.remove('hidden');
|
||||
document.getElementById('add-subnet-name').value = '';
|
||||
document.getElementById('add-subnet-cidr').value = '';
|
||||
document.getElementById('add-subnet-site').value = '';
|
||||
}
|
||||
|
||||
function closeAddSubnetModal() {
|
||||
document.getElementById('add-subnet-modal').classList.add('hidden');
|
||||
document.getElementById('cidr-error').classList.add('hidden');
|
||||
}
|
||||
|
||||
function editSubnet(subnetId, name, cidr, site) {
|
||||
document.getElementById('edit-subnet-id').value = subnetId;
|
||||
document.getElementById('edit-subnet-name').value = name;
|
||||
document.getElementById('edit-subnet-cidr').value = cidr;
|
||||
document.getElementById('edit-subnet-site').value = site;
|
||||
document.getElementById('edit-subnet-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeEditSubnetModal() {
|
||||
document.getElementById('edit-subnet-modal').classList.add('hidden');
|
||||
document.getElementById('edit-cidr-error').classList.add('hidden');
|
||||
}
|
||||
|
||||
function validateEditSubnetForm() {
|
||||
const cidrInput = document.getElementById('edit-subnet-cidr');
|
||||
const cidrError = document.getElementById('edit-cidr-error');
|
||||
const cidr = cidrInput.value.trim();
|
||||
|
||||
// Basic CIDR validation
|
||||
const cidrPattern = /^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/;
|
||||
if (!cidrPattern.test(cidr)) {
|
||||
cidrError.textContent = 'Invalid CIDR format. Use format like 192.168.1.0/24';
|
||||
cidrError.classList.remove('hidden');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check prefix length
|
||||
const parts = cidr.split('/');
|
||||
if (parts.length === 2) {
|
||||
const prefixLen = parseInt(parts[1]);
|
||||
if (prefixLen < 24 || prefixLen > 32) {
|
||||
cidrError.textContent = 'Subnet must be /24 or smaller (e.g., /24, /25, ... /32)';
|
||||
cidrError.classList.remove('hidden');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
cidrError.classList.add('hidden');
|
||||
return true;
|
||||
}
|
||||
|
||||
// Close modals when clicking outside
|
||||
window.onclick = function(event) {
|
||||
const addModal = document.getElementById('add-subnet-modal');
|
||||
const editModal = document.getElementById('edit-subnet-modal');
|
||||
if (event.target === addModal) {
|
||||
closeAddSubnetModal();
|
||||
}
|
||||
if (event.target === editModal) {
|
||||
closeEditSubnetModal();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script src="/static/js/admin.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-118
@@ -187,123 +187,6 @@
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Filter toggle functionality
|
||||
const filterToggle = document.getElementById('filter-toggle');
|
||||
const filterForm = document.getElementById('audit-filter-form');
|
||||
const filterArrow = document.getElementById('filter-arrow');
|
||||
|
||||
if (filterToggle && filterForm && filterArrow) {
|
||||
filterToggle.addEventListener('click', function() {
|
||||
filterForm.classList.toggle('hidden');
|
||||
// Toggle rotation using inline style for better compatibility
|
||||
if (filterForm.classList.contains('hidden')) {
|
||||
filterArrow.style.transform = 'rotate(0deg)';
|
||||
} else {
|
||||
filterArrow.style.transform = 'rotate(180deg)';
|
||||
}
|
||||
});
|
||||
|
||||
// Set initial arrow rotation if form is visible (has active filters or expand_filters param)
|
||||
if (!filterForm.classList.contains('hidden')) {
|
||||
filterArrow.style.transform = 'rotate(180deg)';
|
||||
}
|
||||
}
|
||||
|
||||
// Format timestamps
|
||||
document.querySelectorAll('td[data-utc]').forEach(function(td) {
|
||||
const utc = td.getAttribute('data-utc');
|
||||
if (utc) {
|
||||
const date = new Date(utc + 'Z');
|
||||
td.textContent = date.toLocaleString();
|
||||
}
|
||||
});
|
||||
|
||||
// Parse and display visual diffs
|
||||
document.querySelectorAll('.diff-container').forEach(function(container) {
|
||||
const details = container.getAttribute('data-details');
|
||||
if (!details) return;
|
||||
|
||||
// Try to parse common change patterns
|
||||
let html = details;
|
||||
|
||||
// Pattern 1: "Changed X from 'old' to 'new'"
|
||||
html = html.replace(/Changed (.+?) from ['"](.+?)['"] to ['"](.+?)['"]/gi, function(match, field, oldVal, newVal) {
|
||||
return `Changed ${field} from <span class="diff-removed">${oldVal}</span> to <span class="diff-added">${newVal}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 2: "Renamed X to Y"
|
||||
html = html.replace(/Renamed (.+?) to ['"](.+?)['"]/gi, function(match, oldVal, newVal) {
|
||||
return `Renamed <span class="diff-removed">${oldVal}</span> to <span class="diff-added">${newVal}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 3: "Updated X: old -> new"
|
||||
html = html.replace(/Updated (.+?):\s*(.+?)\s*->\s*(.+?)(?:\s|$)/gi, function(match, field, oldVal, newVal) {
|
||||
return `Updated ${field}: <span class="diff-removed">${oldVal}</span> → <span class="diff-added">${newVal}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 4: "Set X to Y" (when it was previously something else, look for context)
|
||||
html = html.replace(/Set (.+?) to ['"](.+?)['"]/gi, function(match, field, newVal) {
|
||||
return `Set ${field} to <span class="diff-added">${newVal}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 5: "Removed X" or "Deleted X"
|
||||
html = html.replace(/(Removed|Deleted) ['"](.+?)['"]/gi, function(match, action, val) {
|
||||
return `${action} <span class="diff-removed">${val}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 6: "Added X"
|
||||
html = html.replace(/Added ['"](.+?)['"]/gi, function(match, val) {
|
||||
return `Added <span class="diff-added">${val}</span>`;
|
||||
});
|
||||
|
||||
// Pattern 7: "Assigned X to Y" or "Unassigned X from Y"
|
||||
html = html.replace(/(Assigned|Unassigned) (.+?) (to|from) (.+?)(?:\s|$)/gi, function(match, action, item, prep, target) {
|
||||
const actionClass = action === 'Assigned' ? 'diff-added' : 'diff-removed';
|
||||
return `${action} <span class="${actionClass}">${item}</span> ${prep} ${target}`;
|
||||
});
|
||||
|
||||
// Pattern 8: Generic "from X to Y" pattern
|
||||
html = html.replace(/from ['"](.+?)['"] to ['"](.+?)['"]/gi, function(match, oldVal, newVal) {
|
||||
return `from <span class="diff-removed">${oldVal}</span> to <span class="diff-added">${newVal}</span>`;
|
||||
});
|
||||
|
||||
container.innerHTML = html || details;
|
||||
});
|
||||
|
||||
// Export button handler
|
||||
document.getElementById('export-btn').addEventListener('click', function() {
|
||||
const form = document.getElementById('audit-filter-form');
|
||||
const formData = new FormData(form);
|
||||
const params = new URLSearchParams();
|
||||
|
||||
// Add all form fields to params
|
||||
for (const [key, value] of formData.entries()) {
|
||||
if (value) {
|
||||
if (key === 'user_ids') {
|
||||
// Handle multiple user_ids
|
||||
params.append('user_ids', value);
|
||||
} else {
|
||||
params.append(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle multiple user_ids separately
|
||||
const userSelect = form.querySelector('select[name="user_ids"]');
|
||||
if (userSelect) {
|
||||
const selectedUsers = Array.from(userSelect.selectedOptions).map(opt => opt.value);
|
||||
params.delete('user_ids');
|
||||
selectedUsers.forEach(userId => {
|
||||
params.append('user_ids', userId);
|
||||
});
|
||||
}
|
||||
|
||||
// Redirect to export endpoint
|
||||
window.location.href = '/audit/export_csv?' + params.toString();
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script src="/static/js/audit.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -145,180 +145,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
function showTab(tabName) {
|
||||
// Hide all panels
|
||||
document.querySelectorAll('.tab-panel').forEach(panel => panel.classList.add('hidden'));
|
||||
// Remove active class from all tabs
|
||||
document.querySelectorAll('.tab-btn').forEach(btn => btn.classList.remove('active'));
|
||||
// Show selected panel
|
||||
document.getElementById('panel-' + tabName).classList.remove('hidden');
|
||||
// Add active class to selected tab
|
||||
document.getElementById('tab-' + tabName).classList.add('active');
|
||||
}
|
||||
|
||||
// Update selected IP count
|
||||
document.getElementById('bulk-ip-select')?.addEventListener('change', function() {
|
||||
document.getElementById('selected-ip-count').textContent = this.selectedOptions.length;
|
||||
});
|
||||
|
||||
document.getElementById('bulk-tag-device-select')?.addEventListener('change', function() {
|
||||
document.getElementById('selected-tag-device-count').textContent = this.selectedOptions.length;
|
||||
});
|
||||
|
||||
// Load available IPs when subnet changes
|
||||
document.getElementById('bulk-subnet-select')?.addEventListener('change', function() {
|
||||
const subnetId = this.value;
|
||||
const ipSelect = document.getElementById('bulk-ip-select');
|
||||
if (!subnetId) {
|
||||
ipSelect.innerHTML = '<option value="" disabled>Select a subnet first...</option>';
|
||||
document.getElementById('selected-ip-count').textContent = '0';
|
||||
return;
|
||||
}
|
||||
ipSelect.innerHTML = '<option value="" disabled>Loading...</option>';
|
||||
fetch(`/get_available_ips?subnet_id=${subnetId}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
ipSelect.innerHTML = '';
|
||||
if (data.available_ips.length === 0) {
|
||||
ipSelect.innerHTML = '<option value="" disabled>No available IPs in this subnet</option>';
|
||||
} else {
|
||||
data.available_ips.forEach(ip => {
|
||||
const option = document.createElement('option');
|
||||
option.value = ip.id;
|
||||
option.textContent = ip.ip;
|
||||
ipSelect.appendChild(option);
|
||||
});
|
||||
}
|
||||
document.getElementById('selected-ip-count').textContent = '0';
|
||||
})
|
||||
.catch(() => {
|
||||
ipSelect.innerHTML = '<option value="" disabled>Error loading IPs</option>';
|
||||
});
|
||||
});
|
||||
|
||||
// Bulk IP Assignment
|
||||
document.getElementById('bulk-assign-ips-form')?.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const formData = new FormData(this);
|
||||
const resultDiv = document.getElementById('assign-ips-result');
|
||||
resultDiv.classList.remove('hidden');
|
||||
resultDiv.innerHTML = '<p class="text-blue-500">Processing...</p>';
|
||||
|
||||
fetch('/bulk/assign_ips', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
let html = '<div class="space-y-2">';
|
||||
if (data.success.length > 0) {
|
||||
html += `<div class="text-green-600 dark:text-green-400"><strong>Successfully assigned ${data.success.length} IP(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.success.forEach(item => {
|
||||
html += `<li>${item.ip}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
if (data.failed.length > 0) {
|
||||
html += `<div class="text-red-600 dark:text-red-400"><strong>Failed ${data.failed.length} assignment(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.failed.forEach(item => {
|
||||
const ipDisplay = item.ip ? ` (${item.ip})` : '';
|
||||
html += `<li>IP ID ${item.ip_id}${ipDisplay}: ${item.reason}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
html += '</div>';
|
||||
resultDiv.innerHTML = html;
|
||||
// Reload IP list if successful
|
||||
if (data.success.length > 0) {
|
||||
const subnetSelect = document.getElementById('bulk-subnet-select');
|
||||
if (subnetSelect.value) {
|
||||
subnetSelect.dispatchEvent(new Event('change'));
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
resultDiv.innerHTML = `<p class="text-red-600">Error: ${error.message}</p>`;
|
||||
});
|
||||
});
|
||||
|
||||
// Bulk Device Creation
|
||||
document.getElementById('bulk-create-devices-form')?.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const formData = new FormData(this);
|
||||
const resultDiv = document.getElementById('create-devices-result');
|
||||
resultDiv.classList.remove('hidden');
|
||||
resultDiv.innerHTML = '<p class="text-blue-500">Processing...</p>';
|
||||
|
||||
fetch('/bulk/create_devices', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
let html = '<div class="space-y-2">';
|
||||
if (data.success.length > 0) {
|
||||
html += `<div class="text-green-600 dark:text-green-400"><strong>Successfully created ${data.success.length} device(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.success.forEach(item => {
|
||||
html += `<li>${item.name}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
if (data.failed.length > 0) {
|
||||
html += `<div class="text-red-600 dark:text-red-400"><strong>Failed ${data.failed.length} creation(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.failed.forEach(item => {
|
||||
html += `<li>${item.name}: ${item.reason}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
html += '</div>';
|
||||
resultDiv.innerHTML = html;
|
||||
if (data.success.length > 0) {
|
||||
setTimeout(() => window.location.reload(), 2000);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
resultDiv.innerHTML = `<p class="text-red-600">Error: ${error.message}</p>`;
|
||||
});
|
||||
});
|
||||
|
||||
// Bulk Tag Assignment
|
||||
document.getElementById('bulk-assign-tags-form')?.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const formData = new FormData(this);
|
||||
const resultDiv = document.getElementById('assign-tags-result');
|
||||
resultDiv.classList.remove('hidden');
|
||||
resultDiv.innerHTML = '<p class="text-blue-500">Processing...</p>';
|
||||
|
||||
fetch('/bulk/assign_tags', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
let html = '<div class="space-y-2">';
|
||||
if (data.success.length > 0) {
|
||||
html += `<div class="text-green-600 dark:text-green-400"><strong>Successfully assigned ${data.success.length} tag(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.success.forEach(item => {
|
||||
html += `<li>${item.device_name}: ${item.tag_name}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
if (data.failed.length > 0) {
|
||||
html += `<div class="text-red-600 dark:text-red-400"><strong>Failed ${data.failed.length} assignment(s):</strong><ul class="list-disc list-inside mt-2">`;
|
||||
data.failed.forEach(item => {
|
||||
html += `<li>Device ID ${item.device_id}, Tag ID ${item.tag_id}: ${item.reason}</li>`;
|
||||
});
|
||||
html += '</ul></div>';
|
||||
}
|
||||
html += '</div>';
|
||||
resultDiv.innerHTML = html;
|
||||
})
|
||||
.catch(error => {
|
||||
resultDiv.innerHTML = `<p class="text-red-600">Error: ${error.message}</p>`;
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script src="/static/js/bulk_operations.js"></script>
|
||||
<style>
|
||||
.tab-btn.active {
|
||||
background-color: rgb(156 163 175);
|
||||
|
||||
+1
-41
@@ -107,45 +107,5 @@
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
// Check if toast was dismissed in this session
|
||||
const toastDismissed = sessionStorage.getItem('update-toast-dismissed');
|
||||
if (toastDismissed) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Check for updates
|
||||
fetch('/check_update')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.update_available) {
|
||||
const toast = document.getElementById('update-toast');
|
||||
const currentVersionEl = document.getElementById('toast-current-version');
|
||||
const latestVersionEl = document.getElementById('toast-latest-version');
|
||||
const compareLink = document.getElementById('toast-compare-link');
|
||||
const closeBtn = document.getElementById('toast-close');
|
||||
|
||||
// Set versions
|
||||
currentVersionEl.textContent = 'v' + data.current_version;
|
||||
latestVersionEl.textContent = 'v' + data.latest_version;
|
||||
|
||||
// Set compare link (current version to latest version)
|
||||
compareLink.href = `https://github.com/JDB-NET/ipam/compare/v${data.current_version}...v${data.latest_version}`;
|
||||
|
||||
// Show toast
|
||||
toast.classList.remove('hidden');
|
||||
|
||||
// Close button handler
|
||||
closeBtn.addEventListener('click', function() {
|
||||
toast.classList.add('hidden');
|
||||
sessionStorage.setItem('update-toast-dismissed', 'true');
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error checking for updates:', error);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script src="/static/js/update_toast.js"></script>
|
||||
</header>
|
||||
|
||||
+1
-35
@@ -24,16 +24,6 @@
|
||||
<button type="button" id="export-csv" class="hidden sm:flex absolute right-0 bg-gray-200 hover:bg-gray-400 dark:bg-zinc-700 dark:hover:bg-zinc-600 hover:cursor-pointer items-center justify-center rounded-full w-11 h-11 export-csv-btn" title="Export as CSV" data-rack-id="{{ rack.id }}">
|
||||
<i class="fas fa-file-csv fa-lg"></i>
|
||||
</button>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
var btn = document.getElementById('export-csv');
|
||||
if (btn) {
|
||||
btn.addEventListener('click', function() {
|
||||
window.location = '/rack/' + btn.getAttribute('data-rack-id') + '/export_csv';
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</div>
|
||||
<div class="flex flex-col gap-4 mb-6 items-stretch">
|
||||
<div class="flex gap-4 w-full justify-center">
|
||||
@@ -78,31 +68,7 @@
|
||||
</div>
|
||||
<div class="text-xs dark:text-gray-400 mt-2">Add a non-networked device.</div>
|
||||
</form>
|
||||
<script>
|
||||
function showBothAddButtons() {
|
||||
document.getElementById('show-add-device-form').classList.remove('hidden');
|
||||
document.getElementById('show-nonnet-form').classList.remove('hidden');
|
||||
}
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
showBothAddButtons();
|
||||
document.getElementById('show-nonnet-form').onclick = function() {
|
||||
document.getElementById('nonnet-form').classList.remove('hidden');
|
||||
this.classList.add('hidden');
|
||||
};
|
||||
document.getElementById('hide-nonnet-form').onclick = function() {
|
||||
document.getElementById('nonnet-form').classList.add('hidden');
|
||||
showBothAddButtons();
|
||||
};
|
||||
document.getElementById('show-add-device-form').onclick = function() {
|
||||
document.getElementById('add-device-form').classList.remove('hidden');
|
||||
this.classList.add('hidden');
|
||||
};
|
||||
document.getElementById('hide-add-device-form').onclick = function() {
|
||||
document.getElementById('add-device-form').classList.add('hidden');
|
||||
showBothAddButtons();
|
||||
};
|
||||
});
|
||||
</script>
|
||||
<script src="/static/js/rack.js"></script>
|
||||
{% if error %}
|
||||
<div class="mb-4 p-3 bg-red-700 text-white rounded-lg text-center font-semibold">{{ error }}</div>
|
||||
{% endif %}
|
||||
|
||||
+1
-17
@@ -6,7 +6,6 @@
|
||||
<title>{{ subnet.name }} - Subnet Details</title>
|
||||
<link rel="icon" type="image/png" href="{{ LOGO_PNG }}">
|
||||
<link href="/static/css/output.css" rel="stylesheet">
|
||||
<script src="/static/js/subnet.js"></script>
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body class="bg-gray-300 text-gray-900 dark:bg-zinc-900 dark:text-gray-100 min-h-screen flex flex-col">
|
||||
@@ -74,21 +73,6 @@
|
||||
</div>
|
||||
</div>
|
||||
<script src="/static/js/export_csv.js"></script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const toggleBtn = document.getElementById('toggle-desc');
|
||||
const descCols = document.querySelectorAll('.desc-col');
|
||||
const descHeader = document.getElementById('desc-col-header');
|
||||
let shown = false;
|
||||
if (toggleBtn) {
|
||||
toggleBtn.addEventListener('click', function() {
|
||||
shown = !shown;
|
||||
descCols.forEach(col => col.classList.toggle('hidden', !shown));
|
||||
if (descHeader) descHeader.classList.toggle('hidden', !shown);
|
||||
toggleBtn.textContent = shown ? 'Hide Descriptions' : 'Show Descriptions';
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script src="/static/js/subnet.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
+2
-196
@@ -337,204 +337,10 @@
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Template variables passed from server - must be defined before users.js loads
|
||||
const permissions = {{ permissions | tojson | safe }};
|
||||
const rolePermissions = {{ role_permissions | tojson | safe }};
|
||||
|
||||
function showTab(tab) {
|
||||
document.getElementById('users-tab').classList.add('hidden');
|
||||
document.getElementById('roles-tab').classList.add('hidden');
|
||||
document.getElementById('tab-users').classList.remove('border-blue-500', 'text-blue-600', 'dark:text-blue-400');
|
||||
document.getElementById('tab-users').classList.add('border-transparent', 'text-gray-600', 'dark:text-gray-400');
|
||||
document.getElementById('tab-roles').classList.remove('border-blue-500', 'text-blue-600', 'dark:text-blue-400');
|
||||
document.getElementById('tab-roles').classList.add('border-transparent', 'text-gray-600', 'dark:text-gray-400');
|
||||
|
||||
if (tab === 'users') {
|
||||
document.getElementById('users-tab').classList.remove('hidden');
|
||||
document.getElementById('tab-users').classList.remove('border-transparent', 'text-gray-600', 'dark:text-gray-400');
|
||||
document.getElementById('tab-users').classList.add('border-blue-500', 'text-blue-600', 'dark:text-blue-400');
|
||||
} else {
|
||||
document.getElementById('roles-tab').classList.remove('hidden');
|
||||
document.getElementById('tab-roles').classList.remove('border-transparent', 'text-gray-600', 'dark:text-gray-400');
|
||||
document.getElementById('tab-roles').classList.add('border-blue-500', 'text-blue-600', 'dark:text-blue-400');
|
||||
}
|
||||
}
|
||||
|
||||
function editUser(userId, name, email, roleId, apiKey) {
|
||||
document.getElementById('edit-user-id').value = userId;
|
||||
document.getElementById('edit-user-name').value = name;
|
||||
document.getElementById('edit-user-email').value = email;
|
||||
document.getElementById('edit-user-password').value = '';
|
||||
document.getElementById('edit-user-role').value = (roleId === null || roleId === 'null') ? '' : roleId;
|
||||
document.getElementById('edit-user-api-key').textContent = apiKey || 'No API Key';
|
||||
document.getElementById('edit-user-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeEditUserModal() {
|
||||
document.getElementById('edit-user-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
function showAddRoleModal() {
|
||||
// Make sure edit modal is closed first
|
||||
document.getElementById('edit-role-modal').classList.add('hidden');
|
||||
// Clear any form data
|
||||
const addForm = document.querySelector('#add-role-modal form');
|
||||
if (addForm) {
|
||||
addForm.reset();
|
||||
}
|
||||
// Show add modal
|
||||
document.getElementById('add-role-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeAddRoleModal() {
|
||||
document.getElementById('add-role-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
function editRole(roleId, roleName, roleDescription) {
|
||||
// Make sure add modal is closed first
|
||||
document.getElementById('add-role-modal').classList.add('hidden');
|
||||
document.getElementById('edit-role-id').value = roleId;
|
||||
document.getElementById('edit-role-name').value = roleName;
|
||||
document.getElementById('edit-role-description').value = roleDescription || '';
|
||||
|
||||
const permissionsDiv = document.getElementById('edit-role-permissions');
|
||||
permissionsDiv.innerHTML = '';
|
||||
|
||||
const rolePerms = rolePermissions[roleId] || [];
|
||||
|
||||
// Group permissions by merged categories
|
||||
const viewPerms = permissions.filter(p => p[3] === 'View');
|
||||
const devicePerms = permissions.filter(p => p[3] === 'Device');
|
||||
const deviceTypePerms = permissions.filter(p => p[3] === 'Device Type');
|
||||
const subnetPerms = permissions.filter(p => p[3] === 'Subnet');
|
||||
const dhcpPerms = permissions.filter(p => p[3] === 'DHCP');
|
||||
const rackPerms = permissions.filter(p => p[3] === 'Rack');
|
||||
const adminPerms = permissions.filter(p => p[3] === 'Admin');
|
||||
|
||||
let html = '';
|
||||
|
||||
// View Permissions
|
||||
html += ' <!-- View Permissions -->\n';
|
||||
html += ' <div class="col-span-full">\n';
|
||||
html += ' <h4 class="font-semibold text-base mb-2 border-b border-gray-500 pb-1">View Permissions</h4>\n';
|
||||
html += ' <div class="grid grid-cols-1 md:grid-cols-2 gap-2">\n';
|
||||
viewPerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
html += ' </div>\n';
|
||||
html += ' </div>\n';
|
||||
html += ' \n';
|
||||
|
||||
// Device Management
|
||||
html += ' <!-- Device Management -->\n';
|
||||
html += ' <div>\n';
|
||||
html += ' <h4 class="font-semibold text-base mb-2 border-b border-gray-500 pb-1">Device Management</h4>\n';
|
||||
devicePerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
deviceTypePerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
html += ' </div>\n';
|
||||
html += ' \n';
|
||||
|
||||
// Network Management
|
||||
html += ' <!-- Network Management -->\n';
|
||||
html += ' <div>\n';
|
||||
html += ' <h4 class="font-semibold text-base mb-2 border-b border-gray-500 pb-1">Network Management</h4>\n';
|
||||
subnetPerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
dhcpPerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
html += ' </div>\n';
|
||||
html += ' \n';
|
||||
|
||||
// Rack Management
|
||||
html += ' <!-- Rack Management -->\n';
|
||||
html += ' <div>\n';
|
||||
html += ' <h4 class="font-semibold text-base mb-2 border-b border-gray-500 pb-1">Rack Management</h4>\n';
|
||||
rackPerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
html += ' </div>\n';
|
||||
html += ' \n';
|
||||
|
||||
// Admin
|
||||
html += ' <!-- Admin -->\n';
|
||||
html += ' <div>\n';
|
||||
html += ' <h4 class="font-semibold text-base mb-2 border-b border-gray-500 pb-1">Administration</h4>\n';
|
||||
adminPerms.forEach(perm => {
|
||||
const checked = rolePerms.includes(perm[0]) ? 'checked' : '';
|
||||
html += ` <label class="flex items-center mb-2 cursor-pointer hover:bg-gray-200 dark:hover:bg-zinc-800 p-2 rounded">
|
||||
<input type="checkbox" name="permissions" value="${perm[0]}" ${checked} class="mr-2">
|
||||
<span class="text-sm">${perm[2]}</span>
|
||||
</label>\n`;
|
||||
});
|
||||
html += ' </div>\n';
|
||||
|
||||
permissionsDiv.innerHTML = html;
|
||||
|
||||
document.getElementById('edit-role-modal').classList.remove('hidden');
|
||||
}
|
||||
|
||||
function closeEditRoleModal() {
|
||||
document.getElementById('edit-role-modal').classList.add('hidden');
|
||||
}
|
||||
|
||||
function deleteRole(roleId, roleName) {
|
||||
if (confirm(`Are you sure you want to delete the role "${roleName}"?`)) {
|
||||
const form = document.createElement('form');
|
||||
form.method = 'POST';
|
||||
form.action = '/users';
|
||||
form.innerHTML = `
|
||||
<input type="hidden" name="action" value="delete_role">
|
||||
<input type="hidden" name="role_id" value="${roleId}">
|
||||
`;
|
||||
document.body.appendChild(form);
|
||||
form.submit();
|
||||
}
|
||||
}
|
||||
|
||||
// Close modals when clicking outside
|
||||
window.onclick = function(event) {
|
||||
const editUserModal = document.getElementById('edit-user-modal');
|
||||
const editRoleModal = document.getElementById('edit-role-modal');
|
||||
const addRoleModal = document.getElementById('add-role-modal');
|
||||
if (event.target === editUserModal) {
|
||||
closeEditUserModal();
|
||||
}
|
||||
if (event.target === editRoleModal) {
|
||||
closeEditRoleModal();
|
||||
}
|
||||
if (event.target === addRoleModal) {
|
||||
closeAddRoleModal();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<script src="/static/js/users.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user