diff --git a/CMBNet/cmbnet/admin/accounts.py b/CMBNet/cmbnet/admin/accounts.py index 7e8c809..4213198 100644 --- a/CMBNet/cmbnet/admin/accounts.py +++ b/CMBNet/cmbnet/admin/accounts.py @@ -8,6 +8,13 @@ from cmbnet.db import get_db admin_accounts_bp = Blueprint('admin', __name__) +@admin_accounts_bp.route('/dashboard') +@role_required('Administrator') +def dashboard(**kwargs): + """Admin Dashboard""" + return render_template('admin/dashboard.html') + + @admin_accounts_bp.route('/accounts') @role_required('Administrator') def accounts(**kwargs): diff --git a/CMBNet/cmbnet/admin/api.py b/CMBNet/cmbnet/admin/api.py index 89fcb07..ddf93a1 100644 --- a/CMBNet/cmbnet/admin/api.py +++ b/CMBNet/cmbnet/admin/api.py @@ -370,6 +370,38 @@ def import_streets(**kwargs): return jsonify({'success': True, 'count': count}) +@admin_api_bp.route('/broker/status') +@role_required('Administrator') +def broker_status(**kwargs): + """Status aktiver WebSocket-Verbindungen""" + connections = broker.connections.get(g.tenant_id, {}) if hasattr(broker, 'connections') else {} + result = [] + for account_id, conn in connections.items(): + account = db = get_db().execute( + 'SELECT id, name, role FROM accounts WHERE id = ? AND tenant_id = ?', + (account_id, g.tenant_id) + ).fetchone() + if not account: + continue + entry = { + 'account_id': account['id'], + 'account_name': account['name'], + 'role': account['role'], + 'group_id': None, + 'group_alias': None + } + if account['role'] == 'Gruppe': + group = get_db().execute( + 'SELECT id, aliasname FROM groups WHERE account_id = ? AND tenant_id = ?', + (account['id'], g.tenant_id) + ).fetchone() + if group: + entry['group_id'] = group['id'] + entry['group_alias'] = group['aliasname'] + result.append(entry) + return jsonify({'connections': result}) + + @admin_api_bp.route('/hausnummern/import', methods=['POST']) @role_required('Administrator') def import_house_numbers(**kwargs): diff --git a/CMBNet/cmbnet/views/auth.py b/CMBNet/cmbnet/views/auth.py index 266ec4d..9d25cb1 100644 --- a/CMBNet/cmbnet/views/auth.py +++ b/CMBNet/cmbnet/views/auth.py @@ -55,7 +55,7 @@ def login(**kwargs): # Rollenbasierte Weiterleitung role = account['role'] if role == 'Administrator': - return redirect(url_for('admin.accounts', tenant=tenant_selected)) + return redirect(url_for('admin.dashboard', tenant=tenant_selected)) elif role == 'Dispatcher': return redirect(url_for('views.dispatcher', tenant=tenant_selected)) elif role == 'Beobachter': diff --git a/CMBNet/cmbnet/views/main.py b/CMBNet/cmbnet/views/main.py index e6df4cd..7ca3788 100644 --- a/CMBNet/cmbnet/views/main.py +++ b/CMBNet/cmbnet/views/main.py @@ -15,7 +15,7 @@ def index(**kwargs): tenant = g.tenant_code if role == 'Administrator': - return redirect(url_for('admin.accounts', tenant=tenant)) + return redirect(url_for('admin.dashboard', tenant=tenant)) elif role == 'Dispatcher': return redirect(url_for('views.dispatcher', tenant=tenant)) elif role == 'Beobachter': diff --git a/CMBNet/static/css/admin.css b/CMBNet/static/css/admin.css new file mode 100644 index 0000000..42e4fec --- /dev/null +++ b/CMBNet/static/css/admin.css @@ -0,0 +1,45 @@ +/* Admin-Komprimierung für Desktop */ +table { + font-size: 0.9rem; +} + +table th, +table td { + padding: 0.25rem 0.5rem; +} + +dialog article { + max-width: 600px; + width: min(90vw, 600px); +} + +dialog article header { + padding: 0.5rem 1rem; +} + +dialog article label { + margin-bottom: 0.5rem; +} + +dialog article footer { + padding: 0.5rem 1rem; + display: flex; + gap: 0.5rem; + justify-content: flex-end; +} + +input, +select, +textarea { + margin-bottom: 0.5rem; +} + +button { + padding: 0.4rem 0.8rem; +} + +@media (min-width: 1024px) { + main.container { + max-width: 1100px; + } +} diff --git a/CMBNet/static/js/views/admin_dashboard.js b/CMBNet/static/js/views/admin_dashboard.js new file mode 100644 index 0000000..1a7f202 --- /dev/null +++ b/CMBNet/static/js/views/admin_dashboard.js @@ -0,0 +1,48 @@ +const tenantCode = window.location.pathname.split('/')[1]; + +async function loadBrokerStatus() { + try { + const response = await fetch(`/${tenantCode}/admin/api/broker/status`); + if (!response.ok) { + throw new Error('Failed to load status'); + } + const data = await response.json(); + const body = document.getElementById('brokerStatusBody'); + body.innerHTML = ''; + if (!data.connections || data.connections.length === 0) { + const row = document.createElement('tr'); + const cell = document.createElement('td'); + cell.colSpan = 4; + cell.textContent = 'Keine aktiven Verbindungen'; + row.appendChild(cell); + body.appendChild(row); + return; + } + for (const conn of data.connections) { + const row = document.createElement('tr'); + const tdId = document.createElement('td'); + tdId.textContent = conn.account_id; + const tdName = document.createElement('td'); + tdName.textContent = conn.account_name; + const tdRole = document.createElement('td'); + tdRole.textContent = conn.role; + const tdGroup = document.createElement('td'); + if (conn.group_alias) { + tdGroup.textContent = `Gruppe ${conn.group_id}: ${conn.group_alias}`; + } else if (conn.role === 'Gruppe') { + tdGroup.textContent = `Gruppe ${conn.group_id || '-'}`; + } else { + tdGroup.textContent = '-'; + } + row.append(tdId, tdName, tdRole, tdGroup); + body.appendChild(row); + } + } catch (error) { + console.error(error); + const body = document.getElementById('brokerStatusBody'); + body.innerHTML = 'Fehler beim Laden'; + } +} + +loadBrokerStatus(); +setInterval(loadBrokerStatus, 5000); diff --git a/CMBNet/static/js/views/admin_strassen.js b/CMBNet/static/js/views/admin_strassen.js index d9ecc1b..0d4a367 100644 --- a/CMBNet/static/js/views/admin_strassen.js +++ b/CMBNet/static/js/views/admin_strassen.js @@ -170,6 +170,51 @@ function revertStreet(histId) { }); } +function normalizeForFilter(text) { + if (!text) return ''; + let s = String(text).toLowerCase(); + s = s.replace(/ä/g, 'ae') + .replace(/ö/g, 'oe') + .replace(/ü/g, 'ue') + .replace(/ß/g, 'ss'); + s = s.replace(/[-_]/g, ' '); + s = s.replace(/\s+/g, ' ').trim(); + return s; +} + +function applyStreetFilters() { + const nameInput = document.getElementById('streetNameFilter'); + const stateInput = document.getElementById('streetStateFilter'); + const groupInput = document.getElementById('streetGroupFilter'); + const nameQuery = normalizeForFilter(nameInput ? nameInput.value : ''); + const stateQuery = stateInput ? stateInput.value : ''; + const groupQuery = groupInput ? groupInput.value : ''; + + document.querySelectorAll('#strassenTable tbody tr').forEach(row => { + if (!row.dataset.id) return; + const nameCell = row.cells[1]; + const nameText = normalizeForFilter(nameCell ? nameCell.innerText : ''); + const stateSelect = row.cells[2] ? row.cells[2].querySelector('select') : null; + const groupSelect = row.cells[3] ? row.cells[3].querySelector('select') : null; + const stateVal = stateSelect ? stateSelect.value : ''; + const groupVal = groupSelect ? groupSelect.value : ''; + + let visible = true; + if (nameQuery && nameText.indexOf(nameQuery) === -1) { + visible = false; + } + if (visible && stateQuery && stateVal !== stateQuery) { + visible = false; + } + if (visible && groupQuery && groupVal !== groupQuery) { + visible = false; + } + row.style.display = visible ? '' : 'none'; + }); +} + +document.addEventListener('DOMContentLoaded', applyStreetFilters); + function closeStreetHistoryModal() { document.getElementById('streetHistoryModal').close(); } diff --git a/CMBNet/templates/admin/accounts.html b/CMBNet/templates/admin/accounts.html index 37c0365..a38fd2f 100644 --- a/CMBNet/templates/admin/accounts.html +++ b/CMBNet/templates/admin/accounts.html @@ -3,8 +3,8 @@ {% block title %}Accountverwaltung - CMBNet{% endblock %} {% block content %} +

← Zurück zum Dashboard

Accountverwaltung

-

Abmelden

@@ -39,13 +39,7 @@
- - +

← Zurück zum Dashboard

diff --git a/CMBNet/templates/admin/dashboard.html b/CMBNet/templates/admin/dashboard.html new file mode 100644 index 0000000..67c773e --- /dev/null +++ b/CMBNet/templates/admin/dashboard.html @@ -0,0 +1,39 @@ +{% extends "base.html" %} + +{% block title %}Admin Dashboard - CMBNet{% endblock %} + +{% block content %} +

Administrator Dashboard

+ + + +
+

Broker Status

+

Aktive WebSocket-Verbindungen

+ + + + + + + + + + + + +
Account-IDAccountRolleGruppe / Alias
Lade...
+
+ +

Abmelden

+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/CMBNet/templates/admin/gruppen.html b/CMBNet/templates/admin/gruppen.html index 149f29d..6f3d2ff 100644 --- a/CMBNet/templates/admin/gruppen.html +++ b/CMBNet/templates/admin/gruppen.html @@ -3,8 +3,8 @@ {% block title %}Gruppenverwaltung - CMBNet{% endblock %} {% block content %} +

← Zurück zum Dashboard

Gruppenverwaltung

-

← Zurück zur Accountverwaltung

@@ -51,6 +51,7 @@
+

← Zurück zum Dashboard

diff --git a/CMBNet/templates/admin/strassen.html b/CMBNet/templates/admin/strassen.html index 1c43035..5fceb0c 100644 --- a/CMBNet/templates/admin/strassen.html +++ b/CMBNet/templates/admin/strassen.html @@ -3,8 +3,30 @@ {% block title %}Straßenverwaltung - CMBNet{% endblock %} {% block content %} +

← Zurück zum Dashboard

Straßenverwaltung

-

← Zurück zur Accountverwaltung

+ +
+ + + +
@@ -60,6 +82,7 @@ +

← Zurück zum Dashboard

diff --git a/CMBNet/templates/base.html b/CMBNet/templates/base.html index 8b86940..88a1b21 100644 --- a/CMBNet/templates/base.html +++ b/CMBNet/templates/base.html @@ -20,6 +20,7 @@ + {% block head %}{% endblock %}