SPB Git

Repository Public

ActivityView.swift 9.2 KB 190 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : MacLustr Storage Node9// File             : MacLustrStorageNode/Features/Activity/ActivityView.swift10// Description      : Activity: transfers in progress, what waits on the11//                    cluster, totals, history, errors and integrity checks.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 ActivityView: View {93    @EnvironmentObject private var node: NodeController94    @State private var filter = 09596    private var entries: [ActivityEntry] {97        switch filter {98        case 1: return node.activity.filter { [.stored, .returned, .deleted].contains($0.kind) }99        case 2: return node.activity.filter { [.verified, .integrity].contains($0.kind) }100        case 3: return node.activity.filter { !$0.ok || $0.kind == .error }101        default: return node.activity102        }103    }104105    var body: some View {106        let s = node.snapshot107        Page(title: "Activity") {108            Panel(title: "In progress") {109                if s.active.isEmpty { Text("No transfer in progress.").font(.subheadline).foregroundStyle(Theme.textSecondary) }110                ForEach(s.active) { t in111                    VStack(alignment: .leading, spacing: 5) {112                        HStack {113                            Image(systemName: t.op == .retrieve ? "arrow.up" : "arrow.down").font(.caption.weight(.bold)).foregroundStyle(Theme.accent)114                            Text(t.fragment.prefix(12) + "…").font(.system(.footnote, design: .monospaced)).foregroundStyle(Theme.text)115                            Spacer()116                            Text("\(Format.bytes(t.done)) / \(Format.bytes(t.size)) · \(t.path == .lan ? "LAN" : "gateway")").font(.caption.monospacedDigit()).foregroundStyle(Theme.textTertiary)117                        }118                        ProgressView(value: Double(min(t.done, t.size)), total: Double(max(t.size, 1))).tint(Theme.accent)119                    }120                }121                HStack(alignment: .top) {122                    Metric(label: "Waiting on the cluster", value: "\(s.pendingOnServer)")123                    Metric(label: "Errors", value: "\(node.activity.filter { !$0.ok }.count)", tone: node.activity.contains { !$0.ok } ? Theme.warning : Theme.text)124                }125            }126            Panel(title: "Totals since pairing") {127                HStack(alignment: .top) {128                    Metric(label: "Received", value: Format.bytes(s.totalReceived))129                    Metric(label: "Returned", value: Format.bytes(s.totalSent))130                }131                HStack(alignment: .top) {132                    Metric(label: "Integrity checks passed", value: "\(s.verifyOK)")133                    Metric(label: "Failed", value: "\(s.verifyFailed)", tone: s.verifyFailed > 0 ? Theme.critical : Theme.text)134                }135                Text("Last local scrub: \(Format.relative(s.lastScrub))").font(.caption).foregroundStyle(Theme.textTertiary)136            }137            Panel(title: "History") {138                Picker("Filter", selection: $filter) { Text("All").tag(0); Text("Transfers").tag(1); Text("Integrity").tag(2); Text("Errors").tag(3) }.pickerStyle(.segmented)139                if entries.isEmpty { Text("Nothing yet.").font(.subheadline).foregroundStyle(Theme.textSecondary) }140                ForEach(entries.prefix(150)) { e in141                    HStack(alignment: .top, spacing: 10) {142                        Image(systemName: icon(e)).font(.footnote).foregroundStyle(e.ok ? Theme.textSecondary : Theme.critical).frame(width: 18)143                        VStack(alignment: .leading, spacing: 2) {144                            Text(title(e)).font(.subheadline).foregroundStyle(Theme.text)145                            if !subtitle(e).isEmpty { Text(subtitle(e)).font(.caption).foregroundStyle(Theme.textTertiary).fixedSize(horizontal: false, vertical: true) }146                        }147                        Spacer(minLength: 6)148                        Text(e.date, style: .time).font(.caption.monospacedDigit()).foregroundStyle(Theme.textTertiary)149                    }150                    .accessibilityElement(children: .combine)151                }152            }153        }154        .task { await node.reloadActivity() }155        .onChange(of: s.capacity.fragments) { _ in Task { await node.reloadActivity() } }156        .onChange(of: s.lastSync) { _ in Task { await node.reloadActivity() } }157        .refreshable { await node.syncNow() }158    }159160    private func icon(_ e: ActivityEntry) -> String {161        switch e.kind {162        case .stored: return "arrow.down.circle"163        case .returned: return "arrow.up.circle"164        case .verified: return "checkmark.seal"165        case .deleted: return "trash"166        case .integrity: return "exclamationmark.shield"167        case .error: return "exclamationmark.triangle"168        case .system: return "gearshape"169        }170    }171    private func title(_ e: ActivityEntry) -> String {172        switch e.kind {173        case .stored: return "Fragment stored · \(Format.bytes(e.bytes))"174        case .returned: return "Fragment returned · \(Format.bytes(e.bytes))"175        case .verified: return "Integrity verified"176        case .deleted: return "Fragment deleted · \(Format.bytes(e.bytes))"177        case .integrity: return "Integrity failure"178        case .error: return "Error"179        case .system: return e.detail180        }181    }182    private func subtitle(_ e: ActivityEntry) -> String {183        var parts: [String] = []184        if !e.fragment.isEmpty { parts.append(String(e.fragment.prefix(12)) + "…") }185        if e.kind != .system, !e.detail.isEmpty { parts.append(e.detail == "lan" ? "local network" : e.detail) }186        if e.millis > 0, e.bytes > 0, [.stored, .returned].contains(e.kind) { parts.append(String(format: "%.1f MB/s", Double(e.bytes) / 1_000_000 / (Double(e.millis) / 1000))) }187        return parts.joined(separator: " · ")188    }189}190
Files main
Menu

Theme