Skip to content

Commit

Permalink
add loading status while refreshing module (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
asiyani authored Dec 23, 2024
1 parent 146dfc3 commit 59933b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
27 changes: 19 additions & 8 deletions webserver/static/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ function forceRun(namespace, module, planOnly) {
// Disable the buttons and close existing alert
setForcedButtonDisabled(true)

closeOpenAlert()

url = window.location.origin + "/api/v1/forceRun"

fetch(url, {
Expand Down Expand Up @@ -107,7 +105,17 @@ function reLoadModule(namespace, module) {

// Send an XHR request to the server to get module info including run outputs
function loadModule(namespace, module) {
closeOpenAlert()
const moduleElm = document.getElementById("module-info")

moduleElm.innerHTML = `
<div class="card">
<div class="card-body">
<div class="d-flex align-items-center justify-content-center" style="color: #550091;">
<div class="spinner-border mx-4" role="status" aria-hidden="true"></div>
<strong>Loading...</strong>
</div>
</div>
</div>`

url = window.location.origin + "/module"

Expand All @@ -128,7 +136,6 @@ function loadModule(namespace, module) {
})
.then((html) => {
// update module template
const moduleElm = document.getElementById("module-info")
moduleElm.innerHTML = html;

// get current state value to update state in modules list as well
Expand All @@ -147,10 +154,12 @@ function loadModule(namespace, module) {
}
})
.catch((err) => {
showForceAlert(
false,
err + "<br/>Check terraform-applier logs for more info."
)
moduleElm.innerHTML = `
<div class="card">
<div class="card-body text-danger">`
+ err + `<br/>Check terraform-applier logs for more info.
</div>
</div>`
})
}

Expand All @@ -166,6 +175,8 @@ function showForceAlert(success, message) {
].join("")

alertPlaceholder.append(wrapper)
// auto close alert
setTimeout(function () { closeOpenAlert() }, 10000);
}

function closeOpenAlert() {
Expand Down
3 changes: 1 addition & 2 deletions webserver/templates/module.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
{{define "module"}}
{{$m := .}}
<div id="{{sanitizedUniqueName .Module.NamespacedName}}">
<div class='card {{if eq .Module.Status.CurrentState "Running"}}border-info{{end}}' class="d-none"
style="max-height: 90vh;">
<div class='card {{if eq .Module.Status.CurrentState "Running"}}border-info{{end}}' style="max-height: 90vh;">
<div class="card-header bg-transparent">
<div href="#{{ sanitizedUniqueName .Module.NamespacedName}}-info">
<div class="d-flex justify-content-between align-items-center mb-1">
Expand Down

0 comments on commit 59933b7

Please sign in to comment.