SPB Git

Repository Public

DashboardView.swift 7.4 KB 150 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : MacLustr Storage Node9// File             : MacLustrStorageNode/Features/Dashboard/DashboardView.swift10// Description      : State of the node at a glance. Every figure comes from the11//                    engine's live snapshot.12// Module           : MacLustrStorageNode13// Repository       : https://git.spboucher.ai/maclustr-storage-ios14// Project Website  : https://storage.spboucher.ai15// Created          : 2026-12-0116// Last Modified    : 2026-12-0117//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author           : Simon-Pierre Boucher23// Position         : Professor of Finance24// Institution      : Université du Québec en Outaouais (UQO)25// Department       : Département des sciences administratives26// Organization     : SP Boucher27//28// Website          : https://spboucher.ai29// Git              : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General          : info@spboucher.ai36// Professional     : contact@spboucher.ai37// Direct           : simon@spboucher.ai38// Research         : research@spboucher.ai39// Development      : dev@spboucher.ai40// Support          : support@spboucher.ai41// Security/Admin   : admin@spboucher.ai42// Notifications    : notifications@spboucher.ai43//44// Preferred Contact: admin@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification   : Public69// Distribution     : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License          : None specified (no license file in this repository)83// Maintainer       : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import SwiftUI9192struct DashboardView: View {93    @EnvironmentObject private var node: NodeController9495    var body: some View {96        let s = node.snapshot, cap = s.capacity97        Page(title: node.settings.nodeName.isEmpty ? "Storage Node" : node.settings.nodeName) {98            Panel {99                HStack {100                    StateBadge(text: s.stateLabel, color: s.stateColor)101                    Spacer()102                    if s.connection == .online { Text(s.path == .lan ? "Local network" : "Gateway").font(.footnote).foregroundStyle(Theme.textTertiary) }103                }104                if let why = s.pauseExplanation, s.connection != .offline || s.pauseReason == "offline" { Text(why).font(.footnote).foregroundStyle(Theme.warning) }105                if let err = s.lastError, s.connection == .offline { Text(err).font(.caption).foregroundStyle(Theme.textTertiary).lineLimit(2) }106                if let d = s.drain {107                    Text("\(d.remainingFragments) fragment(s), \(Format.bytes(d.remainingBytes)) still to hand back" + (d.awaitingStableCopy > 0 ? " · \(d.awaitingStableCopy) waiting for the cluster to rebuild its own copy" : ""))108                        .font(.footnote).foregroundStyle(Theme.textSecondary)109                }110            }111            Panel(title: "Capacity") {112                HStack(alignment: .firstTextBaseline, spacing: 6) {113                    Text(Format.bytes(cap.used)).font(.system(size: 34, weight: .semibold).monospacedDigit()).foregroundStyle(Theme.text)114                    Text("of \(Format.bytes(cap.quota)) allocated").font(.subheadline).foregroundStyle(Theme.textSecondary)115                }116                SegmentBar(segments: [.init(value: cap.used, color: Theme.accent), .init(value: cap.quotaRemaining, color: Theme.accentMuted)])117                HStack(alignment: .top) {118                    Metric(label: "Available to the cluster now", value: Format.bytes(s.accepting ? cap.writable : 0))119                    Metric(label: "Fragments", value: "\(cap.fragments)")120                }121            }122            Panel(title: "Transfers") {123                HStack(alignment: .top) {124                    Metric(label: "Receiving", value: Format.rate(s.rxBps))125                    Metric(label: "Sending", value: Format.rate(s.txBps))126                }127                HStack(alignment: .top) {128                    TimelineView(.periodic(from: .now, by: 5)) { _ in Metric(label: "Last sync", value: Format.relative(s.lastSync)) }129                    Metric(label: "Active / waiting", value: "\(s.active.count) / \(s.pendingOnServer)")130                }131            }132            Panel(title: "Device") {133                HStack(alignment: .top) {134                    Metric(label: "Reachable, last 24 h", value: Format.percent(s.availability24h))135                    Metric(label: "Thermal state", value: s.thermalLabel, tone: s.thermalColor)136                }137                HStack(alignment: .top) {138                    Metric(label: "Power", value: s.battery.map { String(format: "%.0f %%", $0 * 100) + (s.charging ? " · charging" : "") } ?? (s.charging ? "Charging" : "—"))139                    Metric(label: "Network", value: s.network == "wifi" ? "Wi-Fi" : s.network.capitalized)140                }141            }142            Button { node.enterStation() } label: { Label("Enter station mode", systemImage: "server.rack").frame(maxWidth: .infinity) }143                .buttonStyle(.bordered).controlSize(.large)144            Text("Station mode keeps a dimmed status screen up for a device left plugged in as a dedicated node.")145                .font(.caption).foregroundStyle(Theme.textTertiary).frame(maxWidth: .infinity, alignment: .leading)146        }147        .refreshable { await node.syncNow() }148    }149}150
Files main
Menu

Theme