mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 21:29:13 +00:00
Allow editting query-to-run from the automation config section
This commit is contained in:
4
src/khoj/interface/web/assets/icons/edit.svg
Normal file
4
src/khoj/interface/web/assets/icons/edit.svg
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
||||||
|
<svg width="800px" height="800px" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg" fill="none">
|
||||||
|
<path fill="#000000" fill-rule="evenodd" d="M15.198 3.52a1.612 1.612 0 012.223 2.336L6.346 16.421l-2.854.375 1.17-3.272L15.197 3.521zm3.725-1.322a3.612 3.612 0 00-5.102-.128L3.11 12.238a1 1 0 00-.253.388l-1.8 5.037a1 1 0 001.072 1.328l4.8-.63a1 1 0 00.56-.267L18.8 7.304a3.612 3.612 0 00.122-5.106zM12 17a1 1 0 100 2h6a1 1 0 100-2h-6z"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 571 B |
@@ -689,10 +689,11 @@
|
|||||||
<tr id="automation-item-${automationId}">
|
<tr id="automation-item-${automationId}">
|
||||||
<td><b>${automationObj.subject}</b></td>
|
<td><b>${automationObj.subject}</b></td>
|
||||||
<td><b>${automationObj.scheduling_request}</b></td>
|
<td><b>${automationObj.scheduling_request}</b></td>
|
||||||
<td><b>${automationObj.query_to_run}</b></td>
|
<td id="automation-query-to-run-${automationId}"><b>${automationObj.query_to_run}</b></td>
|
||||||
<td id="automation-${automationId}" title="${automationNextRun}">${automationObj.schedule}</td>
|
<td id="automation-${automationId}" title="${automationNextRun}">${automationObj.schedule}</td>
|
||||||
<td>
|
<td>
|
||||||
<img onclick="deleteAutomation('${automationId}')" class="automation-row-icon api-key-action enabled" src="/static/assets/icons/delete.svg" alt="Delete Automation" title="Delete Automation">
|
<img onclick="deleteAutomation('${automationId}')" class="automation-row-icon api-key-action enabled" src="/static/assets/icons/delete.svg" alt="Delete Automation" title="Delete Automation">
|
||||||
|
<img onclick="editAutomation('${automationId}')" class="automation-row-icon api-key-action enabled" src="/static/assets/icons/edit.svg" alt="Edit Automation" title="Edit Automation">
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
`;
|
`;
|
||||||
@@ -730,6 +731,23 @@
|
|||||||
}
|
}
|
||||||
document.getElementById("create-automation").addEventListener("click", async () => { await createAutomation(); });
|
document.getElementById("create-automation").addEventListener("click", async () => { await createAutomation(); });
|
||||||
|
|
||||||
|
function editAutomation(automationId) {
|
||||||
|
const query_to_run = window.prompt("What is the query you want to run on this automation's schedule?");
|
||||||
|
if (!query_to_run) return;
|
||||||
|
|
||||||
|
fetch(`/api/automation?automation_id=${automationId}&query_to_run=${query_to_run}`, {
|
||||||
|
method: 'PATCH',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
}).then(response => {
|
||||||
|
if (response.ok) {
|
||||||
|
const automationQueryToRunColumn = document.getElementById(`automation-query-to-run-${automationId}`);
|
||||||
|
automationQueryToRunColumn.innerHTML = `<b>${query_to_run}</b>`;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function getIndexedDataSize() {
|
function getIndexedDataSize() {
|
||||||
document.getElementById("indexed-data-size").innerHTML = "Calculating...";
|
document.getElementById("indexed-data-size").innerHTML = "Calculating...";
|
||||||
fetch('/api/config/index/size')
|
fetch('/api/config/index/size')
|
||||||
|
|||||||
@@ -487,3 +487,40 @@ async def make_automation(
|
|||||||
}
|
}
|
||||||
# Return information about the created automation as a JSON response
|
# Return information about the created automation as a JSON response
|
||||||
return Response(content=json.dumps(automation_info), media_type="application/json", status_code=200)
|
return Response(content=json.dumps(automation_info), media_type="application/json", status_code=200)
|
||||||
|
|
||||||
|
|
||||||
|
@api.patch("/automation", response_class=Response)
|
||||||
|
@requires(["authenticated"])
|
||||||
|
def edit_job(
|
||||||
|
request: Request, automation_id: str, query_to_run: Optional[str] = None, crontime: Optional[str] = None
|
||||||
|
) -> Response:
|
||||||
|
user: KhojUser = request.user.object
|
||||||
|
|
||||||
|
# Perform validation checks
|
||||||
|
# Check at least one of query or crontime is provided
|
||||||
|
if not query_to_run and not crontime:
|
||||||
|
return Response(content="A query or crontime is required", status_code=400)
|
||||||
|
# Check if user is allowed to edit this automation id
|
||||||
|
if not automation_id.startswith(f"automation_{user.uuid}_"):
|
||||||
|
return Response(content="Unauthorized automation deletion request", status_code=403)
|
||||||
|
# Check if automation with this id exist
|
||||||
|
automation: Job = state.scheduler.get_job(job_id=automation_id)
|
||||||
|
if not automation:
|
||||||
|
return Response(content="Invalid automation", status_code=403)
|
||||||
|
if not query_to_run.startswith("/automated_task"):
|
||||||
|
query_to_run = f"/automated_task {query_to_run}"
|
||||||
|
|
||||||
|
# Update automation with new query
|
||||||
|
automation_metadata = json.loads(automation.name)
|
||||||
|
automation_metadata["query_to_run"] = query_to_run
|
||||||
|
automation.modify(kwargs={"query_to_run": query_to_run}, name=json.dumps(automation_metadata))
|
||||||
|
|
||||||
|
# Collate info about the modified user automation
|
||||||
|
automation_info = {
|
||||||
|
"id": automation.id,
|
||||||
|
"name": automation.name,
|
||||||
|
"next": automation.next_run_time.strftime("%Y-%m-%d %H:%MS"),
|
||||||
|
}
|
||||||
|
|
||||||
|
# Return modified automation information as a JSON response
|
||||||
|
return Response(content=json.dumps(automation_info), media_type="application/json", status_code=200)
|
||||||
|
|||||||
Reference in New Issue
Block a user