fix user player profile detection

add championship points ranking assimiliation selection
sync_v2
Raz 7 months ago
parent ff66c524d3
commit 5e5c768843
  1. 2
      PadelClub/Data/CustomUser.swift
  2. 6
      PadelClub/Data/Tournament.swift
  3. 35
      PadelClub/Utils/PadelRule.swift
  4. 14
      PadelClub/Views/Tournament/Screen/TournamentRankView.swift

@ -78,7 +78,7 @@ class CustomUser: BaseCustomUser, UserBase {
}
func currentPlayerData() -> ImportedPlayer? {
guard let licenceId else { return nil }
guard let licenceId = self.licenceId?.strippedLicense else { return nil }
let federalContext = PersistenceController.shared.localContainer.viewContext
let fetchRequest = ImportedPlayer.fetchRequest()
let predicate = NSPredicate(format: "license == %@", licenceId)

@ -1190,9 +1190,9 @@ defer {
return teams
}
func setRankings(finalRanks: [Int: [String]]) async -> [Int: [TeamRegistration]] {
func setRankings(assimilationLevel: TournamentLevel? = nil, finalRanks: [Int: [String]]) async -> [Int: [TeamRegistration]] {
guard let tournamentStore = self.tournamentStore else { return [:] }
let tournamentLevel = assimilationLevel ?? tournamentLevel
var rankings: [Int: [TeamRegistration]] = [:]
finalRanks.keys.sorted().forEach { rank in
@ -1383,7 +1383,7 @@ defer {
}
func isAnimation() -> Bool {
federalLevelCategory == .unlisted
federalLevelCategory.isAnimation()
}
func subtitle(_ displayStyle: DisplayStyle = .wide) -> String {

@ -309,15 +309,20 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
case p1000 = 1000
case p1500 = 1500
case p2000 = 2000
case championship = 1
init?(rawValue: Int?) {
guard let value = rawValue else { return nil }
self.init(rawValue: value)
}
static var assimilationAllCases: [TournamentLevel] {
return [.p25, .p100, .p250, .p500, .p1000, .p1500, .p2000]
}
var entryFee: Double? {
switch self {
case .unlisted:
case .unlisted, .championship:
return nil
case .p25:
return 15
@ -325,6 +330,18 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
return 20
}
}
func isAnimation() -> Bool {
switch self {
case .unlisted:
return true
case .championship:
return false
default:
return false
}
}
func searchRawValue() -> String {
String(describing: self)
}
@ -503,6 +520,8 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
return 1
case .p2000:
return 0
case .championship:
return 8
}
}
@ -514,6 +533,14 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
return displayStyle == .title ? "Animation" : "Anim."
}
}
if self == .championship {
if DeviceHelper.isBigScreen() {
return "Championnat"
} else {
return displayStyle == .title ? "Championnat" : "CHPT"
}
}
return String(describing: self).capitalized
}
@ -544,7 +571,7 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
func points(for count: Int) -> [Int] {
switch self {
case .unlisted:
case .unlisted, .championship:
return []
case .p25:
switch count {
@ -682,7 +709,7 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
//
func minimumFormatFinalTableAndQualifier(roundIndex: Int) -> MatchFormat? {
switch self {
case .p25, .unlisted:
case .p25, .unlisted, .championship:
return nil
case .p100:
return .nineGamesDecisivePoint
@ -711,7 +738,7 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
func minimumFormatLoserBracket(roundIndex: Int) -> MatchFormat? {
switch self {
case .p25, .unlisted:
case .p25, .unlisted, .championship:
return nil
case .p100, .p250, .p500:
return .nineGamesDecisivePoint

@ -16,6 +16,7 @@ struct TournamentRankView: View {
@State private var rankings: [Int: [TeamRegistration]] = [:]
@State private var calculating = false
@State private var selectedTeam: TeamRegistration?
@State private var assimilationSelection: TournamentLevel?
var tournamentStore: TournamentStore? {
return self.tournament.tournamentStore
@ -60,6 +61,17 @@ struct TournamentRankView: View {
}
}
if tournament.level == .championship {
Picker(selection: $assimilationSelection) {
Text("Aucune").tag(nil as TournamentLevel?)
ForEach(TournamentLevel.assimilationAllCases) {
Text($0.localizedLevelLabel()).tag($0)
}
} label: {
Text("Assimilation")
}
}
//affiche l'onglet sur le site, car sur le broadcast c'est dispo automatiquement de toute façon
Toggle(isOn: $tournament.publishRankings) {
if calculating {
@ -337,7 +349,7 @@ struct TournamentRankView: View {
self.rankings.removeAll()
let finalRanks = await tournament.finalRanking()
self.rankings = await tournament.setRankings(finalRanks: finalRanks)
self.rankings = await tournament.setRankings(assimilationLevel: assimilationSelection, finalRanks: finalRanks)
calculating = false
}

Loading…
Cancel
Save