plugin-backend #1
@ -79,7 +79,6 @@ async function initialize_elements() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Initialize global state
|
// Initialize global state
|
||||||
current_checks = checks.collected + checks.found;
|
current_checks = checks.collected + checks.found;
|
||||||
current_entrances = entrances.found;
|
current_entrances = entrances.found;
|
||||||
@ -122,32 +121,39 @@ async function initialize_elements() {
|
|||||||
|
|
||||||
async function refresh_elements() {
|
async function refresh_elements() {
|
||||||
try {
|
try {
|
||||||
const response = await update.fetch_api(server_address, "overview");
|
const response = await update.fetch_api(server_address, "overview");
|
||||||
|
|
||||||
// Check if the "Hide completed areas" option is checked
|
// Check if the "Hide completed areas" option is checked
|
||||||
hide_completed_areas = document.getElementById("hideDone").checked;
|
hide_completed_areas = document.getElementById("hideDone").checked;
|
||||||
|
|
||||||
if (response.data) {
|
if (response.data) {
|
||||||
if (!can_access_api_server) {
|
|
||||||
console.info("I found the server!");
|
|
||||||
document.getElementById("status-block").classList.add("hidden");
|
|
||||||
can_access_api_server = true;
|
|
||||||
await initialize_elements();
|
|
||||||
}
|
|
||||||
is_timeout = false;
|
|
||||||
await update_if_changes(response.data);
|
|
||||||
setTimeout(refresh_elements, 500)
|
|
||||||
} else if (response.error) {
|
|
||||||
setTimeout(refresh_elements, 1100)
|
|
||||||
if (response.error.error) {
|
|
||||||
if (!is_timeout) {
|
|
||||||
is_timeout = true;
|
|
||||||
console.debug("Received timeout from API server.");
|
|
||||||
}
|
|
||||||
if (!can_access_api_server) {
|
if (!can_access_api_server) {
|
||||||
console.info("I found the server!");
|
console.info("I found the server!");
|
||||||
document.getElementById("status-block").classList.add("hidden");
|
document.getElementById("status-block").classList.add("hidden");
|
||||||
can_access_api_server = true;
|
can_access_api_server = true;
|
||||||
|
await initialize_elements();
|
||||||
|
}
|
||||||
|
is_timeout = false;
|
||||||
|
await update_if_changes(response.data);
|
||||||
|
setTimeout(refresh_elements, 500);
|
||||||
|
} else if (response.error) {
|
||||||
|
setTimeout(refresh_elements, 1100);
|
||||||
|
if (response.error.error) {
|
||||||
|
if (!is_timeout) {
|
||||||
|
is_timeout = true;
|
||||||
|
console.debug("Received timeout from API server.");
|
||||||
|
}
|
||||||
|
if (!can_access_api_server) {
|
||||||
|
console.info("I found the server!");
|
||||||
|
document.getElementById("status-block").classList.add("hidden");
|
||||||
|
can_access_api_server = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (can_access_api_server) {
|
||||||
|
console.debug("Could not access the API server.");
|
||||||
|
document.getElementById("status-block").classList.remove("hidden");
|
||||||
|
}
|
||||||
|
can_access_api_server = false;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (can_access_api_server) {
|
if (can_access_api_server) {
|
||||||
@ -155,21 +161,11 @@ async function refresh_elements() {
|
|||||||
document.getElementById("status-block").classList.remove("hidden");
|
document.getElementById("status-block").classList.remove("hidden");
|
||||||
}
|
}
|
||||||
can_access_api_server = false;
|
can_access_api_server = false;
|
||||||
|
setTimeout(refresh_elements, 1100);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (can_access_api_server) {
|
|
||||||
console.debug("Could not access the API server.");
|
|
||||||
document.getElementById("status-block").classList.remove("hidden");
|
|
||||||
}
|
|
||||||
can_access_api_server = false;
|
|
||||||
setTimeout(refresh_elements, 1100)
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
setTimeout(refresh_elements, 1100)
|
setTimeout(refresh_elements, 1100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function update_if_changes(overview) {
|
async function update_if_changes(overview) {
|
||||||
@ -574,7 +570,9 @@ async function initialize_checks_list(checks_list, checks) {
|
|||||||
// Update the check totals
|
// Update the check totals
|
||||||
checks_list.querySelector(
|
checks_list.querySelector(
|
||||||
".breakdown-block-checks-title"
|
".breakdown-block-checks-title"
|
||||||
).textContent = `Checks: ${checks.collected + checks.found}/${checks.total} (${checks.remaining} left)`;
|
).textContent = `Checks: ${checks.collected + checks.found}/${
|
||||||
|
checks.total
|
||||||
|
} (${checks.remaining} left)`;
|
||||||
checks_list.querySelector(
|
checks_list.querySelector(
|
||||||
".breakdown-block-checks-title"
|
".breakdown-block-checks-title"
|
||||||
).dataset.checksCollected = checks.collected + checks.found;
|
).dataset.checksCollected = checks.collected + checks.found;
|
||||||
@ -725,7 +723,9 @@ async function initialize_summary(summary_element, scene, checks, entrances) {
|
|||||||
summary_checks.dataset.checksCollected = checks.collected + checks.found;
|
summary_checks.dataset.checksCollected = checks.collected + checks.found;
|
||||||
summary_checks.dataset.checksRemaining = checks.remaining;
|
summary_checks.dataset.checksRemaining = checks.remaining;
|
||||||
summary_checks.dataset.checksTotal = checks.total;
|
summary_checks.dataset.checksTotal = checks.total;
|
||||||
summary_checks.textContent = `Checks: ${checks.collected + checks.found}/${checks.total} (${checks.remaining})`;
|
summary_checks.textContent = `Checks: ${checks.collected + checks.found}/${
|
||||||
|
checks.total
|
||||||
|
} (${checks.remaining})`;
|
||||||
|
|
||||||
const summary_entrances = summary_element.querySelector(".summary-entrances");
|
const summary_entrances = summary_element.querySelector(".summary-entrances");
|
||||||
summary_entrances.dataset.entrancesFound = entrances.found;
|
summary_entrances.dataset.entrancesFound = entrances.found;
|
||||||
@ -787,7 +787,9 @@ async function update_summary(scene, checks, entrances) {
|
|||||||
summary_checks.dataset.checksCollected = checks.collected + checks.found;
|
summary_checks.dataset.checksCollected = checks.collected + checks.found;
|
||||||
summary_checks.dataset.checksRemaining = checks.remaining;
|
summary_checks.dataset.checksRemaining = checks.remaining;
|
||||||
summary_checks.dataset.checksTotal = checks.total;
|
summary_checks.dataset.checksTotal = checks.total;
|
||||||
summary_checks.textContent = `Checks: ${checks.collected + checks.found}/${checks.total} (${checks.remaining})`;
|
summary_checks.textContent = `Checks: ${checks.collected + checks.found}/${
|
||||||
|
checks.total
|
||||||
|
} (${checks.remaining})`;
|
||||||
}
|
}
|
||||||
if (entrances_changed) {
|
if (entrances_changed) {
|
||||||
summary_entrances.dataset.entrancesFound = entrances.found;
|
summary_entrances.dataset.entrancesFound = entrances.found;
|
||||||
@ -856,7 +858,9 @@ async function update_breakdown_checks(scene, checks) {
|
|||||||
// Update the check totals
|
// Update the check totals
|
||||||
document.querySelector(
|
document.querySelector(
|
||||||
`.breakdown[data-scene="${scene}"] .breakdown-block-checks-title`
|
`.breakdown[data-scene="${scene}"] .breakdown-block-checks-title`
|
||||||
).textContent = `Checks: ${checks.collected + checks.found}/${checks.total} (${checks.remaining} left)`;
|
).textContent = `Checks: ${checks.collected + checks.found}/${
|
||||||
|
checks.total
|
||||||
|
} (${checks.remaining} left)`;
|
||||||
document.querySelector(
|
document.querySelector(
|
||||||
`.breakdown[data-scene="${scene}"] .breakdown-block-checks-title`
|
`.breakdown[data-scene="${scene}"] .breakdown-block-checks-title`
|
||||||
).dataset.checksCollected = checks.collected + checks.found;
|
).dataset.checksCollected = checks.collected + checks.found;
|
||||||
@ -925,7 +929,10 @@ async function update_breakdown(scene, checks, entrances) {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Check for changes, and if so, update
|
// Check for changes, and if so, update
|
||||||
if (breakdown_checks.dataset.checksCollected != checks.collected + checks.found) {
|
if (
|
||||||
|
breakdown_checks.dataset.checksCollected !=
|
||||||
|
checks.collected + checks.found
|
||||||
|
) {
|
||||||
update_breakdown_checks(scene, checks);
|
update_breakdown_checks(scene, checks);
|
||||||
}
|
}
|
||||||
if (breakdown_entrances.dataset.entrancesFound != entrances.found) {
|
if (breakdown_entrances.dataset.entrancesFound != entrances.found) {
|
||||||
@ -948,9 +955,12 @@ async function update_breakdown_list(data, changed) {
|
|||||||
update_breakdown(
|
update_breakdown(
|
||||||
scene,
|
scene,
|
||||||
{
|
{
|
||||||
collected: document.querySelector(
|
collected: parseInt(
|
||||||
`.breakdown[data-scene="${scene}"] .breakdown-block-checks-title`
|
document.querySelector(
|
||||||
).dataset.checksCollected,
|
`.breakdown[data-scene="${scene}"] .breakdown-block-checks-title`
|
||||||
|
).dataset.checksCollected
|
||||||
|
),
|
||||||
|
found: 0,
|
||||||
},
|
},
|
||||||
data.scenes[scene]
|
data.scenes[scene]
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user