small fixes

add deadlines access
sync3
Raz 7 months ago
parent a8a7a5ac3d
commit 901cd4e672
  1. 17
      PadelClub/Data/Tournament.swift
  2. 66
      PadelClub/Utils/PadelRule.swift
  3. 2
      PadelClub/ViewModel/FederalDataViewModel.swift
  4. 2
      PadelClub/Views/Cashier/Event/TournamentConfiguratorView.swift
  5. 4
      PadelClub/Views/Navigation/Agenda/TournamentLookUpView.swift
  6. 4
      PadelClub/Views/Player/Components/PlayerPopoverView.swift
  7. 2
      PadelClub/Views/Shared/TournamentFilterView.swift
  8. 6
      PadelClub/Views/Tournament/Screen/AddTeamView.swift
  9. 8
      PadelClub/Views/Tournament/Screen/Components/TournamentGeneralSettingsView.swift
  10. 2
      PadelClub/Views/Tournament/Screen/Components/TournamentLevelPickerView.swift
  11. 15
      PadelClub/Views/Tournament/Shared/TournamentCellView.swift
  12. 22
      PadelClub/Views/Tournament/TournamentView.swift

@ -1304,9 +1304,9 @@ defer {
}
}
let displayStyleCategory = hideSenior ? .short : displayStyle
var levelCategory = [tournamentLevel.localizedLevelLabel(displayStyle), tournamentCategory.localizedLabel(displayStyle)]
var levelCategory = [tournamentLevel.localizedLevelLabel(displayStyle), tournamentCategory.localizedCategoryLabel(displayStyle, ageCategory: federalAgeCategory)]
if displayStyle == .short {
levelCategory = [tournamentLevel.localizedLevelLabel(displayStyle) + tournamentCategory.localizedLabel(displayStyle)]
levelCategory = [tournamentLevel.localizedLevelLabel(displayStyle) + tournamentCategory.localizedCategoryLabel(displayStyle, ageCategory: federalAgeCategory)]
}
let array = levelCategory + [federalTournamentAge.localizedFederalAgeLabel(displayStyleCategory)]
let title: String = array.filter({ $0.isEmpty == false }).joined(separator: " ")
@ -1322,7 +1322,7 @@ defer {
case .unlisted, .championship:
return tournamentLevel.localizedLevelLabel(.short)
default:
return tournamentLevel.localizedLevelLabel(.short) + tournamentCategory.localizedLabel(.short)
return tournamentLevel.localizedLevelLabel(.short) + tournamentCategory.localizedCategoryLabel(.short, ageCategory: federalAgeCategory)
}
}
@ -2370,6 +2370,15 @@ defer {
// MARK: - Status
func shouldTournamentBeOver() async -> Bool {
if hasEnded() {
return true
}
if hasStarted() == false {
return false
}
if hasStarted(), self.startDate.timeIntervalSinceNow > -3600*24 {
return false
}
if tournamentStore?.store.fileCollectionsAllLoaded() == false {
return false
}
@ -2569,7 +2578,7 @@ extension Tournament: FederalTournamentHolder {
func subtitleLabel(forBuild build: any TournamentBuildHolder) -> String {
if isAnimation() {
if displayAgeAndCategory(forBuild: build) == false {
return [build.category.localizedLabel(), build.age.localizedFederalAgeLabel()].filter({ $0.isEmpty == false }).joined(separator: " ")
return [build.category.localizedCategoryLabel(ageCategory: build.age), build.age.localizedFederalAgeLabel()].filter({ $0.isEmpty == false }).joined(separator: " ")
} else if name != nil {
return build.level.localizedLevelLabel(.title)
} else {

@ -48,7 +48,7 @@ struct TournamentBuild: TournamentBuildHolder, Hashable, Codable, Identifiable {
}
var identifier: String {
level.localizedLevelLabel()+":"+category.localizedLabel()+":"+age.localizedFederalAgeLabel()
level.localizedLevelLabel()+":"+category.localizedCategoryLabel(ageCategory: age)+":"+age.localizedFederalAgeLabel()
}
func computedLabel(_ displayStyle: DisplayStyle = .wide) -> String {
@ -57,11 +57,11 @@ struct TournamentBuild: TournamentBuildHolder, Hashable, Codable, Identifiable {
}
func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String {
level.localizedLevelLabel(displayStyle) + " " + category.localizedLabel(displayStyle)
level.localizedLevelLabel(displayStyle) + " " + category.localizedCategoryLabel(displayStyle, ageCategory: age)
}
func localizedTitle(_ displayStyle: DisplayStyle = .wide) -> String {
level.localizedLevelLabel(displayStyle) + " " + category.localizedLabel(displayStyle)
level.localizedLevelLabel(displayStyle) + " " + category.localizedCategoryLabel(displayStyle, ageCategory: age)
}
func localizedAge(_ displayStyle: DisplayStyle = .wide) -> String {
@ -257,13 +257,13 @@ enum FederalTournamentAge: Int, Hashable, Codable, CaseIterable, Identifiable {
case .unlisted:
return displayStyle == .title ? "Aucune" : ""
case .a11_12:
return "11/12 ans"
return "U12"
case .a13_14:
return "13/14 ans"
return "U14"
case .a15_16:
return "15/16 ans"
return "U16"
case .a17_18:
return "17/18 ans"
return "U18"
case .senior:
return displayStyle == .short ? "" : "Senior"
case .a45:
@ -298,6 +298,27 @@ enum FederalTournamentAge: Int, Hashable, Codable, CaseIterable, Identifiable {
return age >= 55
}
}
func isChildCategory() -> Bool {
switch self {
case .unlisted:
return false
case .a11_12:
return true
case .a13_14:
return true
case .a15_16:
return true
case .a17_18:
return true
case .senior:
return false
case .a45:
return false
case .a55:
return false
}
}
}
enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
@ -395,6 +416,15 @@ enum TournamentLevel: Int, Hashable, Codable, CaseIterable, Identifiable {
}
}
func haveDeadlines() -> Bool {
switch self {
case .p500, .p1000, .p1500, .p2000:
return true
default:
return false
}
}
func minimumPlayerRank(category: TournamentCategory, ageCategory: FederalTournamentAge) -> Int {
switch self {
case .p25:
@ -909,26 +939,46 @@ enum TournamentCategory: Int, Hashable, Codable, CaseIterable, Identifiable {
}
}
func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String {
func localizedCategoryLabel(_ displayStyle: DisplayStyle = .wide, ageCategory: FederalTournamentAge? = nil) -> String {
switch self {
case .unlisted:
return displayStyle == .title ? "Aucune" : ""
case .men:
switch displayStyle {
case .title:
if ageCategory?.isChildCategory() == true {
return "Garçons"
}
return "Hommes"
case .wide:
if ageCategory?.isChildCategory() == true {
return "Garçons"
}
return "Hommes"
case .short:
if ageCategory?.isChildCategory() == true {
return "G"
}
return "H"
}
case .women:
switch displayStyle {
case .title:
if ageCategory?.isChildCategory() == true {
return "Filles"
}
return "Dames"
case .wide:
if ageCategory?.isChildCategory() == true {
return "Filles"
}
return "Dames"
case .short:
if ageCategory?.isChildCategory() == true {
return "F"
}
return "D"
}
case .mix:

@ -27,7 +27,7 @@ class FederalDataViewModel {
func filterStatus() -> String {
var labels: [String] = []
labels.append(contentsOf: levels.map { $0.localizedLevelLabel() }.formatList())
labels.append(contentsOf: categories.map { $0.localizedLabel() }.formatList())
labels.append(contentsOf: categories.map { $0.localizedCategoryLabel() }.formatList())
labels.append(contentsOf: ageCategories.map { $0.localizedFederalAgeLabel() }.formatList())
let clubNames = selectedClubs.compactMap { codeClub in
let club: Club? = DataStore.shared.clubs.first(where: { $0.code == codeClub })

@ -41,7 +41,7 @@ struct TournamentConfigurationView: View {
}
Picker(selection: $tournament.federalCategory, label: Text("Catégorie")) {
ForEach(TournamentCategory.allCases) { type in
Text(type.localizedLabel(.title)).tag(type)
Text(type.localizedCategoryLabel(.title, ageCategory: tournament.federalAgeCategory)).tag(type)
}
}
Picker(selection: $tournament.federalAgeCategory, label: Text("Limite d'âge")) {

@ -371,7 +371,7 @@ struct TournamentLookUpView: View {
NavigationLink {
List([TournamentCategory.men, TournamentCategory.women, TournamentCategory.mix], selection: $appSettings.tournamentCategories) { type in
Text(type.localizedLabel())
Text(type.localizedCategoryLabel())
}
.navigationTitle("Catégories")
.environment(\.editMode, Binding.constant(EditMode.active))
@ -456,7 +456,7 @@ struct TournamentLookUpView: View {
if dataStore.appSettings.tournamentCategories.isEmpty || dataStore.appSettings.tournamentCategories.count == TournamentCategory.allCases.count {
Text("Toutes les catégories")
} else {
Text(categories.map({ $0.localizedLabel() }).joined(separator: ", "))
Text(categories.map({ $0.localizedCategoryLabel() }).joined(separator: ", "))
}
}

@ -125,11 +125,11 @@ struct PlayerPopoverView: View {
TextField("Licence", text: $license)
.focused($licenseIsFocused)
.textInputAutocapitalization(.never)
.keyboardType(.numberPad)
.keyboardType(.alphabet)
.submitLabel(.next)
.onSubmit {
license = license.trimmedMultiline
if requiredField.contains(.license) {
if license.isEmpty == false {
if license.isLicenseNumber {
amountIsFocused = true
} else {

@ -85,7 +85,7 @@ struct TournamentFilterView: View {
}
}
} label: {
Text(category.localizedLabel(.wide))
Text(category.localizedCategoryLabel(.wide))
}
}
} header: {

@ -179,6 +179,12 @@ struct AddTeamView: View {
createdPlayerIds.insert(newPlayer.id)
}
} contentUnavailableAction: { searchViewModel in
searchViewModel.selectedPlayers.forEach { player in
let newPlayer = PlayerRegistration(importedPlayer: player)
newPlayer.setComputedRank(in: tournament)
createdPlayers.insert(newPlayer)
createdPlayerIds.insert(newPlayer.id)
}
presentPlayerSearch = false
selectionSearchField = searchViewModel.searchText
}

@ -46,6 +46,14 @@ struct TournamentGeneralSettingsView: View {
.multilineTextAlignment(.trailing)
.frame(maxWidth: .infinity)
.focused($focusedField, equals: ._entryFee)
.onChange(of: focusedField) {
if focusedField == ._entryFee {
DispatchQueue.main.async {
UIApplication.shared.sendAction(#selector(UIResponder.selectAll(_:)), to: nil, from: nil, for: nil)
}
}
}
} label: {
Text("Inscription")
}

@ -36,7 +36,7 @@ struct TournamentLevelPickerView: View {
Picker(selection: $tournament.tournamentCategory, label: Text("Catégorie")) {
ForEach(TournamentCategory.allCases) { type in
Text(type.localizedLabel(.title)).tag(type)
Text(type.localizedCategoryLabel(.title, ageCategory: tournament.federalAgeCategory)).tag(type)
}
}

@ -97,6 +97,10 @@ struct TournamentCellView: View {
}
}
}
.task(priority: .background) {
self.shouldTournamentBeOver = await tournament.shouldTournamentBeOver()
}
.id(tournament.lastTeamRefresh)
} else {
Text(tournament.clubLabel()).lineLimit(1)
.font(.caption)
@ -108,7 +112,7 @@ struct TournamentCellView: View {
.truncationMode(.tail)
if displayStyle == .wide, tournament.displayAgeAndCategory(forBuild: build) {
VStack(alignment: .leading, spacing: 0) {
Text(build.category.localizedLabel())
Text(build.category.localizedCategoryLabel(ageCategory: build.age))
Text(build.age.localizedFederalAgeLabel())
}
.font(.caption)
@ -120,7 +124,7 @@ struct TournamentCellView: View {
} else if tournament.isCanceled {
Text("Annulé".uppercased())
.capsule(foreground: .white, background: .logoRed)
} else if shouldTournamentBeOver {
} else if shouldTournamentBeOver, tournament.hasEnded() == false {
Image(systemName: "clock.badge.questionmark").foregroundStyle(.logoRed)
} else if let teamCount {
Text(teamCount.formatted())
@ -154,16 +158,13 @@ struct TournamentCellView: View {
Spacer()
if let tournament = tournament as? Tournament, tournament.isCanceled == false {
VStack(alignment: .trailing) {
if shouldTournamentBeOver {
if shouldTournamentBeOver, tournament.hasEnded() == false {
Text("à clôturer ?")
.foregroundStyle(.logoRed)
} else if let teamCount {
let hasStarted = tournament.inscriptionClosed() || tournament.hasStarted()
let word = hasStarted ? "équipe" : "inscription"
Text(word + teamCount.pluralSuffix)
.task(priority: .background) {
self.shouldTournamentBeOver = await tournament.shouldTournamentBeOver()
}
}
let value: Int = tournament.onlineTeams().count
if value > 0 {
@ -173,7 +174,7 @@ struct TournamentCellView: View {
}
}
} else {
Text(build.category.localizedLabel())
Text(build.category.localizedCategoryLabel(ageCategory: build.age))
Text(build.age.localizedFederalAgeLabel())
}
}

@ -211,8 +211,8 @@ struct TournamentView: View {
if tournament.isCanceled == false {
ToolbarItem(placement: .topBarTrailing) {
Menu {
#if DEBUG
#if DEBUG
Button {
do {
try self.tournament.payIfNecessary()
@ -222,8 +222,8 @@ struct TournamentView: View {
} label: {
Label("Payer le tournoi", systemImage: "dollarsign.circle.fill")
}
#endif
#endif
if presentationContext == .agenda {
Button {
navigation.openTournamentInOrganizer(tournament)
@ -232,7 +232,7 @@ struct TournamentView: View {
}
Divider()
}
NavigationLink(value: Screen.event) {
Text("Réglages de l'événement")
}
@ -244,6 +244,18 @@ struct TournamentView: View {
Text("Convocations")
}
if tournament.tournamentLevel.haveDeadlines() {
NavigationLink {
List {
TournamentDeadlinesView(tournament: tournament)
}
.toolbarBackground(.visible, for: .navigationBar)
.navigationTitle("Rappel des délais")
} label: {
Text("Rappel des délais")
}
}
NavigationLink(value: Screen.structure) {
LabelStructure()
}

Loading…
Cancel
Save