changes to the deletion process

This commit is contained in:
2026-08-26 14:57:14 +02:00
parent 24b2b31e24
commit 67249cb633
2 changed files with 102 additions and 677 deletions
+37 -227
View File
@@ -458,7 +458,8 @@ def _list_school_instances() -> list:
rows = []
client = None
try:
client, col = _get_collection("school_instances")
# Greife auf "instances" zu (passend zum Async-Provisioning)
client, col = _get_collection("instances")
rows = list(col.find().sort([("updated_at", -1), ("created_at", -1)]))
except PyMongoError:
return []
@@ -472,17 +473,17 @@ def _list_school_instances() -> list:
{
"id": str(row.get("_id") or ""),
"school_name": _sanitize_text(row.get("school_name") or "", 120),
"owner_username": _sanitize_text(row.get("owner_username") or "", 80),
"owner_username": _sanitize_text(row.get("owner_username") or row.get("username") or "", 80),
"subdomain": _sanitize_text(row.get("subdomain") or "", 63),
"domain": _sanitize_text(row.get("domain") or "", 190),
"https_port": int(row.get("https_port") or 0),
"https_port": int(row.get("https_port") or row.get("port") or 0),
"instance_dir": _sanitize_text(row.get("instance_dir") or "", 300),
"app_image_tag": _sanitize_text(row.get("app_image_tag") or "latest", 80),
"library_enabled": bool(row.get("library_enabled", False)),
"status": _sanitize_text(row.get("status") or "Unbekannt", 40),
"nginx_status": _sanitize_text(row.get("nginx_status") or "unbekannt", 80),
"last_message": _sanitize_text(row.get("last_message") or "", 500),
"updated_at": row.get("updated_at") or "",
"updated_at": row.get("updated_at") or row.get("created_at") or "",
}
)
return normalized
@@ -2580,237 +2581,16 @@ def instance_request_delete():
@app.route('/admin/instances', methods=['GET', 'POST'])
@app.route('/admin/instances', methods=['GET'])
@admin_required
def admin_instances():
version_options = _parse_instance_version_options()
available_users = _list_available_instance_users()
if request.method == 'POST':
action = _sanitize_text(request.form.get("action") or "create", 20).lower()
posted_subdomain = _sanitize_text(request.form.get("subdomain") or "", 120)
school_name = _sanitize_text(request.form.get("school_name") or "", 120)
raw_subdomain = _sanitize_text(request.form.get("subdomain") or "", 120)
owner_username = _sanitize_text(request.form.get("owner_username") or "", 80)
app_image_tag = _sanitize_text(request.form.get("app_image_tag") or "latest", 80)
library_enabled = (request.form.get("library_enabled") or "").strip().lower() in {"1", "on", "true", "yes"}
subdomain = _slugify_subdomain(posted_subdomain or raw_subdomain or school_name)
if action == "reload_nginx":
reload_ok, reload_message = _reload_host_nginx()
if not reload_ok:
lowered = (reload_message or "").lower()
if "nicht gefunden" in lowered or "not found" in lowered or "kein nginx-reload-befehl" in lowered:
flash("Host-Nginx kann aus dem Website-Container nicht direkt neu geladen werden.", "error")
flash(_host_reload_hint(), "info")
flash("Nach erfolgreichem Host-Reload bitte 'Reload auf Host bestätigt' ausführen.", "info")
else:
flash(reload_message or "Nginx-Reload fehlgeschlagen.", "error")
return redirect(url_for("admin_instances"))
updated_rows = _promote_manual_nginx_status(
"Nginx erfolgreich neu geladen (Admin-Aktion)."
)
flash("Nginx wurde erfolgreich neu geladen.", "success")
if updated_rows > 0:
flash(f"{updated_rows} Instanz(en) von manual_required auf ok gesetzt.", "info")
else:
flash("Keine Instanz mit nginx_status=manual_required gefunden.", "info")
if reload_message:
flash(reload_message, "info")
return redirect(url_for("admin_instances"))
if action == "confirm_nginx_reload":
updated_rows = _promote_manual_nginx_status(
"Host-Nginx manuell neu geladen und in Admin bestätigt."
)
if updated_rows > 0:
flash(f"{updated_rows} Instanz(en) von manual_required auf ok gesetzt.", "success")
else:
flash("Keine Instanz mit nginx_status=manual_required gefunden.", "info")
return redirect(url_for("admin_instances"))
if action == "delete":
if not _is_valid_subdomain(subdomain):
flash("Ungültige Subdomain für Löschung.", "error")
return redirect(url_for("admin_instances"))
existing_record = _get_school_instance_by_subdomain(subdomain)
target_dir = _instance_dir_path(subdomain)
dir_exists = bool(target_dir and os.path.isdir(target_dir))
if not existing_record and not dir_exists:
flash("Instanz nicht gefunden.", "error")
return redirect(url_for("admin_instances"))
delete_ok, delete_message = _delete_instance_stack(subdomain)
if not delete_ok:
flash(delete_message or "Instanz konnte nicht gelöscht werden.", "error")
return redirect(url_for("admin_instances"))
if existing_record and not _delete_school_instance(subdomain):
flash(
"Instanz wurde technisch gelöscht, aber der Datenbankeintrag konnte nicht entfernt werden.",
"error",
)
return redirect(url_for("admin_instances"))
flash(f"Instanz {subdomain} wurde gelöscht.", "success")
if delete_message:
flash(delete_message, "info")
return redirect(url_for("admin_instances"))
if action == "toggle_library":
target = _get_school_instance_by_subdomain(subdomain)
if not target:
flash("Instanz nicht gefunden.", "error")
return redirect(url_for("admin_instances"))
instance_dir = _resolve_instance_dir(subdomain)
if not instance_dir:
flash("Instanzverzeichnis nicht gefunden.", "error")
return redirect(url_for("admin_instances"))
target_enabled = (request.form.get("library_enabled") or "").strip().lower() in {"1", "on", "true", "yes"}
ok, message = _set_instance_library_enabled(instance_dir, target_enabled)
if not ok:
_upsert_school_instance(
{
"subdomain": subdomain,
"status": "Fehler",
"nginx_status": "error",
"last_message": message,
}
)
flash(message, "error")
return redirect(url_for("admin_instances"))
restart_ok, restart_output = _restart_instance_stack(instance_dir)
client = None
try:
client, col = _get_collection("school_instances")
col.update_one(
{"subdomain": subdomain},
{
"$set": {
"school_name": target.get("school_name") or "",
"owner_username": target.get("owner_username") or "",
"subdomain": subdomain,
"domain": target.get("domain") or f"{subdomain}.{INSTANCE_PARENT_DOMAIN}",
"https_port": int(target.get("https_port") or 0),
"instance_dir": instance_dir,
"app_image_tag": target.get("app_image_tag") or "latest",
"library_enabled": target_enabled,
"status": "Läuft" if restart_ok else "Fehler",
"nginx_status": "ok" if restart_ok else "error",
"last_message": "Bibliothek aktiviert/deaktiviert und Instanz neu gestartet." if restart_ok else _tail_output(restart_output, 18),
"updated_at": _utc_now_iso(),
},
"$setOnInsert": {"created_at": _utc_now_iso()},
},
upsert=True,
)
except PyMongoError:
pass
finally:
if client:
client.close()
if restart_ok:
flash(f"Bibliothek wurde {'aktiviert' if target_enabled else 'deaktiviert'} und die Instanz neu gestartet.", "success")
if restart_output:
flash(_tail_output(restart_output, 12), "info")
else:
flash(f"Bibliothek wurde gespeichert, aber der Neustart ist fehlgeschlagen.\n{_tail_output(restart_output, 18)}", "error")
return redirect(url_for("admin_instances"))
if action not in {"create", "start"}:
flash("Ungültige Aktion für Instanzverwaltung.", "error")
return redirect(url_for("admin_instances"))
if not available_users:
flash("Keine freien Nutzer verfügbar. Bitte zuerst einen neuen Nutzer anlegen oder eine bestehende Instanz löschen.", "error")
return redirect(url_for("admin_instances"))
if not school_name:
flash("Bitte einen Schulnamen angeben.", "error")
return redirect(url_for("admin_instances"))
if not owner_username:
flash("Bitte einen Nutzer zuweisen.", "error")
return redirect(url_for("admin_instances"))
owner_doc = _find_user(owner_username)
if not owner_doc:
flash("Ausgewählter Nutzer wurde nicht gefunden.", "error")
return redirect(url_for("admin_instances"))
if not school_name:
school_name = _sanitize_text(owner_doc.get("display_name") or owner_username, 120)
if app_image_tag not in version_options:
flash("Ungültige Version ausgewählt.", "error")
return redirect(url_for("admin_instances"))
existing_for_owner = _get_instance_for_user(owner_username, "")
if existing_for_owner:
existing_sub = _sanitize_text(existing_for_owner.get("subdomain") or "", 63)
if existing_sub and existing_sub != subdomain:
flash(
f"Nutzer {owner_username} ist bereits der Instanz {existing_sub} zugewiesen. "
"Bitte erst diese Zuweisung ändern.",
"error",
)
return redirect(url_for("admin_instances"))
if not _is_valid_subdomain(subdomain):
flash("Ungültige Subdomain. Erlaubt sind a-z, 0-9 und Bindestriche (3-63 Zeichen).", "error")
return redirect(url_for("admin_instances"))
success, message, details = _run_instance_provision(
action,
school_name,
subdomain,
app_image_tag=app_image_tag,
library_enabled=library_enabled,
)
instance_data = {
"school_name": school_name,
"owner_username": owner_username,
"subdomain": details.get("SUBDOMAIN") or subdomain,
"domain": details.get("DOMAIN") or f"{subdomain}.{INSTANCE_PARENT_DOMAIN}",
"https_port": int((details.get("HTTPS_PORT") or "0") or 0),
"instance_dir": details.get("INSTANCE_DIR") or os.path.join(INSTANCE_BASE_DIR, subdomain),
"app_image_tag": details.get("APP_IMAGE_TAG") or app_image_tag,
"library_enabled": library_enabled if details.get("LIBRARY_ENABLED") is None else details.get("LIBRARY_ENABLED") == "1",
"status": "Läuft" if success else "Fehler",
"nginx_status": details.get("NGINX_STATUS") or ("ok" if success else "error"),
"last_message": message,
}
_upsert_school_instance(instance_data)
if success:
flash(f"Instanz gestartet: {instance_data['domain']}", "success")
if message:
flash(message, "info")
else:
flash(message or "Instanz konnte nicht gestartet werden.", "error")
return redirect(url_for("admin_instances"))
instances = _list_school_instances()
instance_dashboard = _build_instance_dashboard(instances)
return render_template(
"admin_instances.html",
instances=instances,
users=_list_users_for_admin(),
available_users=available_users,
instance_dashboard=instance_dashboard,
version_options=version_options,
instance_repo_url=INSTANCE_REPO_URL,
parent_domain=INSTANCE_PARENT_DOMAIN,
base_dir=INSTANCE_BASE_DIR,
provision_script=INSTANCE_PROVISION_SCRIPT,
)
@@ -3869,6 +3649,36 @@ def tenant_status():
return jsonify({"status": "pending"}), 200
@app.route('/admin/test/drop_all_instances', methods=['POST'])
@login_required
def admin_drop_all_instances():
# 1. Sicherheits-Check: Nur Admins dürfen das!
# Passe diesen Check an deine bestehende Rollenverwaltung an
if not session.get("is_admin") and session.get("role") != "admin":
flash("Zugriff verweigert. Diese Aktion ist nur für Administratoren erlaubt.", "error")
return redirect(url_for('my_instance_management')) # oder zum Dashboard
inst_client, inst_col = _get_collection("instances")
req_client, req_col = _get_collection("instance_requests")
try:
# Löscht alle Dokumente in den beiden Collections
deleted_instances = inst_col.delete_many({}).deleted_count
deleted_requests = req_col.delete_many({}).deleted_count
flash(f"Test-Reset erfolgreich: {deleted_instances} Instanzen und {deleted_requests} Anfragen wurden unwiderruflich gelöscht.", "success")
print(f"[ADMIN ACTION] Alle Instanzen ({deleted_instances}) und Requests ({deleted_requests}) wurden von {session.get('username')} gelöscht.")
except Exception as e:
print(f"[ERROR] Fehler beim Löschen der Datenbank: {e}")
flash("Ein Fehler ist aufgetreten. Datenbank konnte nicht bereinigt werden.", "error")
finally:
inst_client.close()
req_client.close()
# Leite den Admin danach zurück zu einer sicheren Seite
return redirect(url_for('my_instance_management'))
def main():
app.run(host="0.0.0.0", port=4999, debug=False)
+65 -450
View File
@@ -1,137 +1,29 @@
{% extends "base.html" %}
{% block title %}Admin | Instanzen{% endblock %}
{% block title %}Admin | Tenant Instanzen{% endblock %}
{% block content %}
<section class="instance-header">
<h1>Schul-Instanzen starten</h1>
<p>Neue Instanzen des Inventarsystems für Subdomains pro Schule anlegen, sowie die Bibliothek dauerhaft aktivieren oder deaktivieren.</p>
</section>
<section class="dashboard-grid">
<article class="kpi-card">
<p class="kpi-label">Instanzen gesamt</p>
<p class="kpi-value">{{ instance_dashboard.kpis.total }}</p>
</article>
<article class="kpi-card good">
<p class="kpi-label">Laufend</p>
<p class="kpi-value">{{ instance_dashboard.kpis.running }}</p>
</article>
<article class="kpi-card bad">
<p class="kpi-label">Fehlerhaft</p>
<p class="kpi-value">{{ instance_dashboard.kpis.error }}</p>
</article>
<article class="kpi-card">
<p class="kpi-label">Bibliothek aktiv</p>
<p class="kpi-value">{{ instance_dashboard.kpis.library_on }}</p>
</article>
<article class="kpi-card">
<p class="kpi-label">Nutzer zugewiesen</p>
<p class="kpi-value">{{ instance_dashboard.kpis.assigned_users }}</p>
</article>
</section>
<section class="charts-grid">
<article class="chart-card">
<h3>Status</h3>
<canvas id="statusChart" aria-label="Status Chart"></canvas>
</article>
<article class="chart-card">
<h3>Bibliothek</h3>
<canvas id="libraryChart" aria-label="Library Chart"></canvas>
</article>
<article class="chart-card wide">
<h3>Versionen</h3>
<canvas id="versionsChart" aria-label="Versions Chart"></canvas>
</article>
<article class="chart-card wide">
<h3>Instanzen pro Nutzer</h3>
<canvas id="ownersChart" aria-label="Owners Chart"></canvas>
</article>
<article class="chart-card wide">
<h3>Aktivität (letzte 7 Tage)</h3>
<canvas id="activityChart" aria-label="Activity Chart"></canvas>
</article>
</section>
<section class="instance-form-wrap">
<form method="post" class="instance-form">
<input type="hidden" name="action" value="create">
<label for="owner_username">Zugewiesener Nutzer</label>
<select id="owner_username" name="owner_username" required {% if not available_users %}disabled{% endif %}>
{% if available_users %}
<option value="">Nutzer wählen</option>
{% for user in available_users %}
<option value="{{ user.username }}" data-school-name="{{ user.display_name or user.username }}">{{ user.username }}{% if user.display_name %} - {{ user.display_name }}{% endif %}</option>
{% endfor %}
{% else %}
<option value="">Keine freien Nutzer verfügbar</option>
{% endif %}
</select>
{% if not available_users %}
<p class="warn-text">Alle Nutzer sind bereits einer Instanz zugewiesen. Lege einen neuen Nutzer an oder lösche eine bestehende Instanz.</p>
{% endif %}
<label for="school_name">Schulname</label>
<input id="school_name" name="school_name" type="text" placeholder="wird aus dem Nutzer übernommen" required>
<label for="app_image_tag">Version</label>
<select id="app_image_tag" name="app_image_tag" required>
{% for version in version_options %}
<option value="{{ version }}">{{ version }}</option>
{% endfor %}
</select>
<label for="subdomain">Subdomain (optional)</label>
<input id="subdomain" name="subdomain" type="text" placeholder="wird aus Schulname abgeleitet">
<label class="check-row">
<input type="checkbox" name="library_enabled" value="1">
Bibliothek aktivieren
</label>
<button type="submit">Instanz erstellen und starten</button>
</form>
<aside class="instance-meta">
<h2>Systemdaten</h2>
<p><strong>Repository:</strong> {{ instance_repo_url }}</p>
<p><strong>Basis-Domain:</strong> {{ parent_domain }}</p>
<p><strong>Instanz-Pfad:</strong> {{ base_dir }}</p>
<p><strong>Provisioning-Skript:</strong> {{ provision_script }}</p>
<p class="note">Hinweis: Für Docker- und Nginx-Operationen benötigt der laufende Prozess die passenden Host-Berechtigungen.</p>
</aside>
<h1>Tenant Instanzen Übersicht</h1>
<p>Übersicht aller zugewiesenen und aktiven Schul-Instanzen im System.</p>
</section>
<section class="instance-table-wrap">
<div class="table-head">
<h2>Vorhandene Instanzen</h2>
<div class="table-actions">
<form method="post" class="inline-toggle-form">
<input type="hidden" name="action" value="reload_nginx">
<button type="submit">Nginx neu laden &amp; Status aktualisieren</button>
</form>
<form method="post" class="inline-toggle-form">
<input type="hidden" name="action" value="confirm_nginx_reload">
<button type="submit">Reload auf Host bestätigt</button>
</form>
</div>
<h2>Vorhandene Tenant Instanzen</h2>
</div>
{% if instances %}
<table>
<thead>
<tr>
<th>Schule</th>
<th>Nutzer</th>
<th>Subdomain</th>
<th>Nutzer (Owner)</th>
<th>Subdomain / Domain</th>
<th>HTTPS-Port</th>
<th>Version</th>
<th>Bibliothek</th>
<th>Aktion</th>
<th>HTTPS-Port</th>
<th>Status</th>
<th>Nginx</th>
<th>Nginx Status</th>
<th>Letzte Meldung</th>
<th>Aktualisiert</th>
</tr>
@@ -139,185 +31,84 @@
<tbody>
{% for item in instances %}
<tr>
<td>{{ item.school_name }}</td>
<td><strong>{{ item.school_name or '-' }}</strong></td>
<td>{{ item.owner_username or '-' }}</td>
<td>
{% if item.domain %}
<a class="instance-domain-link" href="https://{{ item.domain }}" target="_blank" rel="noopener noreferrer">{{ item.domain }}</a>
<a class="instance-domain-link" href="https://{{ item.domain }}" target="_blank" rel="noopener noreferrer">
{{ item.domain }}
</a>
{% elif item.subdomain %}
{{ item.subdomain }}.{{ parent_domain }}
{% else %}
-
{% endif %}
</td>
<td>{{ item.app_image_tag or 'latest' }}</td>
<td>{{ 'an' if item.library_enabled else 'aus' }}</td>
<td>
<form method="post" class="inline-toggle-form">
<input type="hidden" name="action" value="toggle_library">
<input type="hidden" name="subdomain" value="{{ item.subdomain }}">
<input type="hidden" name="library_enabled" value="{{ 0 if item.library_enabled else 1 }}">
<button type="submit">{{ 'Bibliothek deaktivieren' if item.library_enabled else 'Bibliothek aktivieren' }}</button>
</form>
<form method="post" class="inline-toggle-form" onsubmit="return confirm('Instanz {{ item.subdomain }} wirklich löschen? Dieser Vorgang entfernt Container, Daten und Konfiguration.');">
<input type="hidden" name="action" value="delete">
<input type="hidden" name="subdomain" value="{{ item.subdomain }}">
<button type="submit" class="danger">Instanz löschen</button>
</form>
</td>
<td>{{ item.https_port or '-' }}</td>
<td><code>{{ item.app_image_tag or 'latest' }}</code></td>
<td>
<span class="pill {{ 'ok' if item.status == 'Läuft' else 'error' }}">{{ item.status }}</span>
<span class="pill {{ 'ok' if item.library_enabled else 'inactive' }}">
{{ 'Aktiv' if item.library_enabled else 'Inaktiv' }}
</span>
</td>
<td>{{ item.nginx_status }}</td>
<td>{{ item.last_message }}</td>
<td>{{ item.updated_at }}</td>
<td>
<span class="pill {{ 'ok' if item.status in ['Läuft', 'ready', 'active'] else 'error' }}">
{{ item.status or 'Unbekannt' }}
</span>
</td>
<td>{{ item.nginx_status or 'unbekannt' }}</td>
<td class="last-msg-cell">{{ item.last_message or '-' }}</td>
<td>{{ item.updated_at or '-' }}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>Noch keine Instanzen vorhanden.</p>
<p class="empty-state">Aktuell sind keine Tenant-Instanzen in der Datenbank vorhanden.</p>
{% endif %}
</section>
<style>
.instance-header {
margin-bottom: 1rem;
margin-bottom: 1.5rem;
}
.dashboard-grid {
display: grid;
grid-template-columns: repeat(5, minmax(0, 1fr));
gap: 0.75rem;
margin-bottom: 1rem;
}
.kpi-card {
border: 1px solid #d8e1e8;
background: linear-gradient(160deg, #ffffff 0%, #f4f8fb 100%);
border-radius: 14px;
padding: 0.85rem;
}
.kpi-card.good {
border-color: #8cc9a6;
background: linear-gradient(160deg, #ffffff 0%, #eaf8f1 100%);
}
.kpi-card.bad {
border-color: #e3adad;
background: linear-gradient(160deg, #ffffff 0%, #fef2f2 100%);
}
.kpi-label {
margin: 0;
font-size: 0.84rem;
color: #4b6170;
font-weight: 600;
}
.kpi-value {
margin: 0.3rem 0 0;
font-size: 1.58rem;
font-weight: 800;
color: #11364a;
}
.charts-grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0.85rem;
margin-bottom: 1.2rem;
}
.chart-card {
border: 1px solid #d8e1e8;
background: #ffffff;
border-radius: 14px;
padding: 0.85rem;
}
.chart-card.wide {
grid-column: span 2;
}
.chart-card h3 {
margin: 0 0 0.45rem;
font-size: 1rem;
}
.chart-card canvas {
width: 100%;
max-height: 260px;
}
.instance-form-wrap {
display: grid;
grid-template-columns: 1.2fr 1fr;
gap: 1rem;
margin-bottom: 1.2rem;
}
.instance-form,
.instance-meta,
.instance-table-wrap {
border: 1px solid #d8e1e8;
background: #ffffff;
border-radius: 14px;
padding: 1rem;
padding: 1.25rem;
overflow-x: auto;
}
.table-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 0.75rem;
flex-wrap: wrap;
margin-bottom: 1rem;
}
.table-actions {
display: flex;
align-items: center;
gap: 0.5rem;
flex-wrap: wrap;
.table-head h2 {
margin: 0;
font-size: 1.25rem;
color: #11364a;
}
.instance-form {
display: grid;
gap: 0.5rem;
table {
width: 100%;
border-collapse: collapse;
}
.instance-form input,
.instance-form select {
border: 1px solid #bcd0de;
border-radius: 10px;
padding: 0.55rem 0.65rem;
font: inherit;
}
.check-row {
display: flex;
align-items: center;
gap: 0.45rem;
margin-top: 0.2rem;
font-weight: 600;
}
.instance-form button {
margin-top: 0.4rem;
border: none;
border-radius: 999px;
padding: 0.55rem 0.95rem;
font-weight: 700;
cursor: pointer;
color: #ffffff;
background: linear-gradient(120deg, #0b5b89 0%, #0b4262 100%);
}
.warn-text {
margin: 0.2rem 0 0.1rem;
color: #8b2a27;
th,
td {
text-align: left;
border-bottom: 1px solid #e7edf3;
padding: 0.75rem;
vertical-align: middle;
font-size: 0.9rem;
font-weight: 600;
}
th {
background-color: #f8fafc;
color: #4b6170;
font-weight: 700;
}
.instance-domain-link {
@@ -330,77 +121,23 @@
text-decoration: underline;
}
.inline-toggle-form {
margin: 0;
.last-msg-cell {
max-width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.inline-toggle-form + .inline-toggle-form {
margin-top: 0.35rem;
}
.inline-toggle-form button {
border: 1px solid #bcd0de;
background: #ffffff;
color: #173f5a;
border-radius: 999px;
padding: 0.35rem 0.68rem;
font: inherit;
font-weight: 700;
cursor: pointer;
}
.inline-toggle-form button:hover {
background: #f2f8fc;
}
.inline-toggle-form button.danger {
border-color: #e3adad;
color: #8b2a27;
background: #fef2f2;
}
.inline-toggle-form button.danger:hover {
background: #fde4e4;
}
.instance-meta h2,
.instance-table-wrap h2 {
margin: 0 0 0.5rem;
}
.instance-meta p {
margin: 0.28rem 0;
font-size: 0.92rem;
}
.instance-meta .note {
margin-top: 0.65rem;
padding-top: 0.65rem;
border-top: 1px dashed #c7d2db;
}
.instance-table-wrap {
overflow-x: auto;
}
table {
width: 100%;
border-collapse: collapse;
}
th,
td {
text-align: left;
border-bottom: 1px solid #e7edf3;
padding: 0.62rem;
vertical-align: top;
font-size: 0.9rem;
.empty-state {
color: #64748b;
font-style: italic;
padding: 1rem 0;
}
.pill {
display: inline-flex;
border-radius: 999px;
padding: 0.18rem 0.62rem;
padding: 0.2rem 0.65rem;
font-weight: 700;
font-size: 0.78rem;
}
@@ -417,132 +154,10 @@ td {
color: #8b2a27;
}
@media (max-width: 900px) {
.dashboard-grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
.charts-grid {
grid-template-columns: 1fr;
}
.chart-card.wide {
grid-column: span 1;
}
.instance-form-wrap {
grid-template-columns: 1fr;
}
.pill.inactive {
background: #f1f5f9;
border: 1px solid #cbd5e1;
color: #475569;
}
</style>
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
(function() {
const dashboardData = {{ instance_dashboard|tojson }};
const buildChart = (id, config) => {
const element = document.getElementById(id);
if (!element) {
return;
}
new Chart(element, config);
};
buildChart('statusChart', {
type: 'doughnut',
data: {
labels: dashboardData.status.labels,
datasets: [{
data: dashboardData.status.values,
backgroundColor: ['#3aa675', '#cf4b49', '#8aa6b8']
}]
},
options: { plugins: { legend: { position: 'bottom' } } }
});
buildChart('libraryChart', {
type: 'pie',
data: {
labels: dashboardData.library.labels,
datasets: [{
data: dashboardData.library.values,
backgroundColor: ['#1b6f8e', '#c6d7e2']
}]
},
options: { plugins: { legend: { position: 'bottom' } } }
});
buildChart('versionsChart', {
type: 'bar',
data: {
labels: dashboardData.versions.labels,
datasets: [{
label: 'Instanzen',
data: dashboardData.versions.values,
backgroundColor: '#1b6f8e'
}]
},
options: {
responsive: true,
scales: { y: { beginAtZero: true, ticks: { precision: 0 } } },
plugins: { legend: { display: false } }
}
});
buildChart('ownersChart', {
type: 'bar',
data: {
labels: dashboardData.owners.labels,
datasets: [{
label: 'Instanzen',
data: dashboardData.owners.values,
backgroundColor: '#b3672e'
}]
},
options: {
indexAxis: 'y',
scales: { x: { beginAtZero: true, ticks: { precision: 0 } } },
plugins: { legend: { display: false } }
}
});
buildChart('activityChart', {
type: 'line',
data: {
labels: dashboardData.activity.labels,
datasets: [{
label: 'Updates',
data: dashboardData.activity.values,
borderColor: '#0b5b89',
backgroundColor: 'rgba(11, 91, 137, 0.15)',
fill: true,
tension: 0.25
}]
},
options: {
scales: { y: { beginAtZero: true, ticks: { precision: 0 } } },
plugins: { legend: { display: false } }
}
});
const ownerSelect = document.getElementById('owner_username');
const schoolInput = document.getElementById('school_name');
if (!ownerSelect || !schoolInput) {
return;
}
const updateSchoolName = () => {
const selectedOption = ownerSelect.options[ownerSelect.selectedIndex];
const schoolName = selectedOption ? (selectedOption.dataset.schoolName || '') : '';
if (schoolName) {
schoolInput.value = schoolName;
}
};
ownerSelect.addEventListener('change', updateSchoolName);
updateSchoolName();
})();
</script>
{% endblock %}
{% endblock %}