diff --git a/PadelClub/Data/Match.swift b/PadelClub/Data/Match.swift index 285dde2..4fd7b0b 100644 --- a/PadelClub/Data/Match.swift +++ b/PadelClub/Data/Match.swift @@ -269,7 +269,7 @@ class Match: ModelObject, Storable { } func roundTitle() -> String? { - if groupStage != nil { return "Poule" } + if groupStage != nil { return groupStageObject?.groupStageTitle() } else if let roundObject { return roundObject.roundTitle() } else { return nil } } diff --git a/PadelClub/Data/MatchScheduler.swift b/PadelClub/Data/MatchScheduler.swift index 66b7f7c..801a988 100644 --- a/PadelClub/Data/MatchScheduler.swift +++ b/PadelClub/Data/MatchScheduler.swift @@ -111,7 +111,7 @@ class MatchScheduler : ModelObject, Storable { return lastDate } - func groupStageDispatcher(numberOfCourtsAvailablePerRotation: Int, groupStages: [GroupStage], startingDate: Date?) -> GroupStageMatchDispatcher { + func groupStageDispatcher(numberOfCourtsAvailablePerRotation: Int, groupStages: [GroupStage], startingDate: Date) -> GroupStageMatchDispatcher { let _groupStages = groupStages @@ -156,7 +156,16 @@ class MatchScheduler : ModelObject, Storable { (0..= numberOfCourtsAvailablePerRotation - courtsUnavailable { + return false + } else { + return teamsPerRotation[rotationIndex]!.allSatisfy({ match.containsTeamId($0) == false }) == true + } }) { let timeMatch = GroupStageTimeMatch(matchID: first.id, rotationIndex: rotationIndex, courtIndex: courtIndex, groupIndex: first.groupStageObject!.index) slots.append(timeMatch) diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index 153a49f..51839f0 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -363,8 +363,9 @@ class Tournament : ModelObject, Storable { } func seeds() -> [TeamRegistration] { - let seeds = max(teamCount - groupStageCount * teamsPerGroupStage, 0) - return Array(selectedSortedTeams().prefix(seeds)) + let selectedSortedTeams = selectedSortedTeams() + let seeds = max(selectedSortedTeams.count - groupStageCount * teamsPerGroupStage, 0) + return Array(selectedSortedTeams.prefix(seeds)) } func availableSeeds() -> [TeamRegistration] { diff --git a/PadelClub/Views/Club/CourtView.swift b/PadelClub/Views/Club/CourtView.swift index d9617bd..38b992b 100644 --- a/PadelClub/Views/Club/CourtView.swift +++ b/PadelClub/Views/Club/CourtView.swift @@ -25,9 +25,24 @@ struct CourtView: View { .keyboardType(.alphabet) .multilineTextAlignment(.trailing) .frame(maxWidth: .infinity) + .onSubmit { + court.name = name + if name.isEmpty { + court.name = nil + } + try? dataStore.courts.addOrUpdate(instance: court) + } } label: { Text("Nom du terrain") } + } footer: { + if court.name?.isEmpty == false { + FooterButtonView("nom par défaut") { + name = "" + court.name = nil + try? dataStore.courts.addOrUpdate(instance: court) + } + } } Section { @@ -39,10 +54,6 @@ struct CourtView: View { } } } - .onChange(of: name) { - court.name = name - try? dataStore.courts.addOrUpdate(instance: court) - } .onChange(of: [court.indoor, court.exitAllowed]) { try? dataStore.courts.addOrUpdate(instance: court) } diff --git a/PadelClub/Views/GroupStage/Shared/GroupStageTeamReplacementView.swift b/PadelClub/Views/GroupStage/Shared/GroupStageTeamReplacementView.swift index c4510ea..7a6d41f 100644 --- a/PadelClub/Views/GroupStage/Shared/GroupStageTeamReplacementView.swift +++ b/PadelClub/Views/GroupStage/Shared/GroupStageTeamReplacementView.swift @@ -72,6 +72,8 @@ struct GroupStageTeamReplacementView: View { } .labelsHidden() .pickerStyle(.inline) + } header: { + Text("Remplacer") } footer: { Text("Remplacement de l'équipe ou d'un joueur particulier") } diff --git a/PadelClub/Views/Planning/CourtAvailabilitySettingsView.swift b/PadelClub/Views/Planning/CourtAvailabilitySettingsView.swift index 82b0606..d77a6ae 100644 --- a/PadelClub/Views/Planning/CourtAvailabilitySettingsView.swift +++ b/PadelClub/Views/Planning/CourtAvailabilitySettingsView.swift @@ -33,24 +33,7 @@ struct CourtAvailabilitySettingsView: View { if let dates = courtsUnavailability[key] { Section { ForEach(dates) { dateInterval in - HStack { - VStack(alignment: .leading, spacing: 0) { - Text(dateInterval.startDate.localizedTime()).font(.largeTitle) - Text(dateInterval.startDate.localizedDay()).font(.caption) - } - Spacer() - VStack { - Image(systemName: "arrowshape.forward.fill") - .tint(.master) - Text("indisponible").foregroundStyle(.red).font(.caption) - } - Spacer() - VStack(alignment: .trailing, spacing: 0) { - Text(dateInterval.endDate.localizedTime()).font(.largeTitle) - Text(dateInterval.endDate.localizedDay()).font(.caption) - } - } - .contextMenu(menuItems: { + Menu { Button("dupliquer") { let duplicatedDateInterval = DateInterval(event: event.id, courtIndex: (courtIndex+1)%tournament.courtCount, startDate: dateInterval.startDate, endDate: dateInterval.endDate) try? dataStore.dateIntervals.addOrUpdate(instance: duplicatedDateInterval) @@ -65,7 +48,25 @@ struct CourtAvailabilitySettingsView: View { Button("effacer", role: .destructive) { try? dataStore.dateIntervals.delete(instance: dateInterval) } - }) + } label: { + HStack { + VStack(alignment: .leading, spacing: 0) { + Text(dateInterval.startDate.localizedTime()).font(.largeTitle) + Text(dateInterval.startDate.localizedDay()).font(.caption) + } + Spacer() + VStack { + Image(systemName: "arrowshape.forward.fill") + .tint(.master) + Text("indisponible").foregroundStyle(.red).font(.caption) + } + Spacer() + VStack(alignment: .trailing, spacing: 0) { + Text(dateInterval.endDate.localizedTime()).font(.largeTitle) + Text(dateInterval.endDate.localizedDay()).font(.caption) + } + } + } .swipeActions { Button(role: .destructive) { try? dataStore.dateIntervals.delete(instance: dateInterval) @@ -95,6 +96,8 @@ struct CourtAvailabilitySettingsView: View { Text("Vous pouvez précisez l'indisponibilité d'une ou plusieurs terrains, que ce soit pour une journée entière ou un créneau précis.") } actions: { RowButtonView("Ajouter une indisponibilité", systemImage: "plus.circle.fill") { + startDate = tournament.startDate + endDate = tournament.startDate.addingTimeInterval(5400) showingPopover = true } } diff --git a/PadelClub/Views/Planning/PlanningSettingsView.swift b/PadelClub/Views/Planning/PlanningSettingsView.swift index 7b67c65..75c22df 100644 --- a/PadelClub/Views/Planning/PlanningSettingsView.swift +++ b/PadelClub/Views/Planning/PlanningSettingsView.swift @@ -42,15 +42,13 @@ struct PlanningSettingsView: View { } } header: { Text("Démarrage et durée du tournoi") - } footer: { - Text("todo: Expliquer ce que ca fait") } Section { TournamentFieldsManagerView(localizedStringKey: "Terrains maximum", count: $tournament.courtCount) if tournament.groupStages().isEmpty == false { - TournamentFieldsManagerView(localizedStringKey: "Terrains par poule", count: $groupStageCourtCount, max: tournament.maximumCourtsPerGroupSage()) + TournamentFieldsManagerView(localizedStringKey: "Nombre de poule en même temps", count: $groupStageCourtCount, max: tournament.groupStageCount) } if let event = tournament.eventObject() {