From 524fd1f509981d3ed0560fbfe8c22ba2432406f6 Mon Sep 17 00:00:00 2001 From: Bryan Van Deusen Date: Tue, 30 Jun 2026 23:35:01 -0400 Subject: [PATCH] feat(ansible): default source/playbook dropdowns to the first item MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The schedule and host run forms opened their Source/Playbook fires playbook-options then (hx-on::after-settle) re-triggers the playbook 's own load trigger, while edit mode keeps its server-rendered prefill untouched. Co-Authored-By: Claude Opus 4.8 (1M context) --- steward/ansible/routes.py | 9 +++++++-- steward/templates/ansible/_playbook_options.html | 5 +++-- steward/templates/ansible/schedules.html | 13 +++++++------ steward/templates/hosts/detail.html | 7 +++---- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/steward/ansible/routes.py b/steward/ansible/routes.py index 28b36a3..5217b84 100644 --- a/steward/ansible/routes.py +++ b/steward/ansible/routes.py @@ -373,7 +373,6 @@ async def schedules(): {"name": s["name"], "playbooks": src_module.discover_playbooks(s["path"])} for s in _get_sources() ] - all_playbooks = sorted({p for sd in source_data for p in sd["playbooks"]}) rows = [] editing = None @@ -386,6 +385,12 @@ async def schedules(): if editing_id and s.id == editing_id: editing = s + # Default the source dropdown to the first source (or the edited schedule's + # source), and pre-render that source's playbooks so the playbook dropdown + # starts on a real item rather than a placeholder. + sel_source = editing.source_name if editing else (source_data[0]["name"] if source_data else "") + sel_playbooks = next((sd["playbooks"] for sd in source_data if sd["name"] == sel_source), []) + # Edit mode: pre-render the selected playbook's declared variables so their # saved values show (fresh loads fetch these via HTMX from /playbook-vars). edit_variables: list = [] @@ -401,7 +406,7 @@ async def schedules(): return await render_template( "ansible/schedules.html", rows=rows, groups=groups, targets=targets, - source_data=source_data, all_playbooks=all_playbooks, + source_data=source_data, sel_source=sel_source, sel_playbooks=sel_playbooks, editing=editing, interval_presets=INTERVAL_PRESETS, edit_variables=edit_variables, edit_description=edit_meta["description"], edit_category=edit_meta["category"], edit_confirm=edit_meta["confirm"], diff --git a/steward/templates/ansible/_playbook_options.html b/steward/templates/ansible/_playbook_options.html index 59a9522..fad228f 100644 --- a/steward/templates/ansible/_playbook_options.html +++ b/steward/templates/ansible/_playbook_options.html @@ -1,6 +1,7 @@ {# + hx-target="#sch-playbook" hx-swap="innerHTML" hx-include="this" + hx-on::after-settle="htmx.trigger('#sch-playbook','change')"> {% for sd in source_data %} - + {% endfor %} + {% if not source_data %}{% endif %}
diff --git a/steward/templates/hosts/detail.html b/steward/templates/hosts/detail.html index f553834..39f6f3a 100644 --- a/steward/templates/hosts/detail.html +++ b/steward/templates/hosts/detail.html @@ -161,9 +161,9 @@
@@ -172,7 +172,6 @@