Initial commit for first version of project
This commit is contained in:
82
GasTankAR/Views/ProjectCreate.swift
Normal file
82
GasTankAR/Views/ProjectCreate.swift
Normal file
@ -0,0 +1,82 @@
|
||||
//
|
||||
// ProjectCreate.swift
|
||||
// GasTankAR
|
||||
//
|
||||
// Created by Dennis Nemec on 25.08.26.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import SwiftData
|
||||
|
||||
struct ProjectCreateView: View {
|
||||
@Environment(\.modelContext) private var modelContext
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@State private var leadID: String = ""
|
||||
@State private var customerName: String = ""
|
||||
@State private var creationDate: Date = .now
|
||||
@State private var tank: Tank = Tank()
|
||||
|
||||
/// Whether the entered values are sufficient to create a project.
|
||||
private var canSave: Bool {
|
||||
!leadID.trimmingCharacters(in: .whitespaces).isEmpty
|
||||
&& !customerName.trimmingCharacters(in: .whitespaces).isEmpty
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
Form {
|
||||
Section("Projektdaten") {
|
||||
TextField("Lead-ID", text: $leadID)
|
||||
.textInputAutocapitalization(.characters)
|
||||
.autocorrectionDisabled()
|
||||
|
||||
TextField("Kundenname", text: $customerName)
|
||||
.textInputAutocapitalization(.words)
|
||||
|
||||
DatePicker(
|
||||
"Erstellungsdatum",
|
||||
selection: $creationDate,
|
||||
displayedComponents: [.date]
|
||||
)
|
||||
}
|
||||
|
||||
Section("Tankauswahl") {
|
||||
TankEditor(tank: $tank)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Projekt erstellen")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button("Abbrechen", systemImage: "xmark") {
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
ToolbarItem(placement: .confirmationAction) {
|
||||
Button("Speichern", systemImage: "checkmark") {
|
||||
save()
|
||||
}
|
||||
.buttonStyle(.borderedProminent)
|
||||
.disabled(!canSave)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func save() {
|
||||
let project = Project(
|
||||
leadID: leadID.trimmingCharacters(in: .whitespaces),
|
||||
customerName: customerName.trimmingCharacters(in: .whitespaces),
|
||||
creationDate: creationDate,
|
||||
tank: tank
|
||||
)
|
||||
modelContext.insert(project)
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ProjectCreateView()
|
||||
.modelContainer(for: Project.self, inMemory: true)
|
||||
}
|
||||
Reference in New Issue
Block a user