mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-08 05:39:13 +00:00
Add a dummy POST config endpoint, integrate with editable UI
This commit is contained in:
@@ -37,10 +37,9 @@ def config():
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
@app.post('/config')
|
@app.post('/config')
|
||||||
def config():
|
async def config(updated_config: Request):
|
||||||
print("hello posted config")
|
data = await updated_config.json()
|
||||||
print(config)
|
return data
|
||||||
return config
|
|
||||||
|
|
||||||
@app.get('/search')
|
@app.get('/search')
|
||||||
def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None):
|
def search(q: str, n: Optional[int] = 5, t: Optional[SearchType] = None):
|
||||||
|
|||||||
@@ -16,10 +16,15 @@ fetch("/config")
|
|||||||
|
|
||||||
configForm.addEventListener("submit", (event) => {
|
configForm.addEventListener("submit", (event) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
console.log("submitted!");
|
const response = fetch("/config", {
|
||||||
console.log(event);
|
method: "POST",
|
||||||
console.log(configForm.children);
|
credentials: "same-origin",
|
||||||
console.log(configForm.childNodes);
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify(rawConfig)
|
||||||
|
}).then(response => response.json())
|
||||||
|
.then((data) => console.log(data));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -29,24 +34,21 @@ function processChildren(element, data) {
|
|||||||
child.id = key;
|
child.id = key;
|
||||||
child.className = "config-element";
|
child.className = "config-element";
|
||||||
child.appendChild(document.createTextNode(key + ": "));
|
child.appendChild(document.createTextNode(key + ": "));
|
||||||
if (data[key] === Object(data[key])) {
|
if (data[key] === Object(data[key]) && !Array.isArray(data[key])) {
|
||||||
processChildren(child, data[key]);
|
processChildren(child, data[key]);
|
||||||
} else {
|
} else {
|
||||||
var value = document.createElement("span");
|
var value = document.createElement("span");
|
||||||
value.id = key+"-value";
|
value.id = key+"-value";
|
||||||
value.textContent = data[key];
|
value.textContent = !data[key] ? "🖊️" : data[key];
|
||||||
makeElementEditable(value, data, key);
|
makeElementEditable(value, data, key);
|
||||||
child.appendChild(value);
|
child.appendChild(value);
|
||||||
}
|
}
|
||||||
element.appendChild(child);
|
element.appendChild(child);
|
||||||
// data[key] = "wassup?";
|
|
||||||
}
|
}
|
||||||
console.log(data);
|
|
||||||
console.log(rawConfig);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeElementEditable(original, data, key) {
|
function makeElementEditable(original, data, key) {
|
||||||
original.addEventListener("click", (event) => {
|
original.addEventListener("click", () => {
|
||||||
var inputNewText = document.createElement("input");
|
var inputNewText = document.createElement("input");
|
||||||
inputNewText.type = "text";
|
inputNewText.type = "text";
|
||||||
inputNewText.className = "config-element-edit";
|
inputNewText.className = "config-element-edit";
|
||||||
@@ -59,22 +61,11 @@ function makeElementEditable(original, data, key) {
|
|||||||
|
|
||||||
function fixInputOnFocusOut(original, data, key) {
|
function fixInputOnFocusOut(original, data, key) {
|
||||||
original.addEventListener("blur", () => {
|
original.addEventListener("blur", () => {
|
||||||
console.log(original);
|
|
||||||
var value = document.createElement("span");
|
var value = document.createElement("span");
|
||||||
value.id = original.id;
|
value.id = original.id;
|
||||||
value.textContent = original.value;
|
value.textContent = original.value;
|
||||||
data[key] = value.textContent;
|
data[key] = value.textContent;
|
||||||
console.log(data);
|
makeElementEditable(value, data, key);
|
||||||
console.log(rawConfig);
|
|
||||||
makeElementEditable(value);
|
|
||||||
original.parentNode.replaceChild(value, original);
|
original.parentNode.replaceChild(value, original);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSubmit() {
|
|
||||||
submitButton.addEventListener("click", (event) => {
|
|
||||||
var submitButton = document.createElement("button");
|
|
||||||
submitButton.type = "submit";
|
|
||||||
});
|
|
||||||
configForm.appendChild(submitButton);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user