From c8190be21c2101f14dfc0675769f0d13c4d1136e Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Wed, 13 Aug 2025 09:08:00 -0500 Subject: [PATCH] Starting work on new dynamic widgets using HTMX and Alpine. --- inventory/routes/index.py | 4 + inventory/templates/coffee.html | 6 +- .../fragments/_combobox_fragment.html | 147 ++++++++++++++++++ inventory/templates/layout.html | 2 + inventory/templates/playground.html | 18 +++ 5 files changed, 174 insertions(+), 3 deletions(-) create mode 100644 inventory/templates/playground.html diff --git a/inventory/routes/index.py b/inventory/routes/index.py index eff0caf..99c8610 100644 --- a/inventory/routes/index.py +++ b/inventory/routes/index.py @@ -36,6 +36,10 @@ def coffee(): matrix, clicked = generate_solvable_matrix(level) return render_template("coffee.html", matrix=matrix, level=level, clicked=clicked) +@main.route("/playground") +def playground(): + return render_template("playground.html") + @main.route("/") def index(): worklog_query = eager_load_worklog_relationships( diff --git a/inventory/templates/coffee.html b/inventory/templates/coffee.html index bb0684d..8a2b56c 100644 --- a/inventory/templates/coffee.html +++ b/inventory/templates/coffee.html @@ -7,11 +7,11 @@ {% endblock %} {% block content %} -
+
{% for x in range(level + 3) %}
{% for y in range(level + 3) %} -
+
@@ -85,7 +85,7 @@ // Check if all checkboxes are checked const allChecked = Array.from(document.querySelectorAll('.form-check-input')).every(cb => cb.checked); const allUnchecked = Array.from(document.querySelectorAll('.form-check-input')).every(cb => !cb.checked); - if (allChecked && !window.__alreadyNavigated && {{ level }} < 28) { + if (allChecked && !window.__alreadyNavigated && {{ level }} < 51) { window.__alreadyNavigated = true; location.href = "{{ url_for('main.coffee', level=level + 1) }}"; } else if (allUnchecked && !window.__alreadyNavigated && {{ level }} > -2) { diff --git a/inventory/templates/fragments/_combobox_fragment.html b/inventory/templates/fragments/_combobox_fragment.html index c28dcca..e13c21e 100644 --- a/inventory/templates/fragments/_combobox_fragment.html +++ b/inventory/templates/fragments/_combobox_fragment.html @@ -42,3 +42,150 @@ }); {% endmacro %} + +{% macro dynamic_combobox( + id, options, label = none, placeholder = none, data_attributes = none, + create_url = none, edit_url = none, delete_url = none, refresh_url = none +) %} + {% if label %} + + {% endif %} +
+
+ + + + + +
+ + + + {% if refresh_url %} +
+ {% endif %} +
+ + +{% endmacro %} diff --git a/inventory/templates/layout.html b/inventory/templates/layout.html index 92b867b..1a3ebb4 100644 --- a/inventory/templates/layout.html +++ b/inventory/templates/layout.html @@ -76,6 +76,8 @@ integrity="sha384-zqgMe4cx+N3TuuqXt4kWWDluM5g1CiRwqWBm3vpvY0GcDoXTwU8d17inavaLy3p3" crossorigin="anonymous"> + + diff --git a/inventory/templates/playground.html b/inventory/templates/playground.html new file mode 100644 index 0000000..af7322e --- /dev/null +++ b/inventory/templates/playground.html @@ -0,0 +1,18 @@ +{% extends 'layout.html' %} + +{% block content %} + {{ combos.dynamic_combobox( + 'play', + [ + { + 'id': 1, + 'name': 'Beans' + }, + { + 'id': 2, + 'name': 'Toast' + }, + ], + 'Breakfast!' + ) }} +{% endblock %} \ No newline at end of file