templateManager.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import {DAL} from "../DAL/login";
  2. import {Page} from "./page";
  3. import systemInfo from "./systemInfo";
  4. import systemMonitor from "./systemMonitor";
  5. import systemServices from './services';
  6. class TemplateManager {
  7. public currentSection: Page|null = null;
  8. protected pages: Array<Page> =[];
  9. protected loading: boolean =false;
  10. public constructor() {
  11. this.pages.push(systemInfo);
  12. this.pages.push(systemMonitor);
  13. this.pages.push(systemServices);
  14. addEventListener("hashchange", () => this.showDefaultPage());
  15. }
  16. public async showDefaultPage(): Promise<void> {
  17. this.setLoading(true);
  18. if (!await DAL.isLoggedUser()) {
  19. document.location = "login";
  20. return;
  21. }
  22. const hash = String(window.location.hash).slice(1);
  23. let page = this.pages.find(x => x.getPageName() === hash);
  24. if (!page)
  25. page = systemInfo;
  26. await page.show();
  27. this.setLoading(false);
  28. }
  29. public setLoading(loading: boolean) {
  30. if (this.loading === loading)
  31. return;
  32. this.loading = loading;
  33. document.body.classList.toggle("loading", loading);
  34. }
  35. }
  36. export default new TemplateManager();