From 56a4429f01619c36c43a17d2dc6d6743c55eebb3 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Mon, 1 Aug 2022 00:47:41 +0300 Subject: [PATCH 1/3] Move web interface to configure application into src/interface/web directory - Improve code layout by ensuring all web interface specific code under the src/interface/web directory - Rename config API to more specifi /config instead of /ui - Rename config data GET, POST api to /config/data instead of /config --- .../interface/web/assets/config-style.css | 0 {views/scripts => src/interface/web/assets}/config.js | 9 +++++---- {views => src/interface/web}/config.html | 4 ++-- src/interface/web/index.html | 2 +- src/main.py | 9 ++++----- 5 files changed, 12 insertions(+), 12 deletions(-) rename views/style.css => src/interface/web/assets/config-style.css (100%) rename {views/scripts => src/interface/web/assets}/config.js (96%) rename {views => src/interface/web}/config.html (66%) diff --git a/views/style.css b/src/interface/web/assets/config-style.css similarity index 100% rename from views/style.css rename to src/interface/web/assets/config-style.css diff --git a/views/scripts/config.js b/src/interface/web/assets/config.js similarity index 96% rename from views/scripts/config.js rename to src/interface/web/assets/config.js index c3f47743..30ab6858 100644 --- a/views/scripts/config.js +++ b/src/interface/web/assets/config.js @@ -10,7 +10,7 @@ var emptyValueDefault = "🖊️"; /** * Fetch the existing config file. */ -fetch("/config") +fetch("/config/data") .then(response => response.json()) .then(data => { rawConfig = data; @@ -26,15 +26,16 @@ fetch("/config") configForm.addEventListener("submit", (event) => { event.preventDefault(); console.log(rawConfig); - const response = fetch("/config", { + fetch("/config/data", { method: "POST", credentials: "same-origin", headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(rawConfig) - }).then(response => response.json()) - .then((data) => console.log(data)); + }) + .then(response => response.json()) + .then(data => console.log(data)); }); }); diff --git a/views/config.html b/src/interface/web/config.html similarity index 66% rename from views/config.html rename to src/interface/web/config.html index befa8e24..5c959905 100644 --- a/views/config.html +++ b/src/interface/web/config.html @@ -1,12 +1,12 @@ Set directories for your config file. - +
- + diff --git a/src/interface/web/index.html b/src/interface/web/index.html index 333abc19..542ae63b 100644 --- a/src/interface/web/index.html +++ b/src/interface/web/index.html @@ -85,7 +85,7 @@ function populate_type_dropdown() { // Populate type dropdown field with enabled search types only var possible_search_types = ["org", "markdown", "ledger", "music", "image"]; - fetch("/config") + fetch("/config/data") .then(response => response.json()) .then(data => { document.getElementById("type").innerHTML = diff --git a/src/main.py b/src/main.py index 92da0e9f..b4d3ec46 100644 --- a/src/main.py +++ b/src/main.py @@ -34,22 +34,21 @@ app = FastAPI() web_directory = f'src/interface/web/' app.mount("/static", StaticFiles(directory=web_directory), name="static") -app.mount("/views", StaticFiles(directory="views"), name="views") -templates = Jinja2Templates(directory="views/") +templates = Jinja2Templates(directory=web_directory) @app.get("/", response_class=FileResponse) def index(): return FileResponse(web_directory + "index.html") -@app.get('/ui', response_class=HTMLResponse) +@app.get('/config', response_class=HTMLResponse) def ui(request: Request): return templates.TemplateResponse("config.html", context={'request': request}) -@app.get('/config', response_model=FullConfig) +@app.get('/config/data', response_model=FullConfig) def config_data(): return config -@app.post('/config') +@app.post('/config/data') async def config_data(updated_config: FullConfig): global config config = updated_config From 075dba5d6437fba7e83e43ee6df8f031bfd7bcb3 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Mon, 1 Aug 2022 01:27:14 +0300 Subject: [PATCH 2/3] Use Khoj Title, Favicon in Config Page for Consistency --- src/interface/web/config.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/interface/web/config.html b/src/interface/web/config.html index 5c959905..d8925769 100644 --- a/src/interface/web/config.html +++ b/src/interface/web/config.html @@ -1,7 +1,9 @@ - Set directories for your config file. + + + Khoj - Configure App
From 1201bfddf3a5130a5e96ac3692f3597bc323c4f8 Mon Sep 17 00:00:00 2001 From: Debanjum Singh Solanky Date: Mon, 1 Aug 2022 01:34:00 +0300 Subject: [PATCH 3/3] Simplify name of config css from config-style.css to config.css --- src/interface/web/assets/{config-style.css => config.css} | 0 src/interface/web/config.html | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename src/interface/web/assets/{config-style.css => config.css} (100%) diff --git a/src/interface/web/assets/config-style.css b/src/interface/web/assets/config.css similarity index 100% rename from src/interface/web/assets/config-style.css rename to src/interface/web/assets/config.css diff --git a/src/interface/web/config.html b/src/interface/web/config.html index d8925769..27de4aa9 100644 --- a/src/interface/web/config.html +++ b/src/interface/web/config.html @@ -2,7 +2,7 @@ - + Khoj - Configure App