SPB Git

Repository Public

AllocationView.swift 7.2 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/Allocation/AllocationView.swift10// Description      : Storage Allocation: how the device's storage is split, and11//                    the quota lent to the cluster.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 AllocationView: View {93    @EnvironmentObject private var node: NodeController94    @State private var quota: Int64 = 095    @State private var saving = false9697    var body: some View {98        let cap = node.snapshot.capacity99        Page(title: "Storage Allocation") {100            Panel(title: "This device · \(Format.bytes(cap.total))") {101                SegmentBar(segments: [102                    .init(value: cap.personalAndSystem, color: Theme.personal),103                    .init(value: cap.used, color: Theme.accent),104                    .init(value: min(cap.quotaRemaining, cap.free), color: Theme.accentMuted),105                    .init(value: max(0, cap.free - min(cap.quotaRemaining, cap.free)), color: Theme.inset),106                ], height: 22)107                .overlay(RoundedRectangle(cornerRadius: 3).stroke(Theme.border, lineWidth: 1))108                legend(Theme.personal, "Personal and system", cap.personalAndSystem)109                legend(Theme.accent, "MacLustr, used", cap.used)110                legend(Theme.accentMuted, "MacLustr, remaining in the quota", cap.quotaRemaining)111                legend(Theme.inset, "Free, not allocated", cap.unallocatedFree, outlined: true)112                Divider().overlay(Theme.borderSubtle)113                HStack(alignment: .top) {114                    Metric(label: "Free on the device", value: Format.bytes(cap.free))115                    Metric(label: "Safety reserve", value: Format.bytes(cap.reserve))116                }117                if cap.quotaRemaining > max(0, cap.free - cap.reserve) {118                    Text("Only \(Format.bytes(cap.writable)) of the remaining quota can be used today: the rest would eat into the safety reserve.")119                        .font(.footnote).foregroundStyle(Theme.warning)120                }121            }122            Panel(title: "Capacity lent to the cluster") {123                QuotaPicker(quota: $quota, capacity: cap)124                if quota < cap.used {125                    Text("Below what is stored now (\(Format.bytes(cap.used))): the cluster will take back fragments until the device fits the new limit.")126                        .font(.footnote).foregroundStyle(Theme.warning)127                }128                Button {129                    saving = true130                    Task { var s = node.settings; s.quotaBytes = quota; await node.save(s); saving = false }131                } label: { Text(saving ? "Applying…" : "Apply").frame(maxWidth: .infinity) }132                    .buttonStyle(.borderedProminent).controlSize(.large).disabled(saving || quota == node.settings.quotaBytes)133                Text("Nothing is reserved in advance: space is taken as fragments arrive, and writes stop as soon as free space reaches the reserve.")134                    .font(.caption).foregroundStyle(Theme.textTertiary)135            }136        }137        .onAppear { quota = node.settings.quotaBytes }138    }139140    private func legend(_ color: Color, _ label: String, _ value: Int64, outlined: Bool = false) -> some View {141        HStack(spacing: 10) {142            RoundedRectangle(cornerRadius: 2).fill(color).frame(width: 12, height: 12).overlay(RoundedRectangle(cornerRadius: 2).stroke(Theme.border, lineWidth: outlined ? 1 : 0))143            Text(label).font(.subheadline).foregroundStyle(Theme.textSecondary)144            Spacer()145            Text(Format.bytes(value)).font(.subheadline.monospacedDigit()).foregroundStyle(Theme.text)146        }147        .accessibilityElement(children: .combine)148    }149}150
Files main
Menu

Theme