implemented origins & leases auto refresh button

This commit is contained in:
Oscar Krause 2024-03-04 09:53:06 +01:00
parent e5ad0d0516
commit 139b669495
2 changed files with 40 additions and 2 deletions

View File

@ -18,9 +18,10 @@
</button> </button>
</div> </div>
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="load()" title="refresh"> <button type="button" class="btn btn-sm btn-outline-secondary me-2" onclick="load()" title="refresh">
<i class="bi bi-arrow-clockwise"></i> <i class="bi bi-arrow-clockwise"></i>
</button> </button>
<button id="btn-auto-refresh" type="button" class="btn btn-sm active">auto-refresh</button>
</div> </div>
</div> </div>
@ -31,11 +32,29 @@
{% block scripts %} {% block scripts %}
{{ super() }} {{ super() }}
<script type="application/javascript"> <script type="application/javascript">
let autoRefresh = true
function load() { function load() {
const leases = document.getElementById('leases') const leases = document.getElementById('leases')
fetchLeases(leases) fetchLeases(leases)
} }
load() load()
setInterval(() => {
if(autoRefresh)
load()
}, 5000);
const btnAutoRefresh = document.getElementById('btn-auto-refresh')
btnAutoRefresh.addEventListener("click", () => {
if(btnAutoRefresh.classList.contains('active')) {
autoRefresh = false
btnAutoRefresh.classList.remove('active')
} else {
autoRefresh = false
btnAutoRefresh.classList.add('active')
}
}, true);
</script> </script>
{% endblock %} {% endblock %}

View File

@ -21,9 +21,10 @@
</button> </button>
</div> </div>
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="load()" title="refresh"> <button type="button" class="btn btn-sm btn-outline-secondary me-2" onclick="load()" title="refresh">
<i class="bi bi-arrow-clockwise"></i> <i class="bi bi-arrow-clockwise"></i>
</button> </button>
<button id="btn-auto-refresh" type="button" class="btn btn-sm active">auto-refresh</button>
</div> </div>
</div> </div>
@ -34,6 +35,8 @@
{% block scripts %} {% block scripts %}
{{ super() }} {{ super() }}
<script type="application/javascript"> <script type="application/javascript">
let autoRefresh = true
function load() { function load() {
const origins = document.getElementById('origins') const origins = document.getElementById('origins')
fetchOriginsWithLeases(origins) fetchOriginsWithLeases(origins)
@ -47,5 +50,21 @@
if (response) if (response)
deleteOrigins().finally(() => load()) deleteOrigins().finally(() => load())
} }
setInterval(() => {
if(autoRefresh)
load()
}, 5000);
const btnAutoRefresh = document.getElementById('btn-auto-refresh')
btnAutoRefresh.addEventListener("click", () => {
if(btnAutoRefresh.classList.contains('active')) {
autoRefresh = false
btnAutoRefresh.classList.remove('active')
} else {
autoRefresh = false
btnAutoRefresh.classList.add('active')
}
}, true);
</script> </script>
{% endblock %} {% endblock %}