-
Notifications
You must be signed in to change notification settings - Fork 0
add tab to visualize database contents #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| """Database viewer blueprint for SISmanager.""" | ||
|
|
||
| from .routes import db_viewer_bp | ||
|
|
||
| __all__ = ["db_viewer_bp"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| """ | ||
| Routes for db_viewer blueprint in SISmanager. | ||
| """ | ||
|
|
||
| from flask import Blueprint, render_template, request | ||
| from sismanager.services.inout.central_db_service import CentralDBRepository | ||
|
|
||
| db_viewer_bp = Blueprint( | ||
| "db_viewer", __name__, template_folder="../../templates/db_viewer" | ||
| ) | ||
|
|
||
|
|
||
| @db_viewer_bp.route("/db_viewer", methods=["GET", "POST"]) | ||
| def db_viewer(): | ||
| """Render the database viewer page with current data and optional column filtering.""" | ||
| repo = CentralDBRepository() | ||
| df = repo.read() | ||
|
|
||
| if df.empty: | ||
| db_preview = "<p>No data found in the database.</p>" | ||
| available_columns = [] | ||
| selected_columns = [] | ||
| else: | ||
| available_columns = list(df.columns) | ||
|
|
||
| # Handle column filtering from form submission | ||
| if request.method == "POST": | ||
| selected_columns = request.form.getlist("columns") | ||
| if selected_columns: | ||
| # Filter DataFrame to show only selected columns | ||
| df_filtered = df[selected_columns] | ||
| else: | ||
| df_filtered = df | ||
| else: | ||
| # Default: show all columns | ||
| selected_columns = available_columns | ||
| df_filtered = df | ||
|
|
||
| db_preview = df_filtered.to_html(classes="table table-bordered", index=False) | ||
|
fedem-p marked this conversation as resolved.
|
||
|
|
||
| return render_template( | ||
| "db_viewer/db_viewer.html", | ||
| db_preview=db_preview, | ||
| available_columns=available_columns, | ||
| selected_columns=selected_columns, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| {% extends 'base.html' %} | ||
| {% block content %} | ||
| <style> | ||
| .table-container table thead th { | ||
| position: sticky; | ||
| top: 0; | ||
| background-color: #f8f9fa; | ||
| z-index: 10; | ||
| border-bottom: 2px solid #dee2e6; | ||
| } | ||
| </style> | ||
|
|
||
| <!-- Title on top --> | ||
| <h1>Database Viewer</h1> | ||
| <p>View current database contents.</p> | ||
|
|
||
| <div style="display: flex; gap: 20px; height: 70vh;"> | ||
| <!-- Sidebar --> | ||
| <div style="min-width: 250px; background: #f8f9fa; padding: 15px; border: 1px solid #ddd; display: flex; flex-direction: column;"> | ||
| <h3 style="margin-top: 0;">Column Filter</h3> | ||
| {% if available_columns %} | ||
| <form action="/db_viewer" method="post" style="display: flex; flex-direction: column; height: 100%;"> | ||
|
fedem-p marked this conversation as resolved.
|
||
| <p>Select columns to display:</p> | ||
| <!-- Scrollable options --> | ||
| <div style="flex: 1; overflow-y: auto; border: 1px solid #ddd; padding: 10px; margin-bottom: 10px; background: white;"> | ||
| {% for column in available_columns %} | ||
| <input type="checkbox" id="{{ column }}" name="columns" value="{{ column }}" | ||
| {% if column in selected_columns %}checked{% endif %}> | ||
| <label for="{{ column }}">{{ column }}</label><br> | ||
| {% endfor %} | ||
| </div> | ||
|
|
||
| <div> | ||
| <button type="submit">Apply Filter</button> | ||
| <button type="submit" name="columns" value="">Show All</button> | ||
| </div> | ||
| </form> | ||
| {% endif %} | ||
| </div> | ||
|
|
||
| <!-- Main content area --> | ||
| <div style="flex: 1; min-width: 0;"> | ||
| <!-- Table as before --> | ||
| <div class="table-container" style="max-height:100%; overflow:auto; border:1px solid #ccc; margin-top:10px; max-width: 100%;"> | ||
|
fedem-p marked this conversation as resolved.
|
||
| {{ db_preview|safe }} | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {% endblock %} | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.