Skip to content

Commit

Permalink
who knows
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reynolds committed Apr 29, 2024
1 parent 1ada99b commit 5fbcfbd
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions labapp/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,15 @@
<script>
document.addEventListener('DOMContentLoaded', function() {
function fetchAndUpdateStatus() {
let cachedStatus = getCookie('statusCache');
if (cachedStatus) {
document.getElementById('siteName').textContent = cachedStatus['site_name'];
// Get cached values
let cachedSiteName = getCookie('siteNameCache');
let cachedState = getCookie('stateCache');

// Update the page with cached values if they exist
if (cachedSiteName && cachedState) {
document.getElementById('statusText').textContent = `Site Name: ${cachedSiteName}, State: ${cachedState}`;
} else {
// Fetch from server if no valid cache exists
fetch('/_ce_status')
.then(response => {
if (!response.ok) {
Expand All @@ -145,23 +150,36 @@
return response.json();
})
.then(data => {
document.getElementById('siteName').textContent = data['site_name]'];
// Cache the status in a cookie for 1 day
setCookie('statusCache', data.site_name, 1);
if (!data.err) {
document.getElementById('statusText').textContent = `Site Name: ${data.site_name}, State: ${data.state}`;
// Cache the site name and state in cookies for 1 day
setCookie('siteNameCache', data.site_name, 1);
setCookie('stateCache', data.state, 1);
} else {
// Handle potential errors in data retrieval
document.getElementById('statusText').textContent = 'Error fetching status';
}
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
document.getElementById('statusText').textContent = 'Error';
});
}
}

// Initial fetch on page load
fetchAndUpdateStatus();

// Re-fetch every 20 seconds
setInterval(() => {
setCookie('statusCache', '', 0);
// Expire the cookie explicitly by setting days to 0
setCookie('siteNameCache', '', 0);
setCookie('stateCache', '', 0);
fetchAndUpdateStatus();
}, 10000);
}, 20000);
});
</script>

<div class="status-box align-items-center bg-light p-2">
<p>Status: <strong id="siteName">Loading...</strong></p>
</div>
Expand Down

0 comments on commit 5fbcfbd

Please sign in to comment.