mirror of
https://github.com/Retropex/custom-ocean.xyz-dashboard.git
synced 2025-05-12 19:20:45 +02:00
Update main.js
This commit is contained in:
parent
0280a6fa15
commit
691e0aed25
109
main.js
109
main.js
@ -493,6 +493,20 @@ function updateElementHTML(elementId, html) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update workers_hashing value from metrics, but don't try to access worker details
|
||||||
|
function updateWorkersCount() {
|
||||||
|
if (latestMetrics && latestMetrics.workers_hashing !== undefined) {
|
||||||
|
$("#workers_hashing").text(latestMetrics.workers_hashing || 0);
|
||||||
|
|
||||||
|
// Update miner status with online/offline indicator based on worker count
|
||||||
|
if (latestMetrics.workers_hashing > 0) {
|
||||||
|
updateElementHTML("miner_status", "<span class='status-green'>ONLINE</span> <span class='online-dot'></span>");
|
||||||
|
} else {
|
||||||
|
updateElementHTML("miner_status", "<span class='status-red'>OFFLINE</span> <span class='offline-dot'></span>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Check for block updates and show congratulatory messages
|
// Check for block updates and show congratulatory messages
|
||||||
function checkForBlockUpdates(data) {
|
function checkForBlockUpdates(data) {
|
||||||
if (previousMetrics.last_block_height !== undefined &&
|
if (previousMetrics.last_block_height !== undefined &&
|
||||||
@ -571,16 +585,9 @@ function updateUI() {
|
|||||||
updateElementText("monthly_profit_usd", "$" + numberWithCommas(data.monthly_profit_usd.toFixed(2)));
|
updateElementText("monthly_profit_usd", "$" + numberWithCommas(data.monthly_profit_usd.toFixed(2)));
|
||||||
updateElementText("daily_mined_sats", numberWithCommas(data.daily_mined_sats) + " sats");
|
updateElementText("daily_mined_sats", numberWithCommas(data.daily_mined_sats) + " sats");
|
||||||
updateElementText("monthly_mined_sats", numberWithCommas(data.monthly_mined_sats) + " sats");
|
updateElementText("monthly_mined_sats", numberWithCommas(data.monthly_mined_sats) + " sats");
|
||||||
updateElementText("workers_hashing", data.workers_hashing || 0);
|
|
||||||
|
|
||||||
// Update miner status with online/offline indicator
|
// Update worker count from metrics (just the number, not full worker data)
|
||||||
if (data.workers_hashing > 0) {
|
updateWorkersCount();
|
||||||
updateElementHTML("miner_status", "ONLINE <span class='online-dot'></span>");
|
|
||||||
$("#miner_status").css("color", "#32CD32");
|
|
||||||
} else {
|
|
||||||
updateElementHTML("miner_status", "OFFLINE <span class='offline-dot'></span>");
|
|
||||||
$("#miner_status").css("color", "red");
|
|
||||||
}
|
|
||||||
|
|
||||||
updateElementText("unpaid_earnings", data.unpaid_earnings + " BTC");
|
updateElementText("unpaid_earnings", data.unpaid_earnings + " BTC");
|
||||||
|
|
||||||
@ -620,7 +627,7 @@ function updateUI() {
|
|||||||
|
|
||||||
// Update last updated timestamp
|
// Update last updated timestamp
|
||||||
const now = new Date(Date.now() + serverTimeOffset);
|
const now = new Date(Date.now() + serverTimeOffset);
|
||||||
updateElementHTML("lastUpdated", "<strong>Last Updated:</strong> " + now.toLocaleString());
|
updateElementHTML("lastUpdated", "<strong>Last Updated:</strong> " + now.toLocaleString() + "<span id='terminal-cursor'></span>");
|
||||||
|
|
||||||
// Update chart if it exists
|
// Update chart if it exists
|
||||||
if (trendChart) {
|
if (trendChart) {
|
||||||
@ -678,6 +685,25 @@ function updateUI() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set up refresh synchronization
|
||||||
|
function setupRefreshSync() {
|
||||||
|
// Listen for the dataRefreshed event
|
||||||
|
$(document).on('dataRefreshed', function() {
|
||||||
|
// Broadcast to any other open tabs/pages that the data has been refreshed
|
||||||
|
try {
|
||||||
|
// Store the current timestamp to localStorage
|
||||||
|
localStorage.setItem('dashboardRefreshTime', Date.now().toString());
|
||||||
|
|
||||||
|
// Create a custom event that can be detected across tabs/pages
|
||||||
|
localStorage.setItem('dashboardRefreshEvent', 'refresh-' + Date.now());
|
||||||
|
|
||||||
|
console.log("Dashboard refresh synchronized");
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error synchronizing refresh:", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Document ready initialization
|
// Document ready initialization
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
// Initialize the chart
|
// Initialize the chart
|
||||||
@ -720,6 +746,9 @@ $(document).ready(function() {
|
|||||||
setInterval(updateUptime, 1000);
|
setInterval(updateUptime, 1000);
|
||||||
updateUptime();
|
updateUptime();
|
||||||
|
|
||||||
|
// Set up refresh synchronization with workers page
|
||||||
|
setupRefreshSync();
|
||||||
|
|
||||||
// Add a manual refresh button for fallback
|
// Add a manual refresh button for fallback
|
||||||
$("body").append('<button id="refreshButton" style="position: fixed; bottom: 20px; left: 20px; z-index: 1000; background: #f7931a; color: black; border: none; padding: 8px 16px; display: none; border-radius: 4px; cursor: pointer;">Refresh Data</button>');
|
$("body").append('<button id="refreshButton" style="position: fixed; bottom: 20px; left: 20px; z-index: 1000; background: #f7931a; color: black; border: none; padding: 8px 16px; display: none; border-radius: 4px; cursor: pointer;">Refresh Data</button>');
|
||||||
|
|
||||||
@ -736,37 +765,37 @@ $(document).ready(function() {
|
|||||||
// Force a data refresh when the page loads
|
// Force a data refresh when the page loads
|
||||||
manualRefresh();
|
manualRefresh();
|
||||||
|
|
||||||
// Add emergency refresh button functionality
|
// Add emergency refresh button functionality
|
||||||
$("#forceRefreshBtn").show().on("click", function() {
|
$("#forceRefreshBtn").show().on("click", function() {
|
||||||
$(this).text("Refreshing...");
|
$(this).text("Refreshing...");
|
||||||
$(this).prop("disabled", true);
|
$(this).prop("disabled", true);
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: '/api/force-refresh',
|
url: '/api/force-refresh',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
timeout: 15000,
|
timeout: 15000,
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
console.log("Force refresh successful:", data);
|
console.log("Force refresh successful:", data);
|
||||||
manualRefresh(); // Immediately get the new data
|
manualRefresh(); // Immediately get the new data
|
||||||
$("#forceRefreshBtn").text("Force Refresh").prop("disabled", false);
|
$("#forceRefreshBtn").text("Force Refresh").prop("disabled", false);
|
||||||
},
|
},
|
||||||
error: function(xhr, status, error) {
|
error: function(xhr, status, error) {
|
||||||
console.error("Force refresh failed:", error);
|
console.error("Force refresh failed:", error);
|
||||||
$("#forceRefreshBtn").text("Force Refresh").prop("disabled", false);
|
$("#forceRefreshBtn").text("Force Refresh").prop("disabled", false);
|
||||||
alert("Refresh failed: " + error);
|
alert("Refresh failed: " + error);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
// Add stale data detection
|
// Add stale data detection
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
if (latestMetrics && latestMetrics.server_timestamp) {
|
if (latestMetrics && latestMetrics.server_timestamp) {
|
||||||
const lastUpdate = new Date(latestMetrics.server_timestamp);
|
const lastUpdate = new Date(latestMetrics.server_timestamp);
|
||||||
const timeSinceUpdate = Math.floor((Date.now() - lastUpdate.getTime()) / 1000);
|
const timeSinceUpdate = Math.floor((Date.now() - lastUpdate.getTime()) / 1000);
|
||||||
if (timeSinceUpdate > 120) { // More than 2 minutes
|
if (timeSinceUpdate > 120) { // More than 2 minutes
|
||||||
showConnectionIssue(`Data stale (${timeSinceUpdate}s old). Use Force Refresh.`);
|
showConnectionIssue(`Data stale (${timeSinceUpdate}s old). Use Force Refresh.`);
|
||||||
$("#forceRefreshBtn").show();
|
$("#forceRefreshBtn").show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}, 30000); // Check every 30 seconds
|
||||||
}, 30000); // Check every 30 seconds
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user