simplify front end routes,

simplify ssr fragment fetch methods
This commit is contained in:
2025-04-15 17:13:22 +00:00
parent 844cf4dfb9
commit 099f9c4e42
9 changed files with 33 additions and 23 deletions

View File

@@ -1,4 +1,4 @@
import { requestPVE, requestAPI, goToPage, setAppearance, getSearchSettings, goToURL, getInstancesFragment } from "./utils.js";
import { requestPVE, requestAPI, goToPage, setAppearance, getSearchSettings, goToURL, requestDash } from "./utils.js";
import { alert, dialog } from "./dialog.js";
import { setupClientSync } from "./clientsync.js";
import wfaInit from "../modules/wfa.js";
@@ -179,7 +179,7 @@ class InstanceCard extends HTMLElement {
handleConfigButton () {
if (!this.actionLock && this.status === "stopped") { // if the action lock is false, and the node is stopped, then navigate to the config page with the node info in the search query
goToPage("config.html", { node: this.node.name, type: this.type, vmid: this.vmid });
goToPage("config", { node: this.node.name, type: this.type, vmid: this.vmid });
}
}
@@ -240,6 +240,10 @@ async function init () {
setupClientSync(refreshInstances);
}
async function getInstancesFragment () {
return await requestDash("/index/instances", "GET")
}
async function refreshInstances () {
let instances = await getInstancesFragment();
if (instances.status !== 200) {

View File

@@ -16,7 +16,7 @@ async function init () {
const ticket = await requestTicket(formData.get("username"), formData.get("password"), formData.get("realm"));
if (ticket.status === 200) {
formSubmitButton.innerText = "LOGIN";
goToPage("index.html");
goToPage("index");
}
else if (ticket.status === 401) {
alert("Authenticaton failed.");

View File

@@ -146,18 +146,21 @@ export async function requestAPI (path, method, body = null) {
return response;
}
export async function getInstancesFragment () {
export async function requestDash (path, method, body = null) {
const prms = new URLSearchParams(body);
const content = {
method: "GET",
mode: "cors",
method,
credentials: "include",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
};
content.headers.CSRFPreventionToken = getCookie("CSRFPreventionToken");
if (body) {
content.body = prms.toString();
}
const response = await request(`${window.DASH}/instances_fragment`, content);
const response = await request(`${window.DASH}${path}`, content);
return response;
}
@@ -351,6 +354,7 @@ export function isEmpty (obj) {
}
}
/*
export function addResourceLine (resourceConfig, field, attributesOverride, labelPrefix = null) {
const iconHref = resourceConfig.icon;
const elementType = resourceConfig.element;
@@ -428,3 +432,4 @@ export function addResourceLine (resourceConfig, field, attributesOverride, labe
return { icon, label, element, unit };
}
*/

View File

@@ -21,12 +21,12 @@
<input type="checkbox" id="navtoggle">
<nav id="navigation">
{{if eq .page "login"}}
<a href="login.html" aria-current="page">Login</a>
<a href="login" aria-current="page">Login</a>
{{else}}
<a href="index.html" {{if eq .page "index"}} aria-current="page" {{end}}>Instances</a>
<a href="account.html" {{if eq .page "account"}} aria-current="page" {{end}}>Account</a>
<a href="settings.html" {{if eq .page "settings"}} aria-current="page" {{end}}>Settings</a>
<a href="login.html">Logout</a>
<a href="index" {{if eq .page "index"}} aria-current="page" {{end}}>Instances</a>
<a href="account" {{if eq .page "account"}} aria-current="page" {{end}}>Account</a>
<a href="settings" {{if eq .page "settings"}} aria-current="page" {{end}}>Settings</a>
<a href="login">Logout</a>
{{end}}
</nav>
{{end}}