Administrator Views verbessert

This commit is contained in:
concierge committed 2026-10-25 11:11:37 +01:00
1 parent ffdb399f9e
commit 0a2070fcf5
12 files changed
+247 -12

No files matched your search

+7
View File
@@ -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):
+32
View File
@@ -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):
+1 -1
View File
@@ -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':
+1 -1
View File
@@ -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':
+45
View File
@@ -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;
}
}
+48
View File
@@ -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 = '<tr><td colspan="4">Fehler beim Laden</td></tr>';
}
}
loadBrokerStatus();
setInterval(loadBrokerStatus, 5000);
+45
View File
@@ -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();
}
+2 -8
View File
@@ -3,8 +3,8 @@
{% block title %}Accountverwaltung - CMBNet{% endblock %}
{% block content %}
<p><a href="{{ url_for('admin.dashboard', tenant=session.tenant_code) }}">← Zurück zum Dashboard</a></p>
<h1>Accountverwaltung</h1>
<p><a href="{{ url_for('auth.logout', tenant=session.tenant_code) }}">Abmelden</a></p>
<table id="accountsTable">
<thead>
@@ -39,13 +39,7 @@
</table>
<button onclick="openCreateAccountModal()">Neuer Account</button>
<nav>
<ul>
<li><a href="{{ url_for('admin_gruppen.gruppen', tenant=session.tenant_code) }}">Gruppenverwaltung</a></li>
<li><a href="{{ url_for('admin_strassen.strassen', tenant=session.tenant_code) }}">Straßenverwaltung</a></li>
</ul>
</nav>
<p style="margin-top: 2rem;"><a href="{{ url_for('admin.dashboard', tenant=session.tenant_code) }}">← Zurück zum Dashboard</a></p>
<!-- Passwort Modal -->
<dialog id="passwordModal">
+39
View File
@@ -0,0 +1,39 @@
{% extends "base.html" %}
{% block title %}Admin Dashboard - CMBNet{% endblock %}
{% block content %}
<h1>Administrator Dashboard</h1>
<nav>
<ul style="display: flex; gap: 1rem; flex-wrap: wrap; list-style: none; padding: 0;">
<li><a href="{{ url_for('admin.accounts', tenant=session.tenant_code) }}" role="button">Accountverwaltung</a></li>
<li><a href="{{ url_for('admin_gruppen.gruppen', tenant=session.tenant_code) }}" role="button" class="secondary">Gruppenverwaltung</a></li>
<li><a href="{{ url_for('admin_strassen.strassen', tenant=session.tenant_code) }}" role="button" class="secondary">Straßenverwaltung</a></li>
</ul>
</nav>
<section>
<h2>Broker Status</h2>
<p>Aktive WebSocket-Verbindungen</p>
<table id="brokerStatusTable">
<thead>
<tr>
<th>Account-ID</th>
<th>Account</th>
<th>Rolle</th>
<th>Gruppe / Alias</th>
</tr>
</thead>
<tbody id="brokerStatusBody">
<tr><td colspan="4">Lade...</td></tr>
</tbody>
</table>
</section>
<p style="margin-top: 2rem;"><a href="{{ url_for('auth.logout', tenant=session.tenant_code) }}" role="button" class="contrast">Abmelden</a></p>
{% endblock %}
{% block scripts %}
<script src="{{ url_for('static', filename='js/views/admin_dashboard.js') }}"></script>
{% endblock %}
+2 -1
View File
@@ -3,8 +3,8 @@
{% block title %}Gruppenverwaltung - CMBNet{% endblock %}
{% block content %}
<p><a href="{{ url_for('admin.dashboard', tenant=session.tenant_code) }}">← Zurück zum Dashboard</a></p>
<h1>Gruppenverwaltung</h1>
<p><a href="{{ url_for('admin.accounts', tenant=session.tenant_code) }}">← Zurück zur Accountverwaltung</a></p>
<table id="gruppenTable">
<thead>
@@ -51,6 +51,7 @@
</table>
<button onclick="openCreateGruppeModal()">Neue Gruppe</button>
<p style="margin-top: 2rem;"><a href="{{ url_for('admin.dashboard', tenant=session.tenant_code) }}">← Zurück zum Dashboard</a></p>
<!-- Create Gruppe Modal -->
<dialog id="createGruppeModal">
+24 -1
View File
@@ -3,8 +3,30 @@
{% block title %}Straßenverwaltung - CMBNet{% endblock %}
{% block content %}
<p><a href="{{ url_for('admin.dashboard', tenant=session.tenant_code) }}">← Zurück zum Dashboard</a></p>
<h1>Straßenverwaltung</h1>
<p><a href="{{ url_for('admin.accounts', tenant=session.tenant_code) }}">← Zurück zur Accountverwaltung</a></p>
<div style="display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; margin-bottom: 0.75rem;">
<label style="margin: 0;">Name filtern
<input type="text" id="streetNameFilter" placeholder="z. B. Haupt" oninput="applyStreetFilters()">
</label>
<label style="margin: 0;">State
<select id="streetStateFilter" onchange="applyStreetFilters()">
<option value="">alle</option>
<option value="unbearbeitet">unbearbeitet</option>
<option value="zugewiesen">zugewiesen</option>
<option value="erledigt">erledigt</option>
</select>
</label>
<label style="margin: 0;">Gruppe
<select id="streetGroupFilter" onchange="applyStreetFilters()">
<option value="">alle</option>
{% for gruppe in gruppen %}
<option value="{{ gruppe.id }}">{{ gruppe.aliasname or gruppe.id }}</option>
{% endfor %}
</select>
</label>
</div>
<table id="strassenTable">
<thead>
@@ -60,6 +82,7 @@
</button>
<input type="file" id="houseNumberCsvFile" accept=".csv" style="display:none"
onchange="importHouseNumbers(this)">
<p style="margin-top: 2rem;"><a href="{{ url_for('admin.dashboard', tenant=session.tenant_code) }}">← Zurück zum Dashboard</a></p>
<!-- Create/Edit Strasse Modal -->
<dialog id="strasseModal">
+1
View File
@@ -20,6 +20,7 @@
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css">
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css" />
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/admin.css') }}">
{% block head %}{% endblock %}
</head>
<body class="{% block body_class %}{% endblock %}">