diff --git a/PadelClub.xcodeproj/project.pbxproj b/PadelClub.xcodeproj/project.pbxproj index 18d5c14..0cc3cb6 100644 --- a/PadelClub.xcodeproj/project.pbxproj +++ b/PadelClub.xcodeproj/project.pbxproj @@ -3134,7 +3134,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 3; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; @@ -3179,7 +3179,7 @@ CODE_SIGN_ENTITLEMENTS = PadelClub/PadelClub.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 1; + CURRENT_PROJECT_VERSION = 3; DEFINES_MODULE = YES; DEVELOPMENT_ASSET_PATHS = "\"PadelClub/Preview Content\""; DEVELOPMENT_TEAM = BQ3Y44M3Q6; diff --git a/PadelClub/Utils/FileImportManager.swift b/PadelClub/Utils/FileImportManager.swift index a275e03..deb82db 100644 --- a/PadelClub/Utils/FileImportManager.swift +++ b/PadelClub/Utils/FileImportManager.swift @@ -178,7 +178,7 @@ class FileImportManager { static let FFT_ASSIMILATION_WOMAN_IN_MAN = "A calculer selon la pondération en vigueur" - func createTeams(from fileContent: String, tournament: Tournament, fileProvider: FileProvider = .frenchFederation, checkingCategoryDisabled: Bool) async throws -> [TeamHolder] { + func createTeams(from fileContent: String, tournament: Tournament, fileProvider: FileProvider = .frenchFederation, checkingCategoryDisabled: Bool, chunkByParameter: Bool) async throws -> [TeamHolder] { switch fileProvider { case .frenchFederation: @@ -186,9 +186,9 @@ class FileImportManager { case .padelClub: return await _getPadelClubTeams(from: fileContent, tournament: tournament) case .custom: - return await _getPadelBusinessLeagueTeams(from: fileContent, autoSearch: false, tournament: tournament) + return await _getPadelBusinessLeagueTeams(from: fileContent, chunkByParameter: chunkByParameter, autoSearch: false, tournament: tournament) case .customAutoSearch: - return await _getPadelBusinessLeagueTeams(from: fileContent, autoSearch: true, tournament: tournament) + return await _getPadelBusinessLeagueTeams(from: fileContent, chunkByParameter: chunkByParameter, autoSearch: true, tournament: tournament) } } @@ -424,7 +424,7 @@ class FileImportManager { return results } - private func _getPadelBusinessLeagueTeams(from fileContent: String, autoSearch: Bool, tournament: Tournament) async -> [TeamHolder] { + private func _getPadelBusinessLeagueTeams(from fileContent: String, chunkByParameter: Bool, autoSearch: Bool, tournament: Tournament) async -> [TeamHolder] { let lines = fileContent.replacingOccurrences(of: "\"", with: "").components(separatedBy: "\n") guard let firstLine = lines.first else { return [] } var separator = "," @@ -434,7 +434,13 @@ class FileImportManager { let fetchRequest = ImportedPlayer.fetchRequest() let federalContext = PersistenceController.shared.localContainer.viewContext - let results: [TeamHolder] = lines.chunked(byParameterAt: 1).map { team in + var chunks: [[String]] = [] + if chunkByParameter { + chunks = lines.chunked(byParameterAt: 1) + } else { + chunks = lines.chunked(into: 2) + } + let results = chunks.map { team in var teamName: String? = nil let players = team.map { player in let data = player.components(separatedBy: separator) diff --git a/PadelClub/Views/Match/MatchDetailView.swift b/PadelClub/Views/Match/MatchDetailView.swift index 0e61b10..300a5fa 100644 --- a/PadelClub/Views/Match/MatchDetailView.swift +++ b/PadelClub/Views/Match/MatchDetailView.swift @@ -448,17 +448,13 @@ struct MatchDetailView: View { } if match.startDate != nil || startDateSetup == .customDate { - DatePicker(selection: $startDate) { - Label("Début", systemImage: "calendar").labelStyle(.titleOnly) - } - .datePickerStyle(.compact) + DatePicker("Début", selection: $startDate) + .datePickerStyle(.compact) } if match.endDate != nil { - DatePicker(selection: $endDate) { - Label("Fin", systemImage: "calendar").labelStyle(.titleOnly) - } - .datePickerStyle(.compact) + DatePicker("Fin", selection: $endDate) + .datePickerStyle(.compact) } diff --git a/PadelClub/Views/Planning/PlanningView.swift b/PadelClub/Views/Planning/PlanningView.swift index 903ec08..f2b0348 100644 --- a/PadelClub/Views/Planning/PlanningView.swift +++ b/PadelClub/Views/Planning/PlanningView.swift @@ -13,9 +13,19 @@ struct PlanningView: View { let matches: [Match] @Binding var selectedScheduleDestination: ScheduleDestination? - @State private var timeSlots: [Date:[Match]] - @State private var days: [Date] - @State private var keys: [Date] + + var timeSlots: [Date:[Match]] { + Dictionary(grouping: matches) { $0.startDate ?? .distantFuture } + } + + var days: [Date] { + Set(timeSlots.keys.map { $0.startOfDay }).sorted() + } + + var keys: [Date] { + timeSlots.keys.sorted() + } + @State private var filterOption: PlanningFilterOption = .byDefault enum PlanningFilterOption: Int, CaseIterable, Identifiable { @@ -37,10 +47,6 @@ struct PlanningView: View { init(matches: [Match], selectedScheduleDestination: Binding) { self.matches = matches _selectedScheduleDestination = selectedScheduleDestination - let timeSlots = Dictionary(grouping: matches) { $0.startDate ?? .distantFuture } - _timeSlots = State(wrappedValue: timeSlots) - _days = State(wrappedValue: Set(timeSlots.keys.map { $0.startOfDay }).sorted()) - _keys = State(wrappedValue: timeSlots.keys.sorted()) } var body: some View { diff --git a/PadelClub/Views/Tournament/FileImportView.swift b/PadelClub/Views/Tournament/FileImportView.swift index 99bf6b9..9110942 100644 --- a/PadelClub/Views/Tournament/FileImportView.swift +++ b/PadelClub/Views/Tournament/FileImportView.swift @@ -84,6 +84,7 @@ struct FileImportView: View { @State private var multiImport: Bool = false @State private var presentFormatHelperView: Bool = false @State private var validatedTournamentIds: Set = Set() + @State private var chunkByParameter: Bool = true init(defaultFileProvider: FileImportManager.FileProvider = .frenchFederation) { _fileProvider = .init(wrappedValue: defaultFileProvider) @@ -139,6 +140,17 @@ struct FileImportView: View { Text("Padel Club essaiera de chercher les joueurs dans la base fédérale automatiquement") } + if fileProvider == .custom || fileProvider == .customAutoSearch { + Toggle(isOn: $chunkByParameter) { + Text("Détection des équipes") + if chunkByParameter { + Text("via le nom de l'équipe") + } else { + Text("couple de deux lignes") + } + } + } + RowButtonView("Démarrer l'importation") { if let fileContent { do { @@ -523,7 +535,7 @@ struct FileImportView: View { for someTournament in event.tournaments { let combinedCategory = CombinedCategory(tournamentCategory: someTournament.tournamentCategory, federalTournamentAge: someTournament.federalTournamentAge) if categoriesDone.contains(combinedCategory) == false { - let _teams = try await FileImportManager.shared.createTeams(from: fileContent, tournament: someTournament, fileProvider: fileProvider, checkingCategoryDisabled: false) + let _teams = try await FileImportManager.shared.createTeams(from: fileContent, tournament: someTournament, fileProvider: fileProvider, checkingCategoryDisabled: false, chunkByParameter: chunkByParameter) self.teams += _teams categoriesDone.append(combinedCategory) } else { @@ -531,7 +543,7 @@ struct FileImportView: View { } } } else { - self.teams = try await FileImportManager.shared.createTeams(from: fileContent, tournament: tournament, fileProvider: fileProvider, checkingCategoryDisabled: true) + self.teams = try await FileImportManager.shared.createTeams(from: fileContent, tournament: tournament, fileProvider: fileProvider, checkingCategoryDisabled: true, chunkByParameter: chunkByParameter) } await MainActor.run {