fix issue with smart planning save

paca_championship
Raz 1 year ago
parent 884f1d9186
commit e12dbff90d
  1. 18
      PadelClub/Views/Navigation/Umpire/UmpireStatisticView.swift
  2. 8
      PadelClub/Views/Planning/GroupStageScheduleEditorView.swift
  3. 16
      PadelClub/Views/Planning/LoserRoundScheduleEditorView.swift
  4. 21
      PadelClub/Views/Planning/MatchScheduleEditorView.swift
  5. 7
      PadelClub/Views/Planning/RoundScheduleEditorView.swift
  6. 18
      PadelClub/Views/Player/PlayerStatisticView.swift

@ -0,0 +1,18 @@
//
// UmpireStatisticView.swift
// PadelClub
//
// Created by razmig on 06/11/2024.
//
import SwiftUI
struct UmpireStatisticView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
#Preview {
UmpireStatisticView()
}

@ -15,6 +15,7 @@ struct GroupStageScheduleEditorView: View {
@Bindable var groupStage: GroupStage @Bindable var groupStage: GroupStage
var tournament: Tournament var tournament: Tournament
@State private var startDate: Date @State private var startDate: Date
@State private var currentDate: Date?
var tournamentStore: TournamentStore { var tournamentStore: TournamentStore {
return self.tournament.tournamentStore return self.tournament.tournamentStore
@ -24,14 +25,19 @@ struct GroupStageScheduleEditorView: View {
self.groupStage = groupStage self.groupStage = groupStage
self.tournament = tournament self.tournament = tournament
self._startDate = State(wrappedValue: groupStage.startDate ?? tournament.startDate) self._startDate = State(wrappedValue: groupStage.startDate ?? tournament.startDate)
self._currentDate = State(wrappedValue: groupStage.startDate)
} }
var body: some View { var body: some View {
GroupStageDatePickingView(title: groupStage.groupStageTitle(.title), startDate: $startDate, currentDate: $groupStage.startDate, duration: groupStage.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) { GroupStageDatePickingView(title: groupStage.groupStageTitle(.title), startDate: $startDate, currentDate: $currentDate, duration: groupStage.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
groupStage.startDate = startDate groupStage.startDate = startDate
tournament.matchScheduler()?.updateGroupStageSchedule(tournament: tournament, specificGroupStage: groupStage) tournament.matchScheduler()?.updateGroupStageSchedule(tournament: tournament, specificGroupStage: groupStage)
_save() _save()
} }
.onChange(of: currentDate) {
groupStage.startDate = currentDate
_save()
}
} }
private func _save() { private func _save() {

@ -17,6 +17,7 @@ struct LoserRoundScheduleEditorView: View {
var loserRounds: [Round] var loserRounds: [Round]
@State private var startDate: Date @State private var startDate: Date
@State private var matchFormat: MatchFormat @State private var matchFormat: MatchFormat
@State private var currentDate: Date?
var tournamentStore: TournamentStore { var tournamentStore: TournamentStore {
return self.tournament.tournamentStore return self.tournament.tournamentStore
@ -27,8 +28,11 @@ struct LoserRoundScheduleEditorView: View {
self.tournament = tournament self.tournament = tournament
let _loserRounds = upperRound.loserRounds() let _loserRounds = upperRound.loserRounds()
self.loserRounds = _loserRounds self.loserRounds = _loserRounds
self._startDate = State(wrappedValue: _loserRounds.first(where: { $0.startDate != nil })?.startDate ?? _loserRounds.first(where: { $0.isDisabled() == false })?.enabledMatches().first?.startDate ?? tournament.startDate) let startDate = _loserRounds.first(where: { $0.startDate != nil })?.startDate ?? _loserRounds.first(where: { $0.isDisabled() == false })?.enabledMatches().first?.startDate
self._startDate = State(wrappedValue: startDate ?? tournament.startDate)
self._matchFormat = State(wrappedValue: _loserRounds.first?.matchFormat ?? upperRound.matchFormat) self._matchFormat = State(wrappedValue: _loserRounds.first?.matchFormat ?? upperRound.matchFormat)
self._currentDate = State(wrappedValue: startDate)
} }
var body: some View { var body: some View {
@ -37,9 +41,17 @@ struct LoserRoundScheduleEditorView: View {
await _updateSchedule() await _updateSchedule()
} }
DatePickingView(title: "Horaire minimum", startDate: $startDate, currentDate: .constant(nil), duration: matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) { DatePickingView(title: "Horaire minimum", startDate: $startDate, currentDate: $currentDate, duration: matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
await _updateSchedule() await _updateSchedule()
} }
.onChange(of: currentDate) {
let enabledLoserRounds = upperRound.loserRounds().filter({ $0.isDisabled() == false })
for loserRound in enabledLoserRounds {
loserRound.startDate = currentDate
}
_save()
}
let enabledLoserRounds = upperRound.loserRounds().filter({ $0.isDisabled() == false }) let enabledLoserRounds = upperRound.loserRounds().filter({ $0.isDisabled() == false })
ForEach(enabledLoserRounds.indices, id: \.self) { index in ForEach(enabledLoserRounds.indices, id: \.self) { index in

@ -6,16 +6,23 @@
// //
import SwiftUI import SwiftUI
import LeStorage
struct MatchScheduleEditorView: View { struct MatchScheduleEditorView: View {
@Bindable var match: Match @Bindable var match: Match
var tournament: Tournament var tournament: Tournament
@State private var startDate: Date @State private var startDate: Date
@State private var currentDate: Date?
var tournamentStore: TournamentStore {
return self.tournament.tournamentStore
}
init(match: Match, tournament: Tournament) { init(match: Match, tournament: Tournament) {
self.match = match self.match = match
self.tournament = tournament self.tournament = tournament
self._startDate = State(wrappedValue: match.startDate ?? tournament.startDate) self._startDate = State(wrappedValue: match.startDate ?? tournament.startDate)
self._currentDate = State(wrappedValue: match.startDate)
} }
var title: String { var title: String {
@ -31,15 +38,27 @@ struct MatchScheduleEditorView: View {
await _updateSchedule() await _updateSchedule()
} }
DatePickingView(title: title, startDate: $startDate, currentDate: .constant(nil), duration: match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) { DatePickingView(title: title, startDate: $startDate, currentDate: $currentDate, duration: match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
await _updateSchedule() await _updateSchedule()
} }
.onChange(of: currentDate) {
match.startDate = currentDate
_save()
}
} }
private func _updateSchedule() async { private func _updateSchedule() async {
let scheduler: MatchScheduler? = tournament.matchScheduler() let scheduler: MatchScheduler? = tournament.matchScheduler()
scheduler?.updateBracketSchedule(tournament: tournament, fromRoundId: match.round, fromMatchId: match.id, startDate: startDate) scheduler?.updateBracketSchedule(tournament: tournament, fromRoundId: match.round, fromMatchId: match.id, startDate: startDate)
} }
private func _save() {
do {
try tournamentStore.matches.addOrUpdate(instance: match)
} catch {
Logger.error(error)
}
}
} }
//#Preview { //#Preview {

@ -14,6 +14,7 @@ struct RoundScheduleEditorView: View {
var round: Round var round: Round
var tournament: Tournament var tournament: Tournament
@State private var startDate: Date @State private var startDate: Date
@State private var currentDate: Date?
var tournamentStore: TournamentStore { var tournamentStore: TournamentStore {
return self.tournament.tournamentStore return self.tournament.tournamentStore
@ -23,6 +24,7 @@ struct RoundScheduleEditorView: View {
self.round = round self.round = round
self.tournament = tournament self.tournament = tournament
self._startDate = State(wrappedValue: round.startDate ?? round.playedMatches().first?.startDate ?? tournament.startDate) self._startDate = State(wrappedValue: round.startDate ?? round.playedMatches().first?.startDate ?? tournament.startDate)
self._currentDate = State(wrappedValue: round.startDate)
} }
var body: some View { var body: some View {
@ -32,9 +34,12 @@ struct RoundScheduleEditorView: View {
await _updateSchedule() await _updateSchedule()
} }
DatePickingView(title: "Horaire minimum", startDate: $startDate, currentDate: $round.startDate, duration: round.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) { DatePickingView(title: "Horaire minimum", startDate: $startDate, currentDate: $currentDate, duration: round.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
await _updateSchedule() await _updateSchedule()
} }
.onChange(of: currentDate) {
round.startDate = currentDate
}
ForEach(round.playedMatches()) { match in ForEach(round.playedMatches()) { match in
MatchScheduleEditorView(match: match, tournament: tournament) MatchScheduleEditorView(match: match, tournament: tournament)

@ -0,0 +1,18 @@
//
// PlayerStatisticView.swift
// PadelClub
//
// Created by razmig on 06/11/2024.
//
import SwiftUI
struct PlayerStatisticView: View {
var body: some View {
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
}
}
#Preview {
PlayerStatisticView()
}
Loading…
Cancel
Save