mirror of
https://github.com/LibreQoE/LibreQoS.git
synced 2025-02-25 18:55:32 -06:00
Starting to pull together an SPA structure: a router, page interface and the login page with template.
This commit is contained in:
parent
f03d305dc8
commit
274d1c93ac
7
src/rust/long_term_stats/site_build/src/helpers.ts
Normal file
7
src/rust/long_term_stats/site_build/src/helpers.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export function getValueFromForm(id: string): string {
|
||||
let input = document.getElementById(id) as HTMLInputElement;
|
||||
if (input) {
|
||||
return input.value;
|
||||
}
|
||||
return "";
|
||||
}
|
3
src/rust/long_term_stats/site_build/src/page.ts
Normal file
3
src/rust/long_term_stats/site_build/src/page.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export interface Page {
|
||||
wireup(): void;
|
||||
}
|
41
src/rust/long_term_stats/site_build/src/router.ts
Normal file
41
src/rust/long_term_stats/site_build/src/router.ts
Normal file
@ -0,0 +1,41 @@
|
||||
import { LoginPage } from './login/login';
|
||||
import { Page } from './page';
|
||||
|
||||
export class SiteRouter {
|
||||
hasCredentials: boolean;
|
||||
curentPage: Page | undefined;
|
||||
|
||||
constructor() {
|
||||
this.curentPage = undefined;
|
||||
let token = localStorage.getItem("token");
|
||||
if (token) {
|
||||
this.hasCredentials = true;
|
||||
} else {
|
||||
this.hasCredentials = false;
|
||||
}
|
||||
}
|
||||
|
||||
initialRoute() {
|
||||
if (this.hasCredentials) {
|
||||
this.goto("dashboard");
|
||||
} else {
|
||||
this.goto("login");
|
||||
}
|
||||
}
|
||||
|
||||
// Handle actual navigation between pages
|
||||
goto(page: string) {
|
||||
console.log("Navigate to " + page)
|
||||
switch (page) {
|
||||
case "login": {
|
||||
this.curentPage = new LoginPage();
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
alert("I don't know how to go to: " + page);
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.curentPage.wireup();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user