Working spreadsheet view, pending UI updates

This commit is contained in:
2026-04-05 00:15:25 -05:00
parent c228c26589
commit 46e61bae00
3 changed files with 192 additions and 0 deletions

View File

@@ -47,6 +47,7 @@ struct InventoryView: View {
@State private var addMode: AddMode? @State private var addMode: AddMode?
@State private var isSelectMode = false @State private var isSelectMode = false
@State private var selectedIDs: Set<String> = [] @State private var selectedIDs: Set<String> = []
@State private var showSpreadsheet = false
enum AddMode: String, Identifiable { enum AddMode: String, Identifiable {
case manual, scan case manual, scan
@@ -141,6 +142,13 @@ struct InventoryView: View {
.disabled(selectedIDs.isEmpty) .disabled(selectedIDs.isEmpty)
} }
} else { } else {
ToolbarItem(placement: .topBarLeading) {
Button {
showSpreadsheet = true
} label: {
Image(systemName: "tablecells")
}
}
ToolbarItem(placement: .topBarTrailing) { ToolbarItem(placement: .topBarTrailing) {
Menu { Menu {
Button { Button {
@@ -184,5 +192,10 @@ struct InventoryView: View {
.task { .task {
await viewModel.loadChemicals() await viewModel.loadChemicals()
} }
.fullScreenCover(isPresented: $showSpreadsheet) {
SpreadsheetView(chemicals: viewModel.chemicals) {
showSpreadsheet = false
}
}
} }
} }

View File

@@ -1,8 +1,23 @@
import SwiftUI import SwiftUI
import LabWiseKit import LabWiseKit
import UIKit
// Controls which orientations are allowed app-wide at runtime.
// SpreadsheetView flips this to .landscape; all other screens use .allButUpsideDown.
final class AppDelegate: NSObject, UIApplicationDelegate {
static var orientationLock: UIInterfaceOrientationMask = .allButUpsideDown
func application(
_ application: UIApplication,
supportedInterfaceOrientationsFor window: UIWindow?
) -> UIInterfaceOrientationMask {
AppDelegate.orientationLock
}
}
@main @main
struct LabWiseApp: App { struct LabWiseApp: App {
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
@State private var appState = AppState.shared @State private var appState = AppState.shared
var body: some Scene { var body: some Scene {

View File

@@ -0,0 +1,164 @@
import SwiftUI
import LabWiseKit
struct SpreadsheetView: View {
let chemicals: [Chemical]
let onDismiss: () -> Void
private struct ColumnDef {
let label: String
let width: CGFloat
let value: (Chemical) -> String
}
private static let columnDefs: [ColumnDef] = [
ColumnDef(label: "PI First Name", width: 130) { $0.piFirstName },
ColumnDef(label: "Physical State", width: 120) { $0.physicalState },
ColumnDef(label: "Chemical Name", width: 180) { $0.chemicalName },
ColumnDef(label: "Bldg Code", width: 100) { $0.bldgCode },
ColumnDef(label: "LAB", width: 80) { $0.lab },
ColumnDef(label: "Storage Location", width: 145) { $0.storageLocation },
ColumnDef(label: "Storage Device", width: 140) { $0.storageDevice },
ColumnDef(label: "# of Containers", width: 120) { $0.numberOfContainers },
ColumnDef(label: "Amount / Container", width: 150) { $0.amountPerContainer },
ColumnDef(label: "Unit of Measure", width: 130) { $0.unitOfMeasure },
ColumnDef(label: "CAS #", width: 115) { $0.casNumber },
ColumnDef(label: "Chemical Formula", width: 140) { $0.chemicalFormula ?? "" },
ColumnDef(label: "Molecular Weight", width: 130) { $0.molecularWeight ?? "" },
ColumnDef(label: "Vendor", width: 130) { $0.vendor ?? "" },
ColumnDef(label: "Catalog #", width: 120) { $0.catalogNumber ?? "" },
ColumnDef(label: "Lot Number", width: 120) { $0.lotNumber ?? "" },
ColumnDef(label: "Concentration", width: 120) { $0.concentration ?? "" },
ColumnDef(label: "Expiration Date", width: 130) { $0.expirationDate ?? "" },
ColumnDef(label: "Contact", width: 130) { $0.contact ?? "" },
ColumnDef(label: "Barcode", width: 130) { $0.barcode ?? "" },
ColumnDef(label: "Comments", width: 180) { $0.comments ?? "" },
ColumnDef(label: "% Full", width: 80) { c in
c.percentageFull.map { String(format: "%.0f%%", $0) } ?? ""
},
ColumnDef(label: "Date Entered", width: 130) { c in
c.createdAt.map { String($0.prefix(10)) } ?? ""
},
ColumnDef(label: "Last Changed", width: 130) { c in
c.updatedAt.map { String($0.prefix(10)) } ?? ""
},
]
private static let headerHeight: CGFloat = 48
var body: some View {
VStack(spacing: 0) {
// Top bar
HStack(spacing: 4) {
Button {
restorePortrait()
onDismiss()
} label: {
Image(systemName: "xmark.circle.fill")
.font(.title2)
.foregroundStyle(.secondary)
}
.padding(.leading, 12)
Text("Inventory Spreadsheet")
.font(.headline)
.padding(.leading, 4)
Spacer()
Text("\(chemicals.count) item\(chemicals.count == 1 ? "" : "s")")
.font(.subheadline)
.foregroundStyle(.secondary)
.padding(.trailing, 16)
}
.frame(height: 50)
.background(Color(.systemBackground))
Divider()
// Table
GeometryReader { proxy in
ScrollView(.horizontal, showsIndicators: true) {
VStack(alignment: .leading, spacing: 0) {
// Sticky header row
HStack(spacing: 0) {
ForEach(Array(Self.columnDefs.enumerated()), id: \.offset) { i, col in
Text(col.label)
.font(.caption.weight(.semibold))
.foregroundStyle(.white)
.lineLimit(2)
.multilineTextAlignment(.center)
.frame(width: col.width, height: Self.headerHeight)
.padding(.horizontal, 4)
if i < Self.columnDefs.count - 1 {
Rectangle()
.fill(Color.white.opacity(0.35))
.frame(width: 1, height: Self.headerHeight)
}
}
}
.background(Color.accentColor)
Divider()
// Scrollable data rows
ScrollView(.vertical, showsIndicators: true) {
LazyVStack(spacing: 0) {
ForEach(Array(chemicals.enumerated()), id: \.element.id) { idx, chemical in
HStack(spacing: 0) {
ForEach(Array(Self.columnDefs.enumerated()), id: \.offset) { i, col in
Text(col.value(chemical))
.font(.caption)
.lineLimit(1)
.frame(width: col.width, alignment: .leading)
.padding(.vertical, 7)
.padding(.horizontal, 6)
.background(idx % 2 == 0
? Color(.systemBackground)
: Color(.systemGray6))
if i < Self.columnDefs.count - 1 {
Rectangle()
.fill(Color(.separator))
.frame(width: 0.5)
.frame(height: 30)
}
}
}
Divider()
}
}
}
// Subtract header height and the 1-pt divider
.frame(height: proxy.size.height - Self.headerHeight - 1)
}
}
}
}
.onAppear {
// Slight delay so the full-screen cover animation finishes before rotating
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
setLandscape()
}
}
.onDisappear {
// Safety net in case something else dismisses this view
restorePortrait()
}
}
// MARK: - Orientation helpers
private func setLandscape() {
AppDelegate.orientationLock = .landscape
guard let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene else { return }
scene.requestGeometryUpdate(.iOS(interfaceOrientations: .landscape))
}
private func restorePortrait() {
AppDelegate.orientationLock = .allButUpsideDown
guard let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene else { return }
scene.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait))
}
}