Quick search: Ctrl+K palette, live test endpoint and wiring

This commit is contained in:
claude committed 2026-10-11 17:29:20 +02:00
1 parent 26a0394ca9
commit 5793204b1b
3 files changed
+42 -2

No files matched your search

+1
View File
@@ -94,6 +94,7 @@ urlpatterns = [
django.urls.path(r'api/buildinfo/', OpenBench.views.api_build_info),
django.urls.path(r'api/pgns/<int:pgn_id>/', OpenBench.views.api_pgns),
django.urls.path(r'api/test/<int:id>/llr-history/', OpenBench.views.test_llr_history),
django.urls.path(r'api/quick-search/', OpenBench.views.api_quick_search),
# Redirect anything else to the Index
django.urls.path(r'', OpenBench.views.index),
+35
View File
@@ -585,6 +585,41 @@ def test_llr_history(request, id):
return HttpResponse(str(llr_history_graph(test)), content_type='text/plain; charset=utf-8')
def api_quick_search(request):
## Feeds the Ctrl+K palette: up to eight workloads that match a branch name,
## an author, an engine, or a workload id, newest first.
if OPENBENCH_CONFIG['require_login_to_view'] and not request.user.is_authenticated:
return JsonResponse({ 'tests' : [] }, status=403)
from OpenBench.templatetags.mytags import prettyName, workload_url
from OpenBench.templatetags.uitags import test_status
query = request.GET.get('q', '').strip().lstrip('#')[:64]
if not query:
return JsonResponse({ 'tests' : [] })
match = Q(dev__name__icontains=query) | Q(author__icontains=query) | Q(dev_engine__icontains=query)
if query.isdigit() and len(query) <= 9:
match |= Q(id=int(query))
found = list(Test.objects.select_related('dev').filter(match).exclude(deleted=True).order_by('-id')[:8])
# An exact workload id is always the first hit
if query.isdigit():
found.sort(key=lambda test: str(test.id) != query)
return JsonResponse({ 'tests' : [{
'id' : test.id,
'name' : prettyName(test.dev.name),
'author' : test.author.capitalize(),
'engine' : test.dev_engine,
'tc' : test.dev_time_control,
'status' : test_status(test),
'url' : workload_url(test),
} for test in found] })
def create_test(request):
return create_workload(request, 'TEST')
+6 -2
View File
@@ -18,6 +18,7 @@
<link rel="stylesheet" href="{% static 'ux.css' %}?{{ static_version }}">
<link rel="stylesheet" href="{% static 'board.css' %}?{{ static_version }}">
<link rel="stylesheet" href="{% static 'refresh.css' %}?{{ static_version }}">
<link rel="stylesheet" href="{% static 'palette.css' %}?{{ static_version }}">
<link href='https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css' rel='stylesheet'>
@@ -32,6 +33,7 @@
<script src="{% static 'ui.js' %}?{{ static_version }}" defer></script>
<script src="{% static 'ux.js' %}?{{ static_version }}" defer></script>
<script src="{% static 'palette.js' %}?{{ static_version }}" defer></script>
<script>
document.addEventListener('DOMContentLoaded', function() {
@@ -98,8 +100,8 @@
<div class="topbar-spacer"></div>
<nav class="topbar-actions" aria-label="Quick actions">
<a class="topbar-btn" href="/search" title="Search tests">
<i class="fa-solid fa-magnifying-glass fa-fw"></i><span>Search</span>
<a class="topbar-btn" id="palette-open" href="/search" title="Search tests" aria-keyshortcuts="Control+K Meta+K">
<i class="fa-solid fa-magnifying-glass fa-fw"></i><span>Search</span><kbd class="topbar-kbd" aria-hidden="true">Ctrl K</kbd>
</a>
<a class="topbar-btn topbar-btn-primary" href="/newTest" title="Create a new test">
<i class="fa-solid fa-plus fa-fw"></i><span>Create Test</span>
@@ -224,5 +226,7 @@
<div id="toast" role="status" aria-live="polite"></div>
{% include "OpenBench/Blocks/palette.html" %}
</body>
</html>