parent
8eadd30759
commit
9291d63d05
@ -0,0 +1,80 @@ |
|||||||
|
// |
||||||
|
// DrawLog.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by razmig on 22/10/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import Foundation |
||||||
|
import SwiftUI |
||||||
|
import LeStorage |
||||||
|
|
||||||
|
@Observable |
||||||
|
final class DrawLog: ModelObject, Storable { |
||||||
|
static func resourceName() -> String { return "draw-logs" } |
||||||
|
static func tokenExemptedMethods() -> [HTTPMethod] { return [] } |
||||||
|
static func filterByStoreIdentifier() -> Bool { return false } |
||||||
|
static var relationshipNames: [String] = [] |
||||||
|
|
||||||
|
var id: String = Store.randomId() |
||||||
|
var tournament: String |
||||||
|
var drawDate: Date = Date() |
||||||
|
var drawSeed: Int? |
||||||
|
var drawPosition: Int |
||||||
|
var drawTeamPosition: TeamPosition |
||||||
|
|
||||||
|
internal init(id: String = Store.randomId(), tournament: String, drawDate: Date = Date(), drawSeed: Int?, drawPosition: Int, drawTeamPosition: TeamPosition) { |
||||||
|
self.id = id |
||||||
|
self.tournament = tournament |
||||||
|
self.drawDate = drawDate |
||||||
|
self.drawSeed = drawSeed |
||||||
|
self.drawPosition = drawPosition |
||||||
|
self.drawTeamPosition = drawTeamPosition |
||||||
|
} |
||||||
|
|
||||||
|
func exportedDrawLog() -> String { |
||||||
|
[drawDate.localizedDate(), localizedDrawLogLabel(), localizedDrawBranch()].joined(separator: " ") |
||||||
|
} |
||||||
|
|
||||||
|
func localizedDrawSeedLabel() -> String { |
||||||
|
if let drawSeed { |
||||||
|
return "Tête de série #\(drawSeed + 1)" |
||||||
|
} else { |
||||||
|
return "Tête de série non trouvé" |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
func localizedDrawLogLabel() -> String { |
||||||
|
return [localizedDrawSeedLabel(), positionLabel()].joined(separator: " -> ") |
||||||
|
} |
||||||
|
|
||||||
|
func localizedDrawBranch() -> String { |
||||||
|
drawTeamPosition.localizedBranchLabel() |
||||||
|
} |
||||||
|
|
||||||
|
func positionLabel() -> String { |
||||||
|
let roundIndex = RoundRule.roundIndex(fromMatchIndex: drawPosition) |
||||||
|
return tournamentStore.rounds.first(where: { $0.parent == nil && $0.index == roundIndex })?._matches().first(where: { $0.index == drawPosition })?.roundAndMatchTitle() ?? "" |
||||||
|
} |
||||||
|
|
||||||
|
var tournamentStore: TournamentStore { |
||||||
|
return TournamentStore.instance(tournamentId: self.tournament) |
||||||
|
} |
||||||
|
|
||||||
|
override func deleteDependencies() throws { |
||||||
|
} |
||||||
|
|
||||||
|
enum CodingKeys: String, CodingKey { |
||||||
|
case _id = "id" |
||||||
|
case _tournament = "tournament" |
||||||
|
case _drawDate = "drawDate" |
||||||
|
case _drawSeed = "drawSeed" |
||||||
|
case _drawPosition = "drawPosition" |
||||||
|
case _drawTeamPosition = "drawTeamPosition" |
||||||
|
} |
||||||
|
|
||||||
|
func insertOnServer() throws { |
||||||
|
self.tournamentStore.drawLogs.writeChangeAndInsertOnServer(instance: self) |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,51 @@ |
|||||||
|
// |
||||||
|
// DrawLogsView.swift |
||||||
|
// PadelClub |
||||||
|
// |
||||||
|
// Created by razmig on 22/10/2024. |
||||||
|
// |
||||||
|
|
||||||
|
import SwiftUI |
||||||
|
import LeStorage |
||||||
|
|
||||||
|
struct DrawLogsView: View { |
||||||
|
@Environment(Tournament.self) var tournament |
||||||
|
|
||||||
|
var drawLogs: [DrawLog] { |
||||||
|
tournament.drawLogs().reversed() |
||||||
|
} |
||||||
|
|
||||||
|
var body: some View { |
||||||
|
List { |
||||||
|
ForEach(drawLogs) { drawLog in |
||||||
|
LabeledContent { |
||||||
|
Text(drawLog.localizedDrawBranch()) |
||||||
|
} label: { |
||||||
|
Text(drawLog.localizedDrawSeedLabel()) |
||||||
|
Text(drawLog.positionLabel()) |
||||||
|
Text(drawLog.drawDate.localizedDate()) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
.overlay(content: { |
||||||
|
if drawLogs.isEmpty { |
||||||
|
ContentUnavailableView("Aucun tirage", systemImage: "dice", description: Text("Aucun tirage au sort n'a été effectué.")) |
||||||
|
} |
||||||
|
}) |
||||||
|
.toolbar(content: { |
||||||
|
ToolbarItem(placement: .topBarTrailing) { |
||||||
|
Menu { |
||||||
|
ShareLink(item: tournament.exportedDrawLogs()) { |
||||||
|
Label("Partager les tirages", systemImage: "square.and.arrow.up") |
||||||
|
.labelStyle(.titleAndIcon) |
||||||
|
} |
||||||
|
} label: { |
||||||
|
LabelOptions() |
||||||
|
} |
||||||
|
} |
||||||
|
}) |
||||||
|
.navigationBarTitleDisplayMode(.inline) |
||||||
|
.toolbarBackground(.visible, for: .navigationBar) |
||||||
|
.navigationTitle("Journal des tirages") |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue