Skip to content

Commit

Permalink
move on
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reynolds committed Apr 29, 2024
1 parent 73774a9 commit a26a5bc
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions labapp/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,63 @@
</div>
</li>
</ul>
{% if udf %}
<script>
document.addEventListener('DOMContentLoaded', function() {
function fetchAndUpdateStatus() {
fetch('/_ce_status')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then(data => {
if (!data.err) {
document.getElementById('siteName').textContent = data.site_name;
//document.getElementById('siteState').textContent = data.state;
document.getElementById('statusImage').src = data.state === "PROVISIONED" ? "/static/good.png" : "/static/bad.png";

// Update cookies
setCookie('siteNameCache', data.site_name, 1);
setCookie('stateCache', data.state, 1);
} else {
document.getElementById('siteName').textContent = 'Error fetching data';
//document.getElementById('siteState').textContent = '';
document.getElementById('statusImage').src = "/static/bad.png";
}
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
document.getElementById('siteName').textContent = 'Error';
//document.getElementById('siteState').textContent = '';
document.getElementById('statusImage').src = "/static/bad.png";
});
}
});

document.addEventListener('DOMContentLoaded', function() {
let cachedSiteName = getCookie('siteNameCache');
let cachedState = getCookie('stateCache');

if (cachedSiteName && cachedState) {
document.getElementById('siteName').textContent = cachedSiteName;
//document.getElementById('siteState').textContent = cachedState;
document.getElementById('statusImage').src = cachedState === "PROVISIONED" ? "/static/good.png" : "/static/bad.png";
} else {
fetchAndUpdateStatus();
}

setInterval(fetchAndUpdateStatus, 20000);
});

</script>
<div class="status-box align-items-center bg-light p-2 text-center">
<p><strong id="siteName">Loading...</strong></p>
<img id="statusImage" src="/static/bad.png" alt="Status" style="width:50px; height:auto;">
</div>
{% endif %}

</div>
</div>

Expand Down

0 comments on commit a26a5bc

Please sign in to comment.