Skip to content

Commit

Permalink
stop messing
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Reynolds committed Apr 29, 2024
1 parent 4dd99d3 commit 9c7fd03
Showing 1 changed file with 60 additions and 58 deletions.
118 changes: 60 additions & 58 deletions labapp/app/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,66 @@
<img src="/static/logo.png" width="100" height="auto" alt="Logo">
<span class="fs-5 fw-semibold">MCN Practical</span>
</a>

{% 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 %}



<ul class="list-unstyled ps-0">
<li class="mb-1">
<button class="btn btn-toggle align-items-center rounded collapsed" data-bs-toggle="collapse" data-bs-target="#home-collapse" aria-expanded="false">
Expand Down Expand Up @@ -128,64 +188,6 @@
</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 9c7fd03

Please sign in to comment.