multistore
Razmig Sarkissian 1 year ago
parent fd06a0bcc8
commit 7fdfb0aec2
  1. 2
      PadelClub/Data/TeamRegistration.swift
  2. 17
      PadelClub/ViewModel/SearchViewModel.swift
  3. 2
      PadelClub/Views/Calling/Components/MenuWarningView.swift
  4. 13
      PadelClub/Views/Navigation/Agenda/CalendarView.swift
  5. 3
      PadelClub/Views/Shared/SelectablePlayerListView.swift
  6. 25
      PadelClub/Views/Tournament/Screen/Components/TournamentStatusView.swift
  7. 12
      PadelClub/Views/Tournament/Shared/TournamentCellView.swift
  8. 5
      PadelClub/Views/Tournament/TournamentView.swift

@ -19,7 +19,7 @@ class TeamRegistration: ModelObject, Storable {
var registrationDate: Date?
var callDate: Date?
var bracketPosition: Int?
var groupStagePosition: Int? //todo devrait être non nil ?
var groupStagePosition: Int?
var comment: String?
var source: String?
var sourceValue: String?

@ -10,7 +10,6 @@ import SwiftUI
class SearchViewModel: ObservableObject, Identifiable {
let id: UUID = UUID()
var allowSelection : Int = 0
var user: User? = nil
var codeClub: String? = nil
var clubName: String? = nil
var ligueName: String? = nil
@ -74,13 +73,13 @@ class SearchViewModel: ObservableObject, Identifiable {
func getCodeClub() -> String? {
if let codeClub { return codeClub }
// if let userCodeClub = user?.player?.codeClub { return userCodeClub }
if let userCodeClub = DataStore.shared.user.currentPlayerData()?.clubCode { return userCodeClub }
return nil
}
func getClubName() -> String? {
if let clubName { return clubName }
// if let userClubName = user?.player?.clubName { return userClubName }
func getLigueName() -> String? {
if let ligueName { return ligueName }
if let userLigueName = DataStore.shared.user.currentPlayerData()?.ligueName { return userLigueName }
return nil
}
@ -217,13 +216,13 @@ class SearchViewModel: ObservableObject, Identifiable {
case .national:
break
case .ligue:
if let ligueName {
if let ligueName = getLigueName() {
predicates.append(NSPredicate(format: "ligueName == %@", ligueName))
} else {
predicates.append(NSPredicate(format: "ligueName == nil"))
}
case .club:
if let codeClub {
if let codeClub = getCodeClub() {
predicates.append(NSPredicate(format: "clubCode == %@", codeClub))
} else {
predicates.append(NSPredicate(format: "clubCode == nil"))
@ -352,13 +351,15 @@ enum SearchToken: String, CaseIterable, Identifiable {
}
}
enum DataSet: Int, CaseIterable, Identifiable {
enum DataSet: Int, Identifiable {
case national
case ligue
case club
case favoriteClubs
case favoritePlayers
static let allCases : [DataSet] = [.national, .ligue, .club, .favoriteClubs]
var id: Int { rawValue }
func localizedLabel(_ displayStyle: DisplayStyle = .wide) -> String {
switch self {

@ -37,7 +37,7 @@ struct MenuWarningView: View {
var body: some View {
Menu {
if let team = teams.first {
if let team = teams.first, teams.count == 1 {
_teamActionView(team)
} else {
Menu("Tout le monde") {

@ -1,14 +1,9 @@
//
// Created for Custom Calendar
// by Stewart Lynch on 2024-01-22
// CalendarView.swift
// PadelClub
//
// Created by Razmig Sarkissian on 01/03/2024.
//
// Follow me on Mastodon: @StewartLynch@iosdev.space
// Follow me on Threads: @StewartLynch (https://www.threads.net)
// Follow me on X: https://x.com/StewartLynch
// Follow me on LinkedIn: https://linkedin.com/in/StewartLynch
// Subscribe on YouTube: https://youTube.com/@StewartLynch
// Buy me a ko-fi: https://ko-fi.com/StewartLynch
import SwiftUI

@ -34,7 +34,7 @@ struct SelectablePlayerListView: View {
return URL.importDateFormatter.date(from: lastDataSource)
}
init(allowSelection: Int = 0, searchField: String? = nil, user: User? = nil, dataSet: DataSet = .national, filterOption: PlayerFilterOption = .all, hideAssimilation: Bool = false, ascending: Bool = true, sortOption: SortOption = .rank, fromPlayer: FederalPlayer? = nil, codeClub: String? = nil, ligue: String? = nil, showFemaleInMaleAssimilation: Bool = false, tokens: [SearchToken] = [], hidePlayers: [String]? = nil, playerSelectionAction: PlayerSelectionAction? = nil, contentUnavailableAction: ContentUnavailableAction? = nil) {
init(allowSelection: Int = 0, searchField: String? = nil, dataSet: DataSet = .national, filterOption: PlayerFilterOption = .all, hideAssimilation: Bool = false, ascending: Bool = true, sortOption: SortOption = .rank, fromPlayer: FederalPlayer? = nil, codeClub: String? = nil, ligue: String? = nil, showFemaleInMaleAssimilation: Bool = false, tokens: [SearchToken] = [], hidePlayers: [String]? = nil, playerSelectionAction: PlayerSelectionAction? = nil, contentUnavailableAction: ContentUnavailableAction? = nil) {
self.allowSelection = allowSelection
self.playerSelectionAction = playerSelectionAction
self.contentUnavailableAction = contentUnavailableAction
@ -46,7 +46,6 @@ struct SelectablePlayerListView: View {
searchViewModel.showFemaleInMaleAssimilation = showFemaleInMaleAssimilation
searchViewModel.searchText = searchField ?? ""
searchViewModel.isPresented = allowSelection != 0
searchViewModel.user = user
searchViewModel.allowSelection = allowSelection
searchViewModel.codeClub = fromPlayer?.clubCode ?? codeClub
searchViewModel.clubName = nil

@ -35,7 +35,11 @@ struct TournamentStatusView: View {
}
}
} footer: {
Text("todo: expliquer ce que ca fait")
if tournament.endDate == nil {
Text("Indique une date de fin pour le tournoi. Il sera considéré terminé.")
} else {
Text("Retire la date de fin du tournoi. Il sera considéré en cours.")
}
}
Section {
@ -48,23 +52,36 @@ struct TournamentStatusView: View {
}
} else {
tournament.endDate = Date()
tournament.isDeleted.toggle()
tournament.isDeleted = true
tournament.navigationPath.removeAll()
do {
try dataStore.tournaments.addOrUpdate(instance: tournament)
} catch {
Logger.error(error)
}
}
navigation.path = NavigationPath()
}
} footer: {
Text("todo: expliquer ce que ca fait")
if tournament.payment == nil {
Text("")
}
}
if tournament.hasEnded() == false && tournament.isCanceled == false {
Section {
RowButtonView("Annuler le tournoi", role: .destructive) {
tournament.endDate = Date()
tournament.isCanceled = true
do {
try dataStore.tournaments.addOrUpdate(instance: tournament)
} catch {
Logger.error(error)
}
dismiss()
}
} footer: {
Text("todo: expliquer ce que ca fait")
Text(.init("Si votre tournoi n'a pas pu aboutir à cause de la météo ou autre, vous pouvez l'annuler et il ne sera pas comptabilisé. Toutes les données du tournoi seront conservées. Le tournoi visible sur [Padel Club](\(URLs.main)"))
}
}

@ -70,9 +70,13 @@ struct TournamentCellView: View {
}
Spacer()
if let tournament = tournament as? Tournament, displayStyle == .wide {
let hasStarted = tournament.inscriptionClosed() || tournament.hasStarted()
let count = hasStarted ? tournament.selectedSortedTeams().count : tournament.unsortedTeamsWithoutWO().count
Text(count.formatted())
if tournament.isCanceled {
Text("Annulé").foregroundStyle(.logoRed)
} else {
let hasStarted = tournament.inscriptionClosed() || tournament.hasStarted()
let count = hasStarted ? tournament.selectedSortedTeams().count : tournament.unsortedTeamsWithoutWO().count
Text(count.formatted())
}
} else if let federalTournament = tournament as? FederalTournament {
Button {
_createOrShow(federalTournament: federalTournament, existingTournament: existingTournament, build: build)
@ -91,7 +95,7 @@ struct TournamentCellView: View {
HStack {
Text(tournament.durationLabel())
Spacer()
if let tournament = tournament as? Tournament {
if let tournament = tournament as? Tournament, tournament.isCanceled == false {
let hasStarted = tournament.inscriptionClosed() || tournament.hasStarted()
let word = hasStarted ? "équipes" : "inscriptions"
Text(word)

@ -51,10 +51,9 @@ struct TournamentView: View {
Section {
RowButtonView("Reprendre le tournoi", role: .destructive) {
tournament.isCanceled = false
tournament.endDate = nil
_save()
}
} footer: {
Text("todo expliquer cet état")
}
case .initial:
TournamentInscriptionView(tournament: tournament)
@ -131,7 +130,7 @@ struct TournamentView: View {
}
}
if presentationContext == .agenda || tournament.state() == .running {
if (presentationContext == .agenda || tournament.state() == .running) && tournament.isCanceled == false {
ToolbarItem(placement: .topBarTrailing) {
Menu {
if presentationContext == .agenda {

Loading…
Cancel
Save