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
49
main.js
49
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>');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user