Neue Verwaltung der Gruppenzuordnung 1:n
This commit is contained in:
1 parent
fa02a7ade0
commit
02c017d53d
34 files changed
+1301
-246
No files matched your search
@@ -92,6 +92,11 @@ def create_app(config_name=None):
|
||||
static_folder='../static')
|
||||
app.config.from_object(config[config_name])
|
||||
|
||||
# Anzeigetitel für alle Web-Views. Der interne Projektname bleibt CMBNet.
|
||||
app.jinja_env.globals['APP_TITLE'] = app.config.get(
|
||||
'DISPLAY_TITLE', '20*C+M+B+27'
|
||||
)
|
||||
|
||||
# Middleware registrieren
|
||||
app.wsgi_app = PrefixMiddleware(app.wsgi_app)
|
||||
|
||||
@@ -104,9 +109,14 @@ def create_app(config_name=None):
|
||||
|
||||
# Datenbank-Setup
|
||||
from cmbnet.db import close_db, init_db_command
|
||||
from cmbnet.db.database import ensure_schema
|
||||
app.teardown_appcontext(close_db)
|
||||
app.cli.add_command(init_db_command)
|
||||
|
||||
# Bestehende Installationen idempotent auf das aktuelle Schema heben.
|
||||
with app.app_context():
|
||||
ensure_schema()
|
||||
|
||||
# Tenant und Account für Requests laden
|
||||
@app.before_request
|
||||
def load_current_account():
|
||||
|
||||
+35
-48
@@ -10,7 +10,7 @@ from cmbnet.models.groups import GroupModel
|
||||
from cmbnet.models.streets import StreetModel
|
||||
from cmbnet.services.groups_service import GroupsService
|
||||
from cmbnet.services.history_service import HistoryService
|
||||
from cmbnet.utils.helpers import log_transaction
|
||||
from cmbnet.utils.helpers import log_transaction, notify_reload
|
||||
from cmbnet.utils.csv_utils import parse_streets_csv, parse_house_numbers_csv
|
||||
from cmbnet.ws import broker
|
||||
from cmbnet.ws.protocol import WSMessage
|
||||
@@ -38,6 +38,7 @@ def create_account(**kwargs):
|
||||
password_hash = hash_password(password)
|
||||
account_id = AccountModel.create(g.tenant_id, name, password_hash, role)
|
||||
log_transaction('account.create', 'account', account_id, {'name': name, 'role': role})
|
||||
notify_reload(f'Administration: Account „{name}“ wurde erstellt.')
|
||||
|
||||
return jsonify({'success': True, 'id': account_id})
|
||||
|
||||
@@ -47,9 +48,12 @@ def create_account(**kwargs):
|
||||
def update_account_role(account_id, **kwargs):
|
||||
data = request.get_json()
|
||||
role = data.get('role')
|
||||
account = AccountModel.get_by_id(account_id, g.tenant_id)
|
||||
AccountModel.update_role(account_id, g.tenant_id, role)
|
||||
log_transaction('account.role_change', 'account', account_id, {'role': role})
|
||||
GroupsService.invalidate(g.tenant_id)
|
||||
name = account['name'] if account else f'#{account_id}'
|
||||
notify_reload(f'Administration: Rolle von Account „{name}“ wurde geändert.')
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@@ -61,17 +65,23 @@ def reset_password(account_id, **kwargs):
|
||||
if not password:
|
||||
return jsonify({'error': 'Passwort erforderlich'}), 400
|
||||
password_hash = hash_password(password)
|
||||
account = AccountModel.get_by_id(account_id, g.tenant_id)
|
||||
AccountModel.set_password(account_id, g.tenant_id, password_hash)
|
||||
log_transaction('account.password_reset', 'account', account_id, {})
|
||||
name = account['name'] if account else f'#{account_id}'
|
||||
notify_reload(f'Administration: Passwort für Account „{name}“ wurde zurückgesetzt.')
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@admin_api_bp.route('/accounts/<int:account_id>', methods=['DELETE'])
|
||||
@role_required('Administrator')
|
||||
def delete_account(account_id, **kwargs):
|
||||
account = AccountModel.get_by_id(account_id, g.tenant_id)
|
||||
AccountModel.delete(account_id, g.tenant_id)
|
||||
log_transaction('account.delete', 'account', account_id, {})
|
||||
GroupsService.invalidate(g.tenant_id)
|
||||
name = account['name'] if account else f'#{account_id}'
|
||||
notify_reload(f'Administration: Account „{name}“ wurde gelöscht.')
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@@ -81,37 +91,18 @@ def delete_account(account_id, **kwargs):
|
||||
def create_group(**kwargs):
|
||||
data = request.get_json() or {}
|
||||
aliasname = str(data.get('aliasname') or '').strip()
|
||||
account_id = data.get('account_id')
|
||||
db = get_db()
|
||||
|
||||
if account_id == '' or account_id is None:
|
||||
account_id = None
|
||||
else:
|
||||
try:
|
||||
account_id = int(account_id)
|
||||
except (TypeError, ValueError):
|
||||
return jsonify({'error': 'Ungültiger Account'}), 400
|
||||
|
||||
account = AccountModel.get_by_id(account_id, g.tenant_id)
|
||||
if not account or account['role'] != 'Gruppe':
|
||||
return jsonify({'error': 'Account muss die Rolle "Gruppe" haben'}), 400
|
||||
|
||||
linked = db.execute(
|
||||
'SELECT id FROM groups WHERE tenant_id = ? AND account_id = ?',
|
||||
(g.tenant_id, account_id)
|
||||
).fetchone()
|
||||
if linked:
|
||||
return jsonify({'error': 'Dieser Account ist bereits mit einer Gruppe verknüpft'}), 400
|
||||
|
||||
group_id = GroupModel.create(g.tenant_id, aliasname, account_id, 'offen')
|
||||
group_id = GroupModel.create(g.tenant_id, aliasname, 'offen')
|
||||
db.execute(
|
||||
'INSERT INTO group_state_history (tenant_id, group_id, from_state, to_state, actor_account_id) VALUES (?, ?, ?, ?, ?)',
|
||||
(g.tenant_id, group_id, None, 'offen', session['account_id'])
|
||||
)
|
||||
db.commit()
|
||||
log_transaction('group.create', 'group', group_id, {'aliasname': aliasname, 'account_id': account_id})
|
||||
log_transaction('group.create', 'group', group_id, {'aliasname': aliasname})
|
||||
GroupsService.invalidate(g.tenant_id)
|
||||
GroupsService.load_from_db(g.tenant_id)
|
||||
notify_reload(f'Administration: Gruppe „{aliasname or group_id}“ wurde erstellt.')
|
||||
return jsonify({'success': True, 'id': group_id})
|
||||
|
||||
|
||||
@@ -128,30 +119,6 @@ def update_group(group_id, **kwargs):
|
||||
if 'aliasname' in data:
|
||||
updates['aliasname'] = data['aliasname']
|
||||
|
||||
if 'account_id' in data:
|
||||
account_id = data['account_id']
|
||||
if account_id in ('', None):
|
||||
account_id = None
|
||||
else:
|
||||
try:
|
||||
account_id = int(account_id)
|
||||
except (TypeError, ValueError):
|
||||
return jsonify({'error': 'Ungültiger Account'}), 400
|
||||
|
||||
account = AccountModel.get_by_id(account_id, g.tenant_id)
|
||||
if not account or account['role'] != 'Gruppe':
|
||||
return jsonify({'error': 'Account muss die Rolle "Gruppe" haben'}), 400
|
||||
|
||||
linked = db.execute(
|
||||
'SELECT id FROM groups WHERE tenant_id = ? AND account_id = ? AND id != ?',
|
||||
(g.tenant_id, account_id, group_id)
|
||||
).fetchone()
|
||||
if linked:
|
||||
return jsonify({'error': 'Dieser Account ist bereits mit einer Gruppe verknüpft'}), 400
|
||||
|
||||
if account_id != old['account_id']:
|
||||
updates['account_id'] = account_id
|
||||
|
||||
allowed_states = {'offen', 'unterwegs', 'online', 'pausierend', 'fertig'}
|
||||
state_changed = False
|
||||
if 'state' in data:
|
||||
@@ -183,15 +150,20 @@ def update_group(group_id, **kwargs):
|
||||
log_transaction('group.update', 'group', group_id, updates)
|
||||
GroupsService.invalidate(g.tenant_id)
|
||||
GroupsService.load_from_db(g.tenant_id)
|
||||
display_name = updates.get('aliasname', old['aliasname']) or group_id
|
||||
notify_reload(f'Administration: Gruppe „{display_name}“ wurde geändert.')
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@admin_api_bp.route('/gruppen/<int:group_id>', methods=['DELETE'])
|
||||
@role_required('Administrator')
|
||||
def delete_group(group_id, **kwargs):
|
||||
group = GroupModel.get_by_id(group_id, g.tenant_id)
|
||||
GroupModel.delete(group_id, g.tenant_id)
|
||||
log_transaction('group.delete', 'group', group_id, {})
|
||||
GroupsService.invalidate(g.tenant_id)
|
||||
display_name = (group['aliasname'] if group and group['aliasname'] else group_id)
|
||||
notify_reload(f'Administration: Gruppe „{display_name}“ wurde gelöscht.')
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@@ -212,6 +184,7 @@ def revert_group_hist(group_id, hist_id, **kwargs):
|
||||
success, msg = HistoryService.revert_group(g.tenant_id, group_id, hist_id, session['account_id'])
|
||||
if not success:
|
||||
return jsonify({'error': msg}), 400
|
||||
notify_reload('Administration: Gruppenhistorie wurde wiederhergestellt.')
|
||||
return jsonify({'success': True, 'message': msg})
|
||||
|
||||
|
||||
@@ -223,6 +196,7 @@ def set_group_position_from_history(group_id, hist_id, **kwargs):
|
||||
)
|
||||
if not success:
|
||||
return jsonify({'error': msg}), 400
|
||||
notify_reload('Administration: Gruppenposition wurde aus der Historie gesetzt.')
|
||||
return jsonify({'success': True, 'message': msg})
|
||||
|
||||
|
||||
@@ -234,6 +208,7 @@ def clear_group_position(group_id, **kwargs):
|
||||
)
|
||||
if not success:
|
||||
return jsonify({'error': msg}), 400
|
||||
notify_reload('Administration: Gruppenposition wurde gelöscht.')
|
||||
return jsonify({'success': True, 'message': msg})
|
||||
|
||||
|
||||
@@ -258,6 +233,7 @@ def create_street(**kwargs):
|
||||
)
|
||||
db.commit()
|
||||
log_transaction('street.create', 'street', street_id, {'name': name})
|
||||
notify_reload(f'Administration: Straße „{name}“ wurde erstellt.')
|
||||
return jsonify({'success': True, 'id': street_id})
|
||||
|
||||
|
||||
@@ -303,6 +279,8 @@ def update_street(street_id, **kwargs):
|
||||
if changes:
|
||||
StreetModel.update(street_id, g.tenant_id, **changes)
|
||||
log_transaction('street.update', 'street', street_id, changes)
|
||||
display_name = changes.get('name', old['name'])
|
||||
notify_reload(f'Administration: Straße „{display_name}“ wurde geändert.')
|
||||
|
||||
db.commit()
|
||||
return jsonify({'success': True})
|
||||
@@ -311,8 +289,11 @@ def update_street(street_id, **kwargs):
|
||||
@admin_api_bp.route('/strassen/<int:street_id>', methods=['DELETE'])
|
||||
@role_required('Administrator')
|
||||
def delete_street(street_id, **kwargs):
|
||||
street = StreetModel.get_by_id(street_id, g.tenant_id)
|
||||
StreetModel.delete(street_id, g.tenant_id)
|
||||
log_transaction('street.delete', 'street', street_id, {})
|
||||
name = street['name'] if street else f'#{street_id}'
|
||||
notify_reload(f'Administration: Straße „{name}“ wurde gelöscht.')
|
||||
return jsonify({'success': True})
|
||||
|
||||
|
||||
@@ -333,6 +314,7 @@ def revert_street_hist(street_id, hist_id, **kwargs):
|
||||
success, msg = HistoryService.revert_street(g.tenant_id, street_id, hist_id, session['account_id'])
|
||||
if not success:
|
||||
return jsonify({'error': msg}), 400
|
||||
notify_reload('Administration: Straßenhistorie wurde wiederhergestellt.')
|
||||
return jsonify({'success': True, 'message': msg})
|
||||
|
||||
|
||||
@@ -367,6 +349,7 @@ def import_streets(**kwargs):
|
||||
count += 1
|
||||
|
||||
db.commit()
|
||||
notify_reload(f'Administration: {count} Straßen wurden importiert.')
|
||||
return jsonify({'success': True, 'count': count})
|
||||
|
||||
|
||||
@@ -392,7 +375,10 @@ def broker_status(**kwargs):
|
||||
}
|
||||
if account['role'] == 'Gruppe':
|
||||
group = get_db().execute(
|
||||
'SELECT id, aliasname FROM groups WHERE account_id = ? AND tenant_id = ?',
|
||||
'''SELECT g.id, g.aliasname FROM groups g
|
||||
JOIN group_accounts ga
|
||||
ON ga.group_id = g.id AND ga.tenant_id = g.tenant_id
|
||||
WHERE ga.account_id = ? AND g.tenant_id = ?''',
|
||||
(account['id'], g.tenant_id)
|
||||
).fetchone()
|
||||
if group:
|
||||
@@ -447,4 +433,5 @@ def import_house_numbers(**kwargs):
|
||||
None,
|
||||
{'count': len(house_numbers)}
|
||||
)
|
||||
notify_reload(f'Administration: {len(house_numbers)} Hausnummern wurden importiert.')
|
||||
return jsonify({'success': True, 'count': len(house_numbers)})
|
||||
@@ -14,11 +14,7 @@ def gruppen(**kwargs):
|
||||
"""Gruppenverwaltung"""
|
||||
db = get_db()
|
||||
gruppen = db.execute(
|
||||
'SELECT g.*, a.name as account_name FROM groups g LEFT JOIN accounts a ON g.account_id = a.id WHERE g.tenant_id = ? ORDER BY g.id',
|
||||
'SELECT * FROM groups WHERE tenant_id = ? ORDER BY id',
|
||||
(g.tenant_id,)
|
||||
).fetchall()
|
||||
accounts = db.execute(
|
||||
"SELECT * FROM accounts WHERE tenant_id = ? AND role = 'Gruppe'",
|
||||
(g.tenant_id,)
|
||||
).fetchall()
|
||||
return render_template('admin/gruppen.html', gruppen=gruppen, accounts=accounts)
|
||||
return render_template('admin/gruppen.html', gruppen=gruppen)
|
||||
@@ -4,9 +4,10 @@ API-Endpunkte für Gruppen im Dispatcher-View.
|
||||
from flask import Blueprint, jsonify, g, request
|
||||
|
||||
from cmbnet.auth import role_required
|
||||
from cmbnet.db import get_db
|
||||
from cmbnet.models.groups import GroupModel
|
||||
from cmbnet.services.groups_service import GroupsService
|
||||
from cmbnet.utils.helpers import log_transaction
|
||||
from cmbnet.utils.helpers import log_transaction, notify_reload
|
||||
|
||||
api_groups_bp = Blueprint('api_groups', __name__)
|
||||
|
||||
@@ -16,9 +17,10 @@ api_groups_bp = Blueprint('api_groups', __name__)
|
||||
def get_my_group(**kwargs):
|
||||
from cmbnet.services.groups_service import GroupsService
|
||||
groups = GroupsService.get_all(g.tenant_id)
|
||||
account_id = g.current_account['id']
|
||||
account_id = int(g.current_account['id'])
|
||||
for group in groups.values():
|
||||
if group.get('account_id') == account_id:
|
||||
account_ids = {int(value) for value in group.get('account_ids', [])}
|
||||
if account_id in account_ids:
|
||||
return jsonify(group)
|
||||
return jsonify({'error': 'Gruppe nicht gefunden'}), 404
|
||||
|
||||
@@ -47,3 +49,87 @@ def update_group_alias(group_id, **kwargs):
|
||||
GroupsService.load_from_db(g.tenant_id)
|
||||
|
||||
return jsonify({'success': True, 'aliasname': aliasname})
|
||||
|
||||
|
||||
@api_groups_bp.route('/groups/assignments', methods=['POST'])
|
||||
@role_required(['Dispatcher', 'Administrator'])
|
||||
def update_group_assignments(**kwargs):
|
||||
'''Speichert die Zuordnung von Gruppen-Accounts zu Gruppen.
|
||||
|
||||
Die Tabelle ``group_accounts`` erzwingt über ``UNIQUE(tenant_id,
|
||||
account_id)``, dass ein Gruppen-Account höchstens einer Gruppe zugeordnet
|
||||
ist. Ein ``null``-Wert in ``assignments`` bedeutet "Nicht dabei".
|
||||
'''
|
||||
data = request.get_json(silent=True) or {}
|
||||
raw_assignments = data.get('assignments')
|
||||
if not isinstance(raw_assignments, dict):
|
||||
return jsonify({'error': 'Ungültige Zuordnungen'}), 400
|
||||
|
||||
db = get_db()
|
||||
account_rows = db.execute(
|
||||
"SELECT id FROM accounts WHERE tenant_id = ? AND role = 'Gruppe'",
|
||||
(g.tenant_id,)
|
||||
).fetchall()
|
||||
allowed_accounts = {int(row['id']) for row in account_rows}
|
||||
|
||||
group_rows = db.execute(
|
||||
'SELECT id FROM groups WHERE tenant_id = ?',
|
||||
(g.tenant_id,)
|
||||
).fetchall()
|
||||
allowed_groups = {int(row['id']) for row in group_rows}
|
||||
|
||||
normalized = {}
|
||||
for raw_account_id, raw_group_id in raw_assignments.items():
|
||||
try:
|
||||
account_id = int(raw_account_id)
|
||||
except (TypeError, ValueError):
|
||||
return jsonify({'error': 'Ungültiger Account'}), 400
|
||||
if account_id not in allowed_accounts:
|
||||
return jsonify({'error': 'Account muss die Rolle "Gruppe" haben'}), 400
|
||||
|
||||
if raw_group_id in (None, '', 'none'):
|
||||
group_id = None
|
||||
else:
|
||||
try:
|
||||
group_id = int(raw_group_id)
|
||||
except (TypeError, ValueError):
|
||||
return jsonify({'error': 'Ungültige Gruppe'}), 400
|
||||
if group_id not in allowed_groups:
|
||||
return jsonify({'error': 'Gruppe nicht gefunden'}), 400
|
||||
|
||||
normalized[account_id] = group_id
|
||||
|
||||
changes = []
|
||||
for account_id, group_id in normalized.items():
|
||||
current = db.execute(
|
||||
'''SELECT group_id FROM group_accounts
|
||||
WHERE tenant_id = ? AND account_id = ?''',
|
||||
(g.tenant_id, account_id)
|
||||
).fetchone()
|
||||
current_group_id = current['group_id'] if current else None
|
||||
if current_group_id == group_id:
|
||||
continue
|
||||
|
||||
db.execute(
|
||||
'DELETE FROM group_accounts WHERE tenant_id = ? AND account_id = ?',
|
||||
(g.tenant_id, account_id)
|
||||
)
|
||||
if group_id is not None:
|
||||
db.execute(
|
||||
'''INSERT INTO group_accounts (tenant_id, group_id, account_id)
|
||||
VALUES (?, ?, ?)''',
|
||||
(g.tenant_id, group_id, account_id)
|
||||
)
|
||||
changes.append({'account_id': account_id, 'group_id': group_id})
|
||||
|
||||
if changes:
|
||||
db.commit()
|
||||
log_transaction(
|
||||
'group.assignment_update', 'group', None,
|
||||
{'changes': changes}
|
||||
)
|
||||
GroupsService.invalidate(g.tenant_id)
|
||||
GroupsService.load_from_db(g.tenant_id)
|
||||
|
||||
notify_reload('Gruppenzuordnungen wurden geändert.')
|
||||
return jsonify({'success': True, 'changes': len(changes)})
|
||||
@@ -23,6 +23,104 @@ def close_db(e=None):
|
||||
db.close()
|
||||
|
||||
|
||||
def ensure_schema():
|
||||
"""Ergänzt bestehende Datenbanken um das Gruppen-Account-Zuordnungsmodell.
|
||||
|
||||
Neue Installationen erhalten das Schema über ``migrations/schema.sql``.
|
||||
Für bestehende Datenbanken wird die frühere 1:1-Verknüpfung
|
||||
``groups.account_id`` in die neue Tabelle ``group_accounts`` übernommen
|
||||
und die alte Spalte durch einen Tabellen-Neubau entfernt.
|
||||
"""
|
||||
db = get_db()
|
||||
groups_table = db.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type = 'table' AND name = 'groups'"
|
||||
).fetchone()
|
||||
if not groups_table:
|
||||
return
|
||||
|
||||
db.executescript('''
|
||||
CREATE TABLE IF NOT EXISTS group_accounts (
|
||||
tenant_id INTEGER NOT NULL,
|
||||
group_id INTEGER NOT NULL,
|
||||
account_id INTEGER NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (tenant_id, group_id, account_id),
|
||||
UNIQUE (tenant_id, account_id),
|
||||
FOREIGN KEY (tenant_id) REFERENCES tenants(id),
|
||||
FOREIGN KEY (group_id) REFERENCES groups(id),
|
||||
FOREIGN KEY (account_id) REFERENCES accounts(id)
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_group_accounts_group
|
||||
ON group_accounts(tenant_id, group_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_groups_tenant ON groups(tenant_id);
|
||||
''')
|
||||
db.commit()
|
||||
|
||||
columns = {
|
||||
row['name'] for row in db.execute('PRAGMA table_info(groups)').fetchall()
|
||||
}
|
||||
if 'account_id' not in columns:
|
||||
return
|
||||
|
||||
db.execute(
|
||||
'''INSERT OR IGNORE INTO group_accounts (tenant_id, group_id, account_id)
|
||||
SELECT g.tenant_id, g.id, g.account_id
|
||||
FROM groups g
|
||||
JOIN accounts a
|
||||
ON a.id = g.account_id AND a.tenant_id = g.tenant_id
|
||||
WHERE g.account_id IS NOT NULL AND a.role = 'Gruppe' '''
|
||||
)
|
||||
db.commit()
|
||||
|
||||
# SQLite kann eine UNIQUE-Spalte nicht per ALTER TABLE DROP COLUMN
|
||||
# entfernen. Deshalb wird die Tabelle ohne die alte Spalte neu aufgebaut.
|
||||
# Die bereits kopierten Zuordnungen bleiben dabei erhalten.
|
||||
fk_enabled = db.execute('PRAGMA foreign_keys').fetchone()[0]
|
||||
db.execute('PRAGMA foreign_keys = OFF')
|
||||
try:
|
||||
db.execute('DROP TABLE IF EXISTS groups_new')
|
||||
db.execute('BEGIN IMMEDIATE')
|
||||
db.execute('''
|
||||
CREATE TABLE groups_new (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
tenant_id INTEGER NOT NULL,
|
||||
aliasname TEXT,
|
||||
state TEXT NOT NULL DEFAULT 'offen'
|
||||
CHECK(state IN ('offen', 'unterwegs', 'online', 'pausierend', 'fertig')),
|
||||
last_lat REAL,
|
||||
last_lon REAL,
|
||||
last_pos_at TIMESTAMP,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (tenant_id) REFERENCES tenants(id)
|
||||
)
|
||||
''')
|
||||
db.execute('''
|
||||
INSERT INTO groups_new
|
||||
(id, tenant_id, aliasname, state, last_lat, last_lon,
|
||||
last_pos_at, created_at, updated_at)
|
||||
SELECT id, tenant_id, aliasname, state, last_lat, last_lon,
|
||||
last_pos_at, created_at, updated_at
|
||||
FROM groups
|
||||
''')
|
||||
db.execute('DROP TABLE groups')
|
||||
db.execute('ALTER TABLE groups_new RENAME TO groups')
|
||||
db.execute('CREATE INDEX IF NOT EXISTS idx_groups_tenant ON groups(tenant_id)')
|
||||
db.commit()
|
||||
except sqlite3.DatabaseError as exc:
|
||||
db.rollback()
|
||||
try:
|
||||
db.execute('DROP TABLE IF EXISTS groups_new')
|
||||
db.commit()
|
||||
except sqlite3.DatabaseError:
|
||||
pass
|
||||
current_app.logger.warning(
|
||||
'groups.account_id konnte nicht entfernt werden: %s', exc
|
||||
)
|
||||
finally:
|
||||
db.execute('PRAGMA foreign_keys = ON' if fk_enabled else 'PRAGMA foreign_keys = OFF')
|
||||
|
||||
|
||||
def init_db():
|
||||
"""Initialisiert die Datenbank mit dem Schema"""
|
||||
db = get_db()
|
||||
@@ -30,6 +128,7 @@ def init_db():
|
||||
with open(schema_path, 'r', encoding='utf-8') as f:
|
||||
db.executescript(f.read())
|
||||
db.commit()
|
||||
ensure_schema()
|
||||
|
||||
|
||||
@click.command('init-db')
|
||||
|
||||
@@ -48,6 +48,13 @@ class AccountModel:
|
||||
'UPDATE accounts SET role = ?, updated_at = CURRENT_TIMESTAMP WHERE id = ? AND tenant_id = ?',
|
||||
(role, account_id, tenant_id)
|
||||
)
|
||||
# Ein Account, der nicht mehr die Rolle "Gruppe" hat, darf keine
|
||||
# Gruppenzuordnung behalten.
|
||||
if role != 'Gruppe':
|
||||
db.execute(
|
||||
'DELETE FROM group_accounts WHERE tenant_id = ? AND account_id = ?',
|
||||
(tenant_id, account_id)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
@staticmethod
|
||||
@@ -62,5 +69,9 @@ class AccountModel:
|
||||
@staticmethod
|
||||
def delete(account_id, tenant_id):
|
||||
db = get_db()
|
||||
db.execute(
|
||||
'DELETE FROM group_accounts WHERE tenant_id = ? AND account_id = ?',
|
||||
(tenant_id, account_id)
|
||||
)
|
||||
db.execute('DELETE FROM accounts WHERE id = ? AND tenant_id = ?', (account_id, tenant_id))
|
||||
db.commit()
|
||||
@@ -25,16 +25,44 @@ class GroupModel:
|
||||
def get_by_account_id(account_id, tenant_id):
|
||||
db = get_db()
|
||||
return db.execute(
|
||||
'SELECT * FROM groups WHERE account_id = ? AND tenant_id = ?',
|
||||
'''SELECT g.* FROM groups g
|
||||
JOIN group_accounts ga
|
||||
ON ga.group_id = g.id AND ga.tenant_id = g.tenant_id
|
||||
WHERE ga.account_id = ? AND g.tenant_id = ?''',
|
||||
(account_id, tenant_id)
|
||||
).fetchone()
|
||||
|
||||
@staticmethod
|
||||
def create(tenant_id, aliasname, account_id=None, state='offen'):
|
||||
def get_account_ids_for_group(group_id, tenant_id):
|
||||
db = get_db()
|
||||
rows = db.execute(
|
||||
'''SELECT account_id FROM group_accounts
|
||||
WHERE group_id = ? AND tenant_id = ?
|
||||
ORDER BY account_id''',
|
||||
(group_id, tenant_id)
|
||||
).fetchall()
|
||||
return [row['account_id'] for row in rows]
|
||||
|
||||
@staticmethod
|
||||
def get_account_ids_by_group(tenant_id):
|
||||
db = get_db()
|
||||
rows = db.execute(
|
||||
'''SELECT group_id, account_id FROM group_accounts
|
||||
WHERE tenant_id = ?
|
||||
ORDER BY group_id, account_id''',
|
||||
(tenant_id,)
|
||||
).fetchall()
|
||||
result = {}
|
||||
for row in rows:
|
||||
result.setdefault(row['group_id'], []).append(row['account_id'])
|
||||
return result
|
||||
|
||||
@staticmethod
|
||||
def create(tenant_id, aliasname, state='offen'):
|
||||
db = get_db()
|
||||
cursor = db.execute(
|
||||
'INSERT INTO groups (tenant_id, aliasname, account_id, state) VALUES (?, ?, ?, ?)',
|
||||
(tenant_id, aliasname, account_id, state)
|
||||
'INSERT INTO groups (tenant_id, aliasname, state) VALUES (?, ?, ?)',
|
||||
(tenant_id, aliasname, state)
|
||||
)
|
||||
db.commit()
|
||||
return cursor.lastrowid
|
||||
@@ -42,7 +70,7 @@ class GroupModel:
|
||||
@staticmethod
|
||||
def update(group_id, tenant_id, **kwargs):
|
||||
db = get_db()
|
||||
allowed = ['aliasname', 'state', 'account_id', 'last_lat', 'last_lon', 'last_pos_at']
|
||||
allowed = ['aliasname', 'state', 'last_lat', 'last_lon', 'last_pos_at']
|
||||
updates = []
|
||||
values = []
|
||||
for k, v in kwargs.items():
|
||||
@@ -59,5 +87,9 @@ class GroupModel:
|
||||
@staticmethod
|
||||
def delete(group_id, tenant_id):
|
||||
db = get_db()
|
||||
db.execute(
|
||||
'DELETE FROM group_accounts WHERE group_id = ? AND tenant_id = ?',
|
||||
(group_id, tenant_id)
|
||||
)
|
||||
db.execute('DELETE FROM groups WHERE id = ? AND tenant_id = ?', (group_id, tenant_id))
|
||||
db.commit()
|
||||
@@ -15,8 +15,10 @@ class GroupsService:
|
||||
def load_from_db(cls, tenant_id):
|
||||
"""Lädt alle Gruppen eines Mandanten aus der Datenbank in den Cache"""
|
||||
groups = GroupModel.get_all_by_tenant(tenant_id)
|
||||
if tenant_id not in cls._cache:
|
||||
cls._cache[tenant_id] = {}
|
||||
memberships = GroupModel.get_account_ids_by_group(tenant_id)
|
||||
# Vollständig neu aufbauen, damit gelöschte Gruppen nicht im Cache
|
||||
# zurückbleiben.
|
||||
cls._cache[tenant_id] = {}
|
||||
|
||||
for group in groups:
|
||||
cls._cache[tenant_id][group['id']] = {
|
||||
@@ -27,7 +29,7 @@ class GroupsService:
|
||||
'last_lat': group['last_lat'],
|
||||
'last_lon': group['last_lon'],
|
||||
'last_pos_at': group['last_pos_at'],
|
||||
'account_id': group['account_id'],
|
||||
'account_ids': memberships.get(group['id'], []),
|
||||
'created_at': group['created_at'],
|
||||
'updated_at': group['updated_at']
|
||||
}
|
||||
@@ -43,7 +45,7 @@ class GroupsService:
|
||||
@classmethod
|
||||
def get_by_id(cls, tenant_id, group_id):
|
||||
"""Gibt eine spezifische Gruppe aus dem Cache zurück"""
|
||||
if tenant_id not in cls._cache:
|
||||
if tenant_id not in cls._cache or not cls._cache[tenant_id]:
|
||||
cls.load_from_db(tenant_id)
|
||||
return cls._cache.get(tenant_id, {}).get(group_id)
|
||||
|
||||
@@ -64,16 +66,19 @@ class GroupsService:
|
||||
group = cls.get_by_id(tenant_id, group_id)
|
||||
if not group:
|
||||
return False
|
||||
return group.get('account_id') == account_id
|
||||
account_ids = {int(value) for value in group.get('account_ids', [])}
|
||||
return int(account_id) in account_ids
|
||||
|
||||
@classmethod
|
||||
def get_accounts_for_group(cls, group_id, tenant_id):
|
||||
"""Gibt alle mit einer Gruppe verknüpften Accounts zurück"""
|
||||
group = cls.get_by_id(tenant_id, group_id)
|
||||
if not group or not group.get('account_id'):
|
||||
return []
|
||||
account = AccountModel.get_by_id(group['account_id'], tenant_id)
|
||||
return [account] if account else []
|
||||
account_ids = GroupModel.get_account_ids_for_group(group_id, tenant_id)
|
||||
accounts = []
|
||||
for account_id in account_ids:
|
||||
account = AccountModel.get_by_id(account_id, tenant_id)
|
||||
if account:
|
||||
accounts.append(account)
|
||||
return accounts
|
||||
|
||||
@classmethod
|
||||
def get_streets_for_group(cls, group_id, tenant_id):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Hilfsfunktionen für CMBNet
|
||||
"""
|
||||
from flask import g
|
||||
from flask import current_app, g
|
||||
import json
|
||||
|
||||
|
||||
@@ -15,6 +15,33 @@ def get_current_account():
|
||||
return getattr(g, 'current_account', None)
|
||||
|
||||
|
||||
def notify_reload(text, tenant_id=None, sender_id=None):
|
||||
"""Sendet eine interne Code-99-Nachricht an alle Clients eines Mandanten."""
|
||||
from cmbnet.ws import broker
|
||||
from cmbnet.ws.protocol import WSMessage
|
||||
|
||||
tenant_id = tenant_id if tenant_id is not None else get_tenant_id()
|
||||
account = get_current_account()
|
||||
if sender_id is None and account:
|
||||
sender_id = account['id']
|
||||
|
||||
if not tenant_id or not sender_id:
|
||||
return False
|
||||
|
||||
try:
|
||||
broker.route_message(
|
||||
tenant_id,
|
||||
WSMessage(sender_id=sender_id, code=99, msg=str(text))
|
||||
)
|
||||
return True
|
||||
except Exception as exc:
|
||||
try:
|
||||
current_app.logger.warning('Code-99-Nachricht konnte nicht gesendet werden: %s', exc)
|
||||
except Exception:
|
||||
pass
|
||||
return False
|
||||
|
||||
|
||||
def log_transaction(action, entity_type, entity_id, details=None):
|
||||
"""
|
||||
Schreibt einen Eintrag ins Transaktionslog
|
||||
|
||||
@@ -3,7 +3,7 @@ Haupt-Views
|
||||
"""
|
||||
from flask import (
|
||||
Blueprint, render_template, g, redirect, url_for, request, jsonify,
|
||||
make_response, session
|
||||
make_response, session, current_app
|
||||
)
|
||||
from cmbnet.auth import login_required, role_required
|
||||
|
||||
@@ -65,28 +65,23 @@ def manifest(tenant=None, **kwargs):
|
||||
"""Liefert das Web-App-Manifest für die mobilen Views."""
|
||||
account = getattr(g, 'current_account', None)
|
||||
role = account['role'] if account else session.get('role')
|
||||
title = current_app.config.get('DISPLAY_TITLE', '20*C+M+B+27')
|
||||
|
||||
if role == 'Dispatcher':
|
||||
start_url = url_for('views.dispatcher_mobil', tenant=tenant)
|
||||
name = 'CMBNet Dispatcher'
|
||||
short_name = 'CMB Dispo'
|
||||
elif role == 'Gruppe':
|
||||
start_url = url_for('views.gruppen', tenant=tenant)
|
||||
name = 'CMBNet Gruppe'
|
||||
short_name = 'CMB Gruppe'
|
||||
else:
|
||||
start_url = url_for('views.index', tenant=tenant)
|
||||
name = 'CMBNet'
|
||||
short_name = 'CMBNet'
|
||||
|
||||
icon_192 = url_for('static', filename='img/icon-192.png')
|
||||
icon_512 = url_for('static', filename='img/icon-512.png')
|
||||
|
||||
payload = {
|
||||
'id': start_url,
|
||||
'name': name,
|
||||
'short_name': short_name,
|
||||
'description': 'CMBNet – mobile Einsatzansicht',
|
||||
'name': title,
|
||||
'short_name': title,
|
||||
'description': f'{title} – mobile Einsatzansicht',
|
||||
'lang': 'de',
|
||||
'start_url': start_url,
|
||||
'scope': url_for('views.index', tenant=tenant),
|
||||
|
||||
+57
-16
@@ -7,6 +7,8 @@ die Nachricht zu.
|
||||
|
||||
Wichtige Regeln aus der Spezifikation:
|
||||
- Code < 100: rein interne Nachrichten (z. B. Authentifizierung, Heartbeat).
|
||||
Code 99 ist eine serverinterne Aufforderung an alle Clients, die Seite
|
||||
wegen geänderter Daten neu zu laden.
|
||||
- Code 100/200/300: State- bzw. Positionsänderungen an Dispatcher, Beobachter
|
||||
und die jeweils betroffene Gruppe.
|
||||
- Code 1000/1100/2000: Chat-/Broadcast-Nachrichten. Diese werden persistiert,
|
||||
@@ -57,10 +59,13 @@ class WebSocketBroker:
|
||||
role = account['role']
|
||||
|
||||
# Für Gruppen-Accounts die zugehörige Gruppe ermitteln. Ein Account der
|
||||
# Rolle "Gruppe" ist genau einer Gruppe zugeordnet.
|
||||
# Rolle "Gruppe" ist höchstens einer Gruppe zugeordnet.
|
||||
if group_id is None and role == 'Gruppe':
|
||||
group = db.execute(
|
||||
'SELECT id FROM groups WHERE account_id = ? AND tenant_id = ?',
|
||||
'''SELECT g.id FROM groups g
|
||||
JOIN group_accounts ga
|
||||
ON ga.group_id = g.id AND ga.tenant_id = g.tenant_id
|
||||
WHERE ga.account_id = ? AND g.tenant_id = ?''',
|
||||
(account_id, tenant_id)
|
||||
).fetchone()
|
||||
group_id = group['id'] if group else None
|
||||
@@ -226,7 +231,10 @@ class WebSocketBroker:
|
||||
return True
|
||||
if role == 'Gruppe':
|
||||
group = db.execute(
|
||||
'SELECT id FROM groups WHERE account_id = ? AND tenant_id = ?',
|
||||
'''SELECT g.id FROM groups g
|
||||
JOIN group_accounts ga
|
||||
ON ga.group_id = g.id AND ga.tenant_id = g.tenant_id
|
||||
WHERE ga.account_id = ? AND g.tenant_id = ?''',
|
||||
(account_id, tenant_id)
|
||||
).fetchone()
|
||||
return bool(group and msg_row['receiver_id'] == group['id'])
|
||||
@@ -238,7 +246,10 @@ class WebSocketBroker:
|
||||
return True
|
||||
if role == 'Gruppe':
|
||||
group = db.execute(
|
||||
'SELECT id FROM groups WHERE account_id = ? AND tenant_id = ?',
|
||||
'''SELECT g.id FROM groups g
|
||||
JOIN group_accounts ga
|
||||
ON ga.group_id = g.id AND ga.tenant_id = g.tenant_id
|
||||
WHERE ga.account_id = ? AND g.tenant_id = ?''',
|
||||
(account_id, tenant_id)
|
||||
).fetchone()
|
||||
payload = self._payload(msg_row)
|
||||
@@ -293,6 +304,14 @@ class WebSocketBroker:
|
||||
self._deliver(tenant_id, message, sender)
|
||||
return
|
||||
|
||||
# Code 99 ist eine serverinterne Aufforderung zum Neuladen. Clients
|
||||
# dürfen diesen Code nicht selbst auslösen.
|
||||
if code == 99:
|
||||
if apply_business:
|
||||
return
|
||||
self._deliver(tenant_id, message, sender)
|
||||
return
|
||||
|
||||
# Sonstige interne Codes (< 100) werden nicht an die Oberfläche gegeben.
|
||||
if code < 100:
|
||||
return
|
||||
@@ -444,8 +463,14 @@ class WebSocketBroker:
|
||||
return False
|
||||
|
||||
# Ein Gruppen-Account darf nur den Zustand seiner eigenen Gruppe ändern.
|
||||
if sender['role'] == 'Gruppe' and group['account_id'] != sender['id']:
|
||||
return False
|
||||
if sender['role'] == 'Gruppe':
|
||||
linked = db.execute(
|
||||
'''SELECT 1 FROM group_accounts
|
||||
WHERE tenant_id = ? AND group_id = ? AND account_id = ?''',
|
||||
(tenant_id, group_id, sender['id'])
|
||||
).fetchone()
|
||||
if not linked:
|
||||
return False
|
||||
|
||||
new_state = payload.get('state')
|
||||
if new_state not in ('offen', 'unterwegs', 'online', 'pausierend', 'fertig'):
|
||||
@@ -495,8 +520,14 @@ class WebSocketBroker:
|
||||
if not group:
|
||||
return False
|
||||
|
||||
if sender['role'] == 'Gruppe' and group['account_id'] != sender['id']:
|
||||
return False
|
||||
if sender['role'] == 'Gruppe':
|
||||
linked = db.execute(
|
||||
'''SELECT 1 FROM group_accounts
|
||||
WHERE tenant_id = ? AND group_id = ? AND account_id = ?''',
|
||||
(tenant_id, group_id, sender['id'])
|
||||
).fetchone()
|
||||
if not linked:
|
||||
return False
|
||||
|
||||
try:
|
||||
lat = float(payload.get('lat'))
|
||||
@@ -583,7 +614,10 @@ class WebSocketBroker:
|
||||
}
|
||||
if sender and sender['role'] == 'Gruppe':
|
||||
group = db.execute(
|
||||
'SELECT id, aliasname FROM groups WHERE account_id = ? AND tenant_id = ?',
|
||||
'''SELECT g.id, g.aliasname FROM groups g
|
||||
JOIN group_accounts ga
|
||||
ON ga.group_id = g.id AND ga.tenant_id = g.tenant_id
|
||||
WHERE ga.account_id = ? AND g.tenant_id = ?''',
|
||||
(sender['id'], tenant_id)
|
||||
).fetchone()
|
||||
if group:
|
||||
@@ -723,14 +757,18 @@ class WebSocketBroker:
|
||||
def add_group_account(group_id):
|
||||
if not group_id:
|
||||
return
|
||||
group = db.execute(
|
||||
'SELECT account_id FROM groups WHERE id = ? AND tenant_id = ?',
|
||||
rows = db.execute(
|
||||
'''SELECT account_id FROM group_accounts
|
||||
WHERE group_id = ? AND tenant_id = ?''',
|
||||
(group_id, tenant_id)
|
||||
).fetchone()
|
||||
if group and group['account_id']:
|
||||
recipients.add(group['account_id'])
|
||||
).fetchall()
|
||||
recipients.update(row['account_id'] for row in rows)
|
||||
|
||||
if code == 100:
|
||||
if code == 99:
|
||||
# Alle verbundenen Clients des Mandanten müssen die Seite neu laden.
|
||||
add_accounts(('Gast', 'Beobachter', 'Gruppe', 'Dispatcher', 'Administrator'))
|
||||
|
||||
elif code == 100:
|
||||
# Dispatcher, Gast, Beobachter + die mit der Straße verknüpfte
|
||||
# Gruppe. Bei einem Gruppenwechsel werden sowohl die alte als auch
|
||||
# die neue Gruppe benachrichtigt.
|
||||
@@ -836,7 +874,10 @@ class WebSocketBroker:
|
||||
if group_id is None and sender is not None and message.code in (200, 300, 2000):
|
||||
# Bei Gruppen-Nachrichten ist der Absender die Gruppe selbst.
|
||||
group = get_db().execute(
|
||||
'SELECT id FROM groups WHERE account_id = ? AND tenant_id = ?',
|
||||
'''SELECT g.id FROM groups g
|
||||
JOIN group_accounts ga
|
||||
ON ga.group_id = g.id AND ga.tenant_id = g.tenant_id
|
||||
WHERE ga.account_id = ? AND g.tenant_id = ?''',
|
||||
(sender['id'], tenant_id)
|
||||
).fetchone()
|
||||
group_id = group['id'] if group else None
|
||||
|
||||
@@ -9,6 +9,10 @@ class Config:
|
||||
TENANTS = ['BV', 'RV', 'SV']
|
||||
DEFAULT_TENANT = 'RV'
|
||||
|
||||
# Intern heißt das Projekt weiterhin CMBNet. In den Web-Views wird
|
||||
# stattdessen dieser Titel angezeigt.
|
||||
DISPLAY_TITLE = '20*C+M+B+27'
|
||||
|
||||
WS_HEARTBEAT_INTERVAL = int(os.environ.get('CMBNET_WS_HEARTBEAT_INTERVAL', '60'))
|
||||
WS_HEARTBEAT_TIMEOUT = 15
|
||||
LATE_ENTRY_MAX_AGE_HOURS = int(os.environ.get('CMBNET_LATE_ENTRY_MAX_AGE_HOURS', '8'))
|
||||
|
||||
@@ -31,10 +31,22 @@ CREATE TABLE IF NOT EXISTS groups (
|
||||
last_lat REAL,
|
||||
last_lon REAL,
|
||||
last_pos_at TIMESTAMP,
|
||||
account_id INTEGER UNIQUE,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
FOREIGN KEY (tenant_id) REFERENCES tenants(id)
|
||||
);
|
||||
|
||||
-- Zuordnung von Gruppen-Accounts zu Gruppen (1:n: eine Gruppe, viele Accounts).
|
||||
-- Ein Account der Rolle "Gruppe" darf höchstens einer Gruppe zugeordnet sein.
|
||||
CREATE TABLE IF NOT EXISTS group_accounts (
|
||||
tenant_id INTEGER NOT NULL,
|
||||
group_id INTEGER NOT NULL,
|
||||
account_id INTEGER NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (tenant_id, group_id, account_id),
|
||||
UNIQUE (tenant_id, account_id),
|
||||
FOREIGN KEY (tenant_id) REFERENCES tenants(id),
|
||||
FOREIGN KEY (group_id) REFERENCES groups(id),
|
||||
FOREIGN KEY (account_id) REFERENCES accounts(id)
|
||||
);
|
||||
|
||||
@@ -145,6 +157,8 @@ CREATE TABLE IF NOT EXISTS transaction_log (
|
||||
-- Indizes für Performance
|
||||
CREATE INDEX IF NOT EXISTS idx_accounts_tenant ON accounts(tenant_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_groups_tenant ON groups(tenant_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_group_accounts_group
|
||||
ON group_accounts(tenant_id, group_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_streets_tenant ON streets(tenant_id);
|
||||
CREATE INDEX IF NOT EXISTS idx_street_house_numbers_lookup
|
||||
ON street_house_numbers(tenant_id, street_name, house_number);
|
||||
|
||||
@@ -103,11 +103,6 @@ body.dispatcher-page main.container {
|
||||
flex: 1 1 0;
|
||||
}
|
||||
|
||||
.clock-row > #speakerButton {
|
||||
flex: 0 0 auto;
|
||||
margin: 0 0.25rem;
|
||||
}
|
||||
|
||||
.clock-date {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
@@ -254,6 +249,9 @@ body.dispatcher-page main.container {
|
||||
}
|
||||
|
||||
.icon-button {
|
||||
--background-color: var(--primary);
|
||||
--border-color: var(--primary);
|
||||
--color: var(--primary-inverse);
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
@@ -262,22 +260,28 @@ body.dispatcher-page main.container {
|
||||
height: 2.5rem;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: var(--border-width) solid var(--border-color);
|
||||
border-radius: 0.55rem;
|
||||
background-color: var(--background-color);
|
||||
color: var(--color);
|
||||
font-size: 1.2rem;
|
||||
line-height: 1;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
a.icon-button {
|
||||
border: 1px solid var(--dispatcher-border-strong);
|
||||
background: var(--form-element-background-color, #fff);
|
||||
color: inherit;
|
||||
a.icon-button:is(:hover, :focus-visible) {
|
||||
--background-color: var(--primary-hover);
|
||||
--border-color: var(--primary-hover);
|
||||
}
|
||||
|
||||
a.icon-button:focus-visible {
|
||||
box-shadow: 0 0 0 var(--outline-width) var(--primary-focus);
|
||||
}
|
||||
|
||||
.icon-button.active {
|
||||
background: #2f6fdb;
|
||||
border-color: #2f6fdb;
|
||||
color: #fff;
|
||||
--background-color: var(--primary-hover);
|
||||
--border-color: var(--primary-hover);
|
||||
--color: var(--primary-inverse);
|
||||
}
|
||||
|
||||
.connection-status {
|
||||
@@ -294,6 +298,41 @@ a.icon-button {
|
||||
color: #b42318;
|
||||
}
|
||||
|
||||
.header-status-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.75rem;
|
||||
margin-top: 0.45rem;
|
||||
}
|
||||
|
||||
.header-status-row .connection-status {
|
||||
flex: 1 1 auto;
|
||||
margin-top: 0;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.header-action-buttons {
|
||||
display: flex;
|
||||
flex: 0 0 auto;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.header-action-buttons .icon-button {
|
||||
width: 2.25rem;
|
||||
height: 2.25rem;
|
||||
}
|
||||
|
||||
.group-assignment-button svg {
|
||||
display: block;
|
||||
width: 1.8rem;
|
||||
height: 1.35rem;
|
||||
}
|
||||
|
||||
/* ---------- Accordion ---------- */
|
||||
|
||||
.group-accordion {
|
||||
@@ -311,7 +350,8 @@ a.icon-button {
|
||||
}
|
||||
|
||||
.group-item {
|
||||
margin: 0 0 0.55rem;
|
||||
--group-control-size: 2rem;
|
||||
margin: 0 0 0.45rem;
|
||||
border: 1px solid var(--dispatcher-border);
|
||||
border-radius: 0.65rem;
|
||||
background: var(--card-background-color, #fff);
|
||||
@@ -321,8 +361,8 @@ a.icon-button {
|
||||
.group-item > summary {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.55rem;
|
||||
padding: 0.65rem 0.75rem;
|
||||
gap: 0.45rem;
|
||||
padding: 0.5rem 0.65rem;
|
||||
cursor: pointer;
|
||||
list-style: none;
|
||||
user-select: none;
|
||||
@@ -371,67 +411,93 @@ a.icon-button {
|
||||
}
|
||||
|
||||
.group-details {
|
||||
padding: 0 0.75rem 0.75rem;
|
||||
padding: 0 0.65rem 0.55rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0.6rem;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.group-position-row {
|
||||
.group-controls {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.group-position-row .icon-button {
|
||||
width: 2.25rem;
|
||||
height: 2.25rem;
|
||||
font-size: 1.05rem;
|
||||
.group-controls .icon-button {
|
||||
width: var(--group-control-size);
|
||||
height: var(--group-control-size);
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.group-position-row progress {
|
||||
flex: 1 1 auto;
|
||||
width: auto;
|
||||
height: 0.75rem;
|
||||
margin: 0;
|
||||
/* Circular freshness indicator: a full circle is 100 % / Live. */
|
||||
.group-progress-circle {
|
||||
--progress: 0;
|
||||
--progress-color: #2f6fdb;
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex: 0 0 auto;
|
||||
width: var(--group-control-size);
|
||||
height: var(--group-control-size);
|
||||
border-radius: 50%;
|
||||
background: conic-gradient(
|
||||
var(--progress-color) calc(var(--progress) * 1%),
|
||||
var(--dispatcher-subtle-bg) 0
|
||||
);
|
||||
}
|
||||
|
||||
.group-position-meta {
|
||||
font-size: 0.72rem;
|
||||
.group-progress-circle.is-live {
|
||||
--progress-color: #2e9e4f;
|
||||
}
|
||||
|
||||
.group-progress-text {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: calc(100% - 0.4rem);
|
||||
height: calc(100% - 0.4rem);
|
||||
border-radius: 50%;
|
||||
background: var(--card-background-color, #fff);
|
||||
color: var(--muted-color, #5b6771);
|
||||
font-size: 0.5rem;
|
||||
font-weight: 700;
|
||||
line-height: 1;
|
||||
font-variant-numeric: tabular-nums;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.group-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
.group-progress-circle.is-live .group-progress-text {
|
||||
color: #18794e;
|
||||
}
|
||||
|
||||
.group-crosshair,
|
||||
.group-streets,
|
||||
.group-alias {
|
||||
width: 2.35rem;
|
||||
height: 2.35rem;
|
||||
width: var(--group-control-size);
|
||||
height: var(--group-control-size);
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-size: 1.1rem;
|
||||
font-size: 1rem;
|
||||
}
|
||||
|
||||
.group-state-select {
|
||||
.group-controls select.group-state-select {
|
||||
flex: 1 1 auto;
|
||||
width: auto;
|
||||
min-width: 0;
|
||||
height: 2.35rem;
|
||||
height: var(--group-control-size);
|
||||
margin: 0;
|
||||
padding: 0.25rem 1.8rem 0.25rem 0.55rem;
|
||||
font-size: 0.78rem;
|
||||
padding: 0.15rem 1.35rem 0.15rem 0.4rem;
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
|
||||
.group-message {
|
||||
height: 1.9rem;
|
||||
margin: 0;
|
||||
padding: 0.2rem 0.5rem;
|
||||
cursor: pointer;
|
||||
background: var(--dispatcher-subtle-bg);
|
||||
font-size: 0.82rem;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.group-message:focus {
|
||||
@@ -527,6 +593,142 @@ dialog article > .dialog-body {
|
||||
overscroll-behavior: contain;
|
||||
}
|
||||
|
||||
/* Gruppen-Accounts den Gruppen zuordnen */
|
||||
dialog.group-assignment-dialog article {
|
||||
width: min(72rem, 94vw);
|
||||
max-width: 94vw;
|
||||
}
|
||||
|
||||
.group-assignment-hint {
|
||||
margin: 0 0 0.65rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted-color, #5b6771);
|
||||
}
|
||||
|
||||
.group-assignment-scroll {
|
||||
max-width: 100%;
|
||||
max-height: min(58dvh, 34rem);
|
||||
overflow: auto;
|
||||
overscroll-behavior: contain;
|
||||
border: 1px solid var(--dispatcher-border);
|
||||
border-radius: 0.55rem;
|
||||
}
|
||||
|
||||
.group-assignment-table {
|
||||
--assignment-choice-column-width: 4.8rem;
|
||||
width: 100%;
|
||||
margin: 0;
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
font-size: 0.78rem;
|
||||
}
|
||||
|
||||
.group-assignment-table th,
|
||||
.group-assignment-table td {
|
||||
padding: 0.38rem 0.55rem;
|
||||
border-bottom: 1px solid var(--dispatcher-border);
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.group-assignment-table tbody tr:last-child th,
|
||||
.group-assignment-table tbody tr:last-child td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
|
||||
.group-assignment-table .assignment-account-header,
|
||||
.group-assignment-table .assignment-account-name {
|
||||
position: sticky;
|
||||
left: 0;
|
||||
z-index: 2;
|
||||
min-width: 4.5rem;
|
||||
max-width: 16rem;
|
||||
background: var(--card-background-color, #fff);
|
||||
text-align: right;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.group-assignment-table .assignment-account-header {
|
||||
z-index: 3;
|
||||
vertical-align: bottom;
|
||||
}
|
||||
|
||||
.group-assignment-table .assignment-account-name {
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.group-assignment-table .assignment-spacer-header,
|
||||
.group-assignment-table .assignment-spacer-cell {
|
||||
width: 100%;
|
||||
min-width: var(--assignment-right-space, 2rem);
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.group-assignment-table .not-participating-header,
|
||||
.group-assignment-table .not-participating-cell {
|
||||
background: rgba(214, 40, 40, 0.12);
|
||||
border-right: 2px solid rgba(214, 40, 40, 0.45);
|
||||
border-left: 2px solid rgba(214, 40, 40, 0.45);
|
||||
}
|
||||
|
||||
.group-assignment-table .not-participating-header {
|
||||
color: #b42318;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.group-assignment-table .group-column-header,
|
||||
.group-assignment-table .not-participating-header {
|
||||
position: relative;
|
||||
width: var(--assignment-choice-column-width);
|
||||
min-width: var(--assignment-choice-column-width);
|
||||
height: var(--group-header-height, 6.2rem);
|
||||
padding: 0 0.2rem 0.4rem;
|
||||
vertical-align: bottom;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.group-assignment-table .group-column-header {
|
||||
border-left: 1px solid var(--dispatcher-border);
|
||||
}
|
||||
|
||||
.group-assignment-table .not-participating-header .group-column-label {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.group-assignment-table .group-column-label {
|
||||
position: absolute;
|
||||
left: 0.7rem;
|
||||
bottom: 0.55rem;
|
||||
display: block;
|
||||
transform: rotate(-45deg);
|
||||
transform-origin: left bottom;
|
||||
white-space: nowrap;
|
||||
font-size: 0.68rem;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.group-assignment-table .group-assignment-cell,
|
||||
.group-assignment-table .not-participating-cell {
|
||||
width: var(--assignment-choice-column-width);
|
||||
min-width: var(--assignment-choice-column-width);
|
||||
}
|
||||
|
||||
.group-assignment-table input[type="radio"] {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.group-assignment-empty {
|
||||
margin: 0;
|
||||
padding: 1rem;
|
||||
border-radius: 0.5rem;
|
||||
background: var(--dispatcher-subtle-bg);
|
||||
color: var(--muted-color, #5b6771);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* Nicht-modaler Straßendialog: bleibt neben der Karte bedienbar. */
|
||||
dialog.group-streets-dialog {
|
||||
position: fixed;
|
||||
@@ -851,11 +1053,6 @@ dialog.group-streets-dialog.is-dragging article header {
|
||||
height: 2.25rem;
|
||||
}
|
||||
|
||||
.clock-row > #speakerButton {
|
||||
width: 2.25rem;
|
||||
height: 2.25rem;
|
||||
}
|
||||
|
||||
.clock-time {
|
||||
font-size: 1.55rem;
|
||||
}
|
||||
@@ -894,6 +1091,34 @@ html[data-theme="dark"] .connection-status.disconnected {
|
||||
color: #ff8b8b;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .group-assignment-table .assignment-account-header,
|
||||
html[data-theme="dark"] .group-assignment-table .assignment-account-name {
|
||||
background: var(--card-background-color, #111827);
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .group-assignment-table .not-participating-header,
|
||||
html[data-theme="dark"] .group-assignment-table .not-participating-cell {
|
||||
background: rgba(255, 99, 99, 0.17);
|
||||
border-right-color: rgba(255, 139, 139, 0.5);
|
||||
border-left-color: rgba(255, 139, 139, 0.5);
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .group-assignment-table .not-participating-header {
|
||||
color: #ffb4b4;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .group-progress-circle {
|
||||
--progress-color: #58a6ff;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .group-progress-circle.is-live {
|
||||
--progress-color: #5bd6a2;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .group-progress-circle.is-live .group-progress-text {
|
||||
color: #5bd6a2;
|
||||
}
|
||||
|
||||
html[data-theme="dark"] .street-search-status.error {
|
||||
color: #ff8b8b;
|
||||
}
|
||||
|
||||
@@ -140,3 +140,62 @@ html[data-theme="dark"] article.success {
|
||||
border-color: #23633f;
|
||||
color: #9be7b5;
|
||||
}
|
||||
|
||||
/* Code-99-Reload-Hinweis: bewusst auffällig, rot mit weißer Schrift. */
|
||||
dialog.reload-notice-dialog {
|
||||
max-width: 94vw;
|
||||
}
|
||||
|
||||
dialog.reload-notice-dialog article {
|
||||
width: min(36rem, 94vw);
|
||||
max-width: 94vw;
|
||||
background: #b42318;
|
||||
border: 2px solid #f4b4b0;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
dialog.reload-notice-dialog article > header,
|
||||
dialog.reload-notice-dialog article > footer {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
dialog.reload-notice-dialog article > header {
|
||||
border-bottom: 1px solid rgba(255, 255, 255, 0.35);
|
||||
}
|
||||
|
||||
dialog.reload-notice-dialog h3 {
|
||||
margin: 0;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.reload-notice-body {
|
||||
padding: 0.35rem 0 0.75rem;
|
||||
}
|
||||
|
||||
.reload-notice-body p {
|
||||
margin: 0;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.reload-notice-body p + p {
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
.reload-notice-hint {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
dialog.reload-notice-dialog article > footer {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-end;
|
||||
gap: 0.5rem;
|
||||
border-top: 1px solid rgba(255, 255, 255, 0.35);
|
||||
padding-top: 0.75rem;
|
||||
}
|
||||
|
||||
dialog.reload-notice-dialog article > footer button {
|
||||
width: auto;
|
||||
margin: 0;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
/*
|
||||
* Gemeinsamer Hinweis für Code 99: Daten wurden geändert, Seite neu laden.
|
||||
*
|
||||
* Dispatcher- und Mobil-Views rufen window.showReloadNotice(text) aus ihrer
|
||||
* bestehenden WebSocket-Verbindung auf. Admin-Seiten erhalten über den
|
||||
* optionalen Watcher eine eigene Verbindung, damit auch dort Änderungen
|
||||
* anderer Administratoren sichtbar werden.
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
const HINT = 'Die Webseite muss neu geladen werden, damit die Änderungen sichtbar werden.';
|
||||
let dialog = null;
|
||||
let adminSocket = null;
|
||||
let adminRetryTimer = null;
|
||||
let adminStopped = false;
|
||||
|
||||
function ensureDialog() {
|
||||
if (dialog) return dialog;
|
||||
|
||||
dialog = document.createElement('dialog');
|
||||
dialog.id = 'reloadNoticeModal';
|
||||
dialog.className = 'reload-notice-dialog';
|
||||
dialog.setAttribute('aria-labelledby', 'reloadNoticeTitle');
|
||||
|
||||
const article = document.createElement('article');
|
||||
|
||||
const header = document.createElement('header');
|
||||
const title = document.createElement('h3');
|
||||
title.id = 'reloadNoticeTitle';
|
||||
title.textContent = 'Daten geändert';
|
||||
header.appendChild(title);
|
||||
|
||||
const body = document.createElement('div');
|
||||
body.className = 'reload-notice-body';
|
||||
const text = document.createElement('p');
|
||||
text.id = 'reloadNoticeText';
|
||||
text.textContent = 'Die Daten wurden geändert.';
|
||||
const hint = document.createElement('p');
|
||||
hint.className = 'reload-notice-hint';
|
||||
hint.textContent = HINT;
|
||||
body.append(text, hint);
|
||||
|
||||
const footer = document.createElement('footer');
|
||||
|
||||
const laterButton = document.createElement('button');
|
||||
laterButton.type = 'button';
|
||||
laterButton.className = 'secondary';
|
||||
laterButton.textContent = 'Später';
|
||||
laterButton.addEventListener('click', closeReloadNotice);
|
||||
|
||||
const restartButton = document.createElement('button');
|
||||
restartButton.type = 'button';
|
||||
restartButton.textContent = 'Neustarten';
|
||||
restartButton.addEventListener('click', () => window.location.reload());
|
||||
|
||||
footer.append(laterButton, restartButton);
|
||||
article.append(header, body, footer);
|
||||
dialog.appendChild(article);
|
||||
document.body.appendChild(dialog);
|
||||
|
||||
// Escape entspricht "Später": Dialog schließen, keine weitere Aktion.
|
||||
dialog.addEventListener('cancel', event => {
|
||||
event.preventDefault();
|
||||
closeReloadNotice();
|
||||
});
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
function closeReloadNotice() {
|
||||
if (dialog && dialog.open) dialog.close();
|
||||
}
|
||||
|
||||
function showReloadNotice(text) {
|
||||
const currentDialog = ensureDialog();
|
||||
const textElement = currentDialog.querySelector('#reloadNoticeText');
|
||||
if (textElement) {
|
||||
textElement.textContent = text && String(text).trim()
|
||||
? String(text).trim()
|
||||
: 'Die Daten wurden geändert.';
|
||||
}
|
||||
if (!currentDialog.open) {
|
||||
if (typeof currentDialog.showModal === 'function') {
|
||||
currentDialog.showModal();
|
||||
} else {
|
||||
currentDialog.setAttribute('open', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function appUrl(path) {
|
||||
if (typeof window.CMBNET_APP_URL === 'function') {
|
||||
return window.CMBNET_APP_URL(path);
|
||||
}
|
||||
const base = (window.CMBNET_BASE_URL || '').replace(/\/+$/, '');
|
||||
const clean = String(path == null ? '' : path).replace(/^\/+/, '');
|
||||
return clean ? `${base}/${clean}` : (base || '/');
|
||||
}
|
||||
|
||||
function scheduleAdminReconnect() {
|
||||
if (adminStopped || adminRetryTimer) return;
|
||||
adminRetryTimer = setTimeout(() => {
|
||||
adminRetryTimer = null;
|
||||
connectAdminWatcher();
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
async function connectAdminWatcher() {
|
||||
if (adminStopped) return;
|
||||
const tenant = window.CMBNET_TENANT || '';
|
||||
if (!tenant) return;
|
||||
|
||||
try {
|
||||
const response = await fetch(appUrl(`${tenant}/api/auth/ws-token`), {
|
||||
credentials: 'same-origin'
|
||||
});
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const data = await response.json();
|
||||
if (!data.token) throw new Error('Kein WebSocket-Token');
|
||||
|
||||
const wsUrl = `${window.location.protocol === 'https:' ? 'wss' : 'ws'}://` +
|
||||
`${window.location.host}${appUrl(`${tenant}/ws`)}`;
|
||||
const ws = new WebSocket(wsUrl);
|
||||
adminSocket = ws;
|
||||
|
||||
ws.addEventListener('open', () => {
|
||||
ws.send(JSON.stringify({code: 0, msg: data.token}));
|
||||
});
|
||||
|
||||
ws.addEventListener('message', event => {
|
||||
let message;
|
||||
try {
|
||||
message = JSON.parse(event.data);
|
||||
} catch (error) {
|
||||
return;
|
||||
}
|
||||
if (Number(message.code) !== 99) return;
|
||||
const text = typeof message.msg === 'string'
|
||||
? message.msg
|
||||
: '';
|
||||
showReloadNotice(text);
|
||||
});
|
||||
|
||||
ws.addEventListener('close', () => {
|
||||
if (adminSocket === ws) adminSocket = null;
|
||||
scheduleAdminReconnect();
|
||||
});
|
||||
|
||||
ws.addEventListener('error', () => {
|
||||
if (adminSocket === ws) adminSocket = null;
|
||||
scheduleAdminReconnect();
|
||||
});
|
||||
} catch (error) {
|
||||
scheduleAdminReconnect();
|
||||
}
|
||||
}
|
||||
|
||||
window.showReloadNotice = showReloadNotice;
|
||||
window.closeReloadNotice = closeReloadNotice;
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
ensureDialog();
|
||||
if (window.CMBNET_ADMIN_RELOAD_WATCH) {
|
||||
connectAdminWatcher();
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('beforeunload', () => {
|
||||
adminStopped = true;
|
||||
if (adminRetryTimer) clearTimeout(adminRetryTimer);
|
||||
if (adminSocket) adminSocket.close();
|
||||
});
|
||||
})();
|
||||
@@ -5,7 +5,7 @@
|
||||
* damit er sowohl die mobilen Views als auch die statischen Assets
|
||||
* kontrolliert. Der Cache-Name wird pro App-Wurzel gebildet.
|
||||
*/
|
||||
const VERSION = 'cmbnet-pwa-v1';
|
||||
const VERSION = 'cmbnet-pwa-v4';
|
||||
const BASE = new URL('./', self.location).href;
|
||||
const SHELL_CACHE = `${VERSION}-shell`;
|
||||
const TILE_CACHE = `${VERSION}-tiles`;
|
||||
@@ -19,6 +19,7 @@ const PRECACHE_PATHS = [
|
||||
'static/css/mobile.css',
|
||||
'static/js/leaflet.js',
|
||||
'static/js/str2pl.js',
|
||||
'static/js/reload_notice.js',
|
||||
'static/js/views/mobile.js',
|
||||
'static/img/logo.png',
|
||||
'static/img/icon-192.png',
|
||||
@@ -208,7 +209,7 @@ function offlineHtml() {
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>CMBNet – offline</title>
|
||||
<title>20*C+M+B+27 – offline</title>
|
||||
<style>
|
||||
body{font-family:system-ui,-apple-system,sans-serif;margin:0;min-height:100dvh;
|
||||
display:flex;align-items:center;justify-content:center;background:#f7f9fc;color:#1f2937}
|
||||
@@ -220,7 +221,7 @@ p{margin:0;color:#4b5563;font-size:.95rem}
|
||||
<body>
|
||||
<main>
|
||||
<h1>Keine Verbindung</h1>
|
||||
<p>CMBNet ist offline nicht erreichbar. Bitte prüfe die Netzwerkverbindung und lade die Seite erneut.</p>
|
||||
<p>20*C+M+B+27 ist offline nicht erreichbar. Bitte prüfe die Netzwerkverbindung und lade die Seite erneut.</p>
|
||||
</main>
|
||||
</body>
|
||||
</html>`;
|
||||
|
||||
@@ -52,14 +52,12 @@ function deleteGruppe(groupId) {
|
||||
|
||||
function openCreateGruppeModal() {
|
||||
document.getElementById('gruppeAlias').value = '';
|
||||
document.getElementById('gruppeAccount').value = '';
|
||||
document.getElementById('createGruppeModal').showModal();
|
||||
}
|
||||
|
||||
function closeCreateGruppeModal() {
|
||||
document.getElementById('createGruppeModal').close();
|
||||
document.getElementById('gruppeAlias').value = '';
|
||||
document.getElementById('gruppeAccount').value = '';
|
||||
}
|
||||
|
||||
function buildStateSelect(state) {
|
||||
@@ -74,19 +72,6 @@ function buildStateSelect(state) {
|
||||
return select;
|
||||
}
|
||||
|
||||
function buildAccountSelect(accountId) {
|
||||
const select = document.createElement('select');
|
||||
const source = document.getElementById('gruppeAccount');
|
||||
Array.from(source.options).forEach(option => {
|
||||
const copy = document.createElement('option');
|
||||
copy.value = option.value;
|
||||
copy.textContent = option.textContent;
|
||||
copy.selected = String(option.value) === String(accountId ?? '');
|
||||
select.appendChild(copy);
|
||||
});
|
||||
return select;
|
||||
}
|
||||
|
||||
function addGruppeRow(gruppe) {
|
||||
const tbody = document.querySelector('#gruppenTable tbody');
|
||||
const row = document.createElement('tr');
|
||||
@@ -112,13 +97,6 @@ function addGruppeRow(gruppe) {
|
||||
stateCell.appendChild(stateSelect);
|
||||
row.appendChild(stateCell);
|
||||
|
||||
const accountCell = document.createElement('td');
|
||||
const accountSelect = buildAccountSelect(gruppe.account_id);
|
||||
accountSelect.addEventListener('change',
|
||||
() => updateGruppe(gruppe.id, {account_id: accountSelect.value}));
|
||||
accountCell.appendChild(accountSelect);
|
||||
row.appendChild(accountCell);
|
||||
|
||||
const positionCell = document.createElement('td');
|
||||
positionCell.className = 'group-position';
|
||||
positionCell.textContent = formatPosition(gruppe.last_lat, gruppe.last_lon);
|
||||
@@ -141,12 +119,11 @@ function addGruppeRow(gruppe) {
|
||||
|
||||
function createGruppe() {
|
||||
const aliasname = document.getElementById('gruppeAlias').value;
|
||||
const accountId = document.getElementById('gruppeAccount').value;
|
||||
|
||||
fetch(`${apiBase}/gruppen`, {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({aliasname, account_id: accountId})
|
||||
body: JSON.stringify({aliasname})
|
||||
}).then(r => r.json()).then(data => {
|
||||
if (!data.success) {
|
||||
showError(data);
|
||||
@@ -155,7 +132,6 @@ function createGruppe() {
|
||||
addGruppeRow({
|
||||
id: data.id,
|
||||
aliasname: aliasname,
|
||||
account_id: accountId || null,
|
||||
state: 'offen',
|
||||
last_lat: null,
|
||||
last_lon: null
|
||||
|
||||
@@ -577,6 +577,15 @@ function groupDisplayName(group) {
|
||||
: String(group.id);
|
||||
}
|
||||
|
||||
function findGroupForAccount(accountId) {
|
||||
const id = Number(accountId);
|
||||
if (!Number.isFinite(id)) return null;
|
||||
return dispatcherState.groups.find(group =>
|
||||
Array.isArray(group.account_ids)
|
||||
&& group.account_ids.some(value => Number(value) === id)
|
||||
) || null;
|
||||
}
|
||||
|
||||
function groupColor(group) {
|
||||
const id = Number(group.id) || 0;
|
||||
const hue = Math.round((id * 137.508) % 360);
|
||||
@@ -829,8 +838,8 @@ function createGroupElement(group) {
|
||||
const content = document.createElement('div');
|
||||
content.className = 'group-details';
|
||||
|
||||
const positionRow = document.createElement('div');
|
||||
positionRow.className = 'group-position-row';
|
||||
const controls = document.createElement('div');
|
||||
controls.className = 'group-controls';
|
||||
|
||||
const locateButton = document.createElement('button');
|
||||
locateButton.type = 'button';
|
||||
@@ -840,19 +849,19 @@ function createGroupElement(group) {
|
||||
locateButton.setAttribute('aria-label', 'Karte auf Gruppenposition zentrieren');
|
||||
locateButton.addEventListener('click', () => locateGroup(group.id));
|
||||
|
||||
const progress = document.createElement('progress');
|
||||
progress.className = 'group-progress';
|
||||
progress.max = 100;
|
||||
progress.value = 0;
|
||||
const progressCircle = document.createElement('span');
|
||||
progressCircle.className = 'group-progress-circle';
|
||||
progressCircle.setAttribute('role', 'progressbar');
|
||||
progressCircle.setAttribute('aria-valuemin', '0');
|
||||
progressCircle.setAttribute('aria-valuemax', '100');
|
||||
progressCircle.setAttribute('aria-valuenow', '0');
|
||||
progressCircle.setAttribute('aria-label', 'Position unbekannt');
|
||||
progressCircle.title = 'Position unbekannt';
|
||||
|
||||
positionRow.append(locateButton, progress);
|
||||
|
||||
const meta = document.createElement('div');
|
||||
meta.className = 'group-position-meta';
|
||||
meta.textContent = 'Position unbekannt';
|
||||
|
||||
const actions = document.createElement('div');
|
||||
actions.className = 'group-actions';
|
||||
const progressText = document.createElement('span');
|
||||
progressText.className = 'group-progress-text';
|
||||
progressText.textContent = '–';
|
||||
progressCircle.appendChild(progressText);
|
||||
|
||||
const crosshairButton = document.createElement('button');
|
||||
crosshairButton.type = 'button';
|
||||
@@ -895,7 +904,14 @@ function createGroupElement(group) {
|
||||
});
|
||||
stateSelect.addEventListener('change', () => changeGroupState(group.id, stateSelect));
|
||||
|
||||
actions.append(crosshairButton, streetsButton, aliasButton, stateSelect);
|
||||
controls.append(
|
||||
locateButton,
|
||||
progressCircle,
|
||||
stateSelect,
|
||||
crosshairButton,
|
||||
streetsButton,
|
||||
aliasButton
|
||||
);
|
||||
|
||||
const messageInput = document.createElement('input');
|
||||
messageInput.type = 'text';
|
||||
@@ -905,7 +921,7 @@ function createGroupElement(group) {
|
||||
messageInput.title = 'Chatverlauf öffnen';
|
||||
messageInput.addEventListener('click', () => openChat(group.id));
|
||||
|
||||
content.append(positionRow, meta, actions, messageInput);
|
||||
content.append(controls, messageInput);
|
||||
details.appendChild(content);
|
||||
|
||||
return details;
|
||||
@@ -941,8 +957,8 @@ function refreshGroupControls(now = Date.now()) {
|
||||
if (!item) return;
|
||||
|
||||
const locateButton = item.querySelector('.group-locate');
|
||||
const progress = item.querySelector('.group-progress');
|
||||
const meta = item.querySelector('.group-position-meta');
|
||||
const progressCircle = item.querySelector('.group-progress-circle');
|
||||
const progressText = item.querySelector('.group-progress-text');
|
||||
|
||||
const known = hasPosition(group);
|
||||
const positionTs = group.last_pos_ts;
|
||||
@@ -961,13 +977,37 @@ function refreshGroupControls(now = Date.now()) {
|
||||
}
|
||||
}
|
||||
|
||||
locateButton.disabled = !enabled;
|
||||
progress.value = Math.round(value);
|
||||
const rounded = Math.round(value);
|
||||
const isLive = rounded >= 100;
|
||||
|
||||
if (known) {
|
||||
meta.textContent = positionAgeLabel(ageSeconds);
|
||||
} else {
|
||||
meta.textContent = 'Position unbekannt';
|
||||
locateButton.disabled = !enabled;
|
||||
|
||||
if (progressCircle) {
|
||||
progressCircle.style.setProperty('--progress', String(rounded));
|
||||
progressCircle.classList.toggle('is-live', isLive);
|
||||
progressCircle.setAttribute('aria-valuenow', String(rounded));
|
||||
progressCircle.setAttribute(
|
||||
'aria-valuetext',
|
||||
isLive
|
||||
? 'Live'
|
||||
: (known ? positionAgeLabel(ageSeconds) : 'Position unbekannt')
|
||||
);
|
||||
|
||||
const label = !known
|
||||
? 'Position unbekannt'
|
||||
: (isLive ? 'Position: Live' : `Position: ${positionAgeLabel(ageSeconds)}`);
|
||||
progressCircle.title = label;
|
||||
progressCircle.setAttribute('aria-label', label);
|
||||
}
|
||||
|
||||
if (progressText) {
|
||||
if (!known || ageSeconds === null) {
|
||||
progressText.textContent = '–';
|
||||
} else if (isLive) {
|
||||
progressText.textContent = 'Live';
|
||||
} else {
|
||||
progressText.textContent = `${Math.max(1, Math.floor(ageSeconds / 60))}m`;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1129,6 +1169,205 @@ async function saveGroupAlias() {
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ */
|
||||
/* Gruppenzuordnungen */
|
||||
/* ------------------------------------------------------------------ */
|
||||
|
||||
function openGroupAssignmentModal() {
|
||||
if (window.CMBNET_VIEW_MODE === 'observer') return;
|
||||
renderGroupAssignmentTable();
|
||||
const dialog = document.getElementById('groupAssignmentModal');
|
||||
if (dialog && !dialog.open) dialog.showModal();
|
||||
}
|
||||
|
||||
function closeGroupAssignmentModal() {
|
||||
const dialog = document.getElementById('groupAssignmentModal');
|
||||
if (dialog && dialog.open) dialog.close();
|
||||
}
|
||||
|
||||
function buildAssignmentHeaderCell(label, className, rotated = false) {
|
||||
const cell = document.createElement('th');
|
||||
cell.scope = 'col';
|
||||
cell.className = className;
|
||||
if (rotated) {
|
||||
const span = document.createElement('span');
|
||||
span.className = 'group-column-label';
|
||||
span.textContent = label;
|
||||
cell.title = label;
|
||||
cell.appendChild(span);
|
||||
} else {
|
||||
cell.textContent = label;
|
||||
}
|
||||
return cell;
|
||||
}
|
||||
|
||||
function buildAssignmentRadioCell(accountId, accountName, value, checked, className, label) {
|
||||
const cell = document.createElement('td');
|
||||
cell.className = className;
|
||||
const input = document.createElement('input');
|
||||
input.type = 'radio';
|
||||
input.name = `group-assignment-${accountId}`;
|
||||
input.value = String(value);
|
||||
input.checked = checked;
|
||||
input.setAttribute('aria-label', `${label} für ${accountName}`);
|
||||
cell.appendChild(input);
|
||||
return cell;
|
||||
}
|
||||
|
||||
function renderGroupAssignmentTable() {
|
||||
const head = document.getElementById('groupAssignmentHead');
|
||||
const body = document.getElementById('groupAssignmentBody');
|
||||
const empty = document.getElementById('groupAssignmentEmpty');
|
||||
const scroll = document.querySelector('.group-assignment-scroll');
|
||||
const saveButton = document.getElementById('groupAssignmentSaveButton');
|
||||
const table = document.getElementById('groupAssignmentTable');
|
||||
if (!head || !body) return;
|
||||
|
||||
const accounts = dispatcherState.accounts
|
||||
.filter(account => account.role === 'Gruppe')
|
||||
.slice()
|
||||
.sort((a, b) => String(a.name || '').localeCompare(String(b.name || ''), 'de'));
|
||||
const groups = dispatcherState.groups
|
||||
.slice()
|
||||
.sort((a, b) => Number(a.id) - Number(b.id));
|
||||
|
||||
const assignmentByAccount = new Map();
|
||||
groups.forEach(group => {
|
||||
(Array.isArray(group.account_ids) ? group.account_ids : []).forEach(accountId => {
|
||||
assignmentByAccount.set(Number(accountId), Number(group.id));
|
||||
});
|
||||
});
|
||||
|
||||
head.innerHTML = '';
|
||||
body.innerHTML = '';
|
||||
|
||||
const headerRow = document.createElement('tr');
|
||||
const longestGroupLabel = groups.reduce(
|
||||
(maxLength, group) => Math.max(maxLength, groupDisplayName(group).length),
|
||||
0
|
||||
);
|
||||
headerRow.style.setProperty(
|
||||
'--group-header-height',
|
||||
`${Math.min(14, Math.max(6.2, longestGroupLabel * 0.32 + 1.1))}rem`
|
||||
);
|
||||
const lastHeaderLabel = groups.length
|
||||
? groupDisplayName(groups[groups.length - 1])
|
||||
: 'Nicht dabei';
|
||||
if (table) {
|
||||
const rightSpace = Math.min(14, Math.max(1.5, lastHeaderLabel.length * 0.26 - 3.1));
|
||||
table.style.setProperty('--assignment-right-space', `${rightSpace}rem`);
|
||||
}
|
||||
headerRow.appendChild(buildAssignmentHeaderCell('Account', 'assignment-account-header'));
|
||||
headerRow.appendChild(buildAssignmentHeaderCell(
|
||||
'Nicht dabei', 'not-participating-header', true
|
||||
));
|
||||
groups.forEach(group => {
|
||||
headerRow.appendChild(buildAssignmentHeaderCell(
|
||||
groupDisplayName(group), 'group-column-header', true
|
||||
));
|
||||
});
|
||||
const spacerHeader = document.createElement('th');
|
||||
spacerHeader.className = 'assignment-spacer-header';
|
||||
spacerHeader.setAttribute('aria-hidden', 'true');
|
||||
headerRow.appendChild(spacerHeader);
|
||||
head.appendChild(headerRow);
|
||||
|
||||
accounts.forEach(account => {
|
||||
const accountId = Number(account.id);
|
||||
const accountName = account.name || `Account ${accountId}`;
|
||||
const currentGroupId = assignmentByAccount.has(accountId)
|
||||
? assignmentByAccount.get(accountId)
|
||||
: null;
|
||||
|
||||
const row = document.createElement('tr');
|
||||
row.dataset.accountId = String(accountId);
|
||||
const rowHeader = document.createElement('th');
|
||||
rowHeader.scope = 'row';
|
||||
rowHeader.className = 'assignment-account-name';
|
||||
rowHeader.textContent = accountName;
|
||||
row.appendChild(rowHeader);
|
||||
|
||||
row.appendChild(buildAssignmentRadioCell(
|
||||
accountId, accountName, 'none', currentGroupId === null,
|
||||
'not-participating-cell', 'Nicht dabei'
|
||||
));
|
||||
groups.forEach(group => {
|
||||
row.appendChild(buildAssignmentRadioCell(
|
||||
accountId, accountName, group.id,
|
||||
currentGroupId === Number(group.id),
|
||||
'group-assignment-cell', groupDisplayName(group)
|
||||
));
|
||||
});
|
||||
const spacerCell = document.createElement('td');
|
||||
spacerCell.className = 'assignment-spacer-cell';
|
||||
spacerCell.setAttribute('aria-hidden', 'true');
|
||||
row.appendChild(spacerCell);
|
||||
body.appendChild(row);
|
||||
});
|
||||
|
||||
if (empty) empty.hidden = accounts.length > 0;
|
||||
if (scroll) scroll.hidden = accounts.length === 0;
|
||||
if (saveButton) saveButton.disabled = accounts.length === 0;
|
||||
}
|
||||
|
||||
function updateLocalGroupAssignments(assignments) {
|
||||
dispatcherState.groups.forEach(group => {
|
||||
group.account_ids = [];
|
||||
});
|
||||
Object.entries(assignments).forEach(([accountId, groupId]) => {
|
||||
if (groupId === null || groupId === undefined) return;
|
||||
const group = dispatcherState.groupById.get(Number(groupId));
|
||||
if (!group) return;
|
||||
if (!Array.isArray(group.account_ids)) group.account_ids = [];
|
||||
group.account_ids.push(Number(accountId));
|
||||
});
|
||||
}
|
||||
|
||||
async function saveGroupAssignments() {
|
||||
const saveButton = document.getElementById('groupAssignmentSaveButton');
|
||||
if (!saveButton || saveButton.disabled) return;
|
||||
|
||||
const assignments = {};
|
||||
document.querySelectorAll('#groupAssignmentBody tr[data-account-id]').forEach(row => {
|
||||
const checked = row.querySelector('input[type="radio"]:checked');
|
||||
const rawValue = checked ? checked.value : 'none';
|
||||
assignments[row.dataset.accountId] = rawValue === 'none'
|
||||
? null
|
||||
: Number(rawValue);
|
||||
});
|
||||
|
||||
if (!Object.keys(assignments).length) {
|
||||
closeGroupAssignmentModal();
|
||||
return;
|
||||
}
|
||||
|
||||
saveButton.disabled = true;
|
||||
try {
|
||||
const response = await fetch(`${apiBase}/groups/assignments`, {
|
||||
method: 'POST',
|
||||
credentials: 'same-origin',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({assignments})
|
||||
});
|
||||
let data = {};
|
||||
try {
|
||||
data = await response.json();
|
||||
} catch (error) {
|
||||
data = {};
|
||||
}
|
||||
if (!response.ok || !data.success) {
|
||||
throw new Error(data.error || `HTTP ${response.status}`);
|
||||
}
|
||||
updateLocalGroupAssignments(assignments);
|
||||
closeGroupAssignmentModal();
|
||||
} catch (error) {
|
||||
console.error('Gruppenzuordnungen konnten nicht gespeichert werden:', error);
|
||||
alert(`Gruppenzuordnungen konnten nicht gespeichert werden: ${error.message}`);
|
||||
} finally {
|
||||
saveButton.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
function locateGroup(groupId) {
|
||||
const group = dispatcherState.groupById.get(Number(groupId));
|
||||
if (!group || !hasPosition(group)) return;
|
||||
@@ -2142,7 +2381,7 @@ function getSenderDisplay(senderId, messageOrPayload = null) {
|
||||
}
|
||||
|
||||
const account = dispatcherState.accountById.get(id);
|
||||
const group = dispatcherState.groups.find(item => Number(item.account_id) === id);
|
||||
const group = findGroupForAccount(id);
|
||||
const accountName = account && account.name ? account.name : `Account ${id}`;
|
||||
if (group) {
|
||||
const alias = group.aliasname && String(group.aliasname).trim();
|
||||
@@ -2546,6 +2785,21 @@ function handleWsMessage(event) {
|
||||
dispatcherState.ws.send(JSON.stringify({code: 2, msg: 'pong'}));
|
||||
}
|
||||
break;
|
||||
case 99: {
|
||||
if (window.CMBNET_VIEW_MODE === 'observer') {
|
||||
window.location.reload();
|
||||
break;
|
||||
}
|
||||
const text = typeof message.msg === 'string'
|
||||
? message.msg
|
||||
: extractMessageText(message.msg);
|
||||
if (typeof window.showReloadNotice === 'function') {
|
||||
window.showReloadNotice(text);
|
||||
} else {
|
||||
alert(`${text}\n\nBitte die Webseite neu laden.`);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 100:
|
||||
handleStreetUpdate(message);
|
||||
break;
|
||||
@@ -2857,6 +3111,10 @@ function bindStaticUi() {
|
||||
if (speakerButton && window.CMBNET_VIEW_MODE !== 'observer') {
|
||||
speakerButton.addEventListener('click', openSpeakerModal);
|
||||
}
|
||||
const groupAssignmentButton = document.getElementById('groupAssignmentButton');
|
||||
if (groupAssignmentButton && window.CMBNET_VIEW_MODE !== 'observer') {
|
||||
groupAssignmentButton.addEventListener('click', openGroupAssignmentModal);
|
||||
}
|
||||
const streetStateSelect = document.getElementById('streetStateSelect');
|
||||
if (streetStateSelect && window.CMBNET_VIEW_MODE !== 'observer') {
|
||||
streetStateSelect.addEventListener('change', updateStreetGroupVisibility);
|
||||
|
||||
@@ -9,6 +9,7 @@ const storageKey = `cmbnet:${tenant}:mobile`;
|
||||
const viewMode = window.CMBNET_VIEW_MODE || 'mobile_dispatcher';
|
||||
const currentAccountId = Number(window.CMBNET_ACCOUNT_ID) || null;
|
||||
const currentRole = window.CMBNET_ROLE || null;
|
||||
const appTitle = window.CMBNET_APP_TITLE || '20*C+M+B+27';
|
||||
|
||||
const DEFAULT_SETTINGS = {
|
||||
opacity: 0.7,
|
||||
@@ -248,7 +249,7 @@ async function requestNotifications() {
|
||||
if (permission === 'granted' && navigator.serviceWorker) {
|
||||
const registration = await navigator.serviceWorker.getRegistration();
|
||||
if (registration && registration.showNotification) {
|
||||
await registration.showNotification('CMBNet', {
|
||||
await registration.showNotification(appTitle, {
|
||||
body: 'Benachrichtigungen sind aktiviert.',
|
||||
icon: window.CMBNET_ICON_URL || undefined,
|
||||
tag: 'cmbnet-permission'
|
||||
@@ -395,7 +396,11 @@ function groupDisplayName(group) {
|
||||
|
||||
function findGroupForAccount(accountId) {
|
||||
const id = Number(accountId);
|
||||
return state.groups.find(group => Number(group.account_id) === id) || null;
|
||||
if (!Number.isFinite(id)) return null;
|
||||
return state.groups.find(group =>
|
||||
Array.isArray(group.account_ids)
|
||||
&& group.account_ids.some(value => Number(value) === id)
|
||||
) || null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -490,8 +495,7 @@ function getReceiverName(message, payload) {
|
||||
group = state.groups[0];
|
||||
}
|
||||
if (group) {
|
||||
const accountName = getAccountDisplayName(group.account_id);
|
||||
return accountName || groupDisplayName(group) || 'Gruppe';
|
||||
return groupDisplayName(group) || 'Gruppe';
|
||||
}
|
||||
|
||||
const accountName = getAccountDisplayName(receiverId);
|
||||
@@ -927,11 +931,11 @@ async function showChatPopup(text, senderName) {
|
||||
if (navigator.serviceWorker) {
|
||||
const registration = await navigator.serviceWorker.getRegistration();
|
||||
if (registration && registration.showNotification) {
|
||||
await registration.showNotification(senderName || 'CMBNet', options);
|
||||
await registration.showNotification(senderName || appTitle, options);
|
||||
return;
|
||||
}
|
||||
}
|
||||
new Notification(senderName || 'CMBNet', options);
|
||||
new Notification(senderName || appTitle, options);
|
||||
} catch (error) {
|
||||
// Benachrichtigungen sind optional.
|
||||
}
|
||||
@@ -983,6 +987,15 @@ function handleWs(event) {
|
||||
if (state.ws && state.ws.readyState === WebSocket.OPEN) {
|
||||
state.ws.send(JSON.stringify({code: 2, msg: 'pong'}));
|
||||
}
|
||||
} else if (message.code === 99) {
|
||||
const text = typeof message.msg === 'string'
|
||||
? message.msg
|
||||
: extractText(message.msg);
|
||||
if (typeof window.showReloadNotice === 'function') {
|
||||
window.showReloadNotice(text);
|
||||
} else {
|
||||
alert(`${text}\n\nBitte die Webseite neu laden.`);
|
||||
}
|
||||
} else if (message.code === 100) {
|
||||
// Street update
|
||||
try {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<h3>App installieren</h3>
|
||||
</header>
|
||||
<div class="dialog-body">
|
||||
<p>Installiere CMBNet als App auf dem Home-Bildschirm:</p>
|
||||
<p>Installiere {{ APP_TITLE }} als App auf dem Home-Bildschirm:</p>
|
||||
<p class="mobile-dialog-hint" id="mobileInstallGenericHint">
|
||||
Öffne das Browsermenü und wähle „App installieren“ bzw.
|
||||
„Zum Home-Bildschirm hinzufügen“.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Accountverwaltung - CMBNet{% endblock %}
|
||||
{% block title %}Accountverwaltung - {{ APP_TITLE }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p><a href="{{ url_for('admin.dashboard', tenant=session.tenant_code) }}">← Zurück zum Dashboard</a></p>
|
||||
@@ -90,5 +90,6 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>window.CMBNET_ADMIN_RELOAD_WATCH = true;</script>
|
||||
<script src="{{ url_for('static', filename='js/views/admin_accounts.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Admin Dashboard - CMBNet{% endblock %}
|
||||
{% block title %}Admin Dashboard - {{ APP_TITLE }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Administrator Dashboard</h1>
|
||||
@@ -35,5 +35,6 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>window.CMBNET_ADMIN_RELOAD_WATCH = true;</script>
|
||||
<script src="{{ url_for('static', filename='js/views/admin_dashboard.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Gruppenverwaltung - CMBNet{% endblock %}
|
||||
{% block title %}Gruppenverwaltung - {{ APP_TITLE }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p><a href="{{ url_for('admin.dashboard', tenant=session.tenant_code) }}">← Zurück zum Dashboard</a></p>
|
||||
@@ -12,7 +12,6 @@
|
||||
<th>ID</th>
|
||||
<th>Aliasname</th>
|
||||
<th>State</th>
|
||||
<th>Account</th>
|
||||
<th>Position</th>
|
||||
<th>Aktionen</th>
|
||||
</tr>
|
||||
@@ -31,14 +30,6 @@
|
||||
<option value="fertig" {% if gruppe.state == 'fertig' %}selected{% endif %}>fertig</option>
|
||||
</select>
|
||||
</td>
|
||||
<td>
|
||||
<select onchange="updateGruppe({{ gruppe.id }}, {account_id: this.value})">
|
||||
<option value="">-</option>
|
||||
{% for acc in accounts %}
|
||||
<option value="{{ acc.id }}" {% if gruppe.account_id == acc.id %}selected{% endif %}>{{ acc.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</td>
|
||||
<td class="group-position">{% if gruppe.last_lat is not none and gruppe.last_lon is not none %}{{ gruppe.last_lat }}, {{ gruppe.last_lon }}{% else %}unbekannt{% endif %}</td>
|
||||
<td>
|
||||
<button onclick="showHistory({{ gruppe.id }})">Historie</button>
|
||||
@@ -63,14 +54,6 @@
|
||||
<label>Aliasname
|
||||
<input type="text" id="gruppeAlias">
|
||||
</label>
|
||||
<label>Account (Rolle Gruppe)
|
||||
<select id="gruppeAccount">
|
||||
<option value="">-</option>
|
||||
{% for acc in accounts %}
|
||||
<option value="{{ acc.id }}">{{ acc.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
<footer>
|
||||
<button onclick="closeCreateGruppeModal()">Abbrechen</button>
|
||||
<button onclick="createGruppe()">Anlegen</button>
|
||||
@@ -106,5 +89,6 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>window.CMBNET_ADMIN_RELOAD_WATCH = true;</script>
|
||||
<script src="{{ url_for('static', filename='js/views/admin_gruppen.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Straßenverwaltung - CMBNet{% endblock %}
|
||||
{% block title %}Straßenverwaltung - {{ APP_TITLE }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<p><a href="{{ url_for('admin.dashboard', tenant=session.tenant_code) }}">← Zurück zum Dashboard</a></p>
|
||||
@@ -154,5 +154,6 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block scripts %}
|
||||
<script>window.CMBNET_ADMIN_RELOAD_WATCH = true;</script>
|
||||
<script src="{{ url_for('static', filename='js/views/admin_strassen.js') }}"></script>
|
||||
{% endblock %}
|
||||
@@ -3,7 +3,7 @@
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>{% block title %}CMBNet{% endblock %}</title>
|
||||
<title>{% block title %}{{ APP_TITLE }}{% endblock %}</title>
|
||||
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}" type="image/x-icon">
|
||||
<script>
|
||||
(() => {
|
||||
@@ -22,6 +22,7 @@
|
||||
// mit X-Forwarded-Prefix enthält SCRIPT_NAME z. B. "/cmbnet".
|
||||
window.CMBNET_BASE_URL = {{ request.script_root|tojson }};
|
||||
window.CMBNET_TENANT = {{ (session.get('tenant_code') or '')|tojson }};
|
||||
window.CMBNET_APP_TITLE = {{ APP_TITLE|tojson }};
|
||||
window.CMBNET_APP_URL = function (path) {
|
||||
const base = (window.CMBNET_BASE_URL || '').replace(/\/+$/, '');
|
||||
const clean = String(path == null ? '' : path).replace(/^\/+/, '');
|
||||
@@ -51,6 +52,7 @@
|
||||
{% block content %}{% endblock %}
|
||||
</main>
|
||||
<script src="{{ url_for('static', filename='js/leaflet.js') }}"></script>
|
||||
<script src="{{ url_for('static', filename='js/reload_notice.js') }}"></script>
|
||||
{% block scripts %}{% endblock %}
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Beobachter - {{ session.tenant_code }} - CMBNet{% endblock %}
|
||||
{% block title %}Beobachter - {{ session.tenant_code }} - {{ APP_TITLE }}{% endblock %}
|
||||
|
||||
{% block body_class %}dispatcher-page beobachter-page{% endblock %}
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
</div>
|
||||
<img class="dispatcher-logo"
|
||||
src="{{ url_for('static', filename='img/logo.png') }}"
|
||||
alt="CMBNet">
|
||||
alt="{{ APP_TITLE }}">
|
||||
</div>
|
||||
|
||||
<div class="street-search" role="search">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Dispatcher - {{ session.tenant_code }} - CMBNet{% endblock %}
|
||||
{% block title %}Dispatcher - {{ session.tenant_code }} - {{ APP_TITLE }}{% endblock %}
|
||||
|
||||
{% block body_class %}dispatcher-page{% endblock %}
|
||||
|
||||
@@ -26,11 +26,9 @@
|
||||
</div>
|
||||
<div class="clock-time" id="clockTime">--:--:--</div>
|
||||
</div>
|
||||
<button type="button" id="speakerButton" class="icon-button"
|
||||
title="Nachricht an alle senden" aria-label="Nachricht an alle senden">📢</button>
|
||||
<img class="dispatcher-logo"
|
||||
src="{{ url_for('static', filename='img/logo.png') }}"
|
||||
alt="CMBNet">
|
||||
alt="{{ APP_TITLE }}">
|
||||
</div>
|
||||
|
||||
<div class="street-search" role="search">
|
||||
@@ -47,7 +45,31 @@
|
||||
</div>
|
||||
<div class="street-search-status" id="streetSearchStatus"
|
||||
role="status" aria-live="polite"></div>
|
||||
<div class="connection-status" id="connectionStatus">Verbinde …</div>
|
||||
<div class="header-status-row">
|
||||
<div class="connection-status" id="connectionStatus">Verbinde …</div>
|
||||
<div class="header-action-buttons">
|
||||
<button type="button" id="speakerButton" class="icon-button"
|
||||
title="Nachricht an alle senden" aria-label="Nachricht an alle senden">📢</button>
|
||||
<button type="button" id="groupAssignmentButton"
|
||||
class="icon-button group-assignment-button"
|
||||
title="Gruppen-Accounts zuordnen"
|
||||
aria-label="Gruppen-Accounts zuordnen">
|
||||
<svg viewBox="0 0 32 24" fill="none" stroke="currentColor"
|
||||
stroke-width="1.4" stroke-linecap="round"
|
||||
stroke-linejoin="round" aria-hidden="true" focusable="false">
|
||||
<path d="M2.5 5.5 4 7.2 5.6 4.6 7.2 7.2 8.7 5.5 8.2 8.2H3z"/>
|
||||
<circle cx="5.8" cy="10.4" r="1.8"/>
|
||||
<path d="M2.7 18.8c.3-3 1.5-4.6 3.1-4.6s2.8 1.6 3.1 4.6"/>
|
||||
<path d="M12.9 3.5 14.4 5.2 16 2.6 17.6 5.2 19.1 3.5 18.6 6.2H13.4z"/>
|
||||
<circle cx="16" cy="8.4" r="1.8"/>
|
||||
<path d="M13 17c.3-3 1.5-4.6 3-4.6s2.7 1.6 3 4.6"/>
|
||||
<path d="M23.3 5.5 24.8 7.2 26.4 4.6 28 7.2 29.5 5.5 29 8.2h-5.2z"/>
|
||||
<circle cx="26.4" cy="10.4" r="1.8"/>
|
||||
<path d="M23.3 18.8c.3-3 1.5-4.6 3.1-4.6s2.8 1.6 3.1 4.6"/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="group-accordion" id="groupAccordion"></div>
|
||||
@@ -168,6 +190,37 @@
|
||||
</article>
|
||||
</dialog>
|
||||
|
||||
<!-- Gruppen-Accounts den Gruppen zuordnen -->
|
||||
<dialog id="groupAssignmentModal" class="group-assignment-dialog"
|
||||
aria-labelledby="groupAssignmentTitle">
|
||||
<article>
|
||||
<header>
|
||||
<h3 id="groupAssignmentTitle">Gruppen-Accounts zuordnen</h3>
|
||||
</header>
|
||||
<div class="dialog-body group-assignment-body">
|
||||
<p class="group-assignment-hint">
|
||||
Für jeden Account kann höchstens eine Gruppe gewählt werden.
|
||||
„Nicht dabei“ hebt eine bestehende Zuordnung auf.
|
||||
</p>
|
||||
<div class="group-assignment-scroll">
|
||||
<table class="group-assignment-table" id="groupAssignmentTable">
|
||||
<thead id="groupAssignmentHead"></thead>
|
||||
<tbody id="groupAssignmentBody"></tbody>
|
||||
</table>
|
||||
</div>
|
||||
<p id="groupAssignmentEmpty" class="group-assignment-empty" hidden>
|
||||
Es gibt keine Accounts mit der Rolle „Gruppe“.
|
||||
</p>
|
||||
</div>
|
||||
<footer>
|
||||
<button type="button" class="secondary"
|
||||
onclick="closeGroupAssignmentModal()">Abbrechen</button>
|
||||
<button type="button" id="groupAssignmentSaveButton"
|
||||
onclick="saveGroupAssignments()">Speichern</button>
|
||||
</footer>
|
||||
</article>
|
||||
</dialog>
|
||||
|
||||
<!-- Chatverlauf einer Gruppe -->
|
||||
<dialog id="chatModal">
|
||||
<article class="chat-dialog">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Dispatcher Mobil - {{ session.tenant_code }} - CMBNet{% endblock %}
|
||||
{% block title %}Dispatcher Mobil - {{ session.tenant_code }} - {{ APP_TITLE }}{% endblock %}
|
||||
|
||||
{% block body_class %}mobile-page{% endblock %}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
||||
<meta name="apple-mobile-web-app-title" content="CMBNet">
|
||||
<meta name="apple-mobile-web-app-title" content="{{ APP_TITLE }}">
|
||||
<link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon.png') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/pico.min.css') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/leaflet.css') }}">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Gruppen View - {{ session.tenant_code }} - CMBNet{% endblock %}
|
||||
{% block title %}Gruppen View - {{ session.tenant_code }} - {{ APP_TITLE }}{% endblock %}
|
||||
|
||||
{% block body_class %}mobile-page{% endblock %}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
<meta name="mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="default">
|
||||
<meta name="apple-mobile-web-app-title" content="CMBNet">
|
||||
<meta name="apple-mobile-web-app-title" content="{{ APP_TITLE }}">
|
||||
<link rel="apple-touch-icon" href="{{ url_for('static', filename='img/apple-touch-icon.png') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/pico.min.css') }}">
|
||||
<link rel="stylesheet" href="{{ url_for('static', filename='css/leaflet.css') }}">
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Login - CMBNet ({{ tenant_code }}){% endblock %}
|
||||
{% block title %}Login - {{ APP_TITLE }} ({{ tenant_code }}){% endblock %}
|
||||
{% block body_class %}login-page{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<article>
|
||||
<header>
|
||||
<h1>CMBNet Login</h1>
|
||||
<h1>{{ APP_TITLE }} Login</h1>
|
||||
<p>Mandant: <strong>{{ tenant_code }}</strong></p>
|
||||
</header>
|
||||
<form method="post">
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Mandantenauswahl - CMBNet{% endblock %}
|
||||
{% block title %}Mandantenauswahl - {{ APP_TITLE }}{% endblock %}
|
||||
{% block body_class %}login-page{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<article>
|
||||
<header>
|
||||
<h1>CMBNet - Mandantenauswahl</h1>
|
||||
<h1>{{ APP_TITLE }} - Mandantenauswahl</h1>
|
||||
</header>
|
||||
<p>Bitte wählen Sie Ihren Mandanten aus:</p>
|
||||
<div class="grid">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Öffentlicher View - CMBNet{% endblock %}
|
||||
{% block title %}Öffentlicher View - {{ APP_TITLE }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Öffentlicher View</h1>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% block title %}Präsentations View - CMBNet{% endblock %}
|
||||
{% block title %}Präsentations View - {{ APP_TITLE }}{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h1>Präsentations View</h1>
|
||||
|
||||
Reference in new issue
Block a user