|
|
|
|
@ -44,8 +44,16 @@ struct EventListView: View { |
|
|
|
|
Text("\(count.formatted()) tournoi" + count.pluralSuffix) |
|
|
|
|
} |
|
|
|
|
} footer: { |
|
|
|
|
if _tournaments.isEmpty == false, let pcTournaments = _tournaments as? [Tournament] { |
|
|
|
|
_menuOptions(pcTournaments) |
|
|
|
|
if _tournaments.isEmpty == false { |
|
|
|
|
if let pcTournaments = _tournaments as? [Tournament] { |
|
|
|
|
_menuOptions(pcTournaments) |
|
|
|
|
} else if let federalTournaments = _tournaments as? [FederalTournament], navigation.agendaDestination == .tenup { |
|
|
|
|
FooterButtonView("Tout récupérer", role: .destructive) { |
|
|
|
|
federalTournaments.forEach { federalTournament in |
|
|
|
|
_importFederalTournamentBatch(federalTournament: federalTournament) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
.headerProminence(.increased) |
|
|
|
|
@ -76,24 +84,19 @@ struct EventListView: View { |
|
|
|
|
if navigation.agendaDestination == .tenup |
|
|
|
|
&& dataStore.user.hasTenupClubs() == true |
|
|
|
|
&& _tournaments.isEmpty { |
|
|
|
|
_gatherFederalTournaments(startDate: section) |
|
|
|
|
await _gatherFederalTournaments(startDate: section) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _gatherFederalTournaments(startDate: Date) { |
|
|
|
|
// isGatheringFederalTournaments = true |
|
|
|
|
Task { |
|
|
|
|
do { |
|
|
|
|
let clubs : [Club] = dataStore.user.clubsObjects() |
|
|
|
|
try await federalDataViewModel.gatherTournaments(clubs: clubs.filter { $0.code != nil }, startDate: startDate, endDate: startDate.endOfMonth) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
// self.error = error |
|
|
|
|
} |
|
|
|
|
// isGatheringFederalTournaments = false |
|
|
|
|
private func _gatherFederalTournaments(startDate: Date) async { |
|
|
|
|
do { |
|
|
|
|
let clubs : [Club] = dataStore.user.clubsObjects() |
|
|
|
|
try await federalDataViewModel.gatherTournaments(clubs: clubs.filter { $0.code != nil }, startDate: startDate) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -274,7 +277,77 @@ struct EventListView: View { |
|
|
|
|
} label: { |
|
|
|
|
Text("Description des tournois") |
|
|
|
|
} |
|
|
|
|
Divider() |
|
|
|
|
Menu { |
|
|
|
|
Button { |
|
|
|
|
pcTournaments.forEach { tournament in |
|
|
|
|
tournament.umpireCustomMail = nil |
|
|
|
|
tournament.umpireCustomPhone = nil |
|
|
|
|
tournament.umpireCustomContact = nil |
|
|
|
|
} |
|
|
|
|
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments) |
|
|
|
|
} label: { |
|
|
|
|
Text("Effacer les informations du JAP") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let umpireCustomMail = pcTournaments.first(where: { tournament in |
|
|
|
|
tournament.umpireCustomMail != nil |
|
|
|
|
})?.umpireCustomMail |
|
|
|
|
let umpireCustomPhone = pcTournaments.first(where: { tournament in |
|
|
|
|
tournament.umpireCustomPhone != nil |
|
|
|
|
})?.umpireCustomPhone |
|
|
|
|
let umpireCustomContact = pcTournaments.first(where: { tournament in |
|
|
|
|
tournament.umpireCustomContact != nil |
|
|
|
|
})?.umpireCustomContact |
|
|
|
|
Button { |
|
|
|
|
pcTournaments.forEach { tournament in |
|
|
|
|
tournament.umpireCustomMail = umpireCustomMail |
|
|
|
|
tournament.umpireCustomPhone = umpireCustomPhone |
|
|
|
|
tournament.umpireCustomContact = umpireCustomContact |
|
|
|
|
} |
|
|
|
|
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments) |
|
|
|
|
} label: { |
|
|
|
|
Text("Indiquer le même JAP pour tous") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Button { |
|
|
|
|
pcTournaments.forEach { tournament in |
|
|
|
|
tournament.hideUmpireMail = true |
|
|
|
|
} |
|
|
|
|
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments) |
|
|
|
|
} label: { |
|
|
|
|
Text("Masquer le mail") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Button { |
|
|
|
|
pcTournaments.forEach { tournament in |
|
|
|
|
tournament.hideUmpireMail = false |
|
|
|
|
} |
|
|
|
|
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments) |
|
|
|
|
} label: { |
|
|
|
|
Text("Afficher le mail") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Button { |
|
|
|
|
pcTournaments.forEach { tournament in |
|
|
|
|
tournament.hideUmpirePhone = true |
|
|
|
|
} |
|
|
|
|
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments) |
|
|
|
|
} label: { |
|
|
|
|
Text("Masquer le téléphone") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Button { |
|
|
|
|
pcTournaments.forEach { tournament in |
|
|
|
|
tournament.hideUmpirePhone = false |
|
|
|
|
} |
|
|
|
|
dataStore.tournaments.addOrUpdate(contentOfs: pcTournaments) |
|
|
|
|
} label: { |
|
|
|
|
Text("Afficher le téléphone") |
|
|
|
|
} |
|
|
|
|
} label: { |
|
|
|
|
Text("Infos JAP") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _nextMonths() -> [Date] { |
|
|
|
|
@ -363,6 +436,38 @@ struct EventListView: View { |
|
|
|
|
TournamentCellView(tournament: federalTournament) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _event(of tournament: FederalTournament) -> Event? { |
|
|
|
|
return dataStore.events.first(where: { $0.tenupId == tournament.id.string }) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _importFederalTournamentBatch(federalTournament: FederalTournament) { |
|
|
|
|
federalTournament.tournaments.forEach { tournament in |
|
|
|
|
_create(federalTournament: federalTournament, existingTournament: _event(of: federalTournament)?.existingBuild(tournament), build: tournament) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private func _create(federalTournament: FederalTournament, existingTournament: Tournament?, build: any TournamentBuildHolder) { |
|
|
|
|
if let existingTournament { |
|
|
|
|
} else { |
|
|
|
|
let event = federalTournament.getEvent() |
|
|
|
|
let newTournament = Tournament.newEmptyInstance() |
|
|
|
|
newTournament.event = event.id |
|
|
|
|
//todo |
|
|
|
|
//newTournament.umpireMail() |
|
|
|
|
//newTournament.jsonData = jsonData |
|
|
|
|
newTournament.tournamentLevel = build.level |
|
|
|
|
newTournament.tournamentCategory = build.category |
|
|
|
|
newTournament.federalTournamentAge = build.age |
|
|
|
|
newTournament.dayDuration = federalTournament.dayDuration |
|
|
|
|
newTournament.startDate = federalTournament.startDate.atBeginningOfDay(hourInt: 9) |
|
|
|
|
newTournament.setupFederalSettings() |
|
|
|
|
do { |
|
|
|
|
try dataStore.tournaments.addOrUpdate(instance: newTournament) |
|
|
|
|
} catch { |
|
|
|
|
Logger.error(error) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//#Preview { |
|
|
|
|
|