I have refactored the SQL Explorer functionality into its own blueprint (routes/sql_explorer.py) with a /sql URL prefix. This involved moving the relevant routes from app.py, registering the new blueprint, removing the old routes, updating url_for calls in the templates, and documenting the change in the changelog.

Here is a conventional commit message summarizing the changes:

```
feat: Refactor SQL Explorer into blueprint

- Moved SQL Explorer routes (view explorer, save/load/execute/delete queries, view schema, plot queries) from `app.py` into a new blueprint at `routes/sql_explorer.py`.
- Added `/sql` URL prefix to the blueprint.
- Registered the new `sql_explorer_bp` blueprint in `app.py`.
- Removed the original SQL Explorer route definitions from `app.py`.
- Updated `url_for` calls in relevant templates (`sql_explorer.html`, `partials/sql_explorer/sql_query.html`, `base.html`) to reference the new blueprint endpoints (e.g., `sql_explorer.sql_explorer`).
- Updated `templates/changelog/changelog.html` to document this refactoring.
```
This commit is contained in:
Peter Stockings
2025-03-31 23:00:54 +11:00
parent eaeb4ab2c8
commit a8fe28339b
8 changed files with 248 additions and 288 deletions

View File

@@ -5,7 +5,7 @@
</div>
{% endif %}
<form method="POST" hx-post="{{ url_for('sql_query') }}" hx-target="#sql-query">
<form method="POST" hx-post="{{ url_for('sql_explorer.sql_query') }}" hx-target="#sql-query">
<!-- Title Input -->
<div>
<label for="query-title" class="block text-sm font-medium text-gray-700">Title</label>
@@ -26,7 +26,7 @@
<!-- Buttons -->
<div class="flex space-x-2 pt-1">
<!-- Execute Button -->
<button hx-post="{{ url_for('execute_sql_query') }}" hx-target="#execute-query-results"
<button hx-post="{{ url_for('sql_explorer.execute_sql_query') }}" hx-target="#execute-query-results"
hx-include="[name='query']" hx-trigger="click" hx-swap="innerHTML"
class="flex items-center bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 focus:outline-none focus:ring-2 focus:ring-blue-500">
<!-- Execute Icon (Heroicon: Play) -->
@@ -41,8 +41,8 @@
</button>
<!-- Plot Button -->
<button hx-post="{{ url_for('plot_unsaved_query') }}" hx-target="#sql-plot-results" hx-trigger="click"
hx-include="[name='query'],[name='title']" hx-indicator="#sql-plot-results-loader"
<button hx-post="{{ url_for('sql_explorer.plot_unsaved_query') }}" hx-target="#sql-plot-results"
hx-trigger="click" hx-include="[name='query'],[name='title']" hx-indicator="#sql-plot-results-loader"
class="flex items-center bg-blue-100 text-white px-4 py-2 rounded hover:bg-blue-300 focus:outline-none focus:ring-2 focus:ring-blue-300">
<!-- Plot Icon (Heroicon: Chart Bar) -->
@@ -111,7 +111,7 @@
<tr class="hover:bg-gray-100 transition-colors duration-200">
<!-- Query Title as Load Action -->
<td class="py-4 px-6 border-b">
<a href="#" hx-get="{{ url_for('load_sql_query', query_id=saved.id) }}"
<a href="#" hx-get="{{ url_for('sql_explorer.load_sql_query', query_id=saved.id) }}"
hx-target="#sql-query"
class="flex items-center text-blue-500 hover:text-blue-700 cursor-pointer">
<!-- Load Icon (Heroicon: Eye) -->
@@ -128,7 +128,7 @@
<td class="py-4 px-6 border-b">
<div class="flex space-x-4">
<!-- Plot Action -->
<a href="#" hx-get="{{ url_for('plot_query', query_id=saved.id) }}"
<a href="#" hx-get="{{ url_for('sql_explorer.plot_query', query_id=saved.id) }}"
hx-target="#sql-plot-results"
class="flex items-center text-green-500 hover:text-green-700 cursor-pointer"
hx-trigger="click" hx-indicator="#sql-plot-results-loader-{{ saved.id }}">
@@ -154,7 +154,8 @@
</a>
<!-- Delete Action -->
<a href="#" hx-delete="{{ url_for('delete_sql_query', query_id=saved.id) }}"
<a href="#"
hx-delete="{{ url_for('sql_explorer.delete_sql_query', query_id=saved.id) }}"
hx-target="#sql-query"
class="flex items-center text-red-500 hover:text-red-700 cursor-pointer"
hx-confirm="Are you sure you want to delete the query titled '{{ saved.title }}'?">