Set content enabled status on update via config buttons on web app

Previously hitting configure or disable wouldn't update the state of
the content cards. It needed page refresh to see if the content was
synced correctly.

Now cards automatically get set to new state on hitting disable button
on card or global configure buttons
This commit is contained in:
Debanjum Singh Solanky
2023-11-07 04:45:25 -08:00
parent 7c424e0d5f
commit 045c2252d6

View File

@@ -8,11 +8,13 @@
<div class="card"> <div class="card">
<div class="card-title-row"> <div class="card-title-row">
<img class="card-icon" src="/static/assets/icons/computer.png" alt="Computer"> <img class="card-icon" src="/static/assets/icons/computer.png" alt="Computer">
<h3 class="card-title"> <h3 id="card-title-computer" class="card-title">
Files Files
{% if current_model_state.computer == True %} <img id="configured-icon-computer"
<img id="configured-icon-github" class="configured-icon" src="/static/assets/icons/confirm-icon.svg" alt="Configured"> style="display: {% if not current_model_state.computer %}none{% endif %}"
{% endif %} class="configured-icon"
src="/static/assets/icons/confirm-icon.svg"
alt="Configured">
</h3> </h3>
</div> </div>
<div class="card-description-row"> <div class="card-description-row">
@@ -28,22 +30,23 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M12 5l7 7-7 7"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M12 5l7 7-7 7"></path></svg>
</a> </a>
</div> </div>
{% if current_model_state.computer %} <div id="clear-computer" class="card-action-row"
<div id="clear-desktop" class="card-action-row"> style="display: {% if not current_model_state.computer %}none{% endif %}">
<button class="card-button" onclick="clearContentType('computer')"> <button class="card-button" onclick="clearContentType('computer')">
Disable Disable
</button> </button>
</div> </div>
{% endif %}
</div> </div>
<div class="card"> <div class="card">
<div class="card-title-row"> <div class="card-title-row">
<img class="card-icon" src="/static/assets/icons/github.svg" alt="Github"> <img class="card-icon" src="/static/assets/icons/github.svg" alt="Github">
<h3 class="card-title"> <h3 class="card-title">
Github Github
{% if current_model_state.github == True %} <img id="configured-icon-github"
<img id="configured-icon-github" class="configured-icon" src="/static/assets/icons/confirm-icon.svg" alt="Configured"> class="configured-icon"
{% endif %} src="/static/assets/icons/confirm-icon.svg"
alt="Configured"
style="display: {% if not current_model_state.github %}none{% endif %}">
</h3> </h3>
</div> </div>
<div class="card-description-row"> <div class="card-description-row">
@@ -59,22 +62,24 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M12 5l7 7-7 7"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M12 5l7 7-7 7"></path></svg>
</a> </a>
</div> </div>
{% if current_model_state.github %} <div id="clear-github"
<div id="clear-github" class="card-action-row"> class="card-action-row"
<button class="card-button" onclick="clearContentType('github')"> style="display: {% if not current_model_state.github %}none{% endif %}">
Disable <button class="card-button" onclick="clearContentType('github')">
</button> Disable
</div> </button>
{% endif %} </div>
</div> </div>
<div class="card"> <div class="card">
<div class="card-title-row"> <div class="card-title-row">
<img class="card-icon" src="/static/assets/icons/notion.svg" alt="Notion"> <img class="card-icon" src="/static/assets/icons/notion.svg" alt="Notion">
<h3 class="card-title"> <h3 class="card-title">
Notion Notion
{% if current_model_state.notion == True %} <img id="configured-icon-notion"
<img id="configured-icon-notion" class="configured-icon" src="/static/assets/icons/confirm-icon.svg" alt="Configured"> class="configured-icon"
{% endif %} src="/static/assets/icons/confirm-icon.svg"
alt="Configured"
style="display: {% if not current_model_state.notion %}none{% endif %}">
</h3> </h3>
</div> </div>
<div class="card-description-row"> <div class="card-description-row">
@@ -90,13 +95,13 @@
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M12 5l7 7-7 7"></path></svg> <svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14M12 5l7 7-7 7"></path></svg>
</a> </a>
</div> </div>
{% if current_model_state.notion %} <div id="clear-notion"
<div id="clear-notion" class="card-action-row"> class="card-action-row"
<button class="card-button" onclick="clearContentType('notion')"> style="display: {% if not current_model_state.notion %}none{% endif %}">
Disable <button class="card-button" onclick="clearContentType('notion')">
</button> Disable
</div> </button>
{% endif %} </div>
</div> </div>
</div> </div>
</div> </div>
@@ -208,18 +213,11 @@
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
if (data.status == "ok") { if (data.status == "ok") {
var contentTypeClearButton = document.getElementById("clear-" + content_source); document.getElementById("configured-icon-" + content_source).style.display = "none";
contentTypeClearButton.style.display = "none"; document.getElementById("clear-" + content_source).style.display = "none";
} else {
var configuredIcon = document.getElementById("configured-icon-" + content_source); document.getElementById("configured-icon-" + content_source).style.display = "";
if (configuredIcon) { document.getElementById("clear-" + content_source).style.display = "";
configuredIcon.style.display = "none";
}
var misconfiguredIcon = document.getElementById("misconfigured-icon-" + content_source);
if (misconfiguredIcon) {
misconfiguredIcon.style.display = "none";
}
} }
}) })
}; };
@@ -265,6 +263,7 @@
if (data.detail != null) { if (data.detail != null) {
throw new Error(data.detail); throw new Error(data.detail);
} }
document.getElementById("status").innerHTML = emoji + " " + successText; document.getElementById("status").innerHTML = emoji + " " + successText;
document.getElementById("status").style.display = "block"; document.getElementById("status").style.display = "block";
button.disabled = false; button.disabled = false;
@@ -277,6 +276,26 @@
button.disabled = false; button.disabled = false;
button.innerHTML = '⚠️ Unsuccessful'; button.innerHTML = '⚠️ Unsuccessful';
}); });
content_sources = ["computer", "github", "notion"];
content_sources.forEach(content_source => {
fetch(`/api/config/data/${content_source}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
}
})
.then(response => response.json())
.then(data => {
if (data.length > 0) {
document.getElementById("configured-icon-" + content_source).style.display = "";
document.getElementById("clear-" + content_source).style.display = "";
} else {
document.getElementById("configured-icon-" + content_source).style.display = "none";
document.getElementById("clear-" + content_source).style.display = "none";
}
});
});
} }
// Setup the results count slider // Setup the results count slider