- features/admin/: the 10 admin-owned config controllers, the 5 admin pages
(overview/system/charts/metric/storage), ssh-page.js, peers-page.js, plus
admin.css/ip-whitelist.css/ssh.css (eager). config-manager.js kept last in
the load order (it news the sub-managers).
- shared/js/: config-shared.js + config-options.js (ConfigShared/ConfigOptions
globals consumed cross-feature by backup/apps/tasks).
- shared/css/: forms.css + config.css (generic form + config-form primitives
borrowed by apps/backup/admin).
- Updated all path strings in system-loader.js (config component) and
config-manager.js (lazyLoad of admin/ssh/peers controllers); index.html CSS
hrefs. No /js/components/{config,admin,ssh,peers}/ refs remain.
js/components/ now holds only shared UI (topbar, notifications, eo-modal,
update-notifier, mobile-menu, confirmation-dialog).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
133 lines
5.9 KiB
JavaScript
Executable File
133 lines
5.9 KiB
JavaScript
Executable File
// Config Utils - Utility functions for configuration management
|
|
class ConfigUtils {
|
|
constructor() {
|
|
// No initialization needed
|
|
}
|
|
|
|
formatSubcategoryName(subcategoryName) {
|
|
return subcategoryName.replace(/_/g, ' ').replace(/\b\w/g, function(l) { return l.toUpperCase(); });
|
|
}
|
|
|
|
cleanDescription(description) {
|
|
return description
|
|
.replace(/\*\*ADVANCED\*\*/g, '')
|
|
.replace(/\*\*UNUSED\*\*/g, '')
|
|
.replace(/\*\*DEV\*\*/g, '')
|
|
.replace(/^\s+|\s+$/g, '') // Trim whitespace
|
|
.replace(/\s{2,}/g, ' '); // Replace multiple spaces with single space
|
|
}
|
|
|
|
// Per-field test for the **DEV** marker. Dev fields are hidden in the form
|
|
// unless CFG_DEV_MODE is on (unlocked via the 10-click LibrePortal-logo
|
|
// easter egg, or auto-enabled when CFG_INSTALL_MODE is git/local).
|
|
isDevField(description) {
|
|
return typeof description === 'string' && description.includes('**DEV**');
|
|
}
|
|
|
|
isDevModeOn() {
|
|
const v = (window.systemConfigs && window.systemConfigs.CFG_DEV_MODE) || 'false';
|
|
return v === 'true' || v === true;
|
|
}
|
|
|
|
filterSubcategoriesByType(configData, category) {
|
|
// Filter subcategories by category and separate into regular, advanced, and unused
|
|
var regularSubcategories = [];
|
|
var advancedSubcategories = [];
|
|
var unusedSubcategories = [];
|
|
|
|
for (const [subcategoryName, subcategoryData] of Object.entries(configData)) {
|
|
if (subcategoryData.category === category) {
|
|
if (subcategoryData.description.includes('**ADVANCED**')) {
|
|
advancedSubcategories.push(subcategoryName);
|
|
} else if (subcategoryData.description.includes('**UNUSED**')) {
|
|
unusedSubcategories.push(subcategoryName);
|
|
} else {
|
|
regularSubcategories.push(subcategoryName);
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
regular: regularSubcategories,
|
|
advanced: advancedSubcategories,
|
|
unused: unusedSubcategories
|
|
};
|
|
}
|
|
|
|
async renderSectionedContent(formHTML, advancedSubcategories, unusedSubcategories, self, category, configData) {
|
|
// Add danger zone toggle controls if needed
|
|
if (advancedSubcategories.length > 0 || unusedSubcategories.length > 0) {
|
|
// Divider above the advanced/danger-zone container, mirroring the one
|
|
// above the Save/Reset buttons — separates the regular fields from the
|
|
// "Show Advanced Options" toggle.
|
|
formHTML += '<div class="config-divider"></div>';
|
|
formHTML += this.generateToggleControls(advancedSubcategories.length > 0, unusedSubcategories.length > 0);
|
|
}
|
|
|
|
// Render advanced sections (hidden by default). The old grouping
|
|
// header ("🛠️ Advanced Configuration") is gone — each subcategory
|
|
// self-identifies via the red "Advanced" badge on its title (see
|
|
// .is-advanced .domains-header h3::after in config.css).
|
|
if (advancedSubcategories.length > 0) {
|
|
formHTML += '<div id="advanced-sections" class="advanced-sections" style="display: none;">';
|
|
// Divider between the "Show Advanced Options" toggle and the advanced
|
|
// fields. It lives inside #advanced-sections so it only appears once the
|
|
// user reveals them.
|
|
formHTML += '<div class="config-divider"></div>';
|
|
|
|
for (const subcategoryName of advancedSubcategories) {
|
|
const subcategoryData = configData[subcategoryName];
|
|
|
|
if (typeof subcategoryData === 'object' && subcategoryData !== null) {
|
|
formHTML += '<div class="is-advanced">';
|
|
formHTML += await self.renderSubcategory.call(self, category, subcategoryName, subcategoryData);
|
|
formHTML += '</div>';
|
|
}
|
|
}
|
|
formHTML += '</div>';
|
|
}
|
|
|
|
// Render unused sections (hidden by default)
|
|
if (unusedSubcategories.length > 0) {
|
|
formHTML += '<div id="unused-sections" class="unused-sections" style="display: none;">';
|
|
formHTML += '<div class="section-divider"><h3>🗑️ Unused Configuration</h3><p>Deprecated or unused settings</p></div>';
|
|
|
|
for (const subcategoryName of unusedSubcategories) {
|
|
const subcategoryData = configData[subcategoryName];
|
|
//console.log('ConfigUtils: Processing unused subcategory:', subcategoryName, 'data:', subcategoryData);
|
|
|
|
if (typeof subcategoryData === 'object' && subcategoryData !== null) {
|
|
//console.log('ConfigUtils: Calling renderSubcategory for:', subcategoryName);
|
|
formHTML += await self.renderSubcategory.call(self, category, subcategoryName, subcategoryData);
|
|
}
|
|
}
|
|
formHTML += '</div>';
|
|
}
|
|
|
|
return formHTML;
|
|
}
|
|
|
|
generateToggleControls(hasAdvanced = false, hasUnused = false) {
|
|
if (!hasAdvanced && !hasUnused) {
|
|
return ''; // Don't show danger zone if no content
|
|
}
|
|
|
|
let formHTML = '<div class="danger-zone-section"><div class="danger-zone-header"><h3>⚠️ Danger Zone</h3><p>These options are for advanced users and may affect system stability</p></div><div class="config-toggles">';
|
|
|
|
if (hasAdvanced) {
|
|
formHTML += '<div class="toggle-section"><label class="checkbox-label"><input type="checkbox" id="show-advanced" onchange="ConfigShared.toggleAdvancedSections()"><span class="checkbox-custom"></span><div class="toggle-content"><span class="checkbox-text">Show Advanced Options</span><span class="checkbox-description">Display advanced configuration settings for experienced users</span></div></label></div>';
|
|
}
|
|
|
|
if (hasUnused) {
|
|
formHTML += '<div class="toggle-section"><label class="checkbox-label"><input type="checkbox" id="show-unused" onchange="ConfigShared.toggleUnusedSections()"><span class="checkbox-custom"></span><div class="toggle-content"><span class="checkbox-text">Show Unused Options</span><span class="checkbox-description">Display deprecated or unused configuration options</span></div></label></div>';
|
|
}
|
|
|
|
formHTML += '</div></div>';
|
|
|
|
return formHTML;
|
|
}
|
|
}
|
|
|
|
// Export to global scope
|
|
window.ConfigUtils = ConfigUtils;
|