multistore
Razmig Sarkissian 1 year ago
parent 4fb8297512
commit ce235319ba
  1. 29
      PadelClub/Data/Tournament.swift
  2. 15
      PadelClub/Views/Match/Components/MatchDateView.swift
  3. 10
      PadelClub/Views/Shared/TournamentFilterView.swift
  4. 147
      PadelClub/Views/Tournament/TournamentBuildView.swift
  5. 2
      PadelClub/Views/Tournament/TournamentView.swift

@ -1346,38 +1346,43 @@ class Tournament : ModelObject, Storable {
return TournamentStatus(label: label, completion: completionLabel)
}
func bracketStatus() async -> String {
func bracketStatus() async -> (status: String, cut: TeamRegistration.TeamRange?) {
let availableSeeds = availableSeeds()
let cut = TeamRegistration.TeamRange(availableSeeds.first, availableSeeds.last)
if availableSeeds.isEmpty == false {
return "placer \(availableSeeds.count) tête\(availableSeeds.count.pluralSuffix) de série"
return ("placer \(availableSeeds.count) tête\(availableSeeds.count.pluralSuffix) de série", cut)
}
let availableQualifiedTeams = availableQualifiedTeams()
if availableQualifiedTeams.isEmpty == false {
return "placer \(availableQualifiedTeams.count) qualifié" + availableQualifiedTeams.count.pluralSuffix
return ("placer \(availableQualifiedTeams.count) qualifié" + availableQualifiedTeams.count.pluralSuffix, cut)
}
if let round = getActiveRound() {
return [round.roundTitle(.short), round.roundStatus()].joined(separator: " ")
return ([round.roundTitle(.short), round.roundStatus()].joined(separator: " "), cut)
} else {
return "à construire"
return ("à construire", nil)
}
}
func groupStageStatus() async -> String {
let groupStageTeamsCount = groupStageTeams().count
func groupStageStatus() async -> (status: String, cut: TeamRegistration.TeamRange?) {
let groupStageTeams = groupStageTeams()
let groupStageTeamsCount = groupStageTeams.count
if groupStageTeamsCount == 0 || groupStageTeamsCount != groupStageSpots() {
return "à faire"
return ("à faire", nil)
}
let cut = TeamRegistration.TeamRange(groupStageTeams.first, groupStageTeams.last)
let runningGroupStages = groupStages().filter({ $0.isRunning() })
if groupStagesAreOver() { return "terminées" }
if groupStagesAreOver() { return ("terminées", cut) }
if runningGroupStages.isEmpty {
let ongoingGroupStages = runningGroupStages.filter({ $0.hasStarted() && $0.hasEnded() == false })
if ongoingGroupStages.isEmpty == false {
return "Poule" + ongoingGroupStages.count.pluralSuffix + " " + ongoingGroupStages.map { ($0.index + 1).formatted() }.joined(separator: ", ") + " en cours"
return ("Poule" + ongoingGroupStages.count.pluralSuffix + " " + ongoingGroupStages.map { ($0.index + 1).formatted() }.joined(separator: ", ") + " en cours", cut)
}
return groupStages().count.formatted() + " poule" + groupStages().count.pluralSuffix
return (groupStages().count.formatted() + " poule" + groupStages().count.pluralSuffix, cut)
} else {
return "Poule" + runningGroupStages.count.pluralSuffix + " " + runningGroupStages.map { ($0.index + 1).formatted() }.joined(separator: ", ") + " en cours"
return ("Poule" + runningGroupStages.count.pluralSuffix + " " + runningGroupStages.map { ($0.index + 1).formatted() }.joined(separator: ", ") + " en cours", cut)
}
}

@ -26,17 +26,28 @@ struct MatchDateView: View {
var body: some View {
Menu {
let estimatedDuration = match.getDuration()
if match.startDate == nil && isReady {
Button("Démarrer") {
match.startDate = Date()
match.confirmed = true
_save()
}
Button("Échauffement") {
Button("Démarrer dans 5 minutes") {
match.startDate = Calendar.current.date(byAdding: .minute, value: 5, to: Date())
match.confirmed = true
_save()
}
Button("Démarrer dans 15 minutes") {
match.startDate = Calendar.current.date(byAdding: .minute, value: 15, to: Date())
match.confirmed = true
_save()
}
Button("Démarrer dans \(estimatedDuration.formatted()) minutes") {
match.startDate = Calendar.current.date(byAdding: .minute, value: estimatedDuration, to: Date())
match.confirmed = true
_save()
}
} else {
if isReady {
Button("Démarrer maintenant") {
@ -46,8 +57,6 @@ struct MatchDateView: View {
_save()
}
} else {
let tournament = match.currentTournament()
let estimatedDuration = tournament != nil ? match.matchFormat.getEstimatedDuration(tournament!.additionalEstimationDuration) : match.matchFormat.getEstimatedDuration()
Button("Décaler de \(estimatedDuration) minutes") {
match.cleanScheduleAndSave(match.startDate?.addingTimeInterval(Double(estimatedDuration) * 60.0))
}

@ -66,7 +66,7 @@ struct TournamentFilterView: View {
}
}
} label: {
Text(level.localizedLabel())
Text(level.localizedLabel(.title))
}
}
} header: {
@ -88,7 +88,7 @@ struct TournamentFilterView: View {
}
}
} label: {
Text(category.localizedLabel())
Text(category.localizedLabel(.title))
}
}
} header: {
@ -110,7 +110,7 @@ struct TournamentFilterView: View {
}
}
} label: {
Text(category.localizedLabel())
Text(category.localizedLabel(.title))
}
}
} header: {
@ -124,6 +124,10 @@ struct TournamentFilterView: View {
federalDataViewModel.removeFilters()
dismiss()
}
} else {
Button("Fermer", role: .cancel) {
dismiss()
}
}
}
ToolbarItem(placement: .topBarTrailing) {

@ -9,8 +9,8 @@ import SwiftUI
struct TournamentBuildView: View {
var tournament: Tournament
@State private var bracketStatus: String?
@State private var groupStageStatus: String?
@State private var bracketStatus: (status: String, cut: TeamRegistration.TeamRange?)?
@State private var groupStageStatus: (String, TeamRegistration.TeamRange?)?
@State private var callStatus: Tournament.TournamentStatus?
@State private var scheduleStatus: Tournament.TournamentStatus?
@State private var cashierStatus: Tournament.TournamentStatus?
@ -19,6 +19,73 @@ struct TournamentBuildView: View {
var body: some View {
let state = tournament.state()
Section {
if tournament.groupStageCount > 0 {
NavigationLink(value: Screen.groupStage) {
LabeledContent {
if let groupStageStatus {
Text(groupStageStatus.0).lineLimit(1)
.multilineTextAlignment(.trailing)
} else {
ProgressView()
}
} label: {
Text("Poules")
if tournament.shouldVerifyGroupStage {
Text("Vérifier les poules").foregroundStyle(.logoRed)
} else if let range = groupStageStatus?.1 {
HStack {
if let left = range.left {
Text(left.weight.formatted())
}
if let right = range.right {
Image(systemName: "arrowshape.forward.fill")
Text(right.weight.formatted())
}
}
}
}
}
.task {
groupStageStatus = await tournament.groupStageStatus()
}
}
if tournament.rounds().isEmpty == false {
NavigationLink(value: Screen.round) {
LabeledContent {
if let bracketStatus {
Text(bracketStatus.0).lineLimit(1)
.multilineTextAlignment(.trailing)
} else {
ProgressView()
}
} label: {
Text("Tableau")
if tournament.shouldVerifyBracket {
Text("Vérifier la tableau").foregroundStyle(.logoRed)
} else if let range = bracketStatus?.1 {
HStack {
if let left = range.left {
Text(left.weight.formatted())
}
if let right = range.right {
Image(systemName: "arrowshape.forward.fill")
Text(right.weight.formatted())
}
}
}
}
}
.task {
bracketStatus = await tournament.bracketStatus()
}
}
}
Section {
if tournament.hasEnded() {
NavigationLink(value: Screen.rankings) {
@ -31,27 +98,6 @@ struct TournamentBuildView: View {
TournamentBroadcastRowView(tournament: tournament)
}
NavigationLink(value: Screen.cashier) {
let tournamentStatus = cashierStatus
LabeledContent {
if let tournamentStatus {
Text(tournamentStatus.completion)
} else {
ProgressView()
}
} label: {
Text("Encaissement")
if let tournamentStatus {
Text(tournamentStatus.label).lineLimit(1)
} else {
Text(" ")
}
}
}
.task {
cashierStatus = await tournament.cashierStatus()
}
if state != .finished {
NavigationLink(value: Screen.schedule) {
let tournamentStatus = scheduleStatus
@ -95,49 +141,26 @@ struct TournamentBuildView: View {
callStatus = await tournament.callStatus()
}
}
}
Section {
if tournament.groupStageCount > 0 {
NavigationLink(value: Screen.groupStage) {
LabeledContent {
if let groupStageStatus {
Text(groupStageStatus).lineLimit(1)
.multilineTextAlignment(.trailing)
} else {
ProgressView()
}
} label: {
Text("Poules")
if tournament.shouldVerifyGroupStage {
Text("Vérifier les poules").foregroundStyle(.logoRed)
}
NavigationLink(value: Screen.cashier) {
let tournamentStatus = cashierStatus
LabeledContent {
if let tournamentStatus {
Text(tournamentStatus.completion)
} else {
ProgressView()
}
}
.task {
groupStageStatus = await tournament.groupStageStatus()
}
}
if tournament.rounds().isEmpty == false {
NavigationLink(value: Screen.round) {
LabeledContent {
if let bracketStatus {
Text(bracketStatus).lineLimit(1)
.multilineTextAlignment(.trailing)
} else {
ProgressView()
}
} label: {
Text("Tableau")
if tournament.shouldVerifyBracket {
Text("Vérifier la tableau").foregroundStyle(.logoRed)
}
} label: {
Text("Encaissement")
if let tournamentStatus {
Text(tournamentStatus.label).lineLimit(1)
} else {
Text(" ")
}
}
.task {
bracketStatus = await tournament.bracketStatus()
}
}
.task {
cashierStatus = await tournament.cashierStatus()
}
}
}

@ -64,8 +64,8 @@ struct TournamentView: View {
Section {
TournamentInscriptionView(tournament: tournament)
}
TournamentInitView(tournament: tournament)
TournamentBuildView(tournament: tournament)
TournamentInitView(tournament: tournament)
case .running:
TournamentBuildView(tournament: tournament)
TournamentRunningView(tournament: tournament)

Loading…
Cancel
Save