diff --git a/v2_adminpanel/app.py b/v2_adminpanel/app.py index 6b83eff..b1abb26 100644 --- a/v2_adminpanel/app.py +++ b/v2_adminpanel/app.py @@ -4063,6 +4063,10 @@ def resources(): status_filter = request.args.get('status', '') search = request.args.get('search', '') + # Sortierung + sort_by = request.args.get('sort', 'id') + sort_order = request.args.get('order', 'desc') + # Base Query query = """ SELECT @@ -4102,8 +4106,20 @@ def resources(): total = cur.fetchone()[0] total_pages = (total + per_page - 1) // per_page - # Get paginated results - query += " ORDER BY rp.id DESC LIMIT %s OFFSET %s" + # Get paginated results with dynamic sorting + sort_column_map = { + 'id': 'rp.id', + 'type': 'rp.resource_type', + 'resource': 'rp.resource_value', + 'status': 'rp.status', + 'assigned': 'c.name', + 'changed': 'rp.status_changed_at' + } + + sort_column = sort_column_map.get(sort_by, 'rp.id') + sort_direction = 'ASC' if sort_order == 'asc' else 'DESC' + + query += f" ORDER BY {sort_column} {sort_direction} LIMIT %s OFFSET %s" params.extend([per_page, offset]) cur.execute(query, params) @@ -4123,6 +4139,8 @@ def resources(): status_filter=status_filter, search=search, show_test=show_test, + sort_by=sort_by, + sort_order=sort_order, datetime=datetime, timedelta=timedelta) diff --git a/v2_adminpanel/templates/resources.html b/v2_adminpanel/templates/resources.html index 8755bb2..a55cc01 100644 --- a/v2_adminpanel/templates/resources.html +++ b/v2_adminpanel/templates/resources.html @@ -192,6 +192,23 @@ .btn-success { font-weight: 500; } + + /* Sortable Headers */ + thead th a { + display: block; + position: relative; + padding-right: 20px; + } + thead th a:hover { + color: #0d6efd !important; + } + thead th a i { + position: absolute; + right: 0; + top: 50%; + transform: translateY(-50%); + font-size: 0.8rem; + } {% endblock %} @@ -343,12 +360,72 @@ - - - - - - + + + + + + @@ -539,13 +616,13 @@
IDTypRessourceStatusZugewiesen anLetzte Änderung + + ID + {% if sort_by == 'id' %} + + {% else %} + + {% endif %} + + + + Typ + {% if sort_by == 'type' %} + + {% else %} + + {% endif %} + + + + Ressource + {% if sort_by == 'resource' %} + + {% else %} + + {% endif %} + + + + Status + {% if sort_by == 'status' %} + + {% else %} + + {% endif %} + + + + Zugewiesen an + {% if sort_by == 'assigned' %} + + {% else %} + + {% endif %} + + + + Letzte Änderung + {% if sort_by == 'changed' %} + + {% else %} + + {% endif %} + + Aktionen