|
|
|
@ -28,8 +28,9 @@ struct FileImportView: View { |
|
|
|
|
|
|
|
|
|
|
|
@State private var fileProvider: FileImportManager.FileProvider = .frenchFederation |
|
|
|
@State private var fileProvider: FileImportManager.FileProvider = .frenchFederation |
|
|
|
@State private var validationInProgress: Bool = false |
|
|
|
@State private var validationInProgress: Bool = false |
|
|
|
|
|
|
|
@State private var multiImport: Bool = false |
|
|
|
|
|
|
|
|
|
|
|
private var filteredTeams: [FileImportManager.TeamHolder] { |
|
|
|
private func filteredTeams(tournament: Tournament) -> [FileImportManager.TeamHolder] { |
|
|
|
return teams.filter { $0.tournamentCategory == tournament.tournamentCategory }.sorted(by: \.weight) |
|
|
|
return teams.filter { $0.tournamentCategory == tournament.tournamentCategory }.sorted(by: \.weight) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -68,6 +69,24 @@ struct FileImportView: View { |
|
|
|
Text(.init(footerString)) |
|
|
|
Text(.init(footerString)) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if let tournaments = tournament.eventObject()?.tournaments, tournaments.count > 1, fileProvider == .frenchFederation { |
|
|
|
|
|
|
|
Section { |
|
|
|
|
|
|
|
RowButtonView("Importer toutes les épreuves") { |
|
|
|
|
|
|
|
multiImport = true |
|
|
|
|
|
|
|
if let fileContent { |
|
|
|
|
|
|
|
do { |
|
|
|
|
|
|
|
try await _startImport(fileContent: fileContent) |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
errorMessage = error.localizedDescription |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} footer: { |
|
|
|
|
|
|
|
Text("Ce tournoi possède plusieurs épreuves. Vous pouvez importer les équipes du fichier pour toutes les épreuves d'un coup.") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.disabled(fileContent == nil || convertingFile) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// if filteredTeams.isEmpty == false && tournament.unsortedTeams().isEmpty == false { |
|
|
|
// if filteredTeams.isEmpty == false && tournament.unsortedTeams().isEmpty == false { |
|
|
|
@ -128,7 +147,8 @@ struct FileImportView: View { |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
if filteredTeams.isEmpty && teams.isEmpty == false { |
|
|
|
let filteredTeams = filteredTeams(tournament: tournament) |
|
|
|
|
|
|
|
if filteredTeams.isEmpty && teams.isEmpty == false && multiImport == false { |
|
|
|
@Bindable var tournament = tournament |
|
|
|
@Bindable var tournament = tournament |
|
|
|
Section { |
|
|
|
Section { |
|
|
|
Text("Aucune équipe \(tournament.tournamentCategory.importingRawValue) détectée mais \(teams.count) équipes sont dans le fichier") |
|
|
|
Text("Aucune équipe \(tournament.tournamentCategory.importingRawValue) détectée mais \(teams.count) équipes sont dans le fichier") |
|
|
|
@ -157,6 +177,23 @@ struct FileImportView: View { |
|
|
|
.tipStyle(tint: nil) |
|
|
|
.tipStyle(tint: nil) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if multiImport, fileProvider == .frenchFederation, let tournaments = tournament.eventObject()?.tournaments, tournaments.count > 1 { |
|
|
|
|
|
|
|
ForEach(tournaments) { tournament in |
|
|
|
|
|
|
|
let tournamentFilteredTeams = self.filteredTeams(tournament: tournament) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Section { |
|
|
|
|
|
|
|
RowButtonView("Valider") { |
|
|
|
|
|
|
|
await _validate(tournament: tournament) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} header: { |
|
|
|
|
|
|
|
Text("\(tournamentFilteredTeams.count.formatted()) équipe\(tournamentFilteredTeams.count.pluralSuffix)") |
|
|
|
|
|
|
|
} footer: { |
|
|
|
|
|
|
|
Text(tournament.tournamentTitle()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
.headerProminence(.increased) |
|
|
|
|
|
|
|
} else { |
|
|
|
Section { |
|
|
|
Section { |
|
|
|
LabeledContent { |
|
|
|
LabeledContent { |
|
|
|
Text(_filteredTeams.count.formatted()) |
|
|
|
Text(_filteredTeams.count.formatted()) |
|
|
|
@ -174,6 +211,7 @@ struct FileImportView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
.fileImporter(isPresented: $isShowing, allowedContentTypes: [.spreadsheet, .commaSeparatedText, .text], allowsMultipleSelection: false, onCompletion: { results in |
|
|
|
.fileImporter(isPresented: $isShowing, allowedContentTypes: [.spreadsheet, .commaSeparatedText, .text], allowsMultipleSelection: false, onCompletion: { results in |
|
|
|
|
|
|
|
|
|
|
|
switch results { |
|
|
|
switch results { |
|
|
|
@ -215,13 +253,13 @@ struct FileImportView: View { |
|
|
|
.navigationTitle("Importation") |
|
|
|
.navigationTitle("Importation") |
|
|
|
.navigationBarTitleDisplayMode(.large) |
|
|
|
.navigationBarTitleDisplayMode(.large) |
|
|
|
.toolbar { |
|
|
|
.toolbar { |
|
|
|
ToolbarItem(placement: .bottomBar) { |
|
|
|
// ToolbarItem(placement: .bottomBar) { |
|
|
|
PasteButton(payloadType: String.self) { strings in |
|
|
|
// PasteButton(payloadType: String.self) { strings in |
|
|
|
guard let string = strings.first else { return } |
|
|
|
// guard let string = strings.first else { return } |
|
|
|
fileContent = string |
|
|
|
// fileContent = string |
|
|
|
fileProvider = .padelClub |
|
|
|
// fileProvider = .padelClub |
|
|
|
} |
|
|
|
// } |
|
|
|
} |
|
|
|
// } |
|
|
|
ToolbarItem(placement: .cancellationAction) { |
|
|
|
ToolbarItem(placement: .cancellationAction) { |
|
|
|
Button("Annuler", role: .cancel) { |
|
|
|
Button("Annuler", role: .cancel) { |
|
|
|
dismiss() |
|
|
|
dismiss() |
|
|
|
@ -232,8 +270,19 @@ struct FileImportView: View { |
|
|
|
if validationInProgress { |
|
|
|
if validationInProgress { |
|
|
|
ProgressView() |
|
|
|
ProgressView() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ButtonValidateView { |
|
|
|
ButtonValidateView(title: (multiImport ? "Tout Valider" : "Valider")) { |
|
|
|
validationInProgress = true |
|
|
|
validationInProgress = true |
|
|
|
|
|
|
|
Task { |
|
|
|
|
|
|
|
if let tournaments = tournament.eventObject()?.tournaments, tournaments.count > 1, multiImport { |
|
|
|
|
|
|
|
for tournament in tournaments { |
|
|
|
|
|
|
|
await _validate(tournament: tournament) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dismiss() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
await _validate(tournament: tournament) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
.disabled(teams.isEmpty) |
|
|
|
.disabled(teams.isEmpty) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -241,13 +290,10 @@ struct FileImportView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
.interactiveDismissDisabled(validationInProgress) |
|
|
|
.interactiveDismissDisabled(validationInProgress) |
|
|
|
.disabled(validationInProgress) |
|
|
|
.disabled(validationInProgress) |
|
|
|
.onChange(of: validationInProgress) { |
|
|
|
|
|
|
|
_validate() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private func _validate() { |
|
|
|
private func _validate(tournament: Tournament) async { |
|
|
|
Task { |
|
|
|
let filteredTeams = filteredTeams(tournament: tournament) |
|
|
|
let previousTeams = filteredTeams.compactMap({ $0.previousTeam }) |
|
|
|
let previousTeams = filteredTeams.compactMap({ $0.previousTeam }) |
|
|
|
|
|
|
|
|
|
|
|
let unfound = Set(tournament.unsortedTeams()).subtracting(Set(previousTeams)) |
|
|
|
let unfound = Set(tournament.unsortedTeams()).subtracting(Set(previousTeams)) |
|
|
|
@ -265,6 +311,7 @@ struct FileImportView: View { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
tournament.importTeams(filteredTeams) |
|
|
|
tournament.importTeams(filteredTeams) |
|
|
|
|
|
|
|
if multiImport == false { |
|
|
|
dismiss() |
|
|
|
dismiss() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|