diff --git a/PadelClub/Data/Tournament.swift b/PadelClub/Data/Tournament.swift index e5c3914..559dbb3 100644 --- a/PadelClub/Data/Tournament.swift +++ b/PadelClub/Data/Tournament.swift @@ -1931,18 +1931,13 @@ defer { } } - func setupFederalSettings(fromEvent event: Event?) { + func setupFederalSettings() { teamSorting = tournamentLevel.defaultTeamSortingType groupStageMatchFormat = groupStageSmartMatchFormat() loserBracketMatchFormat = loserBracketSmartMatchFormat(5) matchFormat = roundSmartMatchFormat(5) entryFee = tournamentLevel.entryFee - if event?.tenupId != nil { - //enableOnlineRegistration = true - registrationDateLimit = deadline(for: .inscription) - } - - //self.customizeUsingPreferences() + registrationDateLimit = deadline(for: .inscription) } func customizeUsingPreferences() { diff --git a/PadelClub/Extensions/String+Extensions.swift b/PadelClub/Extensions/String+Extensions.swift index abee514..21231bb 100644 --- a/PadelClub/Extensions/String+Extensions.swift +++ b/PadelClub/Extensions/String+Extensions.swift @@ -182,6 +182,17 @@ extension String { firstMatch(of: RegexStatic.phoneNumber) != nil } + func cleanSearchText() -> String { + // Create a character set of all punctuation except slashes and hyphens + var punctuationToRemove = CharacterSet.punctuationCharacters + punctuationToRemove.remove(charactersIn: "/-") + + // Remove the unwanted punctuation + return self.components(separatedBy: punctuationToRemove) + .joined(separator: " ") + .trimmingCharacters(in: .whitespacesAndNewlines) + } + //april 04-2024 bug with accent characters / adobe / fft mutating func replace(characters: [(Character, Character)]) { for (targetChar, replacementChar) in characters { diff --git a/PadelClub/Utils/PadelRule.swift b/PadelClub/Utils/PadelRule.swift index dd7cbd2..f10abed 100644 --- a/PadelClub/Utils/PadelRule.swift +++ b/PadelClub/Utils/PadelRule.swift @@ -1032,7 +1032,7 @@ enum SetFormat: Int, Hashable, Codable { } func winner(teamOne: Int, teamTwo: Int) -> TeamPosition { - return teamOne >= teamTwo ? .one : .two + return teamOne > teamTwo ? .one : .two } func hasEnded(teamOne: Int, teamTwo: Int) -> Bool { diff --git a/PadelClub/ViewModel/SearchViewModel.swift b/PadelClub/ViewModel/SearchViewModel.swift index c9a14df..be32ecd 100644 --- a/PadelClub/ViewModel/SearchViewModel.swift +++ b/PadelClub/ViewModel/SearchViewModel.swift @@ -167,7 +167,8 @@ class SearchViewModel: ObservableObject, Identifiable { } func words() -> [String] { - return searchText.canonicalVersionWithPunctuation.trimmed.components( + let cleanedText = searchText.cleanSearchText().canonicalVersionWithPunctuation.trimmed + return cleanedText.components( separatedBy: .whitespaces) } @@ -436,11 +437,12 @@ class SearchViewModel: ObservableObject, Identifiable { static func getSpecialSlashPredicate(inputString: String) -> NSPredicate? { // Define a regular expression to find slashes between alphabetic characters (not digits) print(inputString) - + let cleanedInput = inputString.cleanSearchText() + let pattern = /(\b[A-Za-z]+)\s*\/\s*([A-Za-z]+\b)/ // Find matches in the input string - guard let match = inputString.firstMatch(of: pattern) else { + guard let match = cleanedInput.firstMatch(of: pattern) else { print("No valid name pairs found") return nil } @@ -498,6 +500,7 @@ class SearchViewModel: ObservableObject, Identifiable { // Prepare text for processing - preserve hyphens but remove digits var text = pasteField + .replacingOccurrences(of: "[\\(\\)\\[\\]\\{\\}]", with: "", options: .regularExpression) .replacingOccurrences(of: "/", with: " ") // Replace slashes with spaces .trimmingCharacters(in: .whitespacesAndNewlines) diff --git a/PadelClub/ViewModel/SetDescriptor.swift b/PadelClub/ViewModel/SetDescriptor.swift index 2d3be78..7ab5e42 100644 --- a/PadelClub/ViewModel/SetDescriptor.swift +++ b/PadelClub/ViewModel/SetDescriptor.swift @@ -30,7 +30,7 @@ struct SetDescriptor: Identifiable, Equatable { } var winner: TeamPosition? { - if let valueTeamTwo, let valueTeamOne { + if let valueTeamTwo, let valueTeamOne, valueTeamOne != valueTeamTwo { return setFormat.winner(teamOne: valueTeamOne, teamTwo: valueTeamTwo) } else { return nil diff --git a/PadelClub/Views/Cashier/Event/EventCreationView.swift b/PadelClub/Views/Cashier/Event/EventCreationView.swift index cad9bac..5ba6f87 100644 --- a/PadelClub/Views/Cashier/Event/EventCreationView.swift +++ b/PadelClub/Views/Cashier/Event/EventCreationView.swift @@ -143,7 +143,7 @@ struct EventCreationView: View { tournament.courtCount = selectedClub?.courtCount ?? 2 tournament.startDate = startingDate tournament.dayDuration = duration - tournament.setupFederalSettings(fromEvent: event) + tournament.setupFederalSettings() } do { diff --git a/PadelClub/Views/Cashier/Event/EventTournamentsView.swift b/PadelClub/Views/Cashier/Event/EventTournamentsView.swift index 4fb75fe..198a313 100644 --- a/PadelClub/Views/Cashier/Event/EventTournamentsView.swift +++ b/PadelClub/Views/Cashier/Event/EventTournamentsView.swift @@ -63,7 +63,7 @@ struct EventTournamentsView: View { newTournament.courtCount = event.eventCourtCount() newTournament.startDate = event.eventStartDate() newTournament.dayDuration = event.eventDayDuration() - newTournament.setupFederalSettings(fromEvent: event) + newTournament.setupFederalSettings() do { try dataStore.tournaments.addOrUpdate(instance: newTournament) diff --git a/PadelClub/Views/Navigation/Agenda/CalendarView.swift b/PadelClub/Views/Navigation/Agenda/CalendarView.swift index f771644..1dab0aa 100644 --- a/PadelClub/Views/Navigation/Agenda/CalendarView.swift +++ b/PadelClub/Views/Navigation/Agenda/CalendarView.swift @@ -173,7 +173,7 @@ struct CalendarView: View { newTournament.federalTournamentAge = build.age newTournament.dayDuration = federalTournament.dayDuration newTournament.startDate = federalTournament.startDate.atBeginningOfDay(hourInt: 9) - newTournament.setupFederalSettings(fromEvent: event) + newTournament.setupFederalSettings() do { try dataStore.tournaments.addOrUpdate(instance: newTournament) } catch { diff --git a/PadelClub/Views/Score/EditScoreView.swift b/PadelClub/Views/Score/EditScoreView.swift index 3ffb742..63661d8 100644 --- a/PadelClub/Views/Score/EditScoreView.swift +++ b/PadelClub/Views/Score/EditScoreView.swift @@ -17,11 +17,13 @@ struct EditScoreView: View { @Binding var confirmScoreEdition: Bool @Environment(\.dismiss) private var dismiss @State private var firstTeamIsFirstScoreToEnter: Bool = true - + @State private var shouldEndMatch: Bool = false + init(match: Match, confirmScoreEdition: Binding) { let matchDescriptor = MatchDescriptor(match: match) _matchDescriptor = .init(wrappedValue: matchDescriptor) _confirmScoreEdition = confirmScoreEdition + _shouldEndMatch = .init(wrappedValue: matchDescriptor.hasEnded) } var defaultTeamIsActive: Bool { @@ -187,27 +189,27 @@ struct EditScoreView: View { } footer: { Text("Termine la rencontre sur ce score") } - } - - if matchDescriptor.match?.hasEnded() == false { + } else if matchDescriptor.match?.hasEnded() == false { Section { - RowButtonView("Mise à jour") { - matchDescriptor.match?.updateScore(fromMatchDescriptor: matchDescriptor) - save() - dismiss() + Toggle(isOn: $shouldEndMatch) { + Text("Terminer le match") } - } footer: { - Text("Met à jour le score, ne termine pas la rencontre") - } - - Section { - RowButtonView("Terminer la rencontre") { - matchDescriptor.match?.setUnfinishedScore(fromMatchDescriptor: matchDescriptor) + + RowButtonView("Confirmer") { + if shouldEndMatch { + matchDescriptor.match?.setUnfinishedScore(fromMatchDescriptor: matchDescriptor) + } else { + matchDescriptor.match?.updateScore(fromMatchDescriptor: matchDescriptor) + } save() dismiss() } } footer: { - Text("Le match n'a pas pu aboutir.") + if shouldEndMatch { + Text("Le match n'a pas pu aboutir.") + } else { + Text("Met à jour le score, ne termine pas la rencontre") + } } } } diff --git a/PadelClub/Views/Tournament/Screen/Components/TournamentCategorySettingsView.swift b/PadelClub/Views/Tournament/Screen/Components/TournamentCategorySettingsView.swift index c0bfcff..14985a6 100644 --- a/PadelClub/Views/Tournament/Screen/Components/TournamentCategorySettingsView.swift +++ b/PadelClub/Views/Tournament/Screen/Components/TournamentCategorySettingsView.swift @@ -83,6 +83,7 @@ struct TournamentCategorySettingsView: View { .onChange(of: [ tournament.federalLevelCategory, ]) { + tournament.setupFederalSettings() _save() } .onChange(of: [ diff --git a/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift b/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift index 54de58a..84a1383 100644 --- a/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift +++ b/PadelClub/Views/Tournament/Screen/RegistrationSetupView.swift @@ -79,11 +79,6 @@ struct RegistrationSetupView: View { var body: some View { List { - if displayWarning() { - Text("Attention, l'inscription en ligne est activée et vous avez des équipes inscrites en ligne, en modifiant la structure ces équipes seront intégrées ou retirées de votre sélection d'équipes. Padel Club saura prévenir les équipes inscrites en ligne automatiquement.") - .foregroundStyle(.logoRed) - } - Section { Toggle(isOn: $enableOnlineRegistration) { Text("Activer") @@ -151,6 +146,12 @@ struct RegistrationSetupView: View { } Section { + if displayWarning() { + Text("Attention, l'inscription en ligne est activée et vous avez des équipes inscrites en ligne, en modifiant la structure ces équipes seront intégrées ou retirées de votre sélection d'équipes. Padel Club saura prévenir les équipes inscrites en ligne automatiquement.") + .foregroundStyle(.logoRed) + } + + // Toggle(isOn: $targetTeamCountEnabled) { // Text("Activer une limite") // } @@ -162,7 +163,7 @@ struct RegistrationSetupView: View { } header: { Text("Paires admises") } footer: { - Text("Les inscriptions seront indiqués en attente pour les joueurs au-délà de cette limite dans le cas où aucune limite de liste d'attente n'est active ou non atteinte. Dans le cas contraire, plus aucune inscription ne seront possibles.") + Text("Les inscriptions seront indiquées en attente pour les joueurs au-délà de cette limite dans le cas où aucune limite de liste d'attente n'est active ou non atteinte. Dans le cas contraire, plus aucune inscription ne seront possibles.") } Section { @@ -311,11 +312,7 @@ struct RegistrationSetupView: View { tournament.registrationDateLimit = registrationDateLimit } - if targetTeamCountEnabled == false { - tournament.teamCount = 24 - } else { - tournament.teamCount = targetTeamCount - } + tournament.teamCount = targetTeamCount if waitingListLimitEnabled == false { tournament.waitingListLimit = nil diff --git a/PadelClub/Views/Tournament/Shared/TournamentCellView.swift b/PadelClub/Views/Tournament/Shared/TournamentCellView.swift index 3b6f6d7..1969855 100644 --- a/PadelClub/Views/Tournament/Shared/TournamentCellView.swift +++ b/PadelClub/Views/Tournament/Shared/TournamentCellView.swift @@ -202,7 +202,7 @@ struct TournamentCellView: View { newTournament.federalTournamentAge = build.age newTournament.dayDuration = federalTournament.dayDuration newTournament.startDate = federalTournament.startDate.atBeginningOfDay(hourInt: 9) - newTournament.setupFederalSettings(fromEvent: event) + newTournament.setupFederalSettings() do { try dataStore.tournaments.addOrUpdate(instance: newTournament) } catch {