import * as plugins from '../plugins.js'; import * as appstate from '../appstate.js'; import { DeesElement, css, cssManager, customElement, html, state, type TemplateResult } from '@design.estate/dees-element'; // Import view components import { OpsViewOverview } from './ops-view-overview.js'; import { OpsViewNetwork } from './ops-view-network.js'; import { OpsViewEmails } from './ops-view-emails.js'; import { OpsViewLogs } from './ops-view-logs.js'; import { OpsViewConfig } from './ops-view-config.js'; import { OpsViewSecurity } from './ops-view-security.js'; @customElement('ops-dashboard') export class OpsDashboard extends DeesElement { @state() private loginState: appstate.ILoginState = { identity: null, isLoggedIn: false, }; @state() private uiState: appstate.IUiState = { activeView: 'overview', sidebarCollapsed: false, autoRefresh: true, refreshInterval: 1000, theme: 'light', }; // Store viewTabs as a property to maintain object references private viewTabs = [ { name: 'Overview', element: OpsViewOverview, }, { name: 'Network', element: OpsViewNetwork, }, { name: 'Emails', element: OpsViewEmails, }, { name: 'Logs', element: OpsViewLogs, }, { name: 'Configuration', element: OpsViewConfig, }, { name: 'Security', element: OpsViewSecurity, }, ]; constructor() { super(); document.title = 'DCRouter OpsServer'; // Subscribe to login state const loginSubscription = appstate.loginStatePart .select((stateArg) => stateArg) .subscribe((loginState) => { this.loginState = loginState; // Trigger data fetch when logged in if (loginState.isLoggedIn) { appstate.statsStatePart.dispatchAction(appstate.fetchAllStatsAction, null); appstate.configStatePart.dispatchAction(appstate.fetchConfigurationAction, null); } }); this.rxSubscriptions.push(loginSubscription); // Subscribe to UI state const uiSubscription = appstate.uiStatePart .select((stateArg) => stateArg) .subscribe((uiState) => { this.uiState = uiState; }); this.rxSubscriptions.push(uiSubscription); } public static styles = [ cssManager.defaultStyles, css` .maincontainer { position: relative; width: 100vw; height: 100vh; } `, ]; public render(): TemplateResult { return html`