|
|
|
|
@ -9,71 +9,66 @@ import SwiftUI |
|
|
|
|
|
|
|
|
|
struct LoserRoundScheduleEditorView: View { |
|
|
|
|
@EnvironmentObject var dataStore: DataStore |
|
|
|
|
@Environment(Tournament.self) var tournament: Tournament |
|
|
|
|
|
|
|
|
|
var upperRound: Round |
|
|
|
|
var tournament: Tournament |
|
|
|
|
var loserRounds: [Round] |
|
|
|
|
@State private var startDate: Date |
|
|
|
|
@State private var matchFormat: MatchFormat |
|
|
|
|
|
|
|
|
|
init(upperRound: Round) { |
|
|
|
|
init(upperRound: Round, tournament: Tournament) { |
|
|
|
|
self.upperRound = upperRound |
|
|
|
|
self.tournament = tournament |
|
|
|
|
let _loserRounds = upperRound.loserRounds() |
|
|
|
|
self.loserRounds = _loserRounds |
|
|
|
|
self._startDate = State(wrappedValue: _loserRounds.first(where: { $0.startDate != nil })?.startDate ?? _loserRounds.first(where: { $0.isDisabled() == false })?.enabledMatches().first?.startDate ?? Date()) |
|
|
|
|
self._startDate = State(wrappedValue: _loserRounds.first(where: { $0.startDate != nil })?.startDate ?? _loserRounds.first(where: { $0.isDisabled() == false })?.enabledMatches().first?.startDate ?? tournament.startDate) |
|
|
|
|
self._matchFormat = State(wrappedValue: _loserRounds.first?.matchFormat ?? upperRound.matchFormat) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var body: some View { |
|
|
|
|
List { |
|
|
|
|
Section { |
|
|
|
|
MatchFormatPickerView(headerLabel: "Format", matchFormat: $matchFormat) |
|
|
|
|
DatePicker(selection: $startDate) { |
|
|
|
|
Text(startDate.formatted(.dateTime.weekday(.wide))).font(.headline) |
|
|
|
|
} |
|
|
|
|
} header: { |
|
|
|
|
Text("Match de classement " + upperRound.roundTitle()) |
|
|
|
|
} footer: { |
|
|
|
|
DateUpdateManagerView(startDate: $startDate, currentDate: .constant(nil), duration: matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) { |
|
|
|
|
_updateSchedule() |
|
|
|
|
} |
|
|
|
|
MatchFormatPickingView(matchFormat: $matchFormat) { |
|
|
|
|
await _updateSchedule() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DatePickingView(title: "Horaire minimum", startDate: $startDate, currentDate: .constant(nil), duration: matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) { |
|
|
|
|
await _updateSchedule() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let enabledLoserRounds = upperRound.loserRounds().filter({ $0.isDisabled() == false }) |
|
|
|
|
ForEach(enabledLoserRounds.indices, id: \.self) { index in |
|
|
|
|
let loserRound = enabledLoserRounds[index] |
|
|
|
|
LoserRoundStepScheduleEditorView(stepIndex: index, round: loserRound, upperRound: upperRound) |
|
|
|
|
LoserRoundStepScheduleEditorView(stepIndex: index, round: loserRound, upperRound: upperRound, tournament: tournament) |
|
|
|
|
.id(UUID()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.onChange(of: matchFormat) { |
|
|
|
|
loserRounds.forEach { round in |
|
|
|
|
round.updateMatchFormatAndAllMatches(matchFormat) |
|
|
|
|
//round.updateIfRequiredMatchFormat(matchFormat, andLoserBracket: true) |
|
|
|
|
round.updateMatchFormat(matchFormat, checkIfPossible: false, andLoserBracket: true) |
|
|
|
|
} |
|
|
|
|
_save() |
|
|
|
|
} |
|
|
|
|
.headerProminence(.increased) |
|
|
|
|
.navigationTitle("Horaires") |
|
|
|
|
.navigationTitle("Classement " + upperRound.roundTitle()) |
|
|
|
|
.toolbarBackground(.visible, for: .navigationBar) |
|
|
|
|
.navigationBarTitleDisplayMode(.inline) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _updateSchedule() { |
|
|
|
|
let matches = upperRound.loserRounds().flatMap({ round in |
|
|
|
|
round.playedMatches() |
|
|
|
|
}) |
|
|
|
|
upperRound.loserRounds().forEach({ round in |
|
|
|
|
round.resetFromRoundAllMatchesStartDate() |
|
|
|
|
}) |
|
|
|
|
private func _updateSchedule() async { |
|
|
|
|
// let matches = upperRound.loserRounds().flatMap({ round in |
|
|
|
|
// round.playedMatches() |
|
|
|
|
// }) |
|
|
|
|
// upperRound.loserRounds().forEach({ round in |
|
|
|
|
// round.resetFromRoundAllMatchesStartDate() |
|
|
|
|
// }) |
|
|
|
|
// |
|
|
|
|
// try? dataStore.matches.addOrUpdate(contentOfs: matches) |
|
|
|
|
// _save() |
|
|
|
|
|
|
|
|
|
try? dataStore.matches.addOrUpdate(contentOfs: matches) |
|
|
|
|
let loserRounds = upperRound.loserRounds().filter { $0.isDisabled() == false } |
|
|
|
|
MatchScheduler.shared.updateBracketSchedule(tournament: tournament, fromRoundId: loserRounds.first?.id, fromMatchId: nil, startDate: startDate) |
|
|
|
|
loserRounds.first?.startDate = startDate |
|
|
|
|
_save() |
|
|
|
|
|
|
|
|
|
MatchScheduler.shared.updateSchedule(tournament: tournament, fromRoundId: upperRound.loserRounds().first?.id, fromMatchId: nil, startDate: startDate) |
|
|
|
|
_save() |
|
|
|
|
|
|
|
|
|
upperRound.loserRounds().first?.startDate = startDate |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _save() { |
|
|
|
|
|