fix groupstage sorting

paca_championship
Raz 1 year ago
parent d6e87daa3d
commit 0e5988b4ed
  1. 2
      PadelClub/Data/GroupStage.swift
  2. 22
      PadelClub/Views/GroupStage/GroupStageView.swift
  3. 29
      PadelClub/Views/GroupStage/GroupStagesView.swift
  4. 18
      PadelClub/Views/Match/MatchSummaryView.swift

@ -304,7 +304,7 @@ final class GroupStage: ModelObject, Storable {
print("func group stage availableToStart", id, duration.formatted(.units(allowed: [.seconds, .milliseconds]))) print("func group stage availableToStart", id, duration.formatted(.units(allowed: [.seconds, .milliseconds])))
} }
#endif #endif
return playedMatches.filter({ $0.isRunning() == false && $0.canBeStarted(inMatches: runningMatches, checkCanPlay: checkCanPlay) }) return playedMatches.filter({ $0.isRunning() == false && $0.canBeStarted(inMatches: runningMatches, checkCanPlay: checkCanPlay) }).sorted(by: \.computedStartDateForSorting)
} }
func runningMatches(playedMatches: [Match]) -> [Match] { func runningMatches(playedMatches: [Match]) -> [Match] {

@ -58,12 +58,24 @@ struct GroupStageView: View {
} }
let runningMatches = groupStage.runningMatches(playedMatches: playedMatches) let runningMatches = groupStage.runningMatches(playedMatches: playedMatches)
MatchListView(section: "en cours", matches: groupStage.runningMatches(playedMatches: playedMatches), hideWhenEmpty: true) Section {
MatchListView(section: "en cours", matches: groupStage.runningMatches(playedMatches: playedMatches), hideWhenEmpty: true)
}
let availableToStart = groupStage.availableToStart(playedMatches: playedMatches, in: runningMatches) let availableToStart = groupStage.availableToStart(playedMatches: playedMatches, in: runningMatches)
MatchListView(section: "prêt à démarrer", matches: availableToStart, hideWhenEmpty: true) Section {
.listRowView(isActive: availableToStart.isEmpty == false, color: .green, hideColorVariation: true) MatchListView(section: "prêt à démarrer", matches: availableToStart, hideWhenEmpty: true)
MatchListView(section: "à lancer", matches: groupStage.readyMatches(playedMatches: playedMatches), hideWhenEmpty: true) .listRowView(isActive: availableToStart.isEmpty == false, color: .green, hideColorVariation: true)
MatchListView(section: "terminés", matches: groupStage.finishedMatches(playedMatches: playedMatches), hideWhenEmpty: playedMatches.isEmpty || playedMatches.flatMap({ $0.teamScores }).isEmpty, isExpanded: false) }
Section {
MatchListView(section: "à lancer", matches: groupStage.readyMatches(playedMatches: playedMatches), hideWhenEmpty: true)
}
Section {
MatchListView(section: "terminés", matches: groupStage.finishedMatches(playedMatches: playedMatches), hideWhenEmpty: playedMatches.isEmpty || playedMatches.flatMap({ $0.teamScores }).isEmpty, isExpanded: false)
}
if playedMatches.isEmpty { if playedMatches.isEmpty {
RowButtonView("Créer les matchs de poules") { RowButtonView("Créer les matchs de poules") {

@ -131,12 +131,7 @@ struct GroupStagesView: View {
} }
} }
} label: { } label: {
Label { Text("Qualifier un \(name) de poule par tirage au sort")
Text("Qualifier un \(name) de poule par tirage au sort")
} icon: {
Image(systemName: "exclamationmark.circle.fill")
.foregroundStyle(.logoBackground)
}
} }
.disabled(tournament.moreQualifiedToDraw() == 0 || missingQualifiedFromGroupStages.isEmpty) .disabled(tournament.moreQualifiedToDraw() == 0 || missingQualifiedFromGroupStages.isEmpty)
} footer: { } footer: {
@ -149,10 +144,24 @@ struct GroupStagesView: View {
} }
let runningMatches = Tournament.runningMatches(allMatches) let runningMatches = Tournament.runningMatches(allMatches)
MatchListView(section: "en cours", matches: runningMatches, matchViewStyle: .standardStyle, isExpanded: false) Section {
MatchListView(section: "prêt à démarrer", matches: Tournament.availableToStart(allMatches, in: runningMatches), matchViewStyle: .standardStyle, isExpanded: false)
MatchListView(section: "à lancer", matches: Tournament.readyMatches(allMatches), matchViewStyle: .standardStyle, isExpanded: false) MatchListView(section: "en cours", matches: runningMatches, matchViewStyle: .standardStyle, isExpanded: false)
MatchListView(section: "terminés", matches: finishedMatches, matchViewStyle: .standardStyle, isExpanded: false) }
Section {
MatchListView(section: "prêt à démarrer", matches: Tournament.availableToStart(allMatches, in: runningMatches), matchViewStyle: .standardStyle, isExpanded: false)
}
Section {
MatchListView(section: "à lancer", matches: Tournament.readyMatches(allMatches), matchViewStyle: .standardStyle, isExpanded: false)
}
Section {
MatchListView(section: "terminés", matches: finishedMatches, matchViewStyle: .standardStyle, isExpanded: false)
}
} }
.navigationTitle("Toutes les poules") .navigationTitle("Toutes les poules")
case .groupStage(let groupStage): case .groupStage(let groupStage):

@ -60,21 +60,21 @@ struct MatchSummaryView: View {
} }
Spacer() Spacer()
VStack(alignment: .trailing, spacing: 0) { VStack(alignment: .trailing, spacing: 0) {
if let courtName, match.canBePlayedInSpecifiedCourt() { if match.hasEnded() == false, match.isRunning() == false {
if match.isRunning() == false { if let courtName, match.canBePlayedInSpecifiedCourt() {
Text("prévu") Text("prévu")
} Text(courtName)
Text(courtName) } else if let first = match.availableCourts().first {
} else if let first = match.availableCourts().first { Text("possible")
Text("possible") Text(match.courtName(for: first))
Text(match.courtName(for: first)) } else if let estimatedStartDate = match.estimatedStartDate() {
} else {
if let estimatedStartDate = match.estimatedStartDate() {
Text(match.courtName(for: estimatedStartDate.0) + " possible") Text(match.courtName(for: estimatedStartDate.0) + " possible")
Text("dans ~ " + estimatedStartDate.1.timeElapsedString()) Text("dans ~ " + estimatedStartDate.1.timeElapsedString())
} else { } else {
Text("aucun terrain disponible") Text("aucun terrain disponible")
} }
} else if let courtName {
Text(courtName)
} }
} }
.foregroundStyle(.secondary) .foregroundStyle(.secondary)

Loading…
Cancel
Save