Files
RouterOS/RouterOSAssistant/Core/Models/OverviewGraph.swift
T
KayandClaude Sonnet 5 10f30a8a7f M11: Übersicht-Tab — IST-Zustand-Diagramm des Routers
Neuer Tab zeigt die komplette aktuelle Router-Konfiguration als grafisches
Diagramm: Interfaces, IP-Adressen, DHCP/Pools, Routen und Firewall/NAT in
Spalten, verbunden durch Linien, die RouterOS' eigene Referenzfelder
abbilden (VLAN->Basis-Interface, DHCP-Server->Pool, Firewall-Regel->
Interface/Adress-Liste usw.), nicht geraten. Rein lesend, kein apply().

Verbindungsarten sind farblich getrennt (8 Kategorien), Hover/Klick auf
eine Karte hebt ihre Linien hervor und blendet den Rest ab. Detail-Panel
zeigt Rohfelder + Verbindungen; Legende erklärt Spalten, Farben und listet
bewusst nicht gegraphte Bereiche (VPN, WLAN-Sicherheitsprofile, Queues,
System, Werkzeuge, Mangle/Raw), die weiterhin im Experte-Tab erreichbar
bleiben.

OverviewViewModel.buildGraph ist eine reine, nonisolated Funktion,
getestet in OverviewGraphTests (6 Fälle: IP/Interface, VLAN-Parent,
DHCP->Pool, DHCP-Netzwerk->passende IP-Adresse über RouterOS' eigenes
"network"-Feld, Route nur bei Interface-Gateway, Firewall->Interface/
Adress-Liste).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CTgRxJTzaQwaRkngbaE1GJ
2026-09-14 10:05:39 +02:00

73 lines
3.0 KiB
Swift

import Foundation
/// One box in the Übersicht diagram — an interface, IP address, DHCP server, firewall rule etc.
/// `kind` is a finer-grained tag than `category` (e.g. "vlan" vs "bridge" within the interface
/// category) used only to pick an icon/color, never for graph logic.
struct OverviewNode: Identifiable, Equatable {
enum Category: String, CaseIterable, Identifiable {
case interface = "Interfaces"
case ipAddress = "IP-Adressen"
case service = "Pools & DHCP"
case route = "Routen"
case firewall = "Firewall & NAT"
var id: String { rawValue }
}
let id: String
let category: Category
let kind: String
let title: String
let subtitle: String?
/// Full raw fields, shown in the detail panel when this node is selected.
let detail: [(key: String, value: String)]
static func == (lhs: OverviewNode, rhs: OverviewNode) -> Bool {
lhs.id == rhs.id && lhs.category == rhs.category && lhs.kind == rhs.kind
&& lhs.title == rhs.title && lhs.subtitle == rhs.subtitle
&& lhs.detail.map(\.key) == rhs.detail.map(\.key) && lhs.detail.map(\.value) == rhs.detail.map(\.value)
}
}
/// What kind of dependency an edge represents — drives its color in the diagram, so different
/// relationship types (a VLAN's parent link vs. a firewall rule's interface) are visually
/// distinct at a glance, not just distinguishable by hovering.
enum OverviewEdgeKind: String, CaseIterable, Identifiable {
case vlan = "VLAN → Basis-Interface"
case bridgePort = "Bridge-Port"
case wireguardPeer = "WireGuard-Peer"
case ipAddress = "Interface → IP-Adresse"
case dhcp = "DHCP / Pool"
case route = "Route → Interface"
case firewallInterface = "Firewall/NAT → Interface"
case addressList = "Adress-Liste → Regel"
var id: String { rawValue }
}
/// One line in the diagram, always drawn from an earlier column to a later one (or within a
/// column) — direction follows the actual dependency (e.g. an interface "carries" an IP address,
/// a DHCP server "uses" a pool), not just which menu was read first.
struct OverviewEdge: Identifiable, Equatable {
var id: String { "\(from)->\(to)>\(label ?? "")" }
let from: String
let to: String
let label: String?
let kind: OverviewEdgeKind
}
struct OverviewGraph: Equatable {
var nodes: [OverviewNode] = []
var edges: [OverviewEdge] = []
/// Router areas that exist but aren't part of this topology diagram (VPN-Benutzer, WLAN-
/// Sicherheitsprofile, Queues, System, Werkzeuge — none of them wire into the interface/IP/
/// firewall dependency chain this diagram is about). Listed so nothing is silently hidden;
/// full access to all of them stays in the Experte-Tab.
static let unmappedAreas = [
"VPN: PPP-Benutzer/-Profile", "WLAN-Sicherheitsprofile", "Queues/Bandbreiten-Steuerung",
"System (Name/Uhrzeit/Scheduler/Skripte/Benutzerkonten)", "Werkzeuge (Netwatch/E-Mail)",
"Firewall: Mangle- und Raw-Regeln"
]
}