simplify front end routes,
simplify ssr fragment fetch methods
This commit is contained in:
13
app/app.go
13
app/app.go
@@ -26,14 +26,15 @@ func Run() {
|
||||
html := common.MinifyStatic(m, web.Templates)
|
||||
common.TMPL = common.LoadHTMLToGin(router, html)
|
||||
|
||||
router.GET("/account.html", routes.HandleGETAccount)
|
||||
router.GET("/account", routes.HandleGETAccount)
|
||||
router.GET("/", routes.HandleGETIndex)
|
||||
router.GET("/index.html", routes.HandleGETIndex)
|
||||
router.GET("/config.html", routes.HandleGETConfig)
|
||||
router.GET("/login.html", routes.HandleGETLogin)
|
||||
router.GET("/settings.html", routes.HandleGETSettings)
|
||||
router.GET("/index", routes.HandleGETIndex)
|
||||
router.GET("/config", routes.HandleGETConfig)
|
||||
router.GET("/login", routes.HandleGETLogin)
|
||||
router.GET("/settings", routes.HandleGETSettings)
|
||||
|
||||
router.GET("/instances_fragment", routes.HandleGETInstancesFragment)
|
||||
router.GET("/index/instances", routes.HandleGETInstancesFragment)
|
||||
router.GET("/config/volumes", routes.HandleGETConfigVolumesFragment)
|
||||
|
||||
log.Fatal(router.Run(fmt.Sprintf("0.0.0.0:%d", common.Global.Port)))
|
||||
}
|
||||
|
@@ -149,7 +149,7 @@ func HandleGETAccount(c *gin.Context) {
|
||||
"account": account,
|
||||
})
|
||||
} else {
|
||||
c.Redirect(http.StatusFound, "/login.html") // if user is not authed, redirect user to login page
|
||||
c.Redirect(http.StatusFound, "/login") // if user is not authed, redirect user to login page
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -84,7 +84,7 @@ func HandleGETIndex(c *gin.Context) {
|
||||
"instances": instances,
|
||||
})
|
||||
} else { // return index without populating
|
||||
c.Redirect(http.StatusFound, "/login.html") // if user is not authed, redirect user to login page
|
||||
c.Redirect(http.StatusFound, "/login") // if user is not authed, redirect user to login page
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,11 +96,11 @@ func HandleGETInstancesFragment(c *gin.Context) {
|
||||
common.HandleNonFatalError(c, err)
|
||||
}
|
||||
c.Header("Content-Type", "text/plain")
|
||||
common.TMPL.ExecuteTemplate(c.Writer, "html/instances.frag", gin.H{
|
||||
common.TMPL.ExecuteTemplate(c.Writer, "html/index-instances.frag", gin.H{
|
||||
"instances": instances,
|
||||
})
|
||||
c.Status(http.StatusOK)
|
||||
} else { // return index without populating
|
||||
} else { // return 401
|
||||
c.Status(http.StatusUnauthorized)
|
||||
}
|
||||
|
||||
|
@@ -15,6 +15,6 @@ func HandleGETSettings(c *gin.Context) {
|
||||
"page": "settings",
|
||||
})
|
||||
} else {
|
||||
c.Redirect(http.StatusFound, "/login.html")
|
||||
c.Redirect(http.StatusFound, "/login")
|
||||
}
|
||||
}
|
||||
|
@@ -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) {
|
||||
|
@@ -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.");
|
||||
|
@@ -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 };
|
||||
}
|
||||
*/
|
||||
|
@@ -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}}
|
Reference in New Issue
Block a user