feat(webui): migrate the Admin area to one feature module
features/admin/index.js owns all /admin* sub-routes (overview, config/<cat>, system[/sub], tools/ssh-access, tools/peers). mount() parses the category and delegates to the system-loader configManager singleton's renderConfig(); unmount() stops AdminSystem's live SSE sub + 30s interval, drops the admin-overview task-refresh registration, and nulls the per-visit sub-controllers (adminOverview/adminSystem/sshPage/peersPage) while leaving configManager intact. Legacy /config /ssh /peers redirect handlers unchanged. With this, every WebUI page now routes through the feature-module kernel; the legacy handleX() methods remain only as fallbacks. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: librelad <librelad@digitalangels.vip>
This commit is contained in:
parent
ff79249fdd
commit
b4105d8cff
58
containers/libreportal/frontend/features/admin/index.js
Normal file
58
containers/libreportal/frontend/features/admin/index.js
Normal file
@ -0,0 +1,58 @@
|
||||
// features/admin/index.js — the whole Admin area as one feature module.
|
||||
//
|
||||
// Admin owns every /admin* sub-route: /admin & /admin/dashboard (overview
|
||||
// board), /admin/config/<cat> (config-form pages), /admin/system[/<sub>]
|
||||
// (system ops boards), /admin/tools/ssh-access, /admin/tools/peers. The router
|
||||
// re-runs mount() on each distinct /admin* path; mount() just parses the
|
||||
// category and hands it to window.configManager.renderConfig(), which owns the
|
||||
// overview/ssh/peers/system/config-form dispatch and lazy-loads the per-category
|
||||
// sub-controllers. configManager is a system-loader singleton — call
|
||||
// renderConfig(), never `new`. (The legacy /config, /ssh, /peers redirect
|
||||
// handlers stay as-is; they just bounce into /admin/* which this feature serves.)
|
||||
LP.features.register({
|
||||
id: 'admin',
|
||||
routes: ['/admin', '/admin*'],
|
||||
|
||||
async mount(ctx) {
|
||||
window.configCategory = window.adminCategoryFromPath(window.location.pathname);
|
||||
|
||||
const html = await ctx.loadFragment('/html/config-content.html');
|
||||
ctx.setContent(html, 'Admin');
|
||||
|
||||
if (window.configManager) {
|
||||
if (typeof window.configManager.renderConfig === 'function') {
|
||||
await window.configManager.renderConfig(window.configCategory || 'overview');
|
||||
}
|
||||
} else {
|
||||
// Preserve the legacy failure rather than rendering blank. _mountFeature
|
||||
// catches this and falls back to handleAdmin (same showError end-state).
|
||||
throw new Error('ConfigManager not initialized by SystemLoader');
|
||||
}
|
||||
},
|
||||
|
||||
async unmount() {
|
||||
// Release only this view's leaks; never destroy the configManager singleton.
|
||||
// The sub-controllers renderConfig() spawns are re-created on each visit, so
|
||||
// null them; AdminSystem additionally holds a live SSE sub + a 30s interval
|
||||
// we can stop cleanly.
|
||||
try {
|
||||
const as = window.adminSystem;
|
||||
if (as) {
|
||||
if (typeof as._stopLive === 'function') as._stopLive();
|
||||
if (as._timer) { clearInterval(as._timer); as._timer = null; }
|
||||
if (as._subview && typeof as._subview.dispose === 'function') {
|
||||
try { as._subview.dispose(); } catch (_) {}
|
||||
}
|
||||
as._subview = null;
|
||||
}
|
||||
} catch (_) {}
|
||||
// Drop AdminOverview's task-refresh registration so a finished verify/update
|
||||
// task doesn't repaint a torn-down board.
|
||||
try { window.taskRefresh && window.taskRefresh.unregister && window.taskRefresh.unregister('admin-overview'); } catch (_) {}
|
||||
window.adminOverview = null;
|
||||
window.adminSystem = null;
|
||||
window.sshPage = null;
|
||||
window.peersPage = null;
|
||||
// configManager (+ its inner managers) intentionally left intact.
|
||||
},
|
||||
});
|
||||
@ -114,6 +114,7 @@
|
||||
<script src="/features/dashboard/index.js"></script>
|
||||
<script src="/features/apps/index.js"></script>
|
||||
<script src="/features/app-detail/index.js"></script>
|
||||
<script src="/features/admin/index.js"></script>
|
||||
<script src="/features/backup/index.js"></script>
|
||||
<script src="/features/tasks/index.js"></script>
|
||||
<!--
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user