Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sismanager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# Import and register blueprints
from sismanager.blueprints.main.routes import main_bp
from sismanager.blueprints.importer.routes import importer_bp
from sismanager.blueprints.db_viewer.routes import db_viewer_bp
from sismanager.blueprints.calendar.routes import calendar_bp
from sismanager.blueprints.materials.routes import materials_bp
from sismanager.blueprints.money.routes import money_bp
Expand All @@ -18,6 +19,7 @@ def create_app():

app.register_blueprint(main_bp)
app.register_blueprint(importer_bp)
app.register_blueprint(db_viewer_bp)
app.register_blueprint(calendar_bp)
app.register_blueprint(materials_bp)
app.register_blueprint(money_bp)
Expand Down
5 changes: 5 additions & 0 deletions sismanager/blueprints/db_viewer/__init__.py
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"]
46 changes: 46 additions & 0 deletions sismanager/blueprints/db_viewer/routes.py
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]
Comment thread
fedem-p marked this conversation as resolved.
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)
Comment thread
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,
)
2 changes: 1 addition & 1 deletion sismanager/static/css/dashboard.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ nav a:hover {
text-decoration: underline;
}
.container {
max-width: 900px;
max-width: 95%;
margin: 30px auto;
background: #fff;
padding: 30px;
Expand Down
1 change: 1 addition & 0 deletions sismanager/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<ul style="display:inline;list-style:none;margin-left:30px;">
<li style="display:inline;margin-right:15px;"><a href="/">Home</a></li>
<li style="display:inline;margin-right:15px;"><a href="/importer">Importer</a></li>
<li style="display:inline;margin-right:15px;"><a href="/db_viewer">Database Viewer</a></li>
<li style="display:inline;margin-right:15px;"><a href="/calendar">Calendar</a></li>
<li style="display:inline;margin-right:15px;"><a href="/materials">Parts Organizer</a></li>
<li style="display:inline;"><a href="/money">Money</a></li>
Expand Down
49 changes: 49 additions & 0 deletions sismanager/templates/db_viewer/db_viewer.html
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%;">
Comment thread
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%;">
Comment thread
fedem-p marked this conversation as resolved.
{{ db_preview|safe }}
</div>
</div>
</div>
{% endblock %}
Loading