From 5be8ef5d199897bdd567bd9d325ddf885676dad6 Mon Sep 17 00:00:00 2001 From: Razmig Sarkissian Date: Tue, 18 Jun 2024 18:50:46 +0200 Subject: [PATCH] fix stuff --- PadelClub/Utils/FileImportManager.swift | 8 +- .../Views/Cashier/Event/EventLinksView.swift | 4 +- .../GroupStage/GroupStageSettingsView.swift | 2 +- .../Views/Planning/PlanningSettingsView.swift | 143 ++++++++++-------- .../Views/Tournament/FileImportView.swift | 87 +++++++++++ .../Screen/TableStructureView.swift | 4 +- 6 files changed, 172 insertions(+), 76 deletions(-) diff --git a/PadelClub/Utils/FileImportManager.swift b/PadelClub/Utils/FileImportManager.swift index c7f3e33..53fe5f4 100644 --- a/PadelClub/Utils/FileImportManager.swift +++ b/PadelClub/Utils/FileImportManager.swift @@ -82,7 +82,7 @@ class FileImportManager { case frenchFederation case padelClub - case unknown + case custom var localizedLabel: String { switch self { @@ -90,8 +90,8 @@ class FileImportManager { return "Padel Club" case .frenchFederation: return "FFT" - case .unknown: - return "Inconnu" + case .custom: + return "Personnalisé" } } } @@ -158,7 +158,7 @@ class FileImportManager { return try await _getFederalTeams(from: fileContent, tournament: tournament) case .padelClub: return await _getPadelClubTeams(from: fileContent, tournament: tournament) - case .unknown: + case .custom: return await _getPadelBusinessLeagueTeams(from: fileContent, tournament: tournament) } } diff --git a/PadelClub/Views/Cashier/Event/EventLinksView.swift b/PadelClub/Views/Cashier/Event/EventLinksView.swift index 3dcd1b1..81e77cf 100644 --- a/PadelClub/Views/Cashier/Event/EventLinksView.swift +++ b/PadelClub/Views/Cashier/Event/EventLinksView.swift @@ -34,7 +34,7 @@ struct EventLinksView: View { let links : [PageLink] = [.teams, .summons, .groupStages, .matches, .rankings] Picker(selection: $pageLink) { ForEach(links) { pageLink in - Text(pageLink.localizedLabel()) + Text(pageLink.localizedLabel()).tag(pageLink) } } label: { Text("Choisir une page du tournoi en particulier") @@ -49,7 +49,7 @@ struct EventLinksView: View { .multilineTextAlignment(.leading) - ShareLink("Partagez ce message", item: eventLinksPasteData) + ShareLink("Partagez ce lien", item: eventLinksPasteData) } } } diff --git a/PadelClub/Views/GroupStage/GroupStageSettingsView.swift b/PadelClub/Views/GroupStage/GroupStageSettingsView.swift index 13aef34..bbff2e4 100644 --- a/PadelClub/Views/GroupStage/GroupStageSettingsView.swift +++ b/PadelClub/Views/GroupStage/GroupStageSettingsView.swift @@ -43,7 +43,7 @@ struct GroupStageSettingsView: View { Section { menuBuildAllGroupStages } footer: { - Text("efface et recréé les poules, les horaires et les résultats existants seront perdus") + Text("Efface et recréé les poules, les horaires et les résultats existants seront perdus") } } diff --git a/PadelClub/Views/Planning/PlanningSettingsView.swift b/PadelClub/Views/Planning/PlanningSettingsView.swift index a856901..633c918 100644 --- a/PadelClub/Views/Planning/PlanningSettingsView.swift +++ b/PadelClub/Views/Planning/PlanningSettingsView.swift @@ -93,15 +93,29 @@ struct PlanningSettingsView: View { .foregroundStyle(.logoRed) } - NavigationLink { - List { - _optionsView() + if tournament.groupStageCount > 0 { + Section { + TournamentFieldsManagerView(localizedStringKey: "Poule en parallèle", count: $groupStageChunkCount, max: tournament.groupStageCount) + .onChange(of: groupStageChunkCount) { + matchScheduler.groupStageChunkCount = groupStageChunkCount + } + } footer: { + NavigationLink { + _optionsView() + } label: { + Text("Voir les options avancées") + .underline() + .foregroundStyle(.master) + } + } + } else { + Section { + NavigationLink { + _optionsView() + } label: { + Text("Voir les options avancées") + } } - .navigationTitle("Options avancées") - .navigationBarTitleDisplayMode(.inline) - .toolbarBackground(.visible, for: .navigationBar) - } label: { - Text("Voir les options avancées") } let allMatches = tournament.allMatches() @@ -204,75 +218,70 @@ struct PlanningSettingsView: View { @ViewBuilder private func _optionsView() -> some View { - if tournament.groupStageCount > 0 { + List { Section { - TournamentFieldsManagerView(localizedStringKey: "Poule en parallèle", count: $groupStageChunkCount, max: tournament.groupStageCount) - .onChange(of: groupStageChunkCount) { - matchScheduler.groupStageChunkCount = groupStageChunkCount - } - } footer: { - Text("Vous pouvez indiquer le nombre de poule démarrant en même temps.") - } - } - - Section { - Toggle(isOn: $matchScheduler.overrideCourtsUnavailability) { - Text("Ne pas tenir compte des autres épreuves") - } + Toggle(isOn: $matchScheduler.overrideCourtsUnavailability) { + Text("Ne pas tenir compte des autres épreuves") + } - Toggle(isOn: $matchScheduler.randomizeCourts) { - Text("Distribuer les terrains au hasard") - } - - Toggle(isOn: $matchScheduler.shouldHandleUpperRoundSlice) { - Text("Équilibrer les matchs d'une manche sur plusieurs tours") - } - - Toggle(isOn: $matchScheduler.shouldEndRoundBeforeStartingNext) { - Text("Finir une manche, classement inclus avant de continuer") - } - } - - Section { - Toggle(isOn: $matchScheduler.accountUpperBracketBreakTime) { - Text("Tenir compte des pauses") - Text("Tableau") + Toggle(isOn: $matchScheduler.randomizeCourts) { + Text("Distribuer les terrains au hasard") + } + + Toggle(isOn: $matchScheduler.shouldHandleUpperRoundSlice) { + Text("Équilibrer les matchs d'une manche sur plusieurs tours") + } + + Toggle(isOn: $matchScheduler.shouldEndRoundBeforeStartingNext) { + Text("Finir une manche, classement inclus avant de continuer") + } } - Toggle(isOn: $matchScheduler.accountLoserBracketBreakTime) { - Text("Tenir compte des pauses") - Text("Classement") - } - } - - Section { - Toggle(isOn: $matchScheduler.rotationDifferenceIsImportant) { - Text("Forcer un créneau supplémentaire entre 2 phases") + Section { + Toggle(isOn: $matchScheduler.accountUpperBracketBreakTime) { + Text("Tenir compte des pauses") + Text("Tableau") + } + + Toggle(isOn: $matchScheduler.accountLoserBracketBreakTime) { + Text("Tenir compte des pauses") + Text("Classement") + } } - LabeledContent { - StepperView(count: $matchScheduler.upperBracketRotationDifference, minimum: 0, maximum: 2) - } label: { - Text("Tableau") + Section { + Toggle(isOn: $matchScheduler.rotationDifferenceIsImportant) { + Text("Forcer un créneau supplémentaire entre 2 phases") + } + + LabeledContent { + StepperView(count: $matchScheduler.upperBracketRotationDifference, minimum: 0, maximum: 2) + } label: { + Text("Tableau") + } + .disabled(matchScheduler.rotationDifferenceIsImportant == false) + + LabeledContent { + StepperView(count: $matchScheduler.loserBracketRotationDifference, minimum: 0, maximum: 2) + } label: { + Text("Classement") + } + .disabled(matchScheduler.rotationDifferenceIsImportant == false) } - .disabled(matchScheduler.rotationDifferenceIsImportant == false) - LabeledContent { - StepperView(count: $matchScheduler.loserBracketRotationDifference, minimum: 0, maximum: 2) - } label: { - Text("Classement") - } - .disabled(matchScheduler.rotationDifferenceIsImportant == false) - } - - Section { - LabeledContent { - StepperView(count: $matchScheduler.timeDifferenceLimit, step: 5) - } label: { - Text("Optimisation des créneaux") - Text("Si libre plus de \(matchScheduler.timeDifferenceLimit) minutes") + Section { + LabeledContent { + StepperView(count: $matchScheduler.timeDifferenceLimit, step: 5) + } label: { + Text("Optimisation des créneaux") + Text("Si libre plus de \(matchScheduler.timeDifferenceLimit) minutes") + } } + } + .navigationTitle("Options avancées") + .navigationBarTitleDisplayMode(.inline) + .toolbarBackground(.visible, for: .navigationBar) } private func _setupSchedule() async -> Bool { diff --git a/PadelClub/Views/Tournament/FileImportView.swift b/PadelClub/Views/Tournament/FileImportView.swift index 54df424..08d836a 100644 --- a/PadelClub/Views/Tournament/FileImportView.swift +++ b/PadelClub/Views/Tournament/FileImportView.swift @@ -9,6 +9,51 @@ import SwiftUI import TipKit import LeStorage +enum FileImportCustomField: Int, Identifiable, CaseIterable { + var id: Int { self.rawValue } + + case sexType + case teamName + case lastName + case firstName + case rank + case licenceId + case clubName + + func columnLabel() -> String { + let columnIndex: Int = self.rawValue + 1 + return columnIndex.formatted() + } + + func descriptionLabel() -> String? { + switch self { + case .sexType: + return "f ou m" + default: + return nil + } + } + + func localizedLabel() -> String { + switch self { + case .sexType: + return "Sexe" + case .teamName: + return "Nom de l'équipe" + case .lastName: + return "Nom" + case .firstName: + return "Prénom" + case .rank: + return "Rang" + case .licenceId: + return "Licence" + case .clubName: + return "Nom du club" + } + } +} + struct FileImportView: View { @EnvironmentObject var dataStore: DataStore @Environment(Tournament.self) var tournament: Tournament @@ -29,6 +74,7 @@ struct FileImportView: View { @State private var fileProvider: FileImportManager.FileProvider = .frenchFederation @State private var validationInProgress: Bool = false @State private var multiImport: Bool = false + @State private var presentFormatHelperView: Bool = false private func filteredTeams(tournament: Tournament) -> [FileImportManager.TeamHolder] { return teams.filter { $0.tournamentCategory == tournament.tournamentCategory }.sorted(by: \.weight) @@ -83,6 +129,10 @@ struct FileImportView: View { if fileProvider == .frenchFederation { let footerString = "Fichier provenant de [beach-padel.app.fft.fr](\(URLs.beachPadel.rawValue))" Text(.init(footerString)) + } else if fileProvider == .custom { + FooterButtonView("Voir le format du fichier") { + presentFormatHelperView = true + } } } @@ -228,6 +278,43 @@ struct FileImportView: View { } } } + .navigationBarTitleDisplayMode(.inline) + .toolbarBackground(.visible, for: .navigationBar) + .sheet(isPresented: $presentFormatHelperView) { + NavigationStack { + List { + Section { + Text("Créer un fichier xls, xlsx ou csv qui contient les colonnes suivantes.") + Text("Chaque ligne correspond à un joueur, et chaque groupe de deux lignes correspond à une équipe.") + Text("Aucune valeur n'est obligatoire.") + } + + Section { + ForEach(FileImportCustomField.allCases) { fileImportCustomField in + LabeledContent { + Text(fileImportCustomField.localizedLabel()) + } label: { + Text("Colonne \(fileImportCustomField.columnLabel())") + if let descriptionLabel = fileImportCustomField.descriptionLabel() { + Text(descriptionLabel) + } + } + } + } + } + .navigationTitle("Description du format") + .navigationBarTitleDisplayMode(.inline) + .toolbarBackground(.visible, for: .navigationBar) + .toolbar { + ToolbarItem(placement: .topBarLeading) { + Button("Fermer") { + presentFormatHelperView = false + } + } + } + } + .tint(.master) + } .fileImporter(isPresented: $isShowing, allowedContentTypes: [.spreadsheet, .commaSeparatedText, .text], allowsMultipleSelection: false, onCompletion: { results in switch results { diff --git a/PadelClub/Views/Tournament/Screen/TableStructureView.swift b/PadelClub/Views/Tournament/Screen/TableStructureView.swift index 4ca44a6..e6dd7e6 100644 --- a/PadelClub/Views/Tournament/Screen/TableStructureView.swift +++ b/PadelClub/Views/Tournament/Screen/TableStructureView.swift @@ -142,7 +142,7 @@ struct TableStructureView: View { } Section { - RowButtonView("Recontruire les poules", role:.destructive) { + RowButtonView("Reconstruire les poules", role:.destructive) { _save(rebuildEverything: false) } } @@ -227,7 +227,7 @@ struct TableStructureView: View { _saveWithoutRebuild() } - Button("Recontruire les poules") { + Button("Reconstruire les poules") { _save(rebuildEverything: false) }