import {DAL} from "../DAL/login"; import {Page} from "./page"; import systemInfo from "./systemInfo"; import systemMonitor from "./systemMonitor"; import systemServices from './services'; class TemplateManager { public currentSection: Page|null = null; protected pages: Array =[]; protected loading: boolean =false; public constructor() { this.pages.push(systemInfo); this.pages.push(systemMonitor); this.pages.push(systemServices); addEventListener("hashchange", () => this.showDefaultPage()); } public async showDefaultPage(): Promise { this.setLoading(true); if (!await DAL.isLoggedUser()) { document.location = "login"; return; } const hash = String(window.location.hash).slice(1); let page = this.pages.find(x => x.getPageName() === hash); if (!page) page = systemInfo; await page.show(); this.setLoading(false); } public setLoading(loading: boolean) { if (this.loading === loading) return; this.loading = loading; document.body.classList.toggle("loading", loading); } } export default new TemplateManager();