From 5877d4a2f36bae815720b15cb08bfa41aa7ff793 Mon Sep 17 00:00:00 2001 From: H4nSolo Date: Tue, 24 Nov 2026 15:00:06 +0100 Subject: [PATCH] Schaubild: neues Design, Konzept v0.7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Dunkles Thema als Standard, hell umschaltbar (ganze App) - Icons je Gerätetyp (Bootstrap Icons 1.13.2, lokal), Name über dem Icon - Linienfarbe = Netz (neues Feld Netz.farbe, Vorgabe je Typ/VLAN), Strichart = Linienart; eckige Linien mit runden Ecken - Beschriftung standardmäßig aus, beim Überfahren/Anklicken sichtbar - Internet-Knoten am DSL-Port (neues Feld Schnittstelle.anbieter) - Hinweis ⚠ bei "(prüfen)" in Notizen oder fehlender Verbindung - Netz-Filter über Netzliste der Linie statt Beschriftung - 73 Tests Co-Authored-By: Claude Opus 5.5 --- AUFBAUPLAN.md | 1 + README.md | 23 ++- inventar/admin.py | 6 +- inventar/migrations/0005_farbe_anbieter.py | 24 +++ inventar/models.py | 24 ++- inventar/tests.py | 16 ++ static/topologie/schaubild.js | 174 +++++++++++++----- static/vendor/bootstrap-icons/LICENSE | 21 +++ static/vendor/bootstrap-icons/VERSION | 1 + static/vendor/bootstrap-icons/box.svg | 3 + .../vendor/bootstrap-icons/broadcast-pin.svg | 3 + static/vendor/bootstrap-icons/cpu.svg | 3 + static/vendor/bootstrap-icons/diagram-3.svg | 3 + static/vendor/bootstrap-icons/display.svg | 3 + static/vendor/bootstrap-icons/globe2.svg | 3 + static/vendor/bootstrap-icons/hdd-network.svg | 4 + static/vendor/bootstrap-icons/hdd-rack.svg | 4 + static/vendor/bootstrap-icons/laptop.svg | 3 + static/vendor/bootstrap-icons/lightbulb.svg | 3 + static/vendor/bootstrap-icons/pc-display.svg | 3 + static/vendor/bootstrap-icons/phone.svg | 4 + static/vendor/bootstrap-icons/printer.svg | 4 + static/vendor/bootstrap-icons/router.svg | 6 + .../vendor/bootstrap-icons/window-stack.svg | 4 + templates/base.html | 29 ++- topologie/schaubild.py | 96 ++++++++-- topologie/templates/topologie/schaubild.html | 8 +- topologie/tests.py | 31 ++++ topologie/views.py | 2 + 29 files changed, 422 insertions(+), 87 deletions(-) create mode 100644 inventar/migrations/0005_farbe_anbieter.py create mode 100644 static/vendor/bootstrap-icons/LICENSE create mode 100644 static/vendor/bootstrap-icons/VERSION create mode 100644 static/vendor/bootstrap-icons/box.svg create mode 100644 static/vendor/bootstrap-icons/broadcast-pin.svg create mode 100644 static/vendor/bootstrap-icons/cpu.svg create mode 100644 static/vendor/bootstrap-icons/diagram-3.svg create mode 100644 static/vendor/bootstrap-icons/display.svg create mode 100644 static/vendor/bootstrap-icons/globe2.svg create mode 100644 static/vendor/bootstrap-icons/hdd-network.svg create mode 100644 static/vendor/bootstrap-icons/hdd-rack.svg create mode 100644 static/vendor/bootstrap-icons/laptop.svg create mode 100644 static/vendor/bootstrap-icons/lightbulb.svg create mode 100644 static/vendor/bootstrap-icons/pc-display.svg create mode 100644 static/vendor/bootstrap-icons/phone.svg create mode 100644 static/vendor/bootstrap-icons/printer.svg create mode 100644 static/vendor/bootstrap-icons/router.svg create mode 100644 static/vendor/bootstrap-icons/window-stack.svg diff --git a/AUFBAUPLAN.md b/AUFBAUPLAN.md index 650d791..8bdf1d6 100644 --- a/AUFBAUPLAN.md +++ b/AUFBAUPLAN.md @@ -106,6 +106,7 @@ _Reihenfolge v0.5: Schaubild vor Formularen, damit Lücken in den Daten früh si - [x] Klick auf Knoten → Details mit Link (vorerst Admin, ab Phase 3 Detailseite) - [x] Filter: Netz, Status - [x] Positionen per Drag & Drop, Rahmen nehmen Inhalt mit; „Anordnung zurücksetzen“ +- [x] Design: dunkel/hell, Icons je Typ, Linienfarbe = Netz, eckige Linien, Internet-Knoten, ⚠-Hinweise **Fertig, wenn:** Das Homelab-Beispiel vollständig und korrekt als Schaubild erscheint. _(Darstellung umgesetzt; Abnahme mit deinen Daten offen)_ diff --git a/README.md b/README.md index 41b2890..1ca08b6 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ |---|---| | **Projekt** | Netzwerk Planer | | **Autor** | Christian Bergs | -| **Version** | 0.6 | +| **Version** | 0.7 | | **Stand** | 24.11.2026 | | **Status** | Konzeptphase | | **Ergänzende Dateien** | [AUFBAUPLAN.md](AUFBAUPLAN.md) · [CLAUDE.md](CLAUDE.md) | @@ -84,9 +84,9 @@ Der Netzwerk Planer dokumentiert die eigene Infrastruktur (Hosts, VMs, LXCs, Net | **Standort** | Gruppierung, z. B. Homelab | Name, Beschreibung | `homelab` | | **Gerät** | Hardware **und** Gäste (VM/LXC) in einem Objekt | Art (Hardware/VM/LXC), Typ und Rolle (nur Hardware), Name, Hersteller/Modell, Standort, **Host**, Proxmox-ID, Betriebssystem, **verwaltet von**, Status, Notizen | global: `pve1`, `vm-1000`, `ct-105` | | **Bridge** | Virtueller Switch im Hypervisor | Host, Name, VLAN-aware, Notizen | je Host: `pve1/vmbr1` | -| **Schnittstelle** | Port, Netzwerkkarte, Switch-Port | Gerät, Name, Art (physisch/virtuell/WLAN/DSL), MAC, **Bridge**, VLAN-Tag, **durchgereicht an**, **SSID**, Switch-Felder (Modus, untagged VLAN, tagged VLANs, PoE), Notizen | je Gerät: `pve1/nic1`, `ct-105/net0` | +| **Schnittstelle** | Port, Netzwerkkarte, Switch-Port | Gerät, Name, Art (physisch/virtuell/WLAN/DSL), MAC, Anbieter (nur DSL), **Bridge**, VLAN-Tag, **durchgereicht an**, **SSID**, Switch-Felder (Modus, untagged VLAN, tagged VLANs, PoE), Notizen | je Gerät: `pve1/nic1`, `ct-105/net0` | | **Verbindung** | Kabel oder VPN zwischen zwei Schnittstellen | Schnittstelle A, Schnittstelle B, Typ, Notiz | – | -| **Netz** | Subnetz | Name, CIDR, Typ (Transfer/LAN/VLAN/VPN), VLAN-ID, Gateway, DHCP von/bis, Standort (bei VPN leer) | global: `lan`, `transfer`, `wireguard` | +| **Netz** | Subnetz | Name, CIDR, Typ (Transfer/LAN/VLAN/VPN), VLAN-ID, Gateway, DHCP von/bis, Standort (bei VPN leer), Farbe (optional) | global: `lan`, `transfer`, `wireguard` | | **IP-Adresse** | Belegte Adresse | IP, Netz, Schnittstelle **oder** Bridge (Host-IP, z. B. pve1 auf vmbr0), Art (statisch/DHCP-Reservierung/DHCP), Notiz | – | | **SSID** | WLAN-Netz eines AP oder Routers | Name, Band, Netz, AP | global: `wlan-5ghz` | @@ -125,15 +125,17 @@ Jedes Gerät (auch VM/LXC) hat einen Status: ## 5 Verbindungstypen Jede Linie im Schaubild entsteht aus den Daten – entweder aus einem Feld oder aus einem Verbindungs-Objekt. +**Farbe = Netz** (Feld `farbe` am Netz, sonst Vorgabe je Typ bzw. je VLAN), **Strichart = Linienart** (Spalte „Linie“). | Typ | Bedeutung | Quelle in den Daten | Linie | |---|---|---|---| -| **Kabel** | Physische Verbindung zwischen zwei Ports | Verbindung, Typ Kabel | durchgezogen, grau | -| **Bridge** | Schnittstelle hängt an einer Bridge (Gast oder Bridge-Port) | Feld `bridge` der Schnittstelle | durchgezogen, grau | -| **Passthrough** | Physischer Port **exklusiv** an einen Gast durchgereicht | Feld `durchgereicht_an` der Schnittstelle | gestrichelt, orange | +| **Kabel** | Physische Verbindung zwischen zwei Ports | Verbindung, Typ Kabel | durchgezogen, kräftig | +| **Bridge** | Schnittstelle hängt an einer Bridge (Gast oder Bridge-Port) | Feld `bridge` der Schnittstelle | durchgezogen | +| **Passthrough** | Physischer Port **exklusiv** an einen Gast durchgereicht | Feld `durchgereicht_an` der Schnittstelle | gestrichelt | | **WLAN** | Endgerät ist einer SSID zugeordnet | Feld `ssid` der Schnittstelle | kurz gestrichelt | -| **VPN** | Tunnel zwischen zwei Endpunkten (z. B. WireGuard) | Verbindung, Typ VPN | farbig, gestrichelt | -| **verwaltet von** | Logische Management-Beziehung (z. B. AP → Controller) | Feld `verwaltet_von` des Geräts | gepunktet | +| **VPN** | Tunnel zwischen zwei Endpunkten (z. B. WireGuard) | Verbindung, Typ VPN | gestrichelt | +| **Internet** | DSL-Port → Knoten „Internet“ (mit Anbieter) | Art DSL der Schnittstelle | durchgezogen, gelb | +| **verwaltet von** | Logische Management-Beziehung (z. B. AP → Controller) | Feld `verwaltet_von` des Geräts | gepunktet, neutral, mit Pfeil | **Bridge-Port vs. Passthrough** - **Bridge-Port:** `pve1/nic1` hat `bridge = vmbr1`. pfSense-LAN, weitere Gäste und das physische Netz teilen sich die Bridge. @@ -187,7 +189,10 @@ Die Regeln liegen im Model (Fat Models) und greifen bei jedem Speichern – auch - Hosts **auf- und zuklappbar**; zugeklappt mit Anzahl der Gäste, Linien nach außen bleiben erhalten - **Drag & Drop ändert nur die Position, nie die Daten.** Gäste bleiben in ihrem Host-Rahmen, Linien folgen den Knoten. - **Positionen werden gespeichert** (App `topologie`, Schlüssel über logische IDs, z. B. `geraet:ct-105`, `bridge:pve1/vmbr0`). Neue Objekte ohne Position werden automatisch platziert; „Anordnung zurücksetzen“ ordnet alles neu. -- Klick auf einen Knoten oder eine Linie zeigt die Details mit Link zur Bearbeitung (bis Phase 2: Admin) +- Klick auf einen Knoten oder eine Linie zeigt die Details mit Link zur Bearbeitung (bis Phase 3: Admin) +- **Design:** dunkel als Standard, hell umschaltbar (Navigationsleiste, gespeichert im Browser); **Icons je Gerätetyp** (Bootstrap Icons, lokal), Name über dem Icon; Gäste als „[LXC 105] pihole“; Bridges als kleine Switch-Icons; Hypervisor-Rahmen mit Hersteller/Modell +- **Linien** eckig mit runden Ecken; Beschriftung standardmäßig aus, sichtbar beim Überfahren/Anklicken oder per Schalter „Beschriftung immer“ +- **⚠ am Gerät** bei „(prüfen)“ in Notizen von Gerät, Schnittstellen, Bridges oder IPs oder wenn keine Linie am Gerät hängt; Gründe im Detailbereich - Filter: Netz, Status **Beschriftung der Linien** – abgeleitet, nicht gepflegt (Format: CIDR und VLAN, z. B. `192.168.178.0/24 · VLAN 20`): diff --git a/inventar/admin.py b/inventar/admin.py index 304ac12..f0f8ef5 100644 --- a/inventar/admin.py +++ b/inventar/admin.py @@ -11,7 +11,7 @@ class SchnittstelleInline(admin.TabularInline): model = Schnittstelle fk_name = "geraet" extra = 0 - fields = ["name", "art", "mac", "bridge", "vlan_tag", "durchgereicht_an", "ssid"] + fields = ["name", "art", "mac", "bridge", "vlan_tag", "durchgereicht_an", "ssid", "anbieter"] show_change_link = True @@ -89,7 +89,7 @@ class SchnittstelleAdmin(admin.ModelAdmin): autocomplete_fields = ["geraet", "durchgereicht_an"] inlines = [IPAdresseInline] fieldsets = [ - (None, {"fields": ["geraet", "name", "art", "mac", "notizen"]}), + (None, {"fields": ["geraet", "name", "art", "mac", "anbieter", "notizen"]}), ("Anbindung", {"fields": ["bridge", "vlan_tag", "durchgereicht_an", "ssid"]}), ("Switch-Port", {"fields": ["switch_modus", "untagged_vlan", "tagged_vlans", "poe"], "classes": ["collapse"]}), ] @@ -106,7 +106,7 @@ class VerbindungAdmin(admin.ModelAdmin): @admin.register(Netz) class NetzAdmin(admin.ModelAdmin): form = GeprueftesModelForm - list_display = ["name", "slug", "cidr", "typ", "vlan_id", "gateway", "dhcp_von", "dhcp_bis", "standort"] + list_display = ["name", "slug", "cidr", "typ", "vlan_id", "gateway", "dhcp_von", "dhcp_bis", "standort", "anzeige_farbe"] list_filter = ["typ", "standort"] prepopulated_fields = {"slug": ["name"]} inlines = [IPAdresseImNetzInline] diff --git a/inventar/migrations/0005_farbe_anbieter.py b/inventar/migrations/0005_farbe_anbieter.py new file mode 100644 index 0000000..a8bafe4 --- /dev/null +++ b/inventar/migrations/0005_farbe_anbieter.py @@ -0,0 +1,24 @@ +# Generated by Django 5.2.19 on 2026-11-24 13:53 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('inventar', '0004_netz_typ_vpn'), + ] + + operations = [ + migrations.AddField( + model_name='netz', + name='farbe', + field=models.CharField(blank=True, help_text='Linienfarbe im Schaubild (#rrggbb). Leer: Vorgabe je Typ bzw. je VLAN.', max_length=7, validators=[django.core.validators.RegexValidator('^#[0-9a-fA-F]{6}$', 'Farbe als #rrggbb, z. B. #22d3ee.')]), + ), + migrations.AddField( + model_name='schnittstelle', + name='anbieter', + field=models.CharField(blank=True, help_text='Nur bei DSL: Internetanbieter, z. B. 1und1.', max_length=50), + ), + ] diff --git a/inventar/models.py b/inventar/models.py index 151dfed..93314d6 100644 --- a/inventar/models.py +++ b/inventar/models.py @@ -9,12 +9,13 @@ import ipaddress import re from django.core.exceptions import ValidationError -from django.core.validators import MaxValueValidator, MinValueValidator, validate_slug +from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator, validate_slug from django.db import models from django.utils.text import slugify VLAN_VALIDATOREN = [MinValueValidator(1), MaxValueValidator(4094)] MAC_MUSTER = re.compile(r"^[0-9a-f]{12}$") +FARBE_VALIDATOR = RegexValidator(r"^#[0-9a-fA-F]{6}$", "Farbe als #rrggbb, z. B. #22d3ee.") class GeprueftesModel(models.Model): @@ -239,6 +240,14 @@ class Netz(GeprueftesModel): Standort, on_delete=models.PROTECT, null=True, blank=True, related_name="netze", help_text="Bei VPN-Netzen leer lassen – ein Tunnelnetz gehört beiden Seiten.", ) + farbe = models.CharField( + max_length=7, blank=True, validators=[FARBE_VALIDATOR], + help_text="Linienfarbe im Schaubild (#rrggbb). Leer: Vorgabe je Typ bzw. je VLAN.", + ) + + # Vorgaben für das Schaubild, gut lesbar auf hellem und dunklem Hintergrund + FARBE_JE_TYP = {"transfer": "#a78bfa", "lan": "#22d3ee", "vpn": "#e879f9"} + VLAN_PALETTE = ["#34d399", "#fb923c", "#f472b6", "#60a5fa", "#facc15", "#4ade80", "#f87171", "#2dd4bf"] class Meta: ordering = ["cidr"] @@ -262,6 +271,14 @@ class Netz(GeprueftesModel): def netzwerk(self): return ipaddress.ip_network(self.cidr) + @property + def anzeige_farbe(self): + if self.farbe: + return self.farbe.lower() + if self.typ == self.Typ.VLAN and self.vlan_id: + return self.VLAN_PALETTE[self.vlan_id % len(self.VLAN_PALETTE)] + return self.FARBE_JE_TYP.get(self.typ, "#94a3b8") + def enthaelt(self, ip): return ipaddress.ip_address(ip) in self.netzwerk @@ -337,6 +354,9 @@ class Schnittstelle(GeprueftesModel): name = models.CharField(max_length=30, validators=[validate_slug], help_text="z. B. nic0, net0, WAN, port-3") art = models.CharField(max_length=10, choices=Art.choices) mac = models.CharField("MAC", max_length=17, blank=True) + anbieter = models.CharField( + max_length=50, blank=True, help_text="Nur bei DSL: Internetanbieter, z. B. 1und1.", + ) bridge = models.ForeignKey(Bridge, on_delete=models.SET_NULL, null=True, blank=True, related_name="schnittstellen") vlan_tag = models.PositiveSmallIntegerField("VLAN-Tag", null=True, blank=True, validators=VLAN_VALIDATOREN) @@ -451,6 +471,8 @@ class Schnittstelle(GeprueftesModel): if self.art == self.Art.DSL and geraet and geraet.typ != Geraet.Typ.ROUTER: fehler["art"] = "DSL-Anschlüsse gibt es nur an Routern/Modems." + if self.anbieter and self.art != self.Art.DSL: + fehler["anbieter"] = "Ein Anbieter wird nur am DSL-Anschluss eingetragen." if self.ssid_id and self.art != self.Art.WLAN: fehler["ssid"] = "SSID nur an WLAN-Schnittstellen." diff --git a/inventar/tests.py b/inventar/tests.py index 1f08155..008692e 100644 --- a/inventar/tests.py +++ b/inventar/tests.py @@ -192,6 +192,13 @@ class DSLTests(Homelab): with self.subTest(typ=typ), self.assertRaises(ValidationError): Verbindung.objects.create(a=self.dsl, b=self.nic1, typ=typ) + def test_anbieter_nur_an_dsl(self): + self.dsl.anbieter = "1und1" + self.dsl.save() + with self.assertRaises(ValidationError) as f: + Schnittstelle.objects.create(geraet=self.fritzbox, name="LAN1", art=Schnittstelle.Art.PHYSISCH, anbieter="1und1") + self.assertIn("anbieter", f.exception.message_dict) + def test_dsl_ohne_ip(self): netz = Netz.objects.create(name="T", slug="t", cidr="192.168.5.0/24", typ=Netz.Typ.TRANSFER, standort=self.homelab) with self.assertRaises(ValidationError): @@ -286,6 +293,15 @@ class NetzTests(Homelab): self.netz(standort=None) self.assertIn("standort", f.exception.message_dict) + def test_farbe(self): + self.assertEqual(self.netz().anzeige_farbe, Netz.FARBE_JE_TYP["lan"]) + vlan = self.netz(slug="iot", cidr="10.0.20.0/24", typ=Netz.Typ.VLAN, vlan_id=20) + self.assertEqual(vlan.anzeige_farbe, Netz.VLAN_PALETTE[20 % len(Netz.VLAN_PALETTE)]) + eigen = self.netz(slug="x", cidr="10.0.30.0/24", farbe="#ABCDEF") + self.assertEqual(eigen.anzeige_farbe, "#abcdef") + with self.assertRaises(ValidationError): + self.netz(slug="y", cidr="10.0.40.0/24", farbe="rot") + def test_vlan_netz_braucht_vlan_id(self): with self.assertRaises(ValidationError): self.netz(typ=Netz.Typ.VLAN) diff --git a/static/topologie/schaubild.js b/static/topologie/schaubild.js index 317c56f..ff87cc6 100644 --- a/static/topologie/schaubild.js +++ b/static/topologie/schaubild.js @@ -23,50 +23,111 @@ // --- Darstellung ------------------------------------------------------------ - const STIL = [ - { selector: "node", style: { - "shape": "round-rectangle", "background-color": "#ffffff", - "border-width": 1.5, "border-color": "#6c757d", - "label": "data(label)", "text-wrap": "wrap", "font-size": 11, - "text-valign": "center", "text-halign": "center", - "width": "data(breite)", "height": "data(hoehe)", "padding": 8, - } }, - { selector: ":parent", style: { - "background-color": "#f8f9fa", "border-color": "#adb5bd", - "text-valign": "top", "text-halign": "center", "text-margin-y": -4, - "font-weight": "bold", "padding": 16, - } }, - { selector: "node.hypervisor", style: { "background-color": "#eef4ff", "border-color": "#0d6efd", "border-width": 2 } }, - { selector: "node.gast", style: { "border-color": "#198754" } }, - { selector: "node.bridge", style: { "shape": "ellipse", "background-color": "#fff3cd", "border-color": "#fd7e14", "padding": 10 } }, - { selector: "node.port", style: { "shape": "rectangle", "font-size": 9, "padding": 4, "background-color": "#e9ecef" } }, - { selector: "node.art-dsl", style: { "background-color": "#f8d7da", "border-color": "#dc3545" } }, - { selector: "node.unbenutzt", style: { "border-style": "dashed", "color": "#adb5bd", "border-color": "#ced4da" } }, - { selector: "node.status-geplant", style: { "border-style": "dashed" } }, - { selector: "node.status-auslaufend", style: { "opacity": 0.45 } }, - { selector: "node.zugeklappt", style: { "background-color": "#eef4ff", "border-color": "#0d6efd", "border-width": 3, "font-weight": "bold" } }, - { selector: "node:selected", style: { "border-color": "#0d6efd", "border-width": 3 } }, + // Farben je Thema; Linienfarbe kommt vom Netz (data.farbe), Strichart von der Linienart + const PALETTE = { + dark: { + flaeche: "#0b1120", text: "#e2e8f0", leise: "#94a3b8", rahmen: "#141c2e", rahmenLinie: "#334155", + host: "#0f1a33", hostLinie: "#3b82f6", port: "#1e293b", portLinie: "#475569", neutral: "#64748b", + labelGrund: "#0b1120", auswahl: "#60a5fa", warnung: "#fbbf24", + }, + light: { + flaeche: "#ffffff", text: "#1f2937", leise: "#6b7280", rahmen: "#f8fafc", rahmenLinie: "#cbd5e1", + host: "#eff6ff", hostLinie: "#2563eb", port: "#e5e7eb", portLinie: "#9ca3af", neutral: "#9ca3af", + labelGrund: "#ffffff", auswahl: "#2563eb", warnung: "#b45309", + }, + }; + const ICON_FARBE = { gast: "#34d399", hypervisor: "#60a5fa", bridge: "#fb923c", internet: "#facc15" }; - { selector: "edge", style: { - "curve-style": "bezier", "width": 2, "line-color": "#adb5bd", - "label": "data(label)", "font-size": 9, "color": "#495057", - "text-background-color": "#ffffff", "text-background-opacity": 0.9, "text-background-padding": 2, - } }, - { selector: "edge.kabel", style: { "line-color": "#6c757d", "width": 3 } }, - { selector: "edge.passthrough", style: { "line-color": "#fd7e14", "line-style": "dashed", "width": 3 } }, - { selector: "edge.wlan", style: { "line-style": "dashed", "line-dash-pattern": [4, 4] } }, - { selector: "edge.vpn", style: { "line-color": "#6f42c1", "line-style": "dashed", "width": 3 } }, - { selector: "edge.verwaltet", style: { - "line-style": "dotted", "line-color": "#6c757d", - "target-arrow-shape": "triangle", "target-arrow-color": "#6c757d", - } }, - { selector: "edge.meta", style: { "width": 4 } }, - { selector: "edge:selected", style: { "line-color": "#0d6efd" } }, + const iconTexte = new Map(); // Icon-Name → SVG-Text + const iconCache = new Map(); // "name|farbe" → data-URI - { selector: ".gedimmt", style: { "opacity": 0.12 } }, - { selector: ".ausgeblendet", style: { "display": "none" } }, - { selector: "edge.ohne-label", style: { "label": "" } }, - ]; + function iconUri(name, farbe) { + const schluessel = `${name}|${farbe}`; + if (!iconCache.has(schluessel)) { + const svg = (iconTexte.get(name) || "").replace(/currentColor/g, farbe); + iconCache.set(schluessel, "data:image/svg+xml;utf8," + encodeURIComponent(svg)); + } + return iconCache.get(schluessel); + } + + function thema() { + return document.documentElement.dataset.bsTheme === "light" ? "light" : "dark"; + } + + function stil() { + const p = PALETTE[thema()]; + const iconFarbe = (ele) => { + for (const k of Object.keys(ICON_FARBE)) if (ele.hasClass(k)) return ICON_FARBE[k]; + return p.text; + }; + return [ + { selector: "node", style: { + "shape": "round-rectangle", "background-color": p.port, "border-width": 1, "border-color": p.portLinie, + "label": "data(label)", "text-wrap": "wrap", "font-size": 11, "color": p.text, + "text-valign": "center", "text-halign": "center", + "width": "data(breite)", "height": "data(hoehe)", "padding": 6, + } }, + // Geräte, Gäste, Bridges, Internet: Icon, Name darüber + { selector: "node[icon]", style: { + "width": 34, "height": 34, "padding": 0, "background-opacity": 0, "border-width": 0, + "background-image": (ele) => iconUri(ele.data("icon"), iconFarbe(ele)), + "background-fit": "contain", "background-clip": "none", + "text-valign": "top", "text-margin-y": -6, "text-background-color": p.flaeche, + "text-background-opacity": 0.6, "text-background-padding": 1, + } }, + { selector: "node.gast", style: { "width": 28, "height": 28 } }, + { selector: "node.bridge", style: { "width": 24, "height": 24, "font-size": 10, "color": p.leise } }, + // Rahmen (Hypervisor mit Gästen, Geräte mit Ports) + { selector: ":parent", style: { + "background-image": "none", "background-opacity": 1, "background-color": p.rahmen, + "border-width": 1, "border-color": p.rahmenLinie, "shape": "round-rectangle", + "text-valign": "top", "text-halign": "center", "text-margin-y": -4, + "font-weight": "bold", "padding": 18, "text-background-opacity": 0, + } }, + { selector: "node.hypervisor:parent", style: { "background-color": p.host, "border-color": p.hostLinie, "border-width": 1.5, "color": p.hostLinie } }, + { selector: "node.port", style: { "shape": "round-rectangle", "font-size": 9, "padding": 4 } }, + { selector: "node.art-dsl", style: { "border-color": "#facc15", "color": "#facc15" } }, + { selector: "node.unbenutzt", style: { "border-style": "dashed", "color": p.leise, "background-opacity": 0.4 } }, + { selector: "node.warnung", style: { "color": p.warnung } }, + { selector: "node.status-geplant", style: { "border-width": 1.5, "border-style": "dashed", "border-color": p.leise } }, + { selector: "node.status-auslaufend", style: { "opacity": 0.45 } }, + { selector: "node.zugeklappt", style: { "font-weight": "bold", "color": p.hostLinie } }, + { selector: "node:selected", style: { "overlay-color": p.auswahl, "overlay-opacity": 0.25, "overlay-padding": 6 } }, + + { selector: "edge", style: { + "curve-style": "round-taxi", "taxi-direction": "auto", "taxi-radius": 10, "taxi-turn": "50%", + "width": 2.5, "line-color": (ele) => ele.data("farbe") || p.neutral, + "label": "", "font-size": 9, "color": p.text, "text-wrap": "wrap", + "text-background-color": p.labelGrund, "text-background-opacity": 0.9, "text-background-padding": 2, + } }, + { selector: "edge.kabel", style: { "width": 3.5 } }, + { selector: "edge.passthrough", style: { "line-style": "dashed", "width": 3 } }, + { selector: "edge.wlan", style: { "line-style": "dashed", "line-dash-pattern": [4, 4] } }, + { selector: "edge.vpn", style: { "line-style": "dashed", "width": 3 } }, + { selector: "edge.internet", style: { "width": 3 } }, + { selector: "edge.verwaltet", style: { + "curve-style": "bezier", "line-style": "dotted", "line-color": p.leise, + "target-arrow-shape": "triangle", "target-arrow-color": p.leise, + } }, + { selector: "edge.meta", style: { "width": 4 } }, + { selector: "edge.mit-label, edge.zeige-label, edge:selected", style: { "label": "data(label)" } }, + { selector: "edge:selected", style: { "overlay-color": p.auswahl, "overlay-opacity": 0.2, "overlay-padding": 4 } }, + + { selector: ".gedimmt", style: { "opacity": 0.12 } }, + { selector: ".ausgeblendet", style: { "display": "none" } }, + ]; + } + + function themaAnwenden() { + document.getElementById("schaubild").style.background = PALETTE[thema()].flaeche; + if (cy) cy.style(stil()); + } + + function iconsLaden(namen) { + return Promise.all([...namen].map((name) => + fetch(`${URLS.icons}${name}.svg`).then((r) => (r.ok ? r.text() : "")).then((t) => iconTexte.set(name, t)) + )); + } // --- Hilfen ----------------------------------------------------------------- @@ -183,10 +244,12 @@ const schluessel = `meta:${q}|${z}|${e.classes}`; if (!meta.has(schluessel)) { meta.set(schluessel, { group: "edges", classes: `${e.classes} meta`, - data: { id: schluessel, source: q, target: z, labels: [], info: [["Art", "zusammengefasst"]], url: "" } }); + data: { id: schluessel, source: q, target: z, labels: [], netze: [], farbe: e.data.farbe, + info: [["Art", "zusammengefasst"]], url: "" } }); } const m = meta.get(schluessel); if (!m.data.labels.includes(e.data.label)) m.data.labels.push(e.data.label); + (e.data.netze || []).forEach((n) => { if (!m.data.netze.includes(n)) m.data.netze.push(n); }); m.data.info.push(["Linie", `${e.data.source} → ${e.data.target}`]); }); meta.forEach((m) => { m.data.label = m.data.labels.join("\n"); kanten.push(m); }); @@ -219,8 +282,15 @@ versatz.set(parent, i); pos = { x: b.x + 70 * (i - 1), y: b.y + 50 }; } else { - pos = { x: rechts, y: Number.isFinite(bb.y1) ? bb.y1 : 0 }; - rechts += 160; + // ohne Rahmen: über einen platzierten Nachbarn (z. B. Internet über dem DSL-Port), sonst rechts daneben + const nachbar = n.neighborhood("node").filter((x) => positionen.has(x.id()) || x.isParent())[0]; + if (nachbar) { + const np = nachbar.isParent() ? nachbar.position() : positionen.get(nachbar.id()); + pos = { x: np.x, y: np.y - 110 }; + } else { + pos = { x: rechts, y: Number.isFinite(bb.y1) ? bb.y1 : 0 }; + rechts += 160; + } } n.position(pos); positionen.set(n.id(), pos); @@ -276,13 +346,12 @@ const netz = document.getElementById("filter-netz").value; if (netz) { - const passend = cy.edges().filter((e) => (e.data("label") || "").includes(netz)); + const passend = cy.edges().filter((e) => (e.data("netze") || []).includes(netz)); const behalten = passend.union(passend.connectedNodes()).union(passend.connectedNodes().ancestors()); cy.elements().not(behalten).addClass("gedimmt"); } - const ohneLabel = !document.getElementById("beschriftung").checked; - cy.edges().toggleClass("ohne-label", ohneLabel); + cy.edges().toggleClass("mit-label", document.getElementById("beschriftung").checked); } // --- Details ---------------------------------------------------------------- @@ -339,6 +408,9 @@ function ereignisse() { cy.on("tap", "node, edge", (e) => details(e.target)); + cy.on("mouseover", "edge", (e) => e.target.addClass("zeige-label")); + cy.on("mouseout", "edge", (e) => e.target.removeClass("zeige-label")); + window.addEventListener("themawechsel", themaAnwenden); cy.on("dbltap", "node.hypervisor", (e) => umschalten(e.target.id())); cy.on("grab", "node", (e) => { griff = { ...e.target.position() }; }); @@ -413,8 +485,12 @@ const auswahl = document.getElementById("filter-netz"); daten.netze.forEach((cidr) => auswahl.add(new Option(cidr, cidr))); + return iconsLaden(new Set([...alle.knoten.values()].map((k) => k.data.icon).filter(Boolean))).then(() => daten); + }) + .then(() => { const ersterAufruf = positionen.size === 0; - cy = cytoscape({ container: document.getElementById("schaubild"), style: STIL }); + themaAnwenden(); + cy = cytoscape({ container: document.getElementById("schaubild"), style: stil() }); cy.add(sichtbareElemente()); ereignisse(); if (ersterAufruf) { diff --git a/static/vendor/bootstrap-icons/LICENSE b/static/vendor/bootstrap-icons/LICENSE new file mode 100644 index 0000000..f952439 --- /dev/null +++ b/static/vendor/bootstrap-icons/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2019-2024 The Bootstrap Authors + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/static/vendor/bootstrap-icons/VERSION b/static/vendor/bootstrap-icons/VERSION new file mode 100644 index 0000000..f42d743 --- /dev/null +++ b/static/vendor/bootstrap-icons/VERSION @@ -0,0 +1 @@ +Bootstrap Icons 1.13.2 (MIT), nur benötigte Icons diff --git a/static/vendor/bootstrap-icons/box.svg b/static/vendor/bootstrap-icons/box.svg new file mode 100644 index 0000000..01b34c7 --- /dev/null +++ b/static/vendor/bootstrap-icons/box.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/broadcast-pin.svg b/static/vendor/bootstrap-icons/broadcast-pin.svg new file mode 100644 index 0000000..9c5f4a6 --- /dev/null +++ b/static/vendor/bootstrap-icons/broadcast-pin.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/cpu.svg b/static/vendor/bootstrap-icons/cpu.svg new file mode 100644 index 0000000..88c0d56 --- /dev/null +++ b/static/vendor/bootstrap-icons/cpu.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/diagram-3.svg b/static/vendor/bootstrap-icons/diagram-3.svg new file mode 100644 index 0000000..ee3fd6f --- /dev/null +++ b/static/vendor/bootstrap-icons/diagram-3.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/display.svg b/static/vendor/bootstrap-icons/display.svg new file mode 100644 index 0000000..40a7d4d --- /dev/null +++ b/static/vendor/bootstrap-icons/display.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/globe2.svg b/static/vendor/bootstrap-icons/globe2.svg new file mode 100644 index 0000000..b302063 --- /dev/null +++ b/static/vendor/bootstrap-icons/globe2.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/hdd-network.svg b/static/vendor/bootstrap-icons/hdd-network.svg new file mode 100644 index 0000000..7223542 --- /dev/null +++ b/static/vendor/bootstrap-icons/hdd-network.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/hdd-rack.svg b/static/vendor/bootstrap-icons/hdd-rack.svg new file mode 100644 index 0000000..d19a514 --- /dev/null +++ b/static/vendor/bootstrap-icons/hdd-rack.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/laptop.svg b/static/vendor/bootstrap-icons/laptop.svg new file mode 100644 index 0000000..8e71020 --- /dev/null +++ b/static/vendor/bootstrap-icons/laptop.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/lightbulb.svg b/static/vendor/bootstrap-icons/lightbulb.svg new file mode 100644 index 0000000..67bf5bd --- /dev/null +++ b/static/vendor/bootstrap-icons/lightbulb.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/pc-display.svg b/static/vendor/bootstrap-icons/pc-display.svg new file mode 100644 index 0000000..c3cf9dd --- /dev/null +++ b/static/vendor/bootstrap-icons/pc-display.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/phone.svg b/static/vendor/bootstrap-icons/phone.svg new file mode 100644 index 0000000..4839331 --- /dev/null +++ b/static/vendor/bootstrap-icons/phone.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/printer.svg b/static/vendor/bootstrap-icons/printer.svg new file mode 100644 index 0000000..0886a57 --- /dev/null +++ b/static/vendor/bootstrap-icons/printer.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/router.svg b/static/vendor/bootstrap-icons/router.svg new file mode 100644 index 0000000..62fac78 --- /dev/null +++ b/static/vendor/bootstrap-icons/router.svg @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/static/vendor/bootstrap-icons/window-stack.svg b/static/vendor/bootstrap-icons/window-stack.svg new file mode 100644 index 0000000..8862976 --- /dev/null +++ b/static/vendor/bootstrap-icons/window-stack.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/templates/base.html b/templates/base.html index 1aa592b..797f807 100644 --- a/templates/base.html +++ b/templates/base.html @@ -1,33 +1,48 @@ {% load static %} - + {% block title %}Netzwerk Planer{% endblock %} + -