sync2
Raz 8 months ago
parent 772061beba
commit 9aed0a118e
  1. 5
      PadelClub/Data/PlayerRegistration.swift
  2. 7
      PadelClub/Data/Tournament.swift
  3. 2
      PadelClub/Views/Player/Components/EditablePlayerView.swift
  4. 2
      PadelClub/Views/Player/PlayerView.swift
  5. 14
      PadelClub/Views/Tournament/FileImportView.swift
  6. 10
      PadelClub/Views/Tournament/Screen/AddTeamView.swift

@ -351,11 +351,6 @@ final class PlayerRegistration: ModelObject, Storable {
} }
func setComputedRank(in tournament: Tournament) { func setComputedRank(in tournament: Tournament) {
if tournament.isAnimation() {
computedRank = rank ?? 0
return
}
let currentRank = rank ?? tournament.unrankValue(for: isMalePlayer()) ?? 90_000 let currentRank = rank ?? tournament.unrankValue(for: isMalePlayer()) ?? 90_000
switch tournament.tournamentCategory { switch tournament.tournamentCategory {
case .men: case .men:

@ -1509,7 +1509,8 @@ defer {
teams.forEach { team in teams.forEach { team in
let players = team.unsortedPlayers() let players = team.unsortedPlayers()
players.forEach { $0.setComputedRank(in: self) } players.forEach { $0.setComputedRank(in: self) }
team.setWeight(from: players, inTournamentCategory: tournamentCategory) let sortedPlayers = players.sorted(by: \.computedRank, order: .ascending)
team.setWeight(from: sortedPlayers, inTournamentCategory: tournamentCategory)
do { do {
try self.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players) try self.tournamentStore.playerRegistrations.addOrUpdate(contentOfs: players)
} catch { } catch {
@ -1638,7 +1639,7 @@ defer {
} }
func hideWeight() -> Bool { func hideWeight() -> Bool {
return hideTeamsWeight || tournamentLevel.hideWeight() return hideTeamsWeight
} }
func isAnimation() -> Bool { func isAnimation() -> Bool {
@ -2664,7 +2665,7 @@ defer {
} }
func shouldWarnOnlineRegistrationUpdates() -> Bool { func shouldWarnOnlineRegistrationUpdates() -> Bool {
onlineTeams().isEmpty == false && hasEnded() == false && hasStarted() == false enableOnlineRegistration && onlineTeams().isEmpty == false && hasEnded() == false && hasStarted() == false
} }
func refreshTeamList() async { func refreshTeamList() async {

@ -97,7 +97,7 @@ struct EditablePlayerView: View {
@ViewBuilder @ViewBuilder
func computedPlayerView(_ player: PlayerRegistration) -> some View { func computedPlayerView(_ player: PlayerRegistration) -> some View {
VStack(alignment: .leading, spacing: 0.0) { VStack(alignment: .leading, spacing: 0.0) {
ImportedPlayerView(player: player) ImportedPlayerView(player: player, showFemaleInMaleAssimilation: player.tournament()?.tournamentCategory.showFemaleInMaleAssimilation ?? false)
// HStack { // HStack {
// Text(player.isImported() ? "importé via beach padel" : "") // Text(player.isImported() ? "importé via beach padel" : "")
// Text(player.formattedLicense().isLicenseNumber ? "licence valide" : "non valide") // Text(player.formattedLicense().isLicenseNumber ? "licence valide" : "non valide")

@ -20,7 +20,7 @@ struct PlayerView: View {
} }
var body: some View { var body: some View {
ImportedPlayerView(player: player) ImportedPlayerView(player: player, showFemaleInMaleAssimilation: tournament.tournamentCategory.showFemaleInMaleAssimilation)
.swipeActions(edge: .trailing, allowsFullSwipe: true) { .swipeActions(edge: .trailing, allowsFullSwipe: true) {
Button(role: .destructive) { Button(role: .destructive) {
do { do {

@ -509,20 +509,6 @@ struct FileImportView: View {
private func _validate(tournament: Tournament) async { private func _validate(tournament: Tournament) async {
let filteredTeams = filteredTeams(tournament: tournament) let filteredTeams = filteredTeams(tournament: tournament)
let unfound = _getUnfound(tournament: tournament, fromTeams: filteredTeams)
unfound.forEach { team in
if team.isWildCard() == false {
team.resetPositions()
team.walkOut = true
}
}
do {
try tournament.tournamentStore.teamRegistrations.addOrUpdate(contentOfs: unfound)
} catch {
Logger.error(error)
}
tournament.importTeams(filteredTeams) tournament.importTeams(filteredTeams)
validatedTournamentIds.insert(tournament.id) validatedTournamentIds.insert(tournament.id)

@ -81,6 +81,14 @@ struct AddTeamView: View {
fetchRequest = FetchRequest(fetchRequest: request, animation: .default) fetchRequest = FetchRequest(fetchRequest: request, animation: .default)
} }
var selectionLimit: Int {
if tournament.isAnimation() {
return -1
} else {
return tournament.significantPlayerCount() - _currentSelectionIds().count
}
}
var body: some View { var body: some View {
if let pasteString, pasteString.isEmpty == false, fetchPlayers.isEmpty == false { if let pasteString, pasteString.isEmpty == false, fetchPlayers.isEmpty == false {
computedBody computedBody
@ -163,7 +171,7 @@ struct AddTeamView: View {
} }
.sheet(isPresented: $presentPlayerSearch) { .sheet(isPresented: $presentPlayerSearch) {
NavigationStack { NavigationStack {
SelectablePlayerListView(allowSelection: 2 - _currentSelectionIds().count, isPresented: true, searchField: searchField, filterOption: _filterOption(), showFemaleInMaleAssimilation: tournament.tournamentCategory.showFemaleInMaleAssimilation) { players in SelectablePlayerListView(allowSelection: selectionLimit, isPresented: true, searchField: searchField, filterOption: _filterOption(), showFemaleInMaleAssimilation: tournament.tournamentCategory.showFemaleInMaleAssimilation) { players in
players.forEach { player in players.forEach { player in
let newPlayer = PlayerRegistration(importedPlayer: player) let newPlayer = PlayerRegistration(importedPlayer: player)
newPlayer.setComputedRank(in: tournament) newPlayer.setComputedRank(in: tournament)

Loading…
Cancel
Save