modularize redirect function
This commit is contained in:
parent
42ebaff402
commit
5dc35cbbf3
@ -1,4 +1,4 @@
|
|||||||
import { request } from "./utils.js";
|
import {request, goToPage} from "./utils.js";
|
||||||
|
|
||||||
const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay));
|
const waitFor = delay => new Promise(resolve => setTimeout(resolve, delay));
|
||||||
|
|
||||||
@ -123,7 +123,11 @@ class Instance extends HTMLElement {
|
|||||||
|
|
||||||
let configButton = this.shadowElement.querySelector("#configure-btn");
|
let configButton = this.shadowElement.querySelector("#configure-btn");
|
||||||
configButton.src = data.status === "running" ? "images/actions/config-inactive.svg" : "images/actions/config-active.svg";
|
configButton.src = data.status === "running" ? "images/actions/config-inactive.svg" : "images/actions/config-active.svg";
|
||||||
configButton
|
configButton.addEventListener("click", () => {
|
||||||
|
if (!this.actionLock && this.status !== "running") {
|
||||||
|
goToPage("https://client.tronnet.net/config.html", {type: this.type, vmid: this.vmid});
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import {requestTicket, setTicket, request} from "./utils.js";
|
import {request, goToPage} from "./utils.js";
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", init);
|
window.addEventListener("DOMContentLoaded", init);
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ async function init () {
|
|||||||
async function populateInstances () {
|
async function populateInstances () {
|
||||||
let cookie = document.cookie;
|
let cookie = document.cookie;
|
||||||
if (cookie === "") {
|
if (cookie === "") {
|
||||||
window.location.href = "login.html";
|
goToPage("https://client.tronnet.net/login.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
let nodes = await request("/nodes", "GET", null);
|
let nodes = await request("/nodes", "GET", null);
|
||||||
|
@ -14,7 +14,7 @@ function init (){
|
|||||||
status.innerText = "Authenticating...";
|
status.innerText = "Authenticating...";
|
||||||
let ticket = await requestTicket(formData.get("username"), formData.get("password"));
|
let ticket = await requestTicket(formData.get("username"), formData.get("password"));
|
||||||
setTicket(ticket.data.ticket, ticket.data.CSRFPreventionToken);
|
setTicket(ticket.data.ticket, ticket.data.CSRFPreventionToken);
|
||||||
window.location.href = "index.html";
|
goToPage("https://client.tronnet.net/index.html");
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
if(error instanceof ResponseError) { // response error is usually 401 auth failed
|
if(error instanceof ResponseError) { // response error is usually 401 auth failed
|
||||||
|
@ -76,4 +76,12 @@ export async function request (path, method, body = null, auth = true) {
|
|||||||
|
|
||||||
let data = await response.json();
|
let data = await response.json();
|
||||||
return data;
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function goToPage (page, data={}) {
|
||||||
|
let url = new URL(url);
|
||||||
|
for(let k in data) {
|
||||||
|
url.searchParams.append(k, data[k]);
|
||||||
|
}
|
||||||
|
window.location.href = url.toString();
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user