|
|
|
|
@ -116,7 +116,7 @@ struct FileImportView: View { |
|
|
|
|
if tournament.isAnimation() { |
|
|
|
|
return teams.sorted(by: \.weight) |
|
|
|
|
} |
|
|
|
|
return teams.filter { $0.tournamentCategory == tournament.tournamentCategory && $0.tournamentAgeCategory == tournament.federalTournamentAge }.sorted(by: \.weight) |
|
|
|
|
return teams.filter { $0.tournamentLevel == tournament.tournamentLevel && $0.tournamentCategory == tournament.tournamentCategory && $0.tournamentAgeCategory == tournament.federalTournamentAge }.sorted(by: \.weight) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _deleteTeams(teams: [TeamRegistration]) async { |
|
|
|
|
@ -174,7 +174,7 @@ struct FileImportView: View { |
|
|
|
|
RowButtonView("Démarrer l'importation") { |
|
|
|
|
if let fileContent { |
|
|
|
|
do { |
|
|
|
|
try await _startImport(fileContent: fileContent) |
|
|
|
|
try await _startImport(fileContent: fileContent, allTournaments: false) |
|
|
|
|
} catch { |
|
|
|
|
errorMessage = error.localizedDescription |
|
|
|
|
} |
|
|
|
|
@ -198,7 +198,7 @@ struct FileImportView: View { |
|
|
|
|
multiImport = true |
|
|
|
|
if let fileContent { |
|
|
|
|
do { |
|
|
|
|
try await _startImport(fileContent: fileContent) |
|
|
|
|
try await _startImport(fileContent: fileContent, allTournaments: true) |
|
|
|
|
} catch { |
|
|
|
|
errorMessage = error.localizedDescription |
|
|
|
|
} |
|
|
|
|
@ -286,7 +286,7 @@ struct FileImportView: View { |
|
|
|
|
Task { |
|
|
|
|
if let fileContent { |
|
|
|
|
do { |
|
|
|
|
try await _startImport(fileContent: fileContent) |
|
|
|
|
try await _startImport(fileContent: fileContent, allTournaments: false) |
|
|
|
|
} catch { |
|
|
|
|
errorMessage = error.localizedDescription |
|
|
|
|
} |
|
|
|
|
@ -305,7 +305,7 @@ struct FileImportView: View { |
|
|
|
|
Task { |
|
|
|
|
if let fileContent { |
|
|
|
|
do { |
|
|
|
|
try await _startImport(fileContent: fileContent) |
|
|
|
|
try await _startImport(fileContent: fileContent, allTournaments: false) |
|
|
|
|
} catch { |
|
|
|
|
errorMessage = error.localizedDescription |
|
|
|
|
} |
|
|
|
|
@ -353,14 +353,20 @@ struct FileImportView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let unfound = _getUnfound(tournament: tournament, fromTeams: _filteredTeams) |
|
|
|
|
let unfound = _getUnfound(tournament: tournament, fromTeams: _filteredTeams).sorted(by: \.weight) |
|
|
|
|
|
|
|
|
|
if unfound.isEmpty == false { |
|
|
|
|
Section { |
|
|
|
|
LabeledContent { |
|
|
|
|
Text(unfound.count.formatted()) |
|
|
|
|
DisclosureGroup { |
|
|
|
|
ForEach(unfound) { |
|
|
|
|
TeamRowView(team: $0) |
|
|
|
|
} |
|
|
|
|
} label: { |
|
|
|
|
Text("Équipe\(unfound.count.pluralSuffix) précédente\(unfound.count.pluralSuffix) introuvable\(unfound.count.pluralSuffix)") |
|
|
|
|
LabeledContent { |
|
|
|
|
Text(unfound.count.formatted()) |
|
|
|
|
} label: { |
|
|
|
|
Text("Équipe\(unfound.count.pluralSuffix) précédente\(unfound.count.pluralSuffix) introuvable\(unfound.count.pluralSuffix)") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} footer: { |
|
|
|
|
Text("Équipes de votre liste précédente non détectées dans ce nouveau fichier") |
|
|
|
|
@ -429,6 +435,7 @@ struct FileImportView: View { |
|
|
|
|
} |
|
|
|
|
selectedFile.stopAccessingSecurityScopedResource() |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
errorMessage = error.localizedDescription |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -437,6 +444,7 @@ struct FileImportView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
case .failure(let error): |
|
|
|
|
Logger.error(error) |
|
|
|
|
errorMessage = error.localizedDescription |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
@ -520,6 +528,7 @@ struct FileImportView: View { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct CombinedCategory: Identifiable, Hashable { |
|
|
|
|
let tournamentLevel: TournamentLevel |
|
|
|
|
let tournamentCategory: TournamentCategory |
|
|
|
|
let federalTournamentAge: FederalTournamentAge |
|
|
|
|
|
|
|
|
|
@ -528,7 +537,7 @@ struct FileImportView: View { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _startImport(fileContent: String) async throws { |
|
|
|
|
private func _startImport(fileContent: String, allTournaments: Bool) async throws { |
|
|
|
|
await MainActor.run { |
|
|
|
|
errorMessage = nil |
|
|
|
|
teams.removeAll() |
|
|
|
|
@ -538,10 +547,10 @@ struct FileImportView: View { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let event: Event? = tournament.eventObject() |
|
|
|
|
if let event, event.federalTournaments().count > 1 { |
|
|
|
|
if let event, event.federalTournaments().count > 1, allTournaments == true { |
|
|
|
|
var categoriesDone: [CombinedCategory] = [] |
|
|
|
|
for someTournament in event.federalTournaments() { |
|
|
|
|
let combinedCategory = CombinedCategory(tournamentCategory: someTournament.tournamentCategory, federalTournamentAge: someTournament.federalTournamentAge) |
|
|
|
|
let combinedCategory = CombinedCategory(tournamentLevel: someTournament.tournamentLevel, 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, chunkByParameter: chunkByParameter) |
|
|
|
|
self.teams += _teams |
|
|
|
|
|