fix date and format stuff

multistore
Razmig Sarkissian 2 years ago
parent 26f8383981
commit 3a2d242e13
  1. 4
      PadelClub.xcodeproj/project.pbxproj
  2. 8
      PadelClub/Data/GroupStage.swift
  3. 12
      PadelClub/Data/Match.swift
  4. 45
      PadelClub/Data/Round.swift
  5. 12
      PadelClub/Data/TeamScore.swift
  6. 26
      PadelClub/PrivacyInfo.xcprivacy
  7. 4
      PadelClub/ViewModel/MatchScheduler.swift
  8. 13
      PadelClub/Views/Planning/Components/DateUpdateManagerView.swift
  9. 49
      PadelClub/Views/Planning/GroupStageScheduleEditorView.swift
  10. 25
      PadelClub/Views/Planning/LoserRoundScheduleEditorView.swift
  11. 27
      PadelClub/Views/Planning/LoserRoundStepScheduleEditorView.swift
  12. 4
      PadelClub/Views/Planning/MatchScheduleEditorView.swift
  13. 27
      PadelClub/Views/Planning/RoundScheduleEditorView.swift
  14. 58
      PadelClub/Views/Planning/SchedulerView.swift
  15. 4
      PadelClub/Views/Tournament/Screen/Components/TournamentMatchFormatsSettingsView.swift
  16. 4
      PadelClub/Views/Tournament/TournamentRunningView.swift

@ -53,6 +53,7 @@
FF089EBB2BB0120700F0AEC7 /* PlayerPopoverView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF089EBA2BB0120700F0AEC7 /* PlayerPopoverView.swift */; };
FF089EBD2BB0287D00F0AEC7 /* PlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF089EBC2BB0287D00F0AEC7 /* PlayerView.swift */; };
FF089EBF2BB0B14600F0AEC7 /* FileImportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF089EBE2BB0B14600F0AEC7 /* FileImportView.swift */; };
FF0CA5752BDA4AE10080E843 /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = FF0CA5742BDA4AE10080E843 /* PrivacyInfo.xcprivacy */; };
FF0E0B6D2BC254C6005F00A9 /* TournamentScheduleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF0E0B6C2BC254C6005F00A9 /* TournamentScheduleView.swift */; };
FF0EC5202BB16F680056B6D1 /* SwiftParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF0EC51D2BB16F680056B6D1 /* SwiftParser.swift */; };
FF0EC5222BB173E70056B6D1 /* UpdateSourceRankDateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FF0EC5212BB173E70056B6D1 /* UpdateSourceRankDateView.swift */; };
@ -354,6 +355,7 @@
FF089EBA2BB0120700F0AEC7 /* PlayerPopoverView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerPopoverView.swift; sourceTree = "<group>"; };
FF089EBC2BB0287D00F0AEC7 /* PlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlayerView.swift; sourceTree = "<group>"; };
FF089EBE2BB0B14600F0AEC7 /* FileImportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FileImportView.swift; sourceTree = "<group>"; };
FF0CA5742BDA4AE10080E843 /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = PadelClub/PrivacyInfo.xcprivacy; sourceTree = SOURCE_ROOT; };
FF0E0B6C2BC254C6005F00A9 /* TournamentScheduleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TournamentScheduleView.swift; sourceTree = "<group>"; };
FF0EC51D2BB16F680056B6D1 /* SwiftParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftParser.swift; sourceTree = "<group>"; };
FF0EC5212BB173E70056B6D1 /* UpdateSourceRankDateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpdateSourceRankDateView.swift; sourceTree = "<group>"; };
@ -609,6 +611,7 @@
C425D3FF2B6D249D002A7B48 /* PadelClub */ = {
isa = PBXGroup;
children = (
FF0CA5742BDA4AE10080E843 /* PrivacyInfo.xcprivacy */,
FFA6D78A2BB0BEB3003A31F3 /* Info.plist */,
C425D44E2B6D24E1002A7B48 /* LeStorage.xcodeproj */,
C425D4002B6D249D002A7B48 /* PadelClubApp.swift */,
@ -1384,6 +1387,7 @@
FF0EC5672BB195E20056B6D1 /* CLASSEMENT-PADEL-MESSIEURS-03-2023.csv in Resources */,
FF0EC5682BB195E20056B6D1 /* CLASSEMENT-PADEL-DAMES-06-2023.csv in Resources */,
FF0EC5692BB195E20056B6D1 /* CLASSEMENT-PADEL-MESSIEURS-11-2022.csv in Resources */,
FF0CA5752BDA4AE10080E843 /* PrivacyInfo.xcprivacy in Resources */,
FF0EC56A2BB195E20056B6D1 /* CLASSEMENT-PADEL-MESSIEURS-12-2022.csv in Resources */,
FF0EC56B2BB195E20056B6D1 /* CLASSEMENT-PADEL-MESSIEURS-06-2023.csv in Resources */,
FF0EC56C2BB195E20056B6D1 /* CLASSEMENT PADEL MESSIEURS_1-07-2023.csv in Resources */,

@ -254,8 +254,12 @@ class GroupStage: ModelObject, Storable {
}
}
func updateMatchFormat(_ matchFormat: MatchFormat) {
self.matchFormat = matchFormat
func updateMatchFormat(_ updatedMatchFormat: MatchFormat) {
self.matchFormat = updatedMatchFormat
self.updateAllMatchesFormat()
}
func updateAllMatchesFormat() {
let playedMatches = playedMatches()
playedMatches.forEach { match in
match.matchFormat = matchFormat

@ -124,7 +124,7 @@ class Match: ModelObject, Storable {
try? DataStore.shared.teamScores.delete(instance: existingTeamScore)
}
let teamScoreWalkout = TeamScore(match: id, teamRegistration: team.id)
let teamScoreWalkout = TeamScore(match: id, team: team)
teamScoreWalkout.walkOut = 1
try? DataStore.shared.teamScores.addOrUpdate(instance: teamScoreWalkout)
}
@ -148,7 +148,7 @@ class Match: ModelObject, Storable {
let matchIndex = index
let position = matchIndex * 2 + teamPosition.rawValue
let teamScoreLuckyLoser = TeamScore(match: id, teamRegistration: team.id)
let teamScoreLuckyLoser = TeamScore(match: id, team: team)
teamScoreLuckyLoser.luckyLoser = position
try? DataStore.shared.teamScores.addOrUpdate(instance: teamScoreLuckyLoser)
}
@ -328,9 +328,9 @@ class Match: ModelObject, Storable {
}
func setWalkOut(_ teamPosition: TeamPosition) {
let teamScoreWalkout = teamScore(teamPosition) ?? TeamScore(match: id, teamRegistration: team(teamPosition)?.id)
let teamScoreWalkout = teamScore(teamPosition) ?? TeamScore(match: id, team: team(teamPosition))
teamScoreWalkout.walkOut = 0
let teamScoreWinning = teamScore(teamPosition.otherTeam) ?? TeamScore(match: id, teamRegistration: team(teamPosition.otherTeam)?.id)
let teamScoreWinning = teamScore(teamPosition.otherTeam) ?? TeamScore(match: id, team: team(teamPosition.otherTeam))
teamScoreWinning.walkOut = nil
try? DataStore.shared.teamScores.addOrUpdate(contentOfs: [teamScoreWalkout, teamScoreWinning])
@ -359,9 +359,9 @@ class Match: ModelObject, Storable {
}
func updateScore(fromMatchDescriptor matchDescriptor: MatchDescriptor) {
let teamScoreOne = teamScore(.one) ?? TeamScore(match: id, teamRegistration: team(.one)?.id)
let teamScoreOne = teamScore(.one) ?? TeamScore(match: id, team: team(.one))
teamScoreOne.score = matchDescriptor.teamOneScores.joined(separator: ",")
let teamScoreTwo = teamScore(.two) ?? TeamScore(match: id, teamRegistration: team(.two)?.id)
let teamScoreTwo = teamScore(.two) ?? TeamScore(match: id, team: team(.two))
teamScoreTwo.score = matchDescriptor.teamTwoScores.joined(separator: ",")
try? DataStore.shared.teamScores.addOrUpdate(contentOfs: [teamScoreOne, teamScoreTwo])
matchFormat = matchDescriptor.matchFormat

@ -194,10 +194,14 @@ class Round: ModelObject, Storable {
return $0.round == id && index == matchIndexInRound
}).first
}
func enabledMatches() -> [Match] {
Store.main.filter { $0.round == self.id && $0.disabled == false }
}
func playedMatches() -> [Match] {
if parent == nil {
Store.main.filter { $0.round == self.id && $0.disabled == false }
enabledMatches()
} else {
_matches()
}
@ -219,33 +223,27 @@ class Round: ModelObject, Storable {
_matches().allSatisfy({ $0.disabled })
}
func resetRound(updateMatchFormat: MatchFormat? = nil) {
let _updateMatchFormat = updateMatchFormat ?? self.matchFormat
func resetFromRoundAllMatchesStartDate() {
_matches().forEach({
$0.startDate = nil
$0.matchFormat = updateMatchFormat ?? $0.matchFormat
})
self.matchFormat = _updateMatchFormat
loserRoundsAndChildren().forEach { round in
round.resetRound(updateMatchFormat: _updateMatchFormat)
round.resetFromRoundAllMatchesStartDate()
}
nextRound()?.resetRound(updateMatchFormat: _updateMatchFormat)
nextRound()?.resetFromRoundAllMatchesStartDate()
}
func resetRound(from match: Match, updateMatchFormat: MatchFormat? = nil) {
let _updateMatchFormat = updateMatchFormat ?? self.matchFormat
self.matchFormat = _updateMatchFormat
func resetFromRoundAllMatchesStartDate(from match: Match) {
let matches = _matches()
if let index = matches.firstIndex(where: { $0.id == match.id }) {
matches[index...].forEach { match in
match.startDate = nil
match.matchFormat = _updateMatchFormat
}
}
loserRoundsAndChildren().forEach { round in
round.resetRound(updateMatchFormat: _updateMatchFormat)
round.resetFromRoundAllMatchesStartDate()
}
nextRound()?.resetRound(updateMatchFormat: _updateMatchFormat)
nextRound()?.resetFromRoundAllMatchesStartDate()
}
func getActiveLoserRound() -> Round? {
@ -401,12 +399,27 @@ class Round: ModelObject, Storable {
guard let parent = parent else { return nil }
return Store.main.findById(parent)
}
func updateIfRequiredMatchFormat(_ updatedMatchFormat: MatchFormat, andLoserBracket: Bool) {
if updatedMatchFormat.weight < self.matchFormat.weight {
updateMatchFormatAndAllMatches(updatedMatchFormat)
if andLoserBracket {
loserRoundsAndChildren().forEach { round in
round.updateIfRequiredMatchFormat(updatedMatchFormat, andLoserBracket: true)
}
}
}
}
func updateMatchFormatAndAllMatches(_ updatedMatchFormat: MatchFormat) {
self.matchFormat = updatedMatchFormat
self.updateMatchFormatOfAllMatches(updatedMatchFormat)
}
func updateMatchFormat(_ matchFormat: MatchFormat) {
self.matchFormat = matchFormat
func updateMatchFormatOfAllMatches(_ updatedMatchFormat: MatchFormat) {
let playedMatches = _matches()
playedMatches.forEach { match in
match.matchFormat = matchFormat
match.matchFormat = updatedMatchFormat
}
try? DataStore.shared.matches.addOrUpdate(contentOfs: playedMatches)
}

@ -21,13 +21,13 @@ class TeamScore: ModelObject, Storable {
var walkOut: Int?
var luckyLoser: Int?
internal init(match: String, teamRegistration: String? = nil, playerRegistrations: [String]? = nil, score: String? = nil, walkOut: Int? = nil, luckyLoser: Int? = nil) {
internal init(match: String, team: TeamRegistration?) {
self.match = match
self.teamRegistration = teamRegistration
self.playerRegistrations = playerRegistrations
self.score = score
self.walkOut = walkOut
self.luckyLoser = luckyLoser
self.teamRegistration = team?.id
self.playerRegistrations = team?.players().map { $0.id }
self.score = nil
self.walkOut = nil
self.luckyLoser = nil
}
func isWalkOut() -> Bool {

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSPrivacyAccessedAPITypes</key>
<array>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryUserDefaults</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>CA92.1</string>
</array>
</dict>
<dict>
<key>NSPrivacyAccessedAPIType</key>
<string>NSPrivacyAccessedAPICategoryFileTimestamp</string>
<key>NSPrivacyAccessedAPITypeReasons</key>
<array>
<string>C617.1</string>
<string>3B52.1</string>
</array>
</dict>
</array>
</dict>
</plist>

@ -497,14 +497,14 @@ class MatchScheduler {
if let roundId {
if let round : Round = Store.main.findById(roundId) {
let matches = round._matches()
round.resetRound()
round.resetFromRoundAllMatchesStartDate()
flattenedMatches = matches + flattenedMatches
}
} else if let matchId {
if let match : Match = Store.main.findById(matchId) {
if let round = match.roundObject {
round.resetRound(from: match)
round.resetFromRoundAllMatchesStartDate(from: match)
}
flattenedMatches = [match] + flattenedMatches
}

@ -18,8 +18,9 @@ enum DateUpdate {
struct DateUpdateManagerView: View {
@Binding var startDate: Date
@Binding var currentDate: Date?
@State private var dateUpdated: Bool = false
var duration: Int?
var validateAction: () -> Void
@ -42,15 +43,17 @@ struct DateUpdateManagerView: View {
Text("décaler")
.underline()
}
.buttonStyle(.borderless)
Spacer()
if dateUpdated {
Button {
FooterButtonView("valider la modification") {
validateAction()
dateUpdated = false
} label: {
Text("valider la modification")
.underline()
}
} else if currentDate != nil {
FooterButtonView("horaire automatique") {
currentDate = nil
}
}
}

@ -9,53 +9,38 @@ import SwiftUI
struct GroupStageScheduleEditorView: View {
@EnvironmentObject var dataStore: DataStore
@Environment(Tournament.self) var tournament: Tournament
var groupStage: GroupStage
@Bindable var groupStage: GroupStage
var tournament: Tournament
@State private var startDate: Date
@State private var dateUpdated: Bool = false
init(groupStage: GroupStage) {
init(groupStage: GroupStage, tournament: Tournament) {
self.groupStage = groupStage
self._startDate = State(wrappedValue: groupStage.startDate ?? Date())
self.tournament = tournament
self._startDate = State(wrappedValue: groupStage.startDate ?? tournament.startDate)
}
var body: some View {
@Bindable var groupStage = groupStage
List {
Section {
MatchFormatPickerView(headerLabel: "Format", matchFormat: $groupStage.matchFormat)
DatePicker(selection: $startDate) {
Text(startDate.formatted(.dateTime.weekday(.wide))).font(.headline)
}
.onChange(of: startDate) {
dateUpdated = true
}
} header: {
Text(groupStage.groupStageTitle())
} footer: {
DateUpdateManagerView(startDate: $startDate, duration: groupStage.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
groupStage.startDate = startDate
_save()
}
Section {
//MatchFormatPickerView(headerLabel: "Format", matchFormat: $groupStage.matchFormat)
DatePicker(selection: $startDate) {
Text(startDate.formatted(.dateTime.weekday(.wide))).font(.headline)
}
} header: {
Text(groupStage.groupStageTitle())
} footer: {
DateUpdateManagerView(startDate: $startDate, currentDate: $groupStage.startDate, duration: groupStage.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
groupStage.startDate = startDate
_save()
}
}
.onChange(of: groupStage.matchFormat) {
_save()
}
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.visible, for: .navigationBar)
}
private func _save() {
let matches = groupStage._matches()
matches.forEach({ $0.matchFormat = groupStage.matchFormat })
try? dataStore.matches.addOrUpdate(contentOfs: matches)
try? dataStore.groupStages.addOrUpdate(instance: groupStage)
}
}
#Preview {
GroupStageScheduleEditorView(groupStage: GroupStage.mock())
GroupStageScheduleEditorView(groupStage: GroupStage.mock(), tournament: Tournament.mock())
}

@ -20,7 +20,7 @@ struct LoserRoundScheduleEditorView: View {
self.upperRound = upperRound
let _loserRounds = upperRound.loserRounds()
self.loserRounds = _loserRounds
self._startDate = State(wrappedValue: _loserRounds.first?.startDate ?? _loserRounds.first?.playedMatches().first?.startDate ?? Date())
self._startDate = State(wrappedValue: _loserRounds.first(where: { $0.startDate != nil })?.startDate ?? _loserRounds.first(where: { $0.isDisabled() == false })?.enabledMatches().first?.startDate ?? Date())
self._matchFormat = State(wrappedValue: _loserRounds.first?.matchFormat ?? upperRound.matchFormat)
}
@ -32,22 +32,27 @@ struct LoserRoundScheduleEditorView: View {
Text(startDate.formatted(.dateTime.weekday(.wide))).font(.headline)
}
} header: {
Text("Classement " + upperRound.roundTitle())
Text("Match de classement " + upperRound.roundTitle())
} footer: {
DateUpdateManagerView(startDate: $startDate, duration: matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
DateUpdateManagerView(startDate: $startDate, currentDate: .constant(nil), duration: matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
_updateSchedule()
}
}
ForEach(upperRound.loserRounds()) { loserRound in
if loserRound.isDisabled() == false {
LoserRoundStepScheduleEditorView(round: loserRound, upperRound: upperRound)
}
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)
}
}
.onChange(of: matchFormat) {
loserRounds.forEach { round in
round.updateIfRequiredMatchFormat(matchFormat, andLoserBracket: true)
}
_save()
}
.headerProminence(.increased)
.navigationTitle("Réglages")
.navigationTitle("Horaires")
.toolbarBackground(.visible, for: .navigationBar)
.navigationBarTitleDisplayMode(.inline)
}
@ -57,7 +62,7 @@ struct LoserRoundScheduleEditorView: View {
round.playedMatches()
})
upperRound.loserRounds().forEach({ round in
round.resetRound(updateMatchFormat: matchFormat)
round.resetFromRoundAllMatchesStartDate()
})
try? dataStore.matches.addOrUpdate(contentOfs: matches)

@ -11,16 +11,18 @@ struct LoserRoundStepScheduleEditorView: View {
@EnvironmentObject var dataStore: DataStore
@Environment(Tournament.self) var tournament: Tournament
var stepIndex: Int
var round: Round
var upperRound: Round
var matches: [Match]
@State private var startDate: Date
@State private var matchFormat: MatchFormat
init(round: Round, upperRound: Round) {
init(stepIndex: Int, round: Round, upperRound: Round) {
self.upperRound = upperRound
self.round = round
let _matches = upperRound.loserRounds(forRoundIndex: round.index).flatMap({ $0.playedMatches() })
self.stepIndex = stepIndex
let _matches = upperRound.loserRounds(forRoundIndex: round.index).flatMap({ $0.enabledMatches() })
self.matches = _matches
self._startDate = State(wrappedValue: round.startDate ?? _matches.first?.startDate ?? Date())
self._matchFormat = State(wrappedValue: round.matchFormat)
@ -29,7 +31,7 @@ struct LoserRoundStepScheduleEditorView: View {
var body: some View {
@Bindable var round = round
Section {
MatchFormatPickerView(headerLabel: "Format", matchFormat: $round.matchFormat)
MatchFormatPickerView(headerLabel: "Format", matchFormat: $matchFormat)
DatePicker(selection: $startDate) {
Text(startDate.formatted(.dateTime.weekday(.wide))).font(.headline)
}
@ -49,26 +51,27 @@ struct LoserRoundStepScheduleEditorView: View {
}
} header: {
Text(round.selectionLabel())
Text("Tour #\(stepIndex + 1)")
} footer: {
HStack {
DateUpdateManagerView(startDate: $startDate, duration: round.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
DateUpdateManagerView(startDate: $startDate, currentDate: .constant(nil), duration: round.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
_updateSchedule()
}
if round.startDate != nil {
FooterButtonView("retirer l'horaire") {
round.startDate = nil
}
}
}
}
.headerProminence(.increased)
.onChange(of: matchFormat) {
round.updateIfRequiredMatchFormat(matchFormat, andLoserBracket: true)
_save()
}
.onChange(of: round.startDate) {
_save()
}
}
private func _updateSchedule() {
upperRound.loserRounds(forRoundIndex: round.index).forEach({ round in
round.resetRound(updateMatchFormat: round.matchFormat)
round.resetFromRoundAllMatchesStartDate()
})
try? dataStore.matches.addOrUpdate(contentOfs: matches)

@ -9,7 +9,7 @@ import SwiftUI
struct MatchScheduleEditorView: View {
@Environment(Tournament.self) var tournament: Tournament
var match: Match
@Bindable var match: Match
@State private var startDate: Date
init(match: Match) {
@ -29,7 +29,7 @@ struct MatchScheduleEditorView: View {
Text(match.matchTitle())
}
} footer: {
DateUpdateManagerView(startDate: $startDate, duration: match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
DateUpdateManagerView(startDate: $startDate, currentDate: .constant(nil), duration: match.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
_updateSchedule()
}
}

@ -28,18 +28,8 @@ struct RoundScheduleEditorView: View {
Text(startDate.formatted(.dateTime.weekday(.wide))).font(.headline)
}
} footer: {
HStack {
DateUpdateManagerView(startDate: $startDate, duration: round.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
_updateSchedule()
}
Spacer()
if round.startDate != nil {
FooterButtonView("retirer l'horaire") {
round.startDate = nil
}
}
DateUpdateManagerView(startDate: $startDate, currentDate: $round.startDate, duration: round.matchFormat.getEstimatedDuration(tournament.additionalEstimationDuration)) {
_updateSchedule()
}
}
@ -49,6 +39,19 @@ struct RoundScheduleEditorView: View {
}
.navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.visible, for: .navigationBar)
.onChange(of: round.startDate) {
_save()
}
.onChange(of: round.matchFormat) {
let upperRounds = tournament.rounds()
round.updateMatchFormatOfAllMatches(round.matchFormat)
for index in (0..<round.index).reversed() {
if let upperRound = upperRounds.filter({ $0.index == index }).first {
upperRound.updateIfRequiredMatchFormat(round.matchFormat, andLoserBracket: false)
}
}
_save()
}
}
private func _updateSchedule() {

@ -19,19 +19,39 @@ extension Round: Schedulable {
}
struct SchedulerView: View {
@EnvironmentObject var dataStore: DataStore
var tournament: Tournament
var destination: ScheduleDestination
var body: some View {
@Bindable var tournament = tournament
List {
switch destination {
case .scheduleGroupStage:
Section {
MatchFormatPickerView(headerLabel: "Format", matchFormat: $tournament.groupStageMatchFormat)
.onChange(of: tournament.groupStageMatchFormat) {
let groupStages = tournament.groupStages()
groupStages.forEach { groupStage in
groupStage.updateMatchFormat(tournament.groupStageMatchFormat)
}
try? dataStore.tournaments.addOrUpdate(instance: tournament)
try? dataStore.groupStages.addOrUpdate(contentOfs: groupStages)
}
// } footer: {
// if tournament.groupStageMatchFormat.weight > tournament.groupStageSmartMatchFormat().weight {
// FooterButtonView("passer en " + tournament.groupStageSmartMatchFormat().format) {
// tournament.groupStageMatchFormat = tournament.groupStageSmartMatchFormat()
// }
// }
}
ForEach(tournament.groupStages()) {
_schedulerView($0)
GroupStageScheduleEditorView(groupStage: $0, tournament: tournament)
}
case .scheduleBracket:
ForEach(tournament.rounds()) { round in
_schedulerView(round)
_roundView(round)
}
default:
EmptyView()
@ -40,25 +60,17 @@ struct SchedulerView: View {
.headerProminence(.increased)
}
func _schedulerView(_ schedulable: any Schedulable) -> some View {
func _roundView(_ round: Round) -> some View {
Section {
NavigationLink {
Group {
if let round = schedulable as? Round {
RoundScheduleEditorView(round: round)
.environment(tournament)
}
else if let groupStage = schedulable as? GroupStage {
GroupStageScheduleEditorView(groupStage: groupStage)
.environment(tournament)
}
}
.navigationTitle(schedulable.titleLabel())
RoundScheduleEditorView(round: round)
.environment(tournament)
.navigationTitle(round.titleLabel())
} label: {
LabeledContent {
Text(schedulable.matchFormat.format).font(.largeTitle)
Text(round.matchFormat.format).font(.largeTitle)
} label: {
if let startDate = schedulable.getStartDate() {
if let startDate = round.getStartDate() {
Text(startDate.formatted(.dateTime.hour().minute())).font(.largeTitle)
Text(startDate.formatted(.dateTime.weekday().day(.twoDigits).month().year()))
} else {
@ -66,16 +78,14 @@ struct SchedulerView: View {
}
}
}
if let round = schedulable as? Round {
NavigationLink {
LoserRoundScheduleEditorView(upperRound: round)
.environment(tournament)
} label: {
Text("Match de classement \(round.roundTitle(.short))")
}
NavigationLink {
LoserRoundScheduleEditorView(upperRound: round)
.environment(tournament)
} label: {
Text("Match de classement \(round.roundTitle(.short))")
}
} header: {
Text(schedulable.titleLabel())
Text(round.titleLabel())
}
.headerProminence(.increased)
}

@ -85,9 +85,9 @@ struct TournamentMatchFormatsSettingsView: View {
let allRounds = tournament.allRounds()
allRounds.forEach { round in
if round.isLoserBracket() {
round.updateMatchFormat(tournament.loserBracketMatchFormat)
round.updateMatchFormatAndAllMatches(tournament.loserBracketMatchFormat)
} else {
round.updateMatchFormat(tournament.matchFormat)
round.updateMatchFormatAndAllMatches(tournament.matchFormat)
}
}
try? dataStore.groupStages.addOrUpdate(contentOfs: groupStages)

@ -73,8 +73,8 @@ struct TournamentRunningView: View {
}
MatchListView(section: "en cours", matches: tournament.runningMatches(allMatches))
//MatchListView(section: "disponible", matches: tournament.availableToStart(allMatches))
//MatchListView(section: "à lancer", matches: tournament.readyMatches(allMatches))
// MatchListView(section: "à lancer", matches: tournament.readyMatches(allMatches))
// MatchListView(section: "disponible", matches: tournament.availableToStart(allMatches))
MatchListView(section: "terminés", matches: tournament.finishedMatches(allMatches))
}
}

Loading…
Cancel
Save