PDF BOM export
This commit is contained in:
@@ -7,18 +7,30 @@
|
||||
|
||||
|
||||
import Foundation
|
||||
import PostHog
|
||||
import UIKit
|
||||
|
||||
class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
func application(_: UIApplication, didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
|
||||
let POSTHOG_API_KEY = "phc_icZY61N3vdg4Sr3lzz9DNAqCRh6hCorVJbytduWORO9"
|
||||
let POSTHOG_HOST = "https://eu.i.posthog.com"
|
||||
|
||||
let config = PostHogConfig(apiKey: POSTHOG_API_KEY, host: POSTHOG_HOST)
|
||||
|
||||
PostHogSDK.shared.setup(config)
|
||||
AnalyticsTracker.configure()
|
||||
NSLog("Launched")
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
enum AnalyticsTracker {
|
||||
static func configure() {}
|
||||
|
||||
static func log(_ event: String, properties: [String: Any] = [:]) {
|
||||
#if DEBUG
|
||||
if properties.isEmpty {
|
||||
NSLog("Analytics: %@", event)
|
||||
} else {
|
||||
let formatted = properties
|
||||
.map { "\($0.key)=\($0.value)" }
|
||||
.sorted()
|
||||
.joined(separator: ", ")
|
||||
NSLog("Analytics: %@ { %@ }", event, formatted)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,29 @@
|
||||
"bom.navigation.title.system" = "BOM – %@";
|
||||
"bom.size.unknown" = "Size TBD";
|
||||
"bom.terminals.detail" = "Ring or spade terminals sized for %@ wiring";
|
||||
"bom.empty.message" = "No components saved in this system yet.";
|
||||
"bom.export.pdf.button" = "Export PDF";
|
||||
"bom.export.pdf.error.title" = "Export Failed";
|
||||
"bom.export.pdf.error.empty" = "Add at least one component before exporting.";
|
||||
"bom.pdf.header.title" = "System Bill of Materials";
|
||||
"bom.pdf.header.subtitle" = "%@ • %@";
|
||||
"bom.pdf.header.inline" = "Unit System: %@";
|
||||
"bom.pdf.placeholder.empty" = "No components available.";
|
||||
"bom.pdf.page.number" = "Page %d";
|
||||
"bom.category.components.title" = "Components & Chargers";
|
||||
"bom.category.components.subtitle" = "Primary devices, controllers, and charging gear.";
|
||||
"bom.category.batteries.title" = "Batteries";
|
||||
"bom.category.batteries.subtitle" = "House banks and storage.";
|
||||
"bom.category.cables.title" = "Cables";
|
||||
"bom.category.cables.subtitle" = "Sized power runs for every circuit.";
|
||||
"bom.category.fuses.title" = "Fuses";
|
||||
"bom.category.fuses.subtitle" = "Circuit protection and holders.";
|
||||
"bom.category.accessories.title" = "Accessories";
|
||||
"bom.category.accessories.subtitle" = "Fuses, lugs, and supporting hardware.";
|
||||
"bom.cable.detail.quantified" = "%1$dx %2$@";
|
||||
"bom.quantity.count.badge" = "%d×";
|
||||
"bom.quantity.length.badge" = "%1$.1f %2$@";
|
||||
"bom.quantity.length.badge.with.spec" = "%1$.1f %2$@ · %3$@";
|
||||
"cable.pro.privacy.label" = "Privacy";
|
||||
"cable.pro.privacy.url" = "https://voltplan.app/privacy";
|
||||
"cable.pro.terms.label" = "Terms";
|
||||
@@ -277,6 +300,7 @@
|
||||
"cable.pro.alert.restored.body" = "Your purchases are available again.";
|
||||
"cable.pro.alert.error.title" = "Purchase Failed";
|
||||
"cable.pro.alert.error.generic" = "Something went wrong. Please try again.";
|
||||
"generic.ok" = "OK";
|
||||
"cable.pro.trial.badge" = "Includes a %@ free trial";
|
||||
"cable.pro.subscription.renews" = "Renews %@.";
|
||||
"cable.pro.subscription.trialThenRenews" = "Free trial, then renews %@.";
|
||||
|
||||
@@ -37,7 +37,7 @@ struct CableApp: App {
|
||||
_unitSettings = StateObject(wrappedValue: unitSettings)
|
||||
_storeKitManager = StateObject(wrappedValue: StoreKitManager(unitSettings: unitSettings))
|
||||
#if DEBUG
|
||||
UITestSampleData.prepareIfNeeded(container: sharedModelContainer)
|
||||
UITestSampleData.handleLaunchArguments(container: sharedModelContainer)
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ final class SavedCharger {
|
||||
var remoteIconURLString: String?
|
||||
var affiliateURLString: String?
|
||||
var affiliateCountryCode: String?
|
||||
var bomCompletedItemIDs: [String] = []
|
||||
var identifier: String
|
||||
|
||||
init(
|
||||
@@ -32,6 +33,7 @@ final class SavedCharger {
|
||||
remoteIconURLString: String? = nil,
|
||||
affiliateURLString: String? = nil,
|
||||
affiliateCountryCode: String? = nil,
|
||||
bomCompletedItemIDs: [String] = [],
|
||||
identifier: String = UUID().uuidString
|
||||
) {
|
||||
self.id = id
|
||||
@@ -47,6 +49,7 @@ final class SavedCharger {
|
||||
self.remoteIconURLString = remoteIconURLString
|
||||
self.affiliateURLString = affiliateURLString
|
||||
self.affiliateCountryCode = affiliateCountryCode
|
||||
self.bomCompletedItemIDs = bomCompletedItemIDs
|
||||
self.identifier = identifier
|
||||
}
|
||||
|
||||
|
||||
@@ -34,31 +34,12 @@ class CableCalculator: ObservableObject {
|
||||
}
|
||||
|
||||
func recommendedCrossSection(for unitSystem: UnitSystem) -> Double {
|
||||
let lengthInMeters = unitSystem == .metric ? length : length * 0.3048 // ft to m
|
||||
// Simplified calculation: minimum cross-section based on current and voltage drop
|
||||
let maxVoltageDrop = voltage * 0.05 // 5% voltage drop limit
|
||||
let resistivity = 0.017 // Copper resistivity at 20°C (Ω⋅mm²/m)
|
||||
let calculatedMinCrossSection = (2 * current * lengthInMeters * resistivity) / maxVoltageDrop
|
||||
|
||||
if unitSystem == .imperial {
|
||||
// Standard AWG wire sizes
|
||||
let standardAWG = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 0, 00, 000, 0000]
|
||||
let awgCrossSections = [0.519, 0.823, 1.31, 2.08, 3.31, 5.26, 8.37, 13.3, 21.2, 33.6, 42.4, 53.5, 67.4, 85.0, 107.0]
|
||||
|
||||
// Find the smallest AWG that meets the requirement
|
||||
for (index, crossSection) in awgCrossSections.enumerated() {
|
||||
if crossSection >= calculatedMinCrossSection {
|
||||
return Double(standardAWG[index])
|
||||
}
|
||||
}
|
||||
return Double(standardAWG.last!) // Largest available
|
||||
} else {
|
||||
// Standard metric cable cross-sections in mm²
|
||||
let standardSizes = [0.75, 1.0, 1.5, 2.5, 4.0, 6.0, 10.0, 16.0, 25.0, 35.0, 50.0, 70.0, 95.0, 120.0, 150.0, 185.0, 240.0, 300.0, 400.0, 500.0, 630.0]
|
||||
|
||||
// Find the smallest standard size that meets the requirement
|
||||
return standardSizes.first { $0 >= max(0.75, calculatedMinCrossSection) } ?? standardSizes.last!
|
||||
}
|
||||
ElectricalCalculations.recommendedCrossSection(
|
||||
length: length,
|
||||
current: current,
|
||||
voltage: voltage,
|
||||
unitSystem: unitSystem
|
||||
)
|
||||
}
|
||||
|
||||
func crossSection(for unitSystem: UnitSystem) -> Double {
|
||||
@@ -66,42 +47,34 @@ class CableCalculator: ObservableObject {
|
||||
}
|
||||
|
||||
func voltageDrop(for unitSystem: UnitSystem) -> Double {
|
||||
let lengthInMeters = unitSystem == .metric ? length : length * 0.3048
|
||||
let crossSectionMM2 = unitSystem == .metric ? crossSection(for: unitSystem) : crossSectionFromAWG(crossSection(for: unitSystem))
|
||||
let resistivity = 0.017
|
||||
let effectiveCurrent = current // Always use the current property which gets updated
|
||||
return (2 * effectiveCurrent * lengthInMeters * resistivity) / crossSectionMM2
|
||||
ElectricalCalculations.voltageDrop(
|
||||
length: length,
|
||||
current: current,
|
||||
voltage: voltage,
|
||||
unitSystem: unitSystem
|
||||
)
|
||||
}
|
||||
|
||||
func voltageDropPercentage(for unitSystem: UnitSystem) -> Double {
|
||||
(voltageDrop(for: unitSystem) / voltage) * 100
|
||||
ElectricalCalculations.voltageDropPercentage(
|
||||
length: length,
|
||||
current: current,
|
||||
voltage: voltage,
|
||||
unitSystem: unitSystem
|
||||
)
|
||||
}
|
||||
|
||||
func powerLoss(for unitSystem: UnitSystem) -> Double {
|
||||
let effectiveCurrent = current
|
||||
return effectiveCurrent * voltageDrop(for: unitSystem)
|
||||
ElectricalCalculations.powerLoss(
|
||||
length: length,
|
||||
current: current,
|
||||
voltage: voltage,
|
||||
unitSystem: unitSystem
|
||||
)
|
||||
}
|
||||
|
||||
var recommendedFuse: Int {
|
||||
let targetFuse = current * 1.25 // 125% of load current for safety
|
||||
|
||||
// Common fuse values in amperes
|
||||
let standardFuses = [1, 2, 3, 5, 7, 10, 15, 20, 25, 30, 35, 40, 50, 60, 70, 80, 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500, 600, 700, 800]
|
||||
|
||||
// Find the smallest standard fuse that's >= target
|
||||
return standardFuses.first { $0 >= Int(targetFuse.rounded(.up)) } ?? standardFuses.last!
|
||||
}
|
||||
|
||||
// AWG conversion helper for voltage drop calculations
|
||||
private func crossSectionFromAWG(_ awg: Double) -> Double {
|
||||
let awgSizes = [20: 0.519, 18: 0.823, 16: 1.31, 14: 2.08, 12: 3.31, 10: 5.26, 8: 8.37, 6: 13.3, 4: 21.2, 2: 33.6, 1: 42.4, 0: 53.5]
|
||||
|
||||
// Handle 00, 000, 0000 AWG (represented as negative values)
|
||||
if awg == 00 { return 67.4 }
|
||||
if awg == 000 { return 85.0 }
|
||||
if awg == 0000 { return 107.0 }
|
||||
|
||||
return awgSizes[Int(awg)] ?? 0.75
|
||||
ElectricalCalculations.recommendedFuse(forCurrent: current)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
138
Cable/Loads/ElectricalCalculations.swift
Normal file
138
Cable/Loads/ElectricalCalculations.swift
Normal file
@@ -0,0 +1,138 @@
|
||||
//
|
||||
// ElectricalCalculations.swift
|
||||
// Cable
|
||||
//
|
||||
// Created by GPT on request.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
struct ElectricalCalculations {
|
||||
private static let maxVoltageDropFraction = 0.05
|
||||
private static let copperResistivity = 0.017 // Ω⋅mm²/m
|
||||
private static let feetToMeters = 0.3048
|
||||
|
||||
private static let standardMetricCrossSections: [Double] = [
|
||||
0.75, 1.0, 1.5, 2.5, 4.0, 6.0, 10.0, 16.0, 25.0, 35.0, 50.0, 70.0, 95.0, 120.0,
|
||||
150.0, 185.0, 240.0, 300.0, 400.0, 500.0, 630.0,
|
||||
]
|
||||
|
||||
private static let standardAWG: [Int] = [20, 18, 16, 14, 12, 10, 8, 6, 4, 2, 1, 0, 00, 000, 0000]
|
||||
private static let awgCrossSections: [Double] = [
|
||||
0.519, 0.823, 1.31, 2.08, 3.31, 5.26, 8.37, 13.3, 21.2, 33.6, 42.4, 53.5, 67.4, 85.0, 107.0,
|
||||
]
|
||||
|
||||
private static let standardFuses: [Int] = [
|
||||
1, 2, 3, 5, 7, 10, 15, 20, 25, 30, 35, 40, 50,
|
||||
60, 70, 80, 100, 125, 150, 175, 200, 225, 250,
|
||||
300, 350, 400, 450, 500, 600, 700, 800,
|
||||
]
|
||||
|
||||
static func recommendedCrossSection(
|
||||
length: Double,
|
||||
current: Double,
|
||||
voltage: Double,
|
||||
unitSystem: UnitSystem
|
||||
) -> Double {
|
||||
let lengthInMeters = unitSystem == .metric ? length : length * feetToMeters
|
||||
let maxVoltageDrop = voltage * maxVoltageDropFraction
|
||||
let minimumCrossSection = guardAgainstZero(maxVoltageDrop) {
|
||||
(2 * current * lengthInMeters * copperResistivity) / maxVoltageDrop
|
||||
}
|
||||
|
||||
if unitSystem == .imperial {
|
||||
for (index, crossSection) in awgCrossSections.enumerated() where crossSection >= minimumCrossSection {
|
||||
return Double(standardAWG[index])
|
||||
}
|
||||
return Double(standardAWG.last ?? 0)
|
||||
} else {
|
||||
return standardMetricCrossSections.first { $0 >= max(standardMetricCrossSections.first ?? 0.75, minimumCrossSection) }
|
||||
?? standardMetricCrossSections.last ?? 0.75
|
||||
}
|
||||
}
|
||||
|
||||
static func voltageDrop(
|
||||
length: Double,
|
||||
current: Double,
|
||||
voltage: Double,
|
||||
unitSystem: UnitSystem,
|
||||
crossSection: Double? = nil
|
||||
) -> Double {
|
||||
let selectedCrossSection = crossSection ?? recommendedCrossSection(
|
||||
length: length,
|
||||
current: current,
|
||||
voltage: voltage,
|
||||
unitSystem: unitSystem
|
||||
)
|
||||
|
||||
let lengthInMeters = unitSystem == .metric ? length : length * feetToMeters
|
||||
let crossSectionMM2: Double
|
||||
if unitSystem == .metric {
|
||||
crossSectionMM2 = selectedCrossSection
|
||||
} else {
|
||||
crossSectionMM2 = crossSectionFromAWG(selectedCrossSection)
|
||||
}
|
||||
|
||||
guard crossSectionMM2 > 0 else { return 0 }
|
||||
return (2 * current * lengthInMeters * copperResistivity) / crossSectionMM2
|
||||
}
|
||||
|
||||
static func voltageDropPercentage(
|
||||
length: Double,
|
||||
current: Double,
|
||||
voltage: Double,
|
||||
unitSystem: UnitSystem,
|
||||
crossSection: Double? = nil
|
||||
) -> Double {
|
||||
guard voltage != 0 else { return 0 }
|
||||
let drop = voltageDrop(
|
||||
length: length,
|
||||
current: current,
|
||||
voltage: voltage,
|
||||
unitSystem: unitSystem,
|
||||
crossSection: crossSection
|
||||
)
|
||||
return (drop / voltage) * 100
|
||||
}
|
||||
|
||||
static func powerLoss(
|
||||
length: Double,
|
||||
current: Double,
|
||||
voltage: Double,
|
||||
unitSystem: UnitSystem,
|
||||
crossSection: Double? = nil
|
||||
) -> Double {
|
||||
let drop = voltageDrop(
|
||||
length: length,
|
||||
current: current,
|
||||
voltage: voltage,
|
||||
unitSystem: unitSystem,
|
||||
crossSection: crossSection
|
||||
)
|
||||
return current * drop
|
||||
}
|
||||
|
||||
static func recommendedFuse(forCurrent current: Double) -> Int {
|
||||
let target = Int((current * 1.25).rounded(.up))
|
||||
return standardFuses.first(where: { $0 >= target }) ?? standardFuses.last ?? target
|
||||
}
|
||||
|
||||
private static func guardAgainstZero(_ divisor: Double, calculation: () -> Double) -> Double {
|
||||
guard divisor > 0 else { return 0 }
|
||||
return calculation()
|
||||
}
|
||||
|
||||
private static func crossSectionFromAWG(_ awg: Double) -> Double {
|
||||
switch awg {
|
||||
case 00: return 67.4
|
||||
case 000: return 85.0
|
||||
case 0000: return 107.0
|
||||
default:
|
||||
let index = standardAWG.firstIndex(of: Int(awg)) ?? -1
|
||||
if index >= 0 && index < awgCrossSections.count {
|
||||
return awgCrossSections[index]
|
||||
}
|
||||
return 0.75
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
import PostHog
|
||||
|
||||
struct LoadsView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@@ -64,6 +63,7 @@ struct LoadsView: View {
|
||||
),
|
||||
systemImage: "rectangle.3.group"
|
||||
)
|
||||
.accessibilityIdentifier("overview-tab")
|
||||
}
|
||||
|
||||
componentsTab
|
||||
@@ -77,6 +77,7 @@ struct LoadsView: View {
|
||||
),
|
||||
systemImage: "square.stack.3d.up"
|
||||
)
|
||||
.accessibilityIdentifier("components-tab")
|
||||
}
|
||||
|
||||
Group {
|
||||
@@ -106,6 +107,7 @@ struct LoadsView: View {
|
||||
),
|
||||
systemImage: "battery.100"
|
||||
)
|
||||
.accessibilityIdentifier("batteries-tab")
|
||||
}
|
||||
.environment(\.editMode, $editMode)
|
||||
|
||||
@@ -127,6 +129,7 @@ struct LoadsView: View {
|
||||
),
|
||||
systemImage: "bolt.fill"
|
||||
)
|
||||
.accessibilityIdentifier("chargers-tab")
|
||||
}
|
||||
.environment(\.editMode, $editMode)
|
||||
}
|
||||
@@ -215,6 +218,8 @@ struct LoadsView: View {
|
||||
SystemBillOfMaterialsView(
|
||||
systemName: system.name,
|
||||
loads: savedLoads,
|
||||
batteries: savedBatteries,
|
||||
chargers: savedChargers,
|
||||
unitSystem: unitSettings.unitSystem
|
||||
)
|
||||
}
|
||||
@@ -266,7 +271,7 @@ struct LoadsView: View {
|
||||
if let loadToOpen = loadToOpenOnAppear, !hasOpenedLoadOnAppear {
|
||||
hasOpenedLoadOnAppear = true
|
||||
DispatchQueue.main.async {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Load Opened",
|
||||
properties: [
|
||||
"mode": loadToOpen.isWattMode ? "watt" : "amp",
|
||||
@@ -469,7 +474,7 @@ struct LoadsView: View {
|
||||
}
|
||||
|
||||
private func selectLoad(_ load: SavedLoad) {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Load Opened",
|
||||
properties: [
|
||||
"mode": load.isWattMode ? "watt" : "amp",
|
||||
@@ -760,7 +765,7 @@ struct LoadsView: View {
|
||||
}
|
||||
|
||||
private func presentSystemEditor(source: String) {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"System Editor Opened",
|
||||
properties: [
|
||||
"source": source,
|
||||
@@ -771,7 +776,7 @@ struct LoadsView: View {
|
||||
}
|
||||
|
||||
private func openComponentLibrary(source: String) {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Component Library Opened",
|
||||
properties: [
|
||||
"source": source,
|
||||
@@ -782,7 +787,7 @@ struct LoadsView: View {
|
||||
}
|
||||
|
||||
private func openBillOfMaterials() {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Bill Of Materials Opened",
|
||||
properties: [
|
||||
"system": system.name
|
||||
@@ -795,7 +800,7 @@ struct LoadsView: View {
|
||||
let loadsToDelete = offsets.map { savedLoads[$0] }
|
||||
withAnimation {
|
||||
for load in loadsToDelete {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Load Deleted",
|
||||
properties: [
|
||||
"name": load.name,
|
||||
@@ -815,7 +820,7 @@ struct LoadsView: View {
|
||||
existingBatteries: savedBatteries,
|
||||
existingChargers: savedChargers
|
||||
)
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Load Created",
|
||||
properties: [
|
||||
"name": newLoad.name,
|
||||
@@ -826,7 +831,7 @@ struct LoadsView: View {
|
||||
}
|
||||
|
||||
private func startBatteryConfiguration() {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Battery Editor Opened",
|
||||
properties: [
|
||||
"source": "create",
|
||||
@@ -850,7 +855,7 @@ struct LoadsView: View {
|
||||
in: modelContext
|
||||
)
|
||||
let eventName = isExisting ? "Battery Updated" : "Battery Created"
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
eventName,
|
||||
properties: [
|
||||
"name": configuration.name,
|
||||
@@ -860,7 +865,7 @@ struct LoadsView: View {
|
||||
}
|
||||
|
||||
private func editBattery(_ battery: SavedBattery) {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Battery Editor Opened",
|
||||
properties: [
|
||||
"source": "edit",
|
||||
@@ -874,7 +879,7 @@ struct LoadsView: View {
|
||||
let batteriesToDelete = offsets.map { savedBatteries[$0] }
|
||||
withAnimation {
|
||||
for battery in batteriesToDelete {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Battery Deleted",
|
||||
properties: [
|
||||
"name": battery.name,
|
||||
@@ -891,7 +896,7 @@ struct LoadsView: View {
|
||||
}
|
||||
|
||||
private func startChargerConfiguration() {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Charger Editor Opened",
|
||||
properties: [
|
||||
"source": "create",
|
||||
@@ -915,7 +920,7 @@ struct LoadsView: View {
|
||||
in: modelContext
|
||||
)
|
||||
let eventName = isExisting ? "Charger Updated" : "Charger Created"
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
eventName,
|
||||
properties: [
|
||||
"name": configuration.name,
|
||||
@@ -925,7 +930,7 @@ struct LoadsView: View {
|
||||
}
|
||||
|
||||
private func editCharger(_ charger: SavedCharger) {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Charger Editor Opened",
|
||||
properties: [
|
||||
"source": "edit",
|
||||
@@ -939,7 +944,7 @@ struct LoadsView: View {
|
||||
let chargersToDelete = offsets.map { savedChargers[$0] }
|
||||
withAnimation {
|
||||
for charger in chargersToDelete {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Charger Deleted",
|
||||
properties: [
|
||||
"name": charger.name,
|
||||
@@ -964,7 +969,7 @@ struct LoadsView: View {
|
||||
existingBatteries: savedBatteries,
|
||||
existingChargers: savedChargers
|
||||
)
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Library Load Added",
|
||||
properties: [
|
||||
"id": item.id,
|
||||
@@ -986,13 +991,7 @@ struct LoadsView: View {
|
||||
}
|
||||
|
||||
private func recommendedFuse(for load: SavedLoad) -> Int {
|
||||
let targetFuse = load.current * 1.25 // 125% of load current for safety
|
||||
|
||||
// Common fuse values in amperes
|
||||
let standardFuses = [1, 2, 3, 5, 7, 10, 15, 20, 25, 30, 35, 40, 50, 60, 70, 80, 100, 125, 150, 175, 200, 225, 250, 300, 350, 400, 450, 500, 600, 700, 800]
|
||||
|
||||
// Find the smallest standard fuse that's >= target
|
||||
return standardFuses.first { $0 >= Int(targetFuse.rounded(.up)) } ?? standardFuses.last!
|
||||
ElectricalCalculations.recommendedFuse(forCurrent: load.current)
|
||||
}
|
||||
|
||||
private enum ComponentTab: Hashable {
|
||||
|
||||
@@ -62,6 +62,7 @@ struct OnboardingInfoView: View {
|
||||
Label(configuration.primaryActionTitle, systemImage: configuration.primaryActionIcon)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
.accessibilityIdentifier("create-component-button")
|
||||
.buttonStyle(.borderedProminent)
|
||||
.controlSize(.large)
|
||||
|
||||
@@ -71,6 +72,7 @@ struct OnboardingInfoView: View {
|
||||
Label(secondaryTitle, systemImage: secondaryIcon)
|
||||
.frame(maxWidth: .infinity)
|
||||
}
|
||||
.accessibilityIdentifier("select-component-button")
|
||||
.buttonStyle(.bordered)
|
||||
.tint(.accentColor)
|
||||
.controlSize(.large)
|
||||
|
||||
@@ -159,8 +159,10 @@ struct SystemOverviewView: View {
|
||||
goalHours: nil,
|
||||
progressFraction: bomCompletionFraction,
|
||||
hasValue: bomItemsCount > 0,
|
||||
action: onShowBillOfMaterials
|
||||
action: onShowBillOfMaterials,
|
||||
accessibilityIdentifier: "system-bom-button"
|
||||
)
|
||||
|
||||
}
|
||||
.padding(.top, 4)
|
||||
}
|
||||
@@ -190,7 +192,8 @@ struct SystemOverviewView: View {
|
||||
goalHours: Double?,
|
||||
progressFraction: Double?,
|
||||
hasValue: Bool,
|
||||
action: (() -> Void)? = nil
|
||||
action: (() -> Void)? = nil,
|
||||
accessibilityIdentifier: String? = nil
|
||||
) -> some View {
|
||||
let content = VStack(alignment: .leading, spacing: 10) {
|
||||
HStack(alignment: .center, spacing: 12) {
|
||||
@@ -240,12 +243,28 @@ struct SystemOverviewView: View {
|
||||
|
||||
let paddedContent = content
|
||||
.padding(.horizontal, 4)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.contentShape(Rectangle())
|
||||
|
||||
if let action {
|
||||
Button(action: action) {
|
||||
paddedContent
|
||||
if let accessibilityIdentifier {
|
||||
Button(action: action) {
|
||||
paddedContent
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityIdentifier(accessibilityIdentifier)
|
||||
.accessibilityLabel(title)
|
||||
.accessibilityAddTraits(.isButton)
|
||||
.contentShape(Rectangle())
|
||||
} else {
|
||||
Button(action: action) {
|
||||
paddedContent
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityLabel(title)
|
||||
.accessibilityAddTraits(.isButton)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
.buttonStyle(.plain)
|
||||
} else {
|
||||
paddedContent
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ class SavedBattery {
|
||||
var iconName: String = "battery.100"
|
||||
var colorName: String = "blue"
|
||||
var system: ElectricalSystem?
|
||||
var bomCompletedItemIDs: [String] = []
|
||||
var timestamp: Date
|
||||
|
||||
init(
|
||||
@@ -32,6 +33,7 @@ class SavedBattery {
|
||||
iconName: String = "battery.100",
|
||||
colorName: String = "blue",
|
||||
system: ElectricalSystem? = nil,
|
||||
bomCompletedItemIDs: [String] = [],
|
||||
timestamp: Date = Date()
|
||||
) {
|
||||
self.id = id
|
||||
@@ -47,6 +49,7 @@ class SavedBattery {
|
||||
self.iconName = iconName
|
||||
self.colorName = colorName
|
||||
self.system = system
|
||||
self.bomCompletedItemIDs = bomCompletedItemIDs
|
||||
self.timestamp = timestamp
|
||||
}
|
||||
|
||||
|
||||
11
Cable/Shared/ShareSheet.swift
Normal file
11
Cable/Shared/ShareSheet.swift
Normal file
@@ -0,0 +1,11 @@
|
||||
import SwiftUI
|
||||
|
||||
struct ShareSheet: UIViewControllerRepresentable {
|
||||
let items: [Any]
|
||||
|
||||
func makeUIViewController(context: Context) -> UIActivityViewController {
|
||||
UIActivityViewController(activityItems: items, applicationActivities: nil)
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) {}
|
||||
}
|
||||
17
Cable/Systems/BillOfMaterialsSnapshot.swift
Normal file
17
Cable/Systems/BillOfMaterialsSnapshot.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
import Foundation
|
||||
|
||||
struct BillOfMaterialsItemSnapshot: Identifiable {
|
||||
let id: String
|
||||
let title: String
|
||||
let detail: String
|
||||
let iconSystemName: String
|
||||
let isPrimaryComponent: Bool
|
||||
let metric: String?
|
||||
}
|
||||
|
||||
struct BillOfMaterialsSectionSnapshot: Identifiable {
|
||||
let id: String
|
||||
let title: String
|
||||
let subtitle: String
|
||||
let items: [BillOfMaterialsItemSnapshot]
|
||||
}
|
||||
313
Cable/Systems/SystemBillOfMaterialsPDFExporter.swift
Normal file
313
Cable/Systems/SystemBillOfMaterialsPDFExporter.swift
Normal file
@@ -0,0 +1,313 @@
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
struct SystemBillOfMaterialsPDFExporter {
|
||||
private let pageRect = CGRect(x: 0, y: 0, width: 595, height: 842) // A4 portrait in points
|
||||
private let margin: CGFloat = 40
|
||||
private let primaryTextColor = UIColor.black
|
||||
private let secondaryTextColor = UIColor.darkGray
|
||||
private let tertiaryTextColor = UIColor.gray
|
||||
private let accentColor = UIColor(red: 0.45, green: 0.34, blue: 0.86, alpha: 1)
|
||||
|
||||
func export(
|
||||
systemName: String,
|
||||
unitSystem: UnitSystem,
|
||||
sections: [BillOfMaterialsSectionSnapshot]
|
||||
) throws -> URL {
|
||||
let format = UIGraphicsPDFRendererFormat()
|
||||
let renderer = UIGraphicsPDFRenderer(bounds: pageRect, format: format)
|
||||
var pageIndex = 1
|
||||
|
||||
let data = renderer.pdfData { context in
|
||||
var cursorY = beginPage(
|
||||
context: context,
|
||||
pageIndex: pageIndex,
|
||||
systemName: systemName,
|
||||
unitSystem: unitSystem,
|
||||
isFirstPage: true
|
||||
)
|
||||
|
||||
if sections.isEmpty {
|
||||
cursorY = ensureSpace(
|
||||
requiredHeight: 60,
|
||||
cursorY: cursorY,
|
||||
context: context,
|
||||
pageIndex: &pageIndex,
|
||||
systemName: systemName,
|
||||
unitSystem: unitSystem
|
||||
)
|
||||
let emptyMessage = NSLocalizedString(
|
||||
"bom.pdf.placeholder.empty",
|
||||
comment: "Message shown in the PDF export when no components are available"
|
||||
)
|
||||
drawPlaceholder(in: context.cgContext, text: emptyMessage, at: cursorY)
|
||||
} else {
|
||||
for section in sections {
|
||||
let requiredHeight = sectionHeight(for: section)
|
||||
cursorY = ensureSpace(
|
||||
requiredHeight: requiredHeight,
|
||||
cursorY: cursorY,
|
||||
context: context,
|
||||
pageIndex: &pageIndex,
|
||||
systemName: systemName,
|
||||
unitSystem: unitSystem
|
||||
)
|
||||
|
||||
cursorY = drawSectionHeader(
|
||||
title: section.title,
|
||||
subtitle: section.subtitle,
|
||||
at: cursorY,
|
||||
in: context.cgContext
|
||||
)
|
||||
|
||||
for item in section.items {
|
||||
cursorY = drawItem(item, at: cursorY, in: context.cgContext)
|
||||
cursorY += 12
|
||||
}
|
||||
|
||||
cursorY += 8
|
||||
}
|
||||
}
|
||||
|
||||
drawFooter(pageIndex: pageIndex, in: context.cgContext)
|
||||
}
|
||||
|
||||
let url = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("System-BOM-\(UUID().uuidString).pdf")
|
||||
try data.write(to: url, options: .atomic)
|
||||
return url
|
||||
}
|
||||
|
||||
private func beginPage(
|
||||
context: UIGraphicsPDFRendererContext,
|
||||
pageIndex: Int,
|
||||
systemName: String,
|
||||
unitSystem: UnitSystem,
|
||||
isFirstPage: Bool
|
||||
) -> CGFloat {
|
||||
context.beginPage()
|
||||
let titleFont = UIFont.systemFont(ofSize: isFirstPage ? 26 : 18, weight: .bold)
|
||||
let subtitleFont = UIFont.systemFont(ofSize: isFirstPage ? 16 : 12, weight: .medium)
|
||||
let title = isFirstPage
|
||||
? NSLocalizedString(
|
||||
"bom.pdf.header.title",
|
||||
comment: "Primary title shown at the top of the BOM PDF"
|
||||
)
|
||||
: systemName
|
||||
|
||||
let subtitle: String
|
||||
if isFirstPage {
|
||||
let format = NSLocalizedString(
|
||||
"bom.pdf.header.subtitle",
|
||||
comment: "Subtitle format combining system name and unit system for the BOM PDF"
|
||||
)
|
||||
subtitle = String(
|
||||
format: format,
|
||||
locale: Locale.current,
|
||||
systemName,
|
||||
unitSystem.displayName
|
||||
)
|
||||
} else {
|
||||
let format = NSLocalizedString(
|
||||
"bom.pdf.header.inline",
|
||||
comment: "Subtitle describing the active unit system on subsequent PDF pages"
|
||||
)
|
||||
subtitle = String(
|
||||
format: format,
|
||||
locale: Locale.current,
|
||||
unitSystem.displayName
|
||||
)
|
||||
}
|
||||
|
||||
let availableWidth = pageRect.width - (margin * 2)
|
||||
let titleRect = CGRect(x: margin, y: margin, width: availableWidth, height: titleFont.lineHeight + 4)
|
||||
title.draw(in: titleRect, withAttributes: [
|
||||
.font: titleFont,
|
||||
.foregroundColor: primaryTextColor
|
||||
])
|
||||
|
||||
let subtitleRect = CGRect(
|
||||
x: margin,
|
||||
y: titleRect.maxY + 4,
|
||||
width: availableWidth,
|
||||
height: subtitleFont.lineHeight + 2
|
||||
)
|
||||
subtitle.draw(in: subtitleRect, withAttributes: [
|
||||
.font: subtitleFont,
|
||||
.foregroundColor: secondaryTextColor
|
||||
])
|
||||
|
||||
return subtitleRect.maxY + (isFirstPage ? 24 : 12)
|
||||
}
|
||||
|
||||
private func ensureSpace(
|
||||
requiredHeight: CGFloat,
|
||||
cursorY: CGFloat,
|
||||
context: UIGraphicsPDFRendererContext,
|
||||
pageIndex: inout Int,
|
||||
systemName: String,
|
||||
unitSystem: UnitSystem
|
||||
) -> CGFloat {
|
||||
if cursorY + requiredHeight <= pageRect.height - margin {
|
||||
return cursorY
|
||||
}
|
||||
|
||||
drawFooter(pageIndex: pageIndex, in: context.cgContext)
|
||||
pageIndex += 1
|
||||
return beginPage(
|
||||
context: context,
|
||||
pageIndex: pageIndex,
|
||||
systemName: systemName,
|
||||
unitSystem: unitSystem,
|
||||
isFirstPage: false
|
||||
)
|
||||
}
|
||||
|
||||
private var sectionHeaderHeight: CGFloat {
|
||||
let headerFont = UIFont.systemFont(ofSize: 18, weight: .semibold)
|
||||
let subtitleFont = UIFont.systemFont(ofSize: 12, weight: .medium)
|
||||
return headerFont.lineHeight + subtitleFont.lineHeight + 14
|
||||
}
|
||||
|
||||
private func sectionHeight(for section: BillOfMaterialsSectionSnapshot) -> CGFloat {
|
||||
let itemsHeight = section.items.reduce(0) { partialResult, item in
|
||||
partialResult + itemBlockHeight(for: item) + 12
|
||||
}
|
||||
return sectionHeaderHeight + itemsHeight + 8
|
||||
}
|
||||
|
||||
private func drawSectionHeader(title: String, subtitle: String, at yPosition: CGFloat, in context: CGContext) -> CGFloat {
|
||||
var cursorY = yPosition
|
||||
let headerFont = UIFont.systemFont(ofSize: 18, weight: .semibold)
|
||||
let subtitleFont = UIFont.systemFont(ofSize: 12, weight: .medium)
|
||||
let availableWidth = pageRect.width - (margin * 2)
|
||||
|
||||
title.draw(
|
||||
in: CGRect(x: margin, y: cursorY, width: availableWidth, height: headerFont.lineHeight + 4),
|
||||
withAttributes: [
|
||||
.font: headerFont,
|
||||
.foregroundColor: primaryTextColor
|
||||
]
|
||||
)
|
||||
cursorY += headerFont.lineHeight + 4
|
||||
|
||||
subtitle.draw(
|
||||
in: CGRect(x: margin, y: cursorY, width: availableWidth, height: subtitleFont.lineHeight + 2),
|
||||
withAttributes: [
|
||||
.font: subtitleFont,
|
||||
.foregroundColor: secondaryTextColor
|
||||
]
|
||||
)
|
||||
cursorY += subtitleFont.lineHeight + 10
|
||||
|
||||
return cursorY
|
||||
}
|
||||
|
||||
private func itemBlockHeight(for item: BillOfMaterialsItemSnapshot) -> CGFloat {
|
||||
let metricFont = UIFont.systemFont(ofSize: 13, weight: .semibold)
|
||||
let titleFont = UIFont.systemFont(ofSize: 14, weight: item.isPrimaryComponent ? .semibold : .medium)
|
||||
let detailFont = UIFont.systemFont(ofSize: 12, weight: .regular)
|
||||
var height: CGFloat = 0
|
||||
if item.metric != nil {
|
||||
height += metricFont.lineHeight + 2
|
||||
}
|
||||
height += titleFont.lineHeight + 2
|
||||
if !item.detail.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||
height += detailFont.lineHeight + 4
|
||||
}
|
||||
return height + 4
|
||||
}
|
||||
|
||||
private func drawItem(_ item: BillOfMaterialsItemSnapshot, at yPosition: CGFloat, in context: CGContext) -> CGFloat {
|
||||
let metricFont = UIFont.systemFont(ofSize: 13, weight: .semibold)
|
||||
let titleFont = UIFont.systemFont(ofSize: 14, weight: item.isPrimaryComponent ? .semibold : .medium)
|
||||
let detailFont = UIFont.systemFont(ofSize: 12, weight: .regular)
|
||||
let titleAttributes: [NSAttributedString.Key: Any] = [
|
||||
.font: titleFont,
|
||||
.foregroundColor: primaryTextColor
|
||||
]
|
||||
let detailAttributes: [NSAttributedString.Key: Any] = [
|
||||
.font: detailFont,
|
||||
.foregroundColor: secondaryTextColor
|
||||
]
|
||||
let metricAttributes: [NSAttributedString.Key: Any] = [
|
||||
.font: metricFont,
|
||||
.foregroundColor: accentColor
|
||||
]
|
||||
|
||||
let bulletWidth: CGFloat = 6
|
||||
let spacing: CGFloat = 8
|
||||
let availableWidth = pageRect.width - (margin * 2) - bulletWidth - spacing
|
||||
let firstLineHeight = item.metric != nil ? metricFont.lineHeight : titleFont.lineHeight
|
||||
let bulletRect = CGRect(
|
||||
x: margin,
|
||||
y: yPosition + (firstLineHeight / 2) - (bulletWidth / 2),
|
||||
width: bulletWidth,
|
||||
height: bulletWidth
|
||||
)
|
||||
context.setFillColor(accentColor.cgColor)
|
||||
context.fillEllipse(in: bulletRect)
|
||||
|
||||
var cursorY = yPosition
|
||||
let textX = margin + bulletWidth + spacing
|
||||
|
||||
if let metric = item.metric {
|
||||
let metricRect = CGRect(x: textX, y: cursorY, width: availableWidth, height: metricFont.lineHeight + 2)
|
||||
metric.draw(in: metricRect, withAttributes: metricAttributes)
|
||||
cursorY = metricRect.maxY + 2
|
||||
}
|
||||
|
||||
let titleRect = CGRect(
|
||||
x: textX,
|
||||
y: cursorY,
|
||||
width: availableWidth,
|
||||
height: titleFont.lineHeight + 2
|
||||
)
|
||||
item.title.draw(in: titleRect, withAttributes: titleAttributes)
|
||||
cursorY = titleRect.maxY + 2
|
||||
|
||||
if !item.detail.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
||||
let detailRect = CGRect(
|
||||
x: textX,
|
||||
y: cursorY,
|
||||
width: availableWidth,
|
||||
height: detailFont.lineHeight + 4
|
||||
)
|
||||
item.detail.draw(in: detailRect, withAttributes: detailAttributes)
|
||||
cursorY = detailRect.maxY
|
||||
}
|
||||
|
||||
return cursorY
|
||||
}
|
||||
|
||||
private func drawFooter(pageIndex: Int, in context: CGContext) {
|
||||
let footerFont = UIFont.systemFont(ofSize: 11, weight: .regular)
|
||||
let attributes: [NSAttributedString.Key: Any] = [
|
||||
.font: footerFont,
|
||||
.foregroundColor: tertiaryTextColor
|
||||
]
|
||||
let format = NSLocalizedString(
|
||||
"bom.pdf.page.number",
|
||||
comment: "Format string for the PDF page number footer"
|
||||
)
|
||||
let text = String(format: format, locale: Locale.current, pageIndex)
|
||||
let size = text.size(withAttributes: attributes)
|
||||
let origin = CGPoint(
|
||||
x: (pageRect.width - size.width) / 2,
|
||||
y: pageRect.height - margin + 10
|
||||
)
|
||||
text.draw(at: origin, withAttributes: attributes)
|
||||
}
|
||||
|
||||
private func drawPlaceholder(in context: CGContext, text: String, at yPosition: CGFloat) {
|
||||
let font = UIFont.systemFont(ofSize: 14, weight: .regular)
|
||||
let attributes: [NSAttributedString.Key: Any] = [
|
||||
.font: font,
|
||||
.foregroundColor: secondaryTextColor
|
||||
]
|
||||
text.draw(
|
||||
in: CGRect(x: margin, y: yPosition, width: pageRect.width - (margin * 2), height: font.lineHeight + 4),
|
||||
withAttributes: attributes
|
||||
)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,4 @@
|
||||
import SwiftUI
|
||||
import PostHog
|
||||
|
||||
struct SystemsOnboardingView: View {
|
||||
@State private var systemName: String = String(localized: "default.system.name", comment: "Default placeholder name for a system")
|
||||
@@ -94,7 +93,7 @@ struct SystemsOnboardingView: View {
|
||||
.onAppear(perform: resetState)
|
||||
.onReceive(timer) { _ in advanceCarousel() }
|
||||
.task {
|
||||
PostHogSDK.shared.capture("Launched")
|
||||
AnalyticsTracker.log("Launched")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +105,7 @@ struct SystemsOnboardingView: View {
|
||||
private func createSystem() {
|
||||
isFieldFocused = false
|
||||
let trimmed = systemName.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
PostHogSDK.shared.capture("System Created", properties: ["name": trimmed])
|
||||
AnalyticsTracker.log("System Created", properties: ["name": trimmed])
|
||||
guard !trimmed.isEmpty else { return }
|
||||
onCreate(trimmed)
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
import PostHog
|
||||
|
||||
struct SystemsView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@@ -77,48 +76,16 @@ struct SystemsView: View {
|
||||
} else {
|
||||
List {
|
||||
ForEach(systems) { system in
|
||||
NavigationLink(destination: LoadsView(system: system)) {
|
||||
HStack(spacing: 12) {
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(Color.componentColor(named: system.colorName))
|
||||
.frame(width: 44, height: 44)
|
||||
|
||||
Image(systemName: system.iconName)
|
||||
.font(.title3)
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(system.name)
|
||||
.fontWeight(.medium)
|
||||
|
||||
if !system.location.isEmpty {
|
||||
Text(system.location)
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
Button {
|
||||
handleSystemSelection(system)
|
||||
} label: {
|
||||
systemRow(for: system)
|
||||
.contentShape(Rectangle())
|
||||
}
|
||||
|
||||
Text(componentSummary(for: system))
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
.simultaneousGesture(
|
||||
TapGesture().onEnded {
|
||||
PostHogSDK.shared.capture(
|
||||
"System Opened",
|
||||
properties: [
|
||||
"name": system.name,
|
||||
"source": "list"
|
||||
]
|
||||
)
|
||||
}
|
||||
)
|
||||
.buttonStyle(.plain)
|
||||
.accessibilityLabel(system.name)
|
||||
.accessibilityHint(Text("systems.list.row.accessibility.hint", comment: "Accessibility hint for systems list row"))
|
||||
.accessibilityAddTraits(.isButton)
|
||||
}
|
||||
.onDelete(perform: deleteSystems)
|
||||
}
|
||||
@@ -137,7 +104,7 @@ struct SystemsView: View {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
HStack {
|
||||
Button(action: {
|
||||
PostHogSDK.shared.capture("System Create Navigation")
|
||||
AnalyticsTracker.log("System Create Navigation")
|
||||
createNewSystem()
|
||||
}) {
|
||||
Image(systemName: "plus")
|
||||
@@ -175,13 +142,67 @@ struct SystemsView: View {
|
||||
}
|
||||
|
||||
private func openSettings() {
|
||||
PostHogSDK.shared.capture("Settings Opened")
|
||||
AnalyticsTracker.log("Settings Opened")
|
||||
showingSettings = true
|
||||
}
|
||||
|
||||
private func handleSystemSelection(_ system: ElectricalSystem) {
|
||||
AnalyticsTracker.log(
|
||||
"System Opened",
|
||||
properties: [
|
||||
"name": system.name,
|
||||
"source": "list"
|
||||
]
|
||||
)
|
||||
navigateToSystem(
|
||||
system,
|
||||
presentSystemEditor: false,
|
||||
loadToOpen: nil,
|
||||
source: "list"
|
||||
)
|
||||
}
|
||||
|
||||
@ViewBuilder
|
||||
private func systemRow(for system: ElectricalSystem) -> some View {
|
||||
HStack(spacing: 12) {
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 10)
|
||||
.fill(Color.componentColor(named: system.colorName))
|
||||
.frame(width: 44, height: 44)
|
||||
|
||||
Image(systemName: system.iconName)
|
||||
.font(.title3)
|
||||
.foregroundColor(.white)
|
||||
}
|
||||
|
||||
VStack(alignment: .leading, spacing: 4) {
|
||||
Text(system.name)
|
||||
.fontWeight(.medium)
|
||||
|
||||
if !system.location.isEmpty {
|
||||
Text(system.location)
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
||||
Text(componentSummary(for: system))
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
Image(systemName: "chevron.right")
|
||||
.font(.footnote.weight(.semibold))
|
||||
.foregroundColor(.secondary.opacity(0.6))
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
private func createNewSystem() {
|
||||
let system = makeSystem()
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"System Created",
|
||||
properties: [
|
||||
"name": system.name,
|
||||
@@ -198,7 +219,7 @@ struct SystemsView: View {
|
||||
|
||||
private func createNewSystem(named name: String) {
|
||||
let system = makeSystem(preferredName: name)
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"System Created",
|
||||
properties: [
|
||||
"name": system.name,
|
||||
@@ -233,7 +254,7 @@ struct SystemsView: View {
|
||||
animated: Bool = true,
|
||||
source: String = "programmatic"
|
||||
) {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"System Opened",
|
||||
properties: [
|
||||
"name": system.name,
|
||||
@@ -300,7 +321,7 @@ struct SystemsView: View {
|
||||
|
||||
private func addComponentFromLibrary(_ item: ComponentLibraryItem) {
|
||||
let system = makeSystem()
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"System Created",
|
||||
properties: [
|
||||
"name": system.name,
|
||||
@@ -308,7 +329,7 @@ struct SystemsView: View {
|
||||
]
|
||||
)
|
||||
let load = createLoad(from: item, in: system)
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Library Load Added",
|
||||
properties: [
|
||||
"id": item.id,
|
||||
@@ -397,7 +418,7 @@ struct SystemsView: View {
|
||||
let systemsToDelete = offsets.map { systems[$0] }
|
||||
withAnimation {
|
||||
for system in systemsToDelete {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"System Deleted",
|
||||
properties: [
|
||||
"name": system.name,
|
||||
@@ -414,7 +435,7 @@ struct SystemsView: View {
|
||||
let descriptor = FetchDescriptor<SavedLoad>()
|
||||
if let loads = try? modelContext.fetch(descriptor) {
|
||||
for load in loads where load.system == system {
|
||||
PostHogSDK.shared.capture(
|
||||
AnalyticsTracker.log(
|
||||
"Load Deleted",
|
||||
properties: [
|
||||
"name": load.name,
|
||||
|
||||
@@ -7,27 +7,44 @@ import Foundation
|
||||
import SwiftData
|
||||
|
||||
enum UITestSampleData {
|
||||
static let argument = "--uitest-sample-data"
|
||||
static let sampleArgument = "--uitest-sample-data"
|
||||
static let resetArgument = "--uitest-reset-data"
|
||||
|
||||
static func prepareIfNeeded(container: ModelContainer) {
|
||||
static func handleLaunchArguments(container: ModelContainer) {
|
||||
#if DEBUG
|
||||
guard ProcessInfo.processInfo.arguments.contains(argument) else { return }
|
||||
let arguments = ProcessInfo.processInfo.arguments
|
||||
NSLog("UITestSampleData arguments: %@", arguments.joined(separator: ", "))
|
||||
guard arguments.contains(sampleArgument) || arguments.contains(resetArgument) else { return }
|
||||
|
||||
let context = ModelContext(container)
|
||||
|
||||
do {
|
||||
try clearExistingData(in: context)
|
||||
try seedSampleData(in: context)
|
||||
try context.save()
|
||||
if arguments.contains(resetArgument) {
|
||||
NSLog("UITestSampleData resetting data store")
|
||||
try clearExistingData(in: context)
|
||||
}
|
||||
|
||||
if arguments.contains(sampleArgument) {
|
||||
NSLog("UITestSampleData seeding sample data")
|
||||
if !arguments.contains(resetArgument) {
|
||||
try clearExistingData(in: context)
|
||||
}
|
||||
try seedSampleData(in: context)
|
||||
}
|
||||
|
||||
if context.hasChanges {
|
||||
try context.save()
|
||||
NSLog("UITestSampleData save completed")
|
||||
}
|
||||
} catch {
|
||||
assertionFailure("Failed to seed UI test sample data: \(error)")
|
||||
assertionFailure("Failed to prepare UI test data: \(error)")
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
private extension UITestSampleData {
|
||||
extension UITestSampleData {
|
||||
static func clearExistingData(in context: ModelContext) throws {
|
||||
let systemDescriptor = FetchDescriptor<ElectricalSystem>()
|
||||
let loadDescriptor = FetchDescriptor<SavedLoad>()
|
||||
|
||||
@@ -144,6 +144,29 @@
|
||||
"bom.navigation.title.system" = "Stückliste – %@";
|
||||
"bom.size.unknown" = "Größe offen";
|
||||
"bom.terminals.detail" = "Ring- oder Gabelkabelschuhe für %@-Leitungen";
|
||||
"bom.empty.message" = "Dieses System hat noch keine Komponenten.";
|
||||
"bom.export.pdf.button" = "PDF exportieren";
|
||||
"bom.export.pdf.error.title" = "Export fehlgeschlagen";
|
||||
"bom.export.pdf.error.empty" = "Füge vor dem Export mindestens eine Komponente hinzu.";
|
||||
"bom.pdf.header.title" = "System-Stückliste";
|
||||
"bom.pdf.header.subtitle" = "%@ • %@";
|
||||
"bom.pdf.header.inline" = "Einheitensystem: %@";
|
||||
"bom.pdf.placeholder.empty" = "Keine Komponenten verfügbar.";
|
||||
"bom.pdf.page.number" = "Seite %d";
|
||||
"bom.category.components.title" = "Komponenten & Ladegeräte";
|
||||
"bom.category.components.subtitle" = "Hauptverbraucher, Regler und Ladehardware.";
|
||||
"bom.category.batteries.title" = "Batterien";
|
||||
"bom.category.batteries.subtitle" = "Hausspeicher und Batteriebänke.";
|
||||
"bom.category.cables.title" = "Kabel";
|
||||
"bom.category.cables.subtitle" = "Passende Leitungen für jede Strecke.";
|
||||
"bom.category.fuses.title" = "Sicherungen";
|
||||
"bom.category.fuses.subtitle" = "Stromkreisschutz und Halter.";
|
||||
"bom.category.accessories.title" = "Zubehör";
|
||||
"bom.category.accessories.subtitle" = "Sicherungen, Kabelschuhe und weiteres Montagematerial.";
|
||||
"bom.cable.detail.quantified" = "%1$dx %2$@";
|
||||
"bom.quantity.count.badge" = "%d×";
|
||||
"bom.quantity.length.badge" = "%1$.1f %2$@";
|
||||
"bom.quantity.length.badge.with.spec" = "%1$.1f %2$@ · %3$@";
|
||||
"cable.pro.privacy.label" = "Datenschutz";
|
||||
"cable.pro.privacy.url" = "https://voltplan.app/de/datenschutz";
|
||||
"cable.pro.terms.label" = "Nutzungsbedingungen";
|
||||
@@ -264,7 +287,7 @@
|
||||
"sample.load.charger.name" = "Werkzeugladegerät";
|
||||
"sample.load.compressor.name" = "Luftkompressor";
|
||||
"sample.load.fridge.name" = "Kompressor-Kühlschrank";
|
||||
"sample.load.lighting.name" = "LED-Streifenbeleuchtung";
|
||||
"sample.load.lighting.name" = "LED-Streifen";
|
||||
"sample.system.rv.location" = "12V Wohnstromkreis";
|
||||
"sample.system.rv.name" = "Abenteuer-Van";
|
||||
"sample.system.workshop.location" = "Werkzeugecke";
|
||||
@@ -337,6 +360,7 @@
|
||||
"cable.pro.alert.restored.body" = "Deine bisherigen Käufe sind wieder verfügbar.";
|
||||
"cable.pro.alert.error.title" = "Kauf fehlgeschlagen";
|
||||
"cable.pro.alert.error.generic" = "Etwas ist schiefgelaufen. Bitte versuche es erneut.";
|
||||
"generic.ok" = "OK";
|
||||
"cable.pro.trial.badge" = "Enthält eine %@ Testphase";
|
||||
"cable.pro.subscription.renews" = "Verlängert sich %@.";
|
||||
"cable.pro.subscription.trialThenRenews" = "Testphase, danach Verlängerung %@.";
|
||||
|
||||
@@ -14,6 +14,29 @@
|
||||
"bom.navigation.title.system" = "Lista de materiales – %@";
|
||||
"bom.size.unknown" = "Tamaño por definir";
|
||||
"bom.terminals.detail" = "Terminales de anillo o de horquilla para cables de %@";
|
||||
"bom.empty.message" = "Todavía no hay componentes guardados en este sistema.";
|
||||
"bom.export.pdf.button" = "Exportar PDF";
|
||||
"bom.export.pdf.error.title" = "Exportación fallida";
|
||||
"bom.export.pdf.error.empty" = "Agrega al menos un componente antes de exportar.";
|
||||
"bom.pdf.header.title" = "Lista de materiales del sistema";
|
||||
"bom.pdf.header.subtitle" = "%@ • %@";
|
||||
"bom.pdf.header.inline" = "Sistema de unidades: %@";
|
||||
"bom.pdf.placeholder.empty" = "No hay componentes disponibles.";
|
||||
"bom.pdf.page.number" = "Página %d";
|
||||
"bom.category.components.title" = "Componentes y cargadores";
|
||||
"bom.category.components.subtitle" = "Dispositivos principales, controladores y equipos de carga.";
|
||||
"bom.category.batteries.title" = "Baterías";
|
||||
"bom.category.batteries.subtitle" = "Bancos domésticos y almacenamiento.";
|
||||
"bom.category.cables.title" = "Cables";
|
||||
"bom.category.cables.subtitle" = "Tendidos dimensionados para cada circuito.";
|
||||
"bom.category.fuses.title" = "Fusibles";
|
||||
"bom.category.fuses.subtitle" = "Protección de circuitos y portafusibles.";
|
||||
"bom.category.accessories.title" = "Accesorios";
|
||||
"bom.category.accessories.subtitle" = "Fusibles, terminales y piezas de soporte.";
|
||||
"bom.cable.detail.quantified" = "%1$dx %2$@";
|
||||
"bom.quantity.count.badge" = "%d×";
|
||||
"bom.quantity.length.badge" = "%1$.1f %2$@";
|
||||
"bom.quantity.length.badge.with.spec" = "%1$.1f %2$@ · %3$@";
|
||||
"component.fallback.name" = "Componente";
|
||||
"default.load.library" = "Carga de la biblioteca";
|
||||
"default.load.name" = "Mi carga";
|
||||
@@ -323,3 +346,4 @@
|
||||
"cable.pro.feature.dutyCycle" = "Calculadoras de cables conscientes del ciclo de trabajo";
|
||||
"cable.pro.feature.batteryCapacity" = "Configura la capacidad utilizable de la batería";
|
||||
"cable.pro.feature.usageBased" = "Cálculos basados en el uso";
|
||||
"generic.ok" = "Aceptar";
|
||||
|
||||
@@ -14,6 +14,29 @@
|
||||
"bom.navigation.title.system" = "Liste de matériel – %@";
|
||||
"bom.size.unknown" = "Taille à déterminer";
|
||||
"bom.terminals.detail" = "Cosses à œillet ou à fourche adaptées aux câbles de %@";
|
||||
"bom.empty.message" = "Aucun composant enregistré pour ce système pour l’instant.";
|
||||
"bom.export.pdf.button" = "Exporter en PDF";
|
||||
"bom.export.pdf.error.title" = "Échec de l’export";
|
||||
"bom.export.pdf.error.empty" = "Ajoutez au moins un composant avant l’export.";
|
||||
"bom.pdf.header.title" = "Liste de matériaux du système";
|
||||
"bom.pdf.header.subtitle" = "%@ • %@";
|
||||
"bom.pdf.header.inline" = "Système d’unités : %@";
|
||||
"bom.pdf.placeholder.empty" = "Aucun composant disponible.";
|
||||
"bom.pdf.page.number" = "Page %d";
|
||||
"bom.category.components.title" = "Composants et chargeurs";
|
||||
"bom.category.components.subtitle" = "Appareils principaux, contrôleurs et équipements de charge.";
|
||||
"bom.category.batteries.title" = "Batteries";
|
||||
"bom.category.batteries.subtitle" = "Banques domestiques et stockage.";
|
||||
"bom.category.cables.title" = "Câbles";
|
||||
"bom.category.cables.subtitle" = "Liaisons dimensionnées pour chaque circuit.";
|
||||
"bom.category.fuses.title" = "Fusibles";
|
||||
"bom.category.fuses.subtitle" = "Protection des circuits et porte-fusibles.";
|
||||
"bom.category.accessories.title" = "Accessoires";
|
||||
"bom.category.accessories.subtitle" = "Fusibles, cosses et pièces complémentaires.";
|
||||
"bom.cable.detail.quantified" = "%1$dx %2$@";
|
||||
"bom.quantity.count.badge" = "%d×";
|
||||
"bom.quantity.length.badge" = "%1$.1f %2$@";
|
||||
"bom.quantity.length.badge.with.spec" = "%1$.1f %2$@ · %3$@";
|
||||
"component.fallback.name" = "Composant";
|
||||
"default.load.library" = "Charge de la bibliothèque";
|
||||
"default.load.name" = "Ma charge";
|
||||
@@ -322,4 +345,5 @@
|
||||
"cable.pro.paywall.subtitle" = "Cable PRO offre davantage d'options de configuration pour les charges, les batteries et les chargeurs.";
|
||||
"cable.pro.feature.dutyCycle" = "Calculs de câbles tenant compte du cycle d'utilisation";
|
||||
"cable.pro.feature.batteryCapacity" = "Configurez la capacité utilisable de la batterie";
|
||||
"cable.pro.feature.usageBased" = "Calculs basés sur l'utilisation";
|
||||
"cable.pro.feature.usageBased" = "Calculs basés sur l’utilisation";
|
||||
"generic.ok" = "OK";
|
||||
|
||||
@@ -14,6 +14,29 @@
|
||||
"bom.navigation.title.system" = "Materiaallijst – %@";
|
||||
"bom.size.unknown" = "Afmeting nog onbekend";
|
||||
"bom.terminals.detail" = "Ring- of vorkklemmen geschikt voor %@-bekabeling";
|
||||
"bom.empty.message" = "Er zijn nog geen componenten voor dit systeem opgeslagen.";
|
||||
"bom.export.pdf.button" = "PDF exporteren";
|
||||
"bom.export.pdf.error.title" = "Export mislukt";
|
||||
"bom.export.pdf.error.empty" = "Voeg minimaal één component toe voordat je exporteert.";
|
||||
"bom.pdf.header.title" = "Stuklijst van het systeem";
|
||||
"bom.pdf.header.subtitle" = "%@ • %@";
|
||||
"bom.pdf.header.inline" = "Maateenheid: %@";
|
||||
"bom.pdf.placeholder.empty" = "Geen componenten beschikbaar.";
|
||||
"bom.pdf.page.number" = "Pagina %d";
|
||||
"bom.category.components.title" = "Componenten en laders";
|
||||
"bom.category.components.subtitle" = "Hoofdapparaten, regelaars en laadapparatuur.";
|
||||
"bom.category.batteries.title" = "Batterijen";
|
||||
"bom.category.batteries.subtitle" = "Huishoudbanken en opslag.";
|
||||
"bom.category.cables.title" = "Kabels";
|
||||
"bom.category.cables.subtitle" = "Op maat gemaakte stroomtrajecten per circuit.";
|
||||
"bom.category.fuses.title" = "Zekeringen";
|
||||
"bom.category.fuses.subtitle" = "Circuitbeveiliging en houders.";
|
||||
"bom.category.accessories.title" = "Accessoires";
|
||||
"bom.category.accessories.subtitle" = "Zekeringen, kabelschoenen en ondersteunende onderdelen.";
|
||||
"bom.cable.detail.quantified" = "%1$dx %2$@";
|
||||
"bom.quantity.count.badge" = "%d×";
|
||||
"bom.quantity.length.badge" = "%1$.1f %2$@";
|
||||
"bom.quantity.length.badge.with.spec" = "%1$.1f %2$@ · %3$@";
|
||||
"component.fallback.name" = "Component";
|
||||
"default.load.library" = "Bibliotheeklast";
|
||||
"default.load.name" = "Mijn last";
|
||||
@@ -323,3 +346,4 @@
|
||||
"cable.pro.feature.dutyCycle" = "Kabelberekeningen die rekening houden met de inschakelduur";
|
||||
"cable.pro.feature.batteryCapacity" = "Configureer bruikbare batterijcapaciteit";
|
||||
"cable.pro.feature.usageBased" = "Gebruiksgestuurde berekeningen";
|
||||
"generic.ok" = "OK";
|
||||
|
||||
Reference in New Issue
Block a user