Files
lichtkasten/Sources/Lichtkasten/Views/UploadWindow.swift
T
Lichtkasten DevandClaude Opus 5.5 93ecdf03fc Gesendet-Status, Agentur-Check, Rückgängig und Spieltag-Assistent
- Gesendet-Status pro Bild: Upload-Historie (FTP + Immich) mit Ziel und Zeit, grünes Abzeichen im Kontaktabzug,
  Anzeige in Lupe und IPTC-Fenster, Filter Gesendet/Nicht gesendet, bereits gesendete beim Upload überspringen,
  'Als nicht gesendet markieren'
- Agentur-Check vor dem FTP-Upload: Pflichtfelder, offene Variablen und Codes, Datum aus alter Vorlage,
  IIM-Längen, offene Trikot-Vorschläge, Mindestgröße; Prüffenster mit Bearbeiten/Erneut prüfen/
  Nur fehlerfreie senden; Einstellungsseite und Schalter pro Server
- Rückgängig/Wiederholen (⌘Z/⇧⌘Z) für Sterne, Farben, Tags, IPTC und Vorlagen, Schreibvorgänge serialisiert,
  in Textfeldern bleibt ⌘Z beim Text
- Spieltag-Assistent (⌘⇧N, auch im Ingest und in der Matchday-Ansicht): Teams, Wettbewerbe und Muster werden
  gespeichert; erzeugt Vorlage im Aufbau der Basis-Vorlage, Ingest-Ordner, Trikot-Teams und aktive Code-Teams;
  Trikotfarben aus der Erkennung fließen ins Team zurück; Matchday nimmt die Teams aus dem Ereignis des Bildes
- Tests für Spieltag-Generator, Agentur-Check und Gesendet-Log, README ergänzt

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012bGzgsxrmbBhDzeMV2L57D
2026-11-05 00:23:03 +00:00

209 lines
11 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import SwiftUI
import LichtkastenCore
/// ⌘U – upload dialog in the Leuchttisch look: destinations as cards, options of the chosen one, summary.
struct UploadWindow: View {
@EnvironmentObject var state: AppState
@Environment(\.dismissWindow) private var dismissWindow
@AppStorage("lastUploadTarget") private var target = ""
@AppStorage("uploadSkipSent") private var skipSent = true
private var destination: FTPDestination? { state.settings.ftpDestinations.first { $0.id.uuidString == target } }
private var destIndex: Int? { state.settings.ftpDestinations.firstIndex { $0.id.uuidString == target } }
private var variant: UploadVariant {
target == "immich" ? state.settings.immich.variant : destination?.variant ?? .jpeg
}
private var files: [URL] { sendItems.flatMap { state.uploadFiles(for: $0, variant: variant) } }
/// selected photos already sent to this destination
private var alreadySent: [PhotoItem] { state.selectedItems.filter { state.sentLog.wasSent($0, to: target) } }
private var sendItems: [PhotoItem] {
guard skipSent else { return state.selectedItems }
let sent = Set(alreadySent.map(\.id))
return state.selectedItems.filter { !sent.contains($0.id) }
}
private var totalBytes: Int64 {
files.reduce(0) { sum, f in sum + (((try? FileManager.default.attributesOfItem(atPath: f.path)[.size]) as? NSNumber)?.int64Value ?? 0) }
}
var body: some View {
VStack(alignment: .leading, spacing: 0) {
// header
HStack(spacing: 14) {
Image(systemName: "icloud.and.arrow.up")
.font(.system(size: 20, weight: .semibold))
.foregroundStyle(LK.onAmber)
.frame(width: 42, height: 42)
.background(RoundedRectangle(cornerRadius: 11).fill(LK.amber))
VStack(alignment: .leading, spacing: 2) {
Text("Bilder hochladen").font(.system(size: 18, weight: .bold)).foregroundStyle(LK.text)
Text(summary).font(LK.mono(12)).foregroundStyle(LK.text2)
}
Spacer()
}
.padding(22)
Rectangle().fill(LK.border).frame(height: 1)
ScrollView {
VStack(alignment: .leading, spacing: 18) {
LKSectionLabel(title: "Ziel")
LazyVGrid(columns: [GridItem(.adaptive(minimum: 220), spacing: 12)], spacing: 12) {
ForEach(state.settings.ftpDestinations) { d in
destinationCard(id: d.id.uuidString, icon: "server.rack", title: d.name,
subtitle: d.host.isEmpty ? "Server fehlt" : d.host,
detail: d.remoteDirectory, warning: credentialsMissing(d))
}
if state.settings.immich.enabled {
destinationCard(id: "immich", icon: "photo.stack", title: "Immich",
subtitle: URL(string: state.settings.immich.serverURL)?.host ?? state.settings.immich.serverURL,
detail: albumPreview, warning: false)
}
}
if let i = destIndex {
LKSectionLabel(title: "Optionen").padding(.top, 4)
VStack(spacing: 0) {
optionRow("Zielordner") {
TextField("/", text: $state.settings.ftpDestinations[i].remoteDirectory).textFieldStyle(.plain).lkField()
}
divider
optionRow("Umbenennen") {
TextField("leer = Originalname, z. B. {isodate}_{filenamebase}", text: $state.settings.ftpDestinations[i].renamePattern)
.textFieldStyle(.plain).lkField()
}
divider
optionRow("Dateien") {
LKSegmented(options: UploadVariant.allCases.map { ($0, $0.rawValue) },
selection: $state.settings.ftpDestinations[i].variant)
}
divider
optionRow("Agentur-Check") {
Toggle("Vor dem Senden prüfen (Pflichtfelder, Codes, Datum …)", isOn: $state.settings.ftpDestinations[i].preflight)
.toggleStyle(.checkbox)
}
}
.background(RoundedRectangle(cornerRadius: 12).fill(LK.card))
.overlay(RoundedRectangle(cornerRadius: 12).stroke(LK.border))
} else if target == "immich" {
LKSectionLabel(title: "Optionen").padding(.top, 4)
VStack(spacing: 0) {
optionRow("Album-Muster") {
TextField("{event}", text: $state.settings.immich.albumName).textFieldStyle(.plain).lkField()
}
divider
optionRow("Dateien") {
LKSegmented(options: UploadVariant.allCases.map { ($0, $0.rawValue) }, selection: $state.settings.immich.variant)
}
}
.background(RoundedRectangle(cornerRadius: 12).fill(LK.card))
.overlay(RoundedRectangle(cornerRadius: 12).stroke(LK.border))
}
if !alreadySent.isEmpty {
Toggle(isOn: $skipSent) {
Label("\(alreadySent.count) Bild(er) wurden schon an dieses Ziel gesendet – überspringen", systemImage: "paperplane.fill")
.font(.system(size: 12, weight: .semibold))
.foregroundStyle(LK.green)
}
.toggleStyle(.checkbox)
}
if files.count < sendItems.count {
Label("\(max(0, sendItems.count - files.count)) Bild(er) ohne JPEG – zuerst in Lightroom exportieren (⌘⌥L).",
systemImage: "exclamationmark.triangle.fill")
.font(.system(size: 12)).foregroundStyle(LK.amber)
}
if let d = destination, credentialsMissing(d) {
Label("Benutzer oder Passwort fehlen – „Server verwalten …“", systemImage: "key.fill")
.font(.system(size: 12)).foregroundStyle(LK.red)
}
}
.padding(22)
}
Rectangle().fill(LK.border).frame(height: 1)
HStack {
SettingsLink { Text("Server verwalten …") }.buttonStyle(LKButtonStyle())
Spacer()
Button("Abbrechen") { dismissWindow(id: "upload") }
.buttonStyle(LKButtonStyle())
.keyboardShortcut(.cancelAction)
Button("\(files.count) Datei(en) hochladen") {
state.requestUpload(state.selectedItems, to: target, skipAlreadySent: skipSent)
if state.pendingUpload == nil { state.openWindow("tasks") }
dismissWindow(id: "upload")
}
.buttonStyle(LKButtonStyle(primary: true))
.keyboardShortcut(.defaultAction)
.disabled(target.isEmpty || files.isEmpty)
}
.padding(18)
}
.frame(width: 620)
.frame(minHeight: 460)
.background(LK.ground)
.onAppear {
if target.isEmpty || (destination == nil && target != "immich"),
let first = state.settings.ftpDestinations.first { target = first.id.uuidString }
}
}
private var summary: String {
let n = state.selectedItems.count
let size = ByteCountFormatter.string(fromByteCount: totalBytes, countStyle: .file)
return "\(n) Bild\(n == 1 ? "" : "er") ausgewählt · \(files.count) Datei(en) · \(size)"
}
private var albumPreview: String {
let albums = Set(state.selectedItems.map { state.immichAlbum(for: $0) }.filter { !$0.isEmpty })
return albums.isEmpty ? "kein Album" : "Album: " + albums.sorted().joined(separator: ", ")
}
private func credentialsMissing(_ d: FTPDestination) -> Bool {
d.username.isEmpty || Keychain.get(d.keychainAccount) == nil
}
private var divider: some View { Rectangle().fill(LK.border).frame(height: 1).padding(.leading, 14) }
private func optionRow<C: View>(_ label: String, @ViewBuilder content: () -> C) -> some View {
HStack(spacing: 14) {
Text(label).font(.system(size: 13)).foregroundStyle(LK.text2).frame(width: 110, alignment: .leading)
content()
}
.padding(.horizontal, 14)
.padding(.vertical, 10)
}
private func destinationCard(id: String, icon: String, title: String, subtitle: String, detail: String, warning: Bool) -> some View {
let on = target == id
return Button { target = id } label: {
HStack(alignment: .top, spacing: 12) {
Image(systemName: icon)
.font(.system(size: 16, weight: .semibold))
.foregroundStyle(on ? LK.onAmber : LK.text2)
.frame(width: 34, height: 34)
.background(RoundedRectangle(cornerRadius: 9).fill(on ? LK.amber : LK.raised))
VStack(alignment: .leading, spacing: 3) {
HStack(spacing: 6) {
Text(title).font(.system(size: 14, weight: .bold)).foregroundStyle(LK.text).lineLimit(1)
if warning { Image(systemName: "key.fill").font(.system(size: 10)).foregroundStyle(LK.red) }
}
Text(subtitle).font(LK.mono(11)).foregroundStyle(LK.muted).lineLimit(1).truncationMode(.middle)
Text(detail).font(LK.mono(11)).foregroundStyle(on ? LK.amber : LK.text2).lineLimit(1).truncationMode(.middle)
}
Spacer(minLength: 0)
if on { Image(systemName: "checkmark.circle.fill").foregroundStyle(LK.amber) }
}
.padding(12)
.frame(maxWidth: .infinity, alignment: .leading)
.background(RoundedRectangle(cornerRadius: 12).fill(on ? LK.selected : LK.card))
.overlay(RoundedRectangle(cornerRadius: 12).stroke(on ? LK.amber : LK.border, lineWidth: on ? 2 : 1))
.contentShape(Rectangle())
}
.buttonStyle(.plain)
}
}