|
|
|
@ -49,7 +49,7 @@
|
|
|
|
{ mode: "test_by", label: "test.it-screen.by", host: "rest.test.it-screen.by" },
|
|
|
|
{ mode: "test_by", label: "test.it-screen.by", host: "rest.test.it-screen.by" },
|
|
|
|
{ mode: "custom", label: "Custom", host: "" }
|
|
|
|
{ mode: "custom", label: "Custom", host: "" }
|
|
|
|
];
|
|
|
|
];
|
|
|
|
const UI_VERSION = "V 3.1.13";
|
|
|
|
const UI_VERSION = "V 3.1.14";
|
|
|
|
const ITSCREEN_LOG_INITIAL_LINES = 50;
|
|
|
|
const ITSCREEN_LOG_INITIAL_LINES = 50;
|
|
|
|
const ITSCREEN_LOG_BUFFER_LIMIT = 300;
|
|
|
|
const ITSCREEN_LOG_BUFFER_LIMIT = 300;
|
|
|
|
const ITSCREEN_LOG_BATCH_MS = 250;
|
|
|
|
const ITSCREEN_LOG_BATCH_MS = 250;
|
|
|
|
@ -152,6 +152,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
const state = {
|
|
|
|
const state = {
|
|
|
|
activeTab: "health",
|
|
|
|
activeTab: "health",
|
|
|
|
|
|
|
|
sessionGeneration: 0,
|
|
|
|
identity: null,
|
|
|
|
identity: null,
|
|
|
|
status: null,
|
|
|
|
status: null,
|
|
|
|
health: null,
|
|
|
|
health: null,
|
|
|
|
@ -1040,7 +1041,20 @@
|
|
|
|
if (nodes.rebootBtn) nodes.rebootBtn.disabled = hide || state.rebootPending;
|
|
|
|
if (nodes.rebootBtn) nodes.rebootBtn.disabled = hide || state.rebootPending;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function resetSessionRequests() {
|
|
|
|
|
|
|
|
state.sessionGeneration += 1;
|
|
|
|
|
|
|
|
state.healthRequest = null;
|
|
|
|
|
|
|
|
cancelItscreenRequest();
|
|
|
|
|
|
|
|
cancelItscreenRegistrationRequest();
|
|
|
|
|
|
|
|
Object.assign(state.itscreen, {
|
|
|
|
|
|
|
|
data: null, runtime: null, error: "", details: "", message: "",
|
|
|
|
|
|
|
|
loadedAt: 0, registrationLoadedAt: 0, loading: false,
|
|
|
|
|
|
|
|
request: null, registrationRequest: null
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function setAuthRequired(message) {
|
|
|
|
function setAuthRequired(message) {
|
|
|
|
|
|
|
|
resetSessionRequests();
|
|
|
|
state.auth.loading = false;
|
|
|
|
state.auth.loading = false;
|
|
|
|
state.auth.authenticated = false;
|
|
|
|
state.auth.authenticated = false;
|
|
|
|
state.auth.busy = false;
|
|
|
|
state.auth.busy = false;
|
|
|
|
@ -1060,6 +1074,7 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function applyAuthSession(payload, message) {
|
|
|
|
function applyAuthSession(payload, message) {
|
|
|
|
|
|
|
|
if (!state.auth.authenticated && payload && payload.authenticated) resetSessionRequests();
|
|
|
|
state.auth.loading = false;
|
|
|
|
state.auth.loading = false;
|
|
|
|
state.auth.authenticated = !!(payload && payload.authenticated);
|
|
|
|
state.auth.authenticated = !!(payload && payload.authenticated);
|
|
|
|
state.auth.busy = false;
|
|
|
|
state.auth.busy = false;
|
|
|
|
@ -1636,7 +1651,7 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function itscreenStatusMeta(payload) {
|
|
|
|
function itscreenStatusMeta(payload) {
|
|
|
|
if (!payload) return { label: t("Loading"), tone: "warn" };
|
|
|
|
if (!payload || (!state.itscreen.registrationLoadedAt && !state.itscreen.error)) return { label: t("Loading"), tone: "warn" };
|
|
|
|
if (state.itscreen.busyAction === "register") return { label: t("Registering..."), tone: "warn" };
|
|
|
|
if (state.itscreen.busyAction === "register") return { label: t("Registering..."), tone: "warn" };
|
|
|
|
if (payload.status === "error" || state.itscreen.error) return { label: t("Error"), tone: "error" };
|
|
|
|
if (payload.status === "error" || state.itscreen.error) return { label: t("Error"), tone: "error" };
|
|
|
|
if (payload.status === "incomplete" || (payload.local_registered && !payload.logged)) return { label: t("Registration incomplete"), tone: "warn" };
|
|
|
|
if (payload.status === "incomplete" || (payload.local_registered && !payload.logged)) return { label: t("Registration incomplete"), tone: "warn" };
|
|
|
|
@ -1803,7 +1818,7 @@
|
|
|
|
const warnings = Array.isArray(card.warnings) ? card.warnings : [];
|
|
|
|
const warnings = Array.isArray(card.warnings) ? card.warnings : [];
|
|
|
|
const errors = Array.isArray(card.errors) ? card.errors : [];
|
|
|
|
const errors = Array.isArray(card.errors) ? card.errors : [];
|
|
|
|
const registrationIncomplete = !!(payload && payload.local_registered && !payload.logged);
|
|
|
|
const registrationIncomplete = !!(payload && payload.local_registered && !payload.logged);
|
|
|
|
const registrationRequired = !!(payload && !payload.registered && !state.itscreen.error);
|
|
|
|
const registrationRequired = !!(state.itscreen.registrationLoadedAt && payload && !payload.registered && !state.itscreen.error);
|
|
|
|
|
|
|
|
|
|
|
|
return `
|
|
|
|
return `
|
|
|
|
<article class="panel card serviceCard">
|
|
|
|
<article class="panel card serviceCard">
|
|
|
|
@ -3016,7 +3031,7 @@
|
|
|
|
: (hostError || (selectedServerDiffers ? t("Register the device on the newly selected server.") : t("Select the target cloud server and start registration.")));
|
|
|
|
: (hostError || (selectedServerDiffers ? t("Register the device on the newly selected server.") : t("Select the target cloud server and start registration.")));
|
|
|
|
const serviceWarnings = Array.isArray(service && service.warnings) ? service.warnings : [];
|
|
|
|
const serviceWarnings = Array.isArray(service && service.warnings) ? service.warnings : [];
|
|
|
|
const serviceErrors = Array.isArray(service && service.errors) ? service.errors : [];
|
|
|
|
const serviceErrors = Array.isArray(service && service.errors) ? service.errors : [];
|
|
|
|
const registrationRequired = !!(payload && !payload.registered && !state.itscreen.error);
|
|
|
|
const registrationRequired = !!(state.itscreen.registrationLoadedAt && payload && !payload.registered && !state.itscreen.error);
|
|
|
|
const registrationWarnClass = registrationRequired ? "registrationWarn" : "";
|
|
|
|
const registrationWarnClass = registrationRequired ? "registrationWarn" : "";
|
|
|
|
const registrationWarnKeyClass = registrationRequired ? "key registrationWarn" : "key";
|
|
|
|
const registrationWarnKeyClass = registrationRequired ? "key registrationWarn" : "key";
|
|
|
|
|
|
|
|
|
|
|
|
@ -4840,8 +4855,14 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function fetchJson(url, options) {
|
|
|
|
async function fetchJson(url, options) {
|
|
|
|
|
|
|
|
const generation = state.sessionGeneration;
|
|
|
|
const response = await fetch(url, options || { cache: "no-store" });
|
|
|
|
const response = await fetch(url, options || { cache: "no-store" });
|
|
|
|
const payload = await response.json().catch(() => ({}));
|
|
|
|
const payload = await response.json().catch(() => ({}));
|
|
|
|
|
|
|
|
if (generation !== state.sessionGeneration) {
|
|
|
|
|
|
|
|
const error = new Error("Discarded response from a previous session");
|
|
|
|
|
|
|
|
error.name = "AbortError";
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (response.status === 401) {
|
|
|
|
if (response.status === 401) {
|
|
|
|
if (String(url || "").indexOf("/api/auth/login") !== 0) {
|
|
|
|
if (String(url || "").indexOf("/api/auth/login") !== 0) {
|
|
|
|
setAuthRequired(t("Session expired, please sign in again"));
|
|
|
|
setAuthRequired(t("Session expired, please sign in again"));
|
|
|
|
@ -4860,8 +4881,14 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function fetchJsonAllowLogicalFailure(url, options) {
|
|
|
|
async function fetchJsonAllowLogicalFailure(url, options) {
|
|
|
|
|
|
|
|
const generation = state.sessionGeneration;
|
|
|
|
const response = await fetch(url, options || { cache: "no-store" });
|
|
|
|
const response = await fetch(url, options || { cache: "no-store" });
|
|
|
|
const payload = await response.json().catch(() => ({}));
|
|
|
|
const payload = await response.json().catch(() => ({}));
|
|
|
|
|
|
|
|
if (generation !== state.sessionGeneration) {
|
|
|
|
|
|
|
|
const error = new Error("Discarded response from a previous session");
|
|
|
|
|
|
|
|
error.name = "AbortError";
|
|
|
|
|
|
|
|
throw error;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (response.status === 401) {
|
|
|
|
if (response.status === 401) {
|
|
|
|
if (String(url || "").indexOf("/api/auth/login") !== 0) {
|
|
|
|
if (String(url || "").indexOf("/api/auth/login") !== 0) {
|
|
|
|
setAuthRequired(t("Session expired, please sign in again"));
|
|
|
|
setAuthRequired(t("Session expired, please sign in again"));
|
|
|
|
@ -4900,6 +4927,7 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function loadHealth() {
|
|
|
|
async function loadHealth() {
|
|
|
|
|
|
|
|
const generation = state.sessionGeneration;
|
|
|
|
if (state.healthRequest) return state.healthRequest;
|
|
|
|
if (state.healthRequest) return state.healthRequest;
|
|
|
|
state.healthRequest = (async () => {
|
|
|
|
state.healthRequest = (async () => {
|
|
|
|
const [summary, services] = await Promise.all([
|
|
|
|
const [summary, services] = await Promise.all([
|
|
|
|
@ -4916,7 +4944,7 @@
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
return await state.healthRequest;
|
|
|
|
return await state.healthRequest;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
state.healthRequest = null;
|
|
|
|
if (generation === state.sessionGeneration) state.healthRequest = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -5072,9 +5100,13 @@
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cancelItscreenRegistrationRequest();
|
|
|
|
cancelItscreenRegistrationRequest();
|
|
|
|
state.itscreen.registrationRequestController = typeof AbortController === "function" ? new AbortController() : null;
|
|
|
|
state.itscreen.registrationRequestController = typeof AbortController === "function" ? new AbortController() : null;
|
|
|
|
|
|
|
|
const controller = state.itscreen.registrationRequestController;
|
|
|
|
|
|
|
|
const generation = state.sessionGeneration;
|
|
|
|
|
|
|
|
const isCurrent = () => generation === state.sessionGeneration && state.itscreen.registrationRequestController === controller;
|
|
|
|
state.itscreen.registrationRequest = (async () => {
|
|
|
|
state.itscreen.registrationRequest = (async () => {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
const payload = await requestItscreenRegistration();
|
|
|
|
const payload = await requestItscreenRegistration();
|
|
|
|
|
|
|
|
if (!isCurrent()) return itscreenRegistration();
|
|
|
|
const nextData = state.itscreen.data || {};
|
|
|
|
const nextData = state.itscreen.data || {};
|
|
|
|
const registrationPayload = (payload && payload.data && typeof payload.data === "object")
|
|
|
|
const registrationPayload = (payload && payload.data && typeof payload.data === "object")
|
|
|
|
? payload.data
|
|
|
|
? payload.data
|
|
|
|
@ -5093,14 +5125,17 @@
|
|
|
|
if (state.activeTab === "tscreen" || state.activeTab === "health") renderActiveTab();
|
|
|
|
if (state.activeTab === "tscreen" || state.activeTab === "health") renderActiveTab();
|
|
|
|
return state.itscreen.data.registration;
|
|
|
|
return state.itscreen.data.registration;
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
if (!isCurrent()) return itscreenRegistration();
|
|
|
|
if (error && error.name === "AbortError") return itscreenRegistration();
|
|
|
|
if (error && error.name === "AbortError") return itscreenRegistration();
|
|
|
|
state.itscreen.error = error.message || t("Cloud registration status is unavailable");
|
|
|
|
state.itscreen.error = error.message || t("Cloud registration status is unavailable");
|
|
|
|
state.itscreen.details = "";
|
|
|
|
state.itscreen.details = "";
|
|
|
|
if (state.activeTab === "tscreen" || state.activeTab === "health") renderActiveTab();
|
|
|
|
if (state.activeTab === "tscreen" || state.activeTab === "health") renderActiveTab();
|
|
|
|
return itscreenRegistration();
|
|
|
|
return itscreenRegistration();
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
state.itscreen.registrationRequestController = null;
|
|
|
|
if (isCurrent()) {
|
|
|
|
state.itscreen.registrationRequest = null;
|
|
|
|
state.itscreen.registrationRequestController = null;
|
|
|
|
|
|
|
|
state.itscreen.registrationRequest = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
})();
|
|
|
|
return state.itscreen.registrationRequest;
|
|
|
|
return state.itscreen.registrationRequest;
|
|
|
|
@ -5113,6 +5148,9 @@
|
|
|
|
if (!force && state.itscreen.loadedAt && Date.now() - state.itscreen.loadedAt < maxAgeMs) return state.itscreen.data;
|
|
|
|
if (!force && state.itscreen.loadedAt && Date.now() - state.itscreen.loadedAt < maxAgeMs) return state.itscreen.data;
|
|
|
|
cancelItscreenRequest();
|
|
|
|
cancelItscreenRequest();
|
|
|
|
state.itscreen.requestController = typeof AbortController === "function" ? new AbortController() : null;
|
|
|
|
state.itscreen.requestController = typeof AbortController === "function" ? new AbortController() : null;
|
|
|
|
|
|
|
|
const controller = state.itscreen.requestController;
|
|
|
|
|
|
|
|
const generation = state.sessionGeneration;
|
|
|
|
|
|
|
|
const isCurrent = () => generation === state.sessionGeneration && state.itscreen.requestController === controller;
|
|
|
|
state.itscreen.loading = true;
|
|
|
|
state.itscreen.loading = true;
|
|
|
|
if (force) {
|
|
|
|
if (force) {
|
|
|
|
state.itscreen.error = "";
|
|
|
|
state.itscreen.error = "";
|
|
|
|
@ -5122,6 +5160,7 @@
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// Initial IT-Screen render must not wait on MQTT-backed registration.
|
|
|
|
// Initial IT-Screen render must not wait on MQTT-backed registration.
|
|
|
|
const [payload, runtime] = await Promise.all([requestItscreenStatus(), requestItscreenRuntime()]);
|
|
|
|
const [payload, runtime] = await Promise.all([requestItscreenStatus(), requestItscreenRuntime()]);
|
|
|
|
|
|
|
|
if (!isCurrent()) return state.itscreen.data;
|
|
|
|
const currentData = state.itscreen.data || {};
|
|
|
|
const currentData = state.itscreen.data || {};
|
|
|
|
state.itscreen.data = { ...currentData, ...(payload.ok === false ? (payload.data || {}) : payload) };
|
|
|
|
state.itscreen.data = { ...currentData, ...(payload.ok === false ? (payload.data || {}) : payload) };
|
|
|
|
state.itscreen.runtime = runtime;
|
|
|
|
state.itscreen.runtime = runtime;
|
|
|
|
@ -5129,13 +5168,14 @@
|
|
|
|
state.itscreen.loadedAt = Date.now();
|
|
|
|
state.itscreen.loadedAt = Date.now();
|
|
|
|
if (!state.itscreen.registrationLoadedAt || force) {
|
|
|
|
if (!state.itscreen.registrationLoadedAt || force) {
|
|
|
|
window.setTimeout(() => {
|
|
|
|
window.setTimeout(() => {
|
|
|
|
if ((state.activeTab === "tscreen" || state.activeTab === "health") && state.auth.authenticated) {
|
|
|
|
if (generation === state.sessionGeneration && (state.activeTab === "tscreen" || state.activeTab === "health") && state.auth.authenticated) {
|
|
|
|
loadItscreenRegistration({ force, maxAgeMs: 30000 }).catch(() => {});
|
|
|
|
loadItscreenRegistration({ force, maxAgeMs: 30000 }).catch(() => {});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
}, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return state.itscreen.data;
|
|
|
|
return state.itscreen.data;
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
if (!isCurrent()) return state.itscreen.data;
|
|
|
|
if (error && error.name === "AbortError") {
|
|
|
|
if (error && error.name === "AbortError") {
|
|
|
|
return state.itscreen.data;
|
|
|
|
return state.itscreen.data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -5160,9 +5200,11 @@
|
|
|
|
};
|
|
|
|
};
|
|
|
|
return state.itscreen.data;
|
|
|
|
return state.itscreen.data;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
state.itscreen.loading = false;
|
|
|
|
if (isCurrent()) {
|
|
|
|
state.itscreen.requestController = null;
|
|
|
|
state.itscreen.loading = false;
|
|
|
|
state.itscreen.request = null;
|
|
|
|
state.itscreen.requestController = null;
|
|
|
|
|
|
|
|
state.itscreen.request = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
})();
|
|
|
|
return state.itscreen.request;
|
|
|
|
return state.itscreen.request;
|
|
|
|
@ -5204,6 +5246,7 @@
|
|
|
|
renderActiveTab();
|
|
|
|
renderActiveTab();
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const generation = state.sessionGeneration;
|
|
|
|
const preserveEditing = !!options.preserveEditing;
|
|
|
|
const preserveEditing = !!options.preserveEditing;
|
|
|
|
nodes.refreshBtn.disabled = true;
|
|
|
|
nodes.refreshBtn.disabled = true;
|
|
|
|
if (nodes.rebootBtn) nodes.rebootBtn.disabled = state.rebootPending;
|
|
|
|
if (nodes.rebootBtn) nodes.rebootBtn.disabled = state.rebootPending;
|
|
|
|
@ -5221,6 +5264,7 @@
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
await loadStatus();
|
|
|
|
await loadStatus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (generation !== state.sessionGeneration) return;
|
|
|
|
if (!(preserveEditing && state.activeTab === "network" && networkFormIsInteractive()) && !(preserveEditing && state.activeTab === "tscreen" && itscreenFormIsInteractive()) && !(preserveEditing && state.activeTab === "security" && timezoneFormIsInteractive())) {
|
|
|
|
if (!(preserveEditing && state.activeTab === "network" && networkFormIsInteractive()) && !(preserveEditing && state.activeTab === "tscreen" && itscreenFormIsInteractive()) && !(preserveEditing && state.activeTab === "security" && timezoneFormIsInteractive())) {
|
|
|
|
renderActiveTab();
|
|
|
|
renderActiveTab();
|
|
|
|
} else if (state.activeTab === "network") {
|
|
|
|
} else if (state.activeTab === "network") {
|
|
|
|
@ -5229,9 +5273,10 @@
|
|
|
|
updateTimezoneFormUi();
|
|
|
|
updateTimezoneFormUi();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
} catch (error) {
|
|
|
|
|
|
|
|
if (generation !== state.sessionGeneration || error.name === "AbortError") return;
|
|
|
|
nodes.content.innerHTML = `<div class="empty">${esc(t("Failed to load {tab}: {message}", { tab: state.activeTab, message: error.message || String(error) }))}</div>`;
|
|
|
|
nodes.content.innerHTML = `<div class="empty">${esc(t("Failed to load {tab}: {message}", { tab: state.activeTab, message: error.message || String(error) }))}</div>`;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
nodes.refreshBtn.disabled = state.rebootPending;
|
|
|
|
nodes.refreshBtn.disabled = !state.auth.authenticated || state.rebootPending;
|
|
|
|
if (nodes.rebootBtn) nodes.rebootBtn.disabled = state.rebootPending;
|
|
|
|
if (nodes.rebootBtn) nodes.rebootBtn.disabled = state.rebootPending;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|