fix some stuff

multistore
Razmig Sarkissian 1 year ago
parent 645beb7171
commit 71f4377f37
  1. 19
      PadelClub/Data/GroupStage.swift
  2. 12
      PadelClub/Data/Match.swift
  3. 11
      PadelClub/Data/Tournament.swift
  4. 8
      PadelClub/Utils/HtmlService.swift
  5. 2
      PadelClub/Utils/Tips.swift
  6. 72
      PadelClub/Views/GroupStage/GroupStageView.swift
  7. 13
      PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift

@ -170,21 +170,20 @@ class GroupStage: ModelObject, Storable {
return _matches().first(where: { matchIndexes.contains($0.index) })
}
func availableToStart() -> [Match] {
let runningMatches = runningMatches()
return playedMatches().filter({ $0.canBeStarted(inMatches: runningMatches) && $0.isRunning() == false })
func availableToStart(playedMatches: [Match], in runningMatches: [Match]) -> [Match] {
return playedMatches.filter({ $0.canBeStarted(inMatches: runningMatches) && $0.isRunning() == false })
}
func runningMatches() -> [Match] {
playedMatches().filter({ $0.isRunning() })
func runningMatches(playedMatches: [Match]) -> [Match] {
playedMatches.filter({ $0.isRunning() })
}
func readyMatches() -> [Match] {
playedMatches().filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false })
func readyMatches(playedMatches: [Match]) -> [Match] {
playedMatches.filter({ $0.isReady() && $0.isRunning() == false && $0.hasEnded() == false })
}
func finishedMatches() -> [Match] {
playedMatches().filter({ $0.hasEnded() })
func finishedMatches(playedMatches: [Match]) -> [Match] {
playedMatches.filter({ $0.hasEnded() })
}
private func _matchOrder() -> [Int] {
@ -366,7 +365,7 @@ extension GroupStage: Selectable {
}
func badgeValue() -> Int? {
runningMatches().count
runningMatches(playedMatches: playedMatches()).count
}
func badgeValueColor() -> Color? {

@ -486,11 +486,11 @@ class Match: ModelObject, Storable {
} catch {
Logger.error(error)
}
followingMatch()?.resetTeamScores()
_loserMatch()?.resetTeamScores()
}
followingMatch()?.resetTeamScores()
_loserMatch()?.resetTeamScores()
}
func createTeamScores() -> [TeamScore] {
let teamOne = team(.one)
let teamTwo = team(.two)
@ -568,15 +568,15 @@ class Match: ModelObject, Storable {
}
func canBeStarted(inMatches matches: [Match]) -> Bool {
let teams = teams()
let teams = teamScores
guard teams.count == 2 else { return false }
guard hasEnded() == false else { return false }
guard hasStarted() == false else { return false }
return teams.allSatisfy({ $0.canPlay() && isTeamPlaying($0, inMatches: matches) == false })
return teams.compactMap({ $0.team }).allSatisfy({ $0.canPlay() && isTeamPlaying($0, inMatches: matches) == false })
}
func isTeamPlaying(_ team: TeamRegistration, inMatches matches: [Match]) -> Bool {
matches.filter({ $0.teams().contains(team) }).isEmpty == false
matches.filter({ $0.teamScores.compactMap { $0.teamRegistration }.contains(team.id) }).isEmpty == false
}
var computedStartDateForSorting: Date {

@ -1399,15 +1399,14 @@ class Tournament : ModelObject, Storable {
print("Position \(index+1) Poule \(groupStages[jIndex].index)")
chunks[index][jIndex].groupStage = groupStages[jIndex].id
chunks[index][jIndex].groupStagePosition = index
do {
try DataStore.shared.teamRegistrations.addOrUpdate(instance: chunks[index][jIndex])
} catch {
Logger.error(error)
}
}
}
do {
try DataStore.shared.teamRegistrations.addOrUpdate(contentOfs: unsortedTeams())
} catch {
Logger.error(error)
}
groupStages.forEach { $0.buildMatches() }
}

@ -84,7 +84,7 @@ enum HtmlService {
if let playerOne = entrant.players()[safe: 0] {
template = template.replacingOccurrences(of: "{{playerOne}}", with: playerOne.playerLabel())
if withRank {
template = template.replacingOccurrences(of: "{{weightOne}}", with: "(\(playerOne.formattedRank())")
template = template.replacingOccurrences(of: "{{weightOne}}", with: "(\(playerOne.formattedRank()))")
} else {
template = template.replacingOccurrences(of: "{{weightOne}}", with: "")
}
@ -93,7 +93,7 @@ enum HtmlService {
if let playerTwo = entrant.players()[safe: 1] {
template = template.replacingOccurrences(of: "{{playerTwo}}", with: playerTwo.playerLabel())
if withRank {
template = template.replacingOccurrences(of: "{{weightTwo}}", with: "(\(playerTwo.formattedRank())")
template = template.replacingOccurrences(of: "{{weightTwo}}", with: "(\(playerTwo.formattedRank()))")
} else {
template = template.replacingOccurrences(of: "{{weightTwo}}", with: "")
}
@ -135,7 +135,7 @@ enum HtmlService {
if let playerOne = entrant.players()[safe: 0] {
template = template.replacingOccurrences(of: "{{playerOne}}", with: playerOne.playerLabel(.short))
if withRank {
template = template.replacingOccurrences(of: "{{weightOne}}", with: "(\(playerOne.formattedRank())")
template = template.replacingOccurrences(of: "{{weightOne}}", with: "(\(playerOne.formattedRank()))")
} else {
template = template.replacingOccurrences(of: "{{weightOne}}", with: "")
}
@ -144,7 +144,7 @@ enum HtmlService {
if let playerTwo = entrant.players()[safe: 1] {
template = template.replacingOccurrences(of: "{{playerTwo}}", with: playerTwo.playerLabel(.short))
if withRank {
template = template.replacingOccurrences(of: "{{weightTwo}}", with: "(\(playerTwo.formattedRank())")
template = template.replacingOccurrences(of: "{{weightTwo}}", with: "(\(playerTwo.formattedRank()))")
} else {
template = template.replacingOccurrences(of: "{{weightTwo}}", with: "")
}

@ -336,7 +336,7 @@ struct TournamentPublishingTip: Tip {
}
var message: Text? {
Text("Padel Club vous permet de publier votre tournoi et rendre accessible à tous les résultats des matchs et l'évolution de l'événement. Les informations seront accessible sur le site Padel Club.")
Text("Padel Club vous permet de publier votre tournoi et rendre accessible à tous les résultats des matchs et l'évolution de l'événement. Les informations seront accessibles sur le site Padel Club.")
}
var image: Image? {

@ -16,9 +16,11 @@ struct GroupStageView: View {
@State private var confirmRemoveAll: Bool = false
@State private var confirmResetMatch: Bool = false
@State private var groupStageName: String = ""
let playedMatches: [Match]
init(groupStage: GroupStage) {
self.groupStage = groupStage
self.playedMatches = groupStage.playedMatches()
_groupStageName = State(wrappedValue: groupStage.groupStageTitle())
}
@ -44,21 +46,18 @@ struct GroupStageView: View {
}
.headerProminence(.increased)
MatchListView(section: "disponible", matches: groupStage.availableToStart()).id(UUID())
MatchListView(section: "en cours", matches: groupStage.runningMatches()).id(UUID())
MatchListView(section: "à lancer", matches: groupStage.readyMatches()).id(UUID())
MatchListView(section: "terminés", matches: groupStage.finishedMatches(), isExpanded: false).id(UUID())
}
.onChange(of: groupStageName) {
groupStage.name = groupStageName
_save()
let runningMatches = groupStage.runningMatches(playedMatches: playedMatches)
MatchListView(section: "disponible", matches: groupStage.availableToStart(playedMatches: playedMatches, in: runningMatches))
MatchListView(section: "en cours", matches: runningMatches)
MatchListView(section: "à lancer", matches: groupStage.readyMatches(playedMatches: playedMatches))
MatchListView(section: "terminés", matches: groupStage.finishedMatches(playedMatches: playedMatches), isExpanded: false)
}
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
_groupStageMenuView()
}
}
.navigationTitle($groupStageName)
.navigationTitle(groupStage.groupStageTitle())
}
private enum GroupStageSortingMode {
@ -178,12 +177,10 @@ struct GroupStageView: View {
private func _groupStageMenuView() -> some View {
Menu {
if groupStage.name != nil {
Button("Retirer le nom") {
groupStage.name = nil
groupStageName = groupStage.groupStageTitle()
_save()
}
NavigationLink {
GroupStageNameEditionView(groupStage: groupStage)
} label: {
Label("Renommer", systemImage: "pencil")
}
Button("Retirer tout le monde", role: .destructive) {
confirmRemoveAll = true
@ -225,3 +222,46 @@ struct GroupStageView: View {
}
}
}
struct GroupStageNameEditionView: View {
@EnvironmentObject var dataStore: DataStore
let groupStage: GroupStage
@State private var groupStageName: String = ""
var body: some View {
Form {
Section {
TextField("Nom de la poule", text: $groupStageName)
.keyboardType(.alphabet)
.frame(maxWidth: .infinity)
.onAppear(perform: {
groupStageName = groupStage.name ?? ""
})
.onSubmit {
groupStageName = groupStageName.trimmed
groupStage.name = groupStageName
_save()
}
} footer: {
HStack {
Spacer()
FooterButtonView("retirer le nom") {
groupStage.name = nil
groupStageName = groupStage.groupStageTitle()
_save()
}
}
}
}
.navigationTitle(groupStage.groupStageTitle())
.toolbarBackground(.visible, for: .navigationBar)
}
private func _save() {
do {
try dataStore.groupStages.addOrUpdate(instance: groupStage)
} catch {
Logger.error(error)
}
}
}

@ -608,15 +608,20 @@ struct InscriptionManagerView: View {
Section {
let unsortedTeams = tournament.unsortedTeams()
let walkoutTeams = tournament.walkoutTeams()
let unsortedTeamsWithoutWO = tournament.unsortedTeamsWithoutWO()
LabeledContent {
Text(unsortedTeams.count.formatted() + "/" + tournament.teamCount.formatted()).font(.largeTitle)
Text(unsortedTeamsWithoutWO.count.formatted() + "/" + tournament.teamCount.formatted()).font(.largeTitle)
} label: {
Text("Paire\(unsortedTeams.count.pluralSuffix) inscrite\(unsortedTeams.count.pluralSuffix)")
Text("dont \(walkoutTeams.count) forfait\(walkoutTeams.count.pluralSuffix)")
Text("Paire\(unsortedTeamsWithoutWO.count.pluralSuffix) inscrite\(unsortedTeamsWithoutWO.count.pluralSuffix)")
}
LabeledContent {
Text(walkoutTeams.count.formatted()).font(.largeTitle)
} label: {
Text("Forfait\(walkoutTeams.count.pluralSuffix)")
}
let unsortedTeamsWithoutWO = tournament.unsortedTeamsWithoutWO()
LabeledContent {
Text(max(0, unsortedTeamsWithoutWO.count - tournament.teamCount).formatted()).font(.largeTitle)
} label: {

Loading…
Cancel
Save