From 045c2252d6e25143e7b5648b2d310446af7d7013 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Tue, 7 Nov 2023 04:45:25 -0800 Subject: [PATCH] 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 --- src/khoj/interface/web/config.html | 105 +++++++++++++++++------------ 1 file changed, 62 insertions(+), 43 deletions(-) diff --git a/src/khoj/interface/web/config.html b/src/khoj/interface/web/config.html index 1410f20b..5a2089ca 100644 --- a/src/khoj/interface/web/config.html +++ b/src/khoj/interface/web/config.html @@ -8,11 +8,13 @@
Computer -

+

Files - {% if current_model_state.computer == True %} - Configured - {% endif %} + Configured

@@ -28,22 +30,23 @@
- {% if current_model_state.computer %} -
- -
- {% endif %} +
+ +
Github

Github - {% if current_model_state.github == True %} - Configured - {% endif %} + Configured

@@ -59,22 +62,24 @@
- {% if current_model_state.github %} -
- -
- {% endif %} +
+ +
Notion

Notion - {% if current_model_state.notion == True %} - Configured - {% endif %} + Configured

@@ -90,13 +95,13 @@
- {% if current_model_state.notion %} -
- -
- {% endif %} +
+ +
@@ -208,18 +213,11 @@ .then(response => response.json()) .then(data => { if (data.status == "ok") { - var contentTypeClearButton = document.getElementById("clear-" + content_source); - contentTypeClearButton.style.display = "none"; - - var configuredIcon = document.getElementById("configured-icon-" + content_source); - if (configuredIcon) { - configuredIcon.style.display = "none"; - } - - var misconfiguredIcon = document.getElementById("misconfigured-icon-" + content_source); - if (misconfiguredIcon) { - misconfiguredIcon.style.display = "none"; - } + document.getElementById("configured-icon-" + content_source).style.display = "none"; + document.getElementById("clear-" + content_source).style.display = "none"; + } else { + document.getElementById("configured-icon-" + content_source).style.display = ""; + document.getElementById("clear-" + content_source).style.display = ""; } }) }; @@ -265,6 +263,7 @@ if (data.detail != null) { throw new Error(data.detail); } + document.getElementById("status").innerHTML = emoji + " " + successText; document.getElementById("status").style.display = "block"; button.disabled = false; @@ -277,6 +276,26 @@ button.disabled = false; 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