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 = '