Rename the Config top-nav to 'Admin' and move SSH Access into its sidebar
under a 'Tools' group, instead of a separate top-level nav item. SSH Access is
rendered by SshPage into the config main pane via a renderConfig('ssh-access')
special case; the sidebar item (config-sidebar.js) routes there. SshPage now
mounts into any container (defaults to #config-section). /ssh redirects to
/config?=ssh-access for old links; the standalone ssh-content.html is removed.
Declutters the top bar and gives system/admin features one home that scales
(updates, users, Connect settings can become sidebar entries later).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
119 lines
4.4 KiB
JavaScript
Executable File
119 lines
4.4 KiB
JavaScript
Executable File
// Config Sidebar - Handles sidebar population and navigation
|
|
class ConfigSidebar {
|
|
constructor() {
|
|
this.categoriesList = null;
|
|
}
|
|
|
|
populateSidebar() {
|
|
//console.log('ConfigSidebar: Populating sidebar with categories...');
|
|
|
|
this.categoriesList = document.getElementById('config-categories-list');
|
|
if (!this.categoriesList) {
|
|
console.error('ConfigSidebar: config-categories-list element not found');
|
|
return;
|
|
}
|
|
|
|
if (!window.configData || !window.configData.categories) {
|
|
console.error('ConfigSidebar: No config data available for sidebar');
|
|
return;
|
|
}
|
|
|
|
this.categoriesList.innerHTML = '';
|
|
|
|
// Convert categories object to array and sort by ORDER
|
|
const categoriesArray = Object.entries(window.configData.categories).map(([key, value]) => ({
|
|
id: key,
|
|
...value
|
|
}));
|
|
|
|
// Sort by ORDER if available, otherwise by title
|
|
categoriesArray.sort(function(a, b) {
|
|
const orderA = parseInt(a.order) || 999;
|
|
const orderB = parseInt(b.order) || 999;
|
|
return orderA - orderB;
|
|
});
|
|
|
|
var self = this; // Preserve 'this' context
|
|
|
|
categoriesArray.forEach(function(category) {
|
|
// Backup category has its own top-level page (/backup) which renders
|
|
// these same fields dynamically — hide it from the /config sidebar to
|
|
// avoid two surfaces for the same data.
|
|
if (category.id === 'backup') return;
|
|
|
|
const categoryItem = document.createElement('div');
|
|
categoryItem.className = 'category';
|
|
categoryItem.setAttribute('data-category', category.id);
|
|
|
|
// Use correct icon from our new structure
|
|
const iconName = category.icon || category.id;
|
|
const iconPath = '/icons/config/' + iconName + '.svg';
|
|
|
|
categoryItem.innerHTML = '<img src="' + iconPath + '" alt="' + category.title + '" style="width: 20px; height: 20px; margin-right: 8px;"/> ' + category.title;
|
|
|
|
categoryItem.addEventListener('click', function() {
|
|
// Update URL without full page reload
|
|
const url = '/config?=' + category.id;
|
|
window.history.pushState({}, '', url);
|
|
|
|
// Update active state
|
|
document.querySelectorAll('.category').forEach(function(item) {
|
|
item.classList.remove('active');
|
|
});
|
|
this.classList.add('active');
|
|
|
|
// Update global category and load dynamically
|
|
window.configCategory = category.id;
|
|
|
|
// Load config dynamically without page refresh
|
|
if (window.configManager && typeof window.configManager.renderConfig === 'function') {
|
|
window.configManager.renderConfig(category.id);
|
|
}
|
|
});
|
|
|
|
self.categoriesList.appendChild(categoryItem);
|
|
});
|
|
|
|
// Tools group — admin pages that live in this area but aren't config
|
|
// categories (rendered by their own controller, not the config form).
|
|
const toolsLabel = document.createElement('div');
|
|
toolsLabel.className = 'sidebar-group-label';
|
|
toolsLabel.textContent = 'Tools';
|
|
self.categoriesList.appendChild(toolsLabel);
|
|
|
|
const sshItem = document.createElement('div');
|
|
sshItem.className = 'category';
|
|
sshItem.setAttribute('data-category', 'ssh-access');
|
|
sshItem.innerHTML = '<img src="/icons/config/security.svg" alt="SSH Access" style="width: 20px; height: 20px; margin-right: 8px;"/> SSH Access';
|
|
sshItem.addEventListener('click', function () {
|
|
window.history.pushState({}, '', '/config?=ssh-access');
|
|
document.querySelectorAll('.category').forEach(function (item) { item.classList.remove('active'); });
|
|
this.classList.add('active');
|
|
window.configCategory = 'ssh-access';
|
|
if (window.configManager && typeof window.configManager.renderConfig === 'function') {
|
|
window.configManager.renderConfig('ssh-access');
|
|
}
|
|
});
|
|
self.categoriesList.appendChild(sshItem);
|
|
|
|
// Set initial active category
|
|
this.setActiveCategory(window.configCategory || 'general');
|
|
|
|
//console.log('ConfigSidebar: Sidebar populated with ' + categoriesArray.length + ' categories');
|
|
}
|
|
|
|
setActiveCategory(categoryId) {
|
|
// Update active state
|
|
document.querySelectorAll('.category').forEach(function(item) {
|
|
item.classList.remove('active');
|
|
});
|
|
var activeItem = document.querySelector('[data-category="' + categoryId + '"]');
|
|
if (activeItem) {
|
|
activeItem.classList.add('active');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Export to global scope
|
|
window.ConfigSidebar = ConfigSidebar;
|