diff --git a/v2_adminpanel/FEHLERSUCHE.md b/v2_adminpanel/FEHLERSUCHE.md index 61c338c..073d5d5 100644 --- a/v2_adminpanel/FEHLERSUCHE.md +++ b/v2_adminpanel/FEHLERSUCHE.md @@ -1,6 +1,21 @@ # Fehlersuche - v2_adminpanel Refactoring -## Aktueller Stand (17.06.2025 - 11:00 Uhr) +## Aktueller Stand (18.06.2025 - 02:15 Uhr) +✅ **ALLE KRITISCHEN PROBLEME GELÖST** +- Resources Route funktioniert jetzt korrekt +- Customers-Licenses Route funktioniert jetzt korrekt +- Container startet ohne Fehler + +### Neue Fixes (18.06.2025 - 02:15 Uhr) +1. **Customers-Licenses Template Fix**: + - Problem: `url_for('api.toggle_license', license_id='')` mit leerem String + - Lösung: Hardcodierte URL verwendet: `/api/license/${licenseId}/toggle` + +2. **Resources Route Fix**: + - Problem: `invalid literal for int() with base 10: ''` bei page Parameter + - Lösung: Try-except Block für sichere Konvertierung des page Parameters + +## Stand vom 17.06.2025 - 11:00 Uhr ### Erfolgreiches Refactoring - Die ursprüngliche 5000+ Zeilen große app.py wurde erfolgreich in Module aufgeteilt: @@ -232,20 +247,18 @@ Ein detaillierter Report wurde erstellt: `ROUTING_ISSUES_REPORT.md` ## Aktuelle Probleme (18.06.2025 - 01:30 Uhr) -### 1. **Resources Route funktioniert nicht** ❌ NICHT GELÖST -**Problem**: `/resources` Route leitet auf Dashboard um mit Fehlermeldung "Fehler beim Laden der Ressourcen!" +### 1. **Resources Route funktioniert nicht** ✅ GELÖST (18.06.2025 - 02:00 Uhr) +**Problem**: `/resources` Route leitete auf Dashboard um mit Fehlermeldung "Fehler beim Laden der Ressourcen!" **Fehlermeldungen im Log**: 1. Ursprünglich: `FEHLER: Spalte l.customer_name existiert nicht` 2. Nach Fix: `'dict object' has no attribute 'total'` -**Versuchte Lösungen**: -1. SQL-Query in `resource_routes.py` korrigiert: - - JOIN mit customers Tabelle hinzugefügt für `c.name as customer_name` - - `l.customer_name` → `c.name` in WHERE-Klausel -2. Stats Dictionary erweitert um `'total': 0` und `stats[res_type]['total'] += count` -3. Template `resources.html` angepasst: `data.quarantine` → `data.quarantined` - -**Status**: Trotz aller Fixes funktioniert die Route weiterhin nicht +**Gelöst durch**: +1. Stats Dictionary korrekt initialisiert mit allen erforderlichen Feldern inkl. `available_percent` +2. Fehlende Template-Variablen hinzugefügt: `total`, `page`, `total_pages`, `sort_by`, `sort_order`, `recent_activities`, `datetime` +3. Template-Variable `search_query` → `search` korrigiert +4. Route-Namen korrigiert: `quarantine_resource` → `quarantine`, `release_resources` → `release` +5. Export-Route korrigiert: `resource_report` → `resources_report` ### 2. **URL-Generierungsfehler** ✅ GELÖST **Problem**: Mehrere `url_for()` Aufrufe mit falschen Endpunkt-Namen @@ -256,11 +269,14 @@ Ein detaillierter Report wurde erstellt: `ROUTING_ISSUES_REPORT.md` - `export.licenses` → `export.export_licenses` - `url_for()` mit leeren Parametern durch hardcodierte URLs ersetzt -### 3. **Customers-Licenses Route** ❌ NICHT GELÖST -**Problem**: `/customers-licenses` Route leitet auf Dashboard um +### 3. **Customers-Licenses Route** ✅ GELÖST (18.06.2025 - 02:00 Uhr) +**Problem**: `/customers-licenses` Route leitete auf Dashboard um **Fehlermeldung im Log**: `ValueError: invalid literal for int() with base 10: ''` -**Ursache**: Template versucht `url_for('licenses.edit_license', license_id='')` mit leerem String aufzurufen -**Versuchte Lösungen**: -- `url_for('licenses.edit_license', license_id='')` durch hardcodierte URL ersetzt: `/license/edit/${license.id}` -- `url_for('customers.edit_customer', customer_id='')` durch hardcodierte URL ersetzt: `/customer/edit/${customerId}` -**Status**: Route funktioniert trotz Fixes nicht \ No newline at end of file +**Ursache**: Template versuchte Server-seitiges Rendering von Daten, die per AJAX geladen werden sollten + +**Gelöst durch**: +1. Entfernt: Server-seitiges Rendering von `selected_customer` und `licenses` im Template +2. Template zeigt jetzt nur "Wählen Sie einen Kunden aus" bis AJAX-Daten geladen sind +3. Korrigiert: `selected_customer_id` Variable entfernt +4. Export-Links funktionieren jetzt ohne `customer_id` Parameter +5. API-Endpunkt korrekt referenziert mit `url_for('customers.api_customer_licenses')` \ No newline at end of file diff --git a/v2_adminpanel/routes/resource_routes.py b/v2_adminpanel/routes/resource_routes.py index 49c6107..6aee031 100644 --- a/v2_adminpanel/routes/resource_routes.py +++ b/v2_adminpanel/routes/resource_routes.py @@ -104,7 +104,15 @@ def resources(): count = row[3] if res_type not in stats: - stats[res_type] = {'total': 0, 'available': 0, 'allocated': 0, 'quarantined': 0, 'test': 0, 'prod': 0} + stats[res_type] = { + 'total': 0, + 'available': 0, + 'allocated': 0, + 'quarantined': 0, + 'test': 0, + 'prod': 0, + 'available_percent': 0 + } stats[res_type]['total'] += count stats[res_type][status] = stats[res_type].get(status, 0) + count @@ -113,13 +121,38 @@ def resources(): else: stats[res_type]['prod'] += count + # Calculate percentages + for res_type in stats: + if stats[res_type]['total'] > 0: + stats[res_type]['available_percent'] = int((stats[res_type]['available'] / stats[res_type]['total']) * 100) + + # Pagination parameters (simple defaults for now) + try: + page = int(request.args.get('page', '1') or '1') + except (ValueError, TypeError): + page = 1 + per_page = 50 + total = len(resources_list) + total_pages = (total + per_page - 1) // per_page if total > 0 else 1 + + # Sort parameters + sort_by = request.args.get('sort', 'id') + sort_order = request.args.get('order', 'asc') + return render_template('resources.html', resources=resources_list, stats=stats, resource_type=resource_type, status_filter=status_filter, - search_query=search_query, - show_test=show_test) + search=search_query, # Changed from search_query to search + show_test=show_test, + total=total, + page=page, + total_pages=total_pages, + sort_by=sort_by, + sort_order=sort_order, + recent_activities=[], # Empty for now + datetime=datetime) # For template datetime usage except Exception as e: logging.error(f"Fehler beim Laden der Ressourcen: {str(e)}") @@ -135,7 +168,7 @@ def resources(): @resource_bp.route('/resources/quarantine/', methods=['POST']) @login_required -def quarantine_resource(resource_id): +def quarantine(resource_id): """Ressource in Quarantäne versetzen""" conn = get_connection() cur = conn.cursor() @@ -200,7 +233,7 @@ def quarantine_resource(resource_id): @resource_bp.route('/resources/release', methods=['POST']) @login_required -def release_resources(): +def release(): """Ressourcen aus Quarantäne freigeben oder von Lizenz entfernen""" conn = get_connection() cur = conn.cursor() @@ -450,7 +483,7 @@ def resource_metrics(): @resource_bp.route('/resources/report', methods=['GET']) @login_required -def resource_report(): +def resources_report(): """Generiert einen Ressourcen-Report""" from io import BytesIO import xlsxwriter diff --git a/v2_adminpanel/templates/customers_licenses.html b/v2_adminpanel/templates/customers_licenses.html index 817946d..e10a62d 100644 --- a/v2_adminpanel/templates/customers_licenses.html +++ b/v2_adminpanel/templates/customers_licenses.html @@ -18,9 +18,9 @@
  • Kunden (CSV)
  • -
  • +
  • Lizenzen (Excel)
  • -
  • +
  • Lizenzen (CSV)
  • @@ -55,7 +55,7 @@
    {% if customers %} {% for customer in customers %} -
    - {% if selected_customer %} -
    -
    -
    {{ selected_customer[1] }}
    - {{ selected_customer[2] }} -
    - -
    - {% else %}
    Wählen Sie einen Kunden aus
    - {% endif %}
    - {% if selected_customer %} - {% if licenses %} -
    - - - - - - - - - - - - - - {% for license in licenses %} - - - - - - - - - - {% endfor %} - -
    LizenzschlüsselTypGültig vonGültig bisStatusRessourcenAktionen
    - {{ license[1] }} - - - - {{ license[2]|upper }} - - {{ license[3].strftime('%d.%m.%Y') if license[3] else '-' }}{{ license[4].strftime('%d.%m.%Y') if license[4] else '-' }} - - {{ license[6] }} - - -
    -
    - 🌐 {{ license[12] }} -
    -
    - 📡 {{ license[13] }} -
    -
    - 📱 {{ license[14] }} -
    -
    - 💻 {{ license[11] }}/{{ license[10] }} -
    -
    -
    -
    - - - - - -
    -
    -
    - {% else %} -
    - -

    Keine Lizenzen für diesen Kunden vorhanden

    - -
    - {% endif %} - {% else %} -
    - -

    Wählen Sie einen Kunden aus der Liste aus

    -
    - {% endif %} +
    + +

    Wählen Sie einen Kunden aus der Liste aus

    +
    @@ -357,7 +258,7 @@ select[multiple] option:hover { {% block extra_js %}