fix table structure check when no group stage

add a way to simply contact list of teams depending of confirmed / called status
paca_championship
Raz 1 year ago
parent 6791aed10a
commit af1c53f1b8
  1. 53
      PadelClub/Views/Calling/CallView.swift
  2. 43
      PadelClub/Views/Calling/TeamsCallingView.swift
  3. 19
      PadelClub/Views/Tournament/Screen/TableStructureView.swift

@ -68,6 +68,24 @@ struct CallView: View {
@State var summonParamByMessage: Bool = false @State var summonParamByMessage: Bool = false
@State var summonParamReSummon: Bool = false @State var summonParamReSummon: Bool = false
let simpleMode : Bool
init(teams: [TeamRegistration], callDate: Date, matchFormat: MatchFormat, roundLabel: String) {
self.teams = teams
self.callDate = callDate
self.matchFormat = matchFormat
self.roundLabel = roundLabel
self.simpleMode = false
}
init(teams: [TeamRegistration]) {
self.teams = teams
self.callDate = Date()
self.matchFormat = MatchFormat.nineGames
self.roundLabel = ""
self.simpleMode = true
}
var tournamentStore: TournamentStore { var tournamentStore: TournamentStore {
return self.tournament.tournamentStore return self.tournament.tournamentStore
} }
@ -83,6 +101,9 @@ struct CallView: View {
} }
private func _called(_ calledTeams: [TeamRegistration], _ success: Bool) { private func _called(_ calledTeams: [TeamRegistration], _ success: Bool) {
if simpleMode {
return
}
if success { if success {
calledTeams.forEach { team in calledTeams.forEach { team in
team.callDate = callDate team.callDate = callDate
@ -96,21 +117,41 @@ struct CallView: View {
} }
func finalMessage(reSummon: Bool) -> String { func finalMessage(reSummon: Bool) -> String {
ContactType.callingMessage(tournament: tournament, startDate: callDate, roundLabel: roundLabel, matchFormat: matchFormat, reSummon: reSummon) if simpleMode {
let signature = dataStore.user.summonsMessageSignature ?? dataStore.user.defaultSignature()
return "\n\n\n\n" + signature
}
return ContactType.callingMessage(tournament: tournament, startDate: callDate, roundLabel: roundLabel, matchFormat: matchFormat, reSummon: reSummon)
} }
var reSummon: Bool { var reSummon: Bool {
if simpleMode {
return false
}
return self.teams.allSatisfy({ $0.called() }) return self.teams.allSatisfy({ $0.called() })
} }
var mainWord: String {
if simpleMode {
return "Contacter"
} else {
return "Convoquer"
}
}
var body: some View { var body: some View {
let callWord : String = (reSummon ? "Reconvoquer" : "Convoquer") let callWord : String = (reSummon ? "Reconvoquer" : mainWord)
HStack { HStack {
if self.teams.count == 1 { if self.teams.count == 1 {
if let previousCallDate = teams.first?.callDate, Calendar.current.compare(previousCallDate, to: callDate, toGranularity: .minute) != .orderedSame { if simpleMode {
Text("Reconvoquer \(self.callDate.localizedDate()) par")
} else {
Text("\(callWord) cette paire par") Text("\(callWord) cette paire par")
} else {
if let previousCallDate = teams.first?.callDate, Calendar.current.compare(previousCallDate, to: callDate, toGranularity: .minute) != .orderedSame {
Text("Reconvoquer \(self.callDate.localizedDate()) par")
} else {
Text("\(callWord) cette paire par")
}
} }
} else { } else {
Text("\(callWord) ces \(self.teams.count) paires par") Text("\(callWord) ces \(self.teams.count) paires par")
@ -222,7 +263,7 @@ struct CallView: View {
private func _summonMenu(byMessage: Bool) -> some View { private func _summonMenu(byMessage: Bool) -> some View {
if self.reSummon { if self.reSummon {
Menu { Menu {
Button("Convoquer") { Button(mainWord) {
self._summon(byMessage: byMessage, reSummon: false) self._summon(byMessage: byMessage, reSummon: false)
} }

@ -12,11 +12,22 @@ struct TeamsCallingView: View {
@Environment(Tournament.self) var tournament: Tournament @Environment(Tournament.self) var tournament: Tournament
let teams : [TeamRegistration] let teams : [TeamRegistration]
@State private var hideConfirmed: Bool = false
@State private var hideGoodSummoned: Bool = false
@State private var hideSummoned: Bool = false
@State private var searchText: String = ""
var filteredTeams: [TeamRegistration] { var filteredTeams: [TeamRegistration] {
teams.filter({ searchText.isEmpty || $0.contains(searchText) }) teams
.filter({ hideConfirmed == false || $0.confirmed() == false })
.filter({ hideSummoned == false || $0.called() == false })
.filter({ hideGoodSummoned == false || tournament.isStartDateIsDifferentThanCallDate($0) == true })
.filter({ searchText.isEmpty || $0.contains(searchText) })
} }
@State private var searchText: String = "" var anyFilterEnabled: Bool {
hideConfirmed || hideGoodSummoned || hideSummoned
}
var body: some View { var body: some View {
List { List {
@ -67,14 +78,40 @@ struct TeamsCallingView: View {
.buttonStyle(.plain) .buttonStyle(.plain)
.listRowView(isActive: team.confirmed(), color: .green, hideColorVariation: true) .listRowView(isActive: team.confirmed(), color: .green, hideColorVariation: true)
} }
} header: {
HStack {
Text("Paire\(filteredTeams.count.pluralSuffix)")
Spacer()
Text(filteredTeams.count.formatted())
}
} footer: {
CallView(teams: filteredTeams)
} }
} else { } else {
ContentUnavailableView("Aucune équipe", systemImage: "person.2.slash") ContentUnavailableView("Aucune équipe", systemImage: "person.2.slash")
} }
} }
.toolbar(content: {
ToolbarItem(placement: .topBarTrailing) {
Menu {
Toggle(isOn: $hideConfirmed) {
Text("Masquer les confirmées")
}
Toggle(isOn: $hideSummoned) {
Text("Masquer les convoquées")
}
Toggle(isOn: $hideGoodSummoned) {
Text("Masquer les convoquées à la bonne heure")
}
} label: {
LabelFilter()
.symbolVariant(anyFilterEnabled ? .fill : .none)
}
}
})
.searchable(text: $searchText, placement: .navigationBarDrawer(displayMode: .always)) .searchable(text: $searchText, placement: .navigationBarDrawer(displayMode: .always))
.headerProminence(.increased) .headerProminence(.increased)
.navigationTitle("Statut des équipes") .navigationTitle("Statut des convocations")
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.toolbarBackground(.visible, for: .navigationBar) .toolbarBackground(.visible, for: .navigationBar)
} }

@ -370,6 +370,17 @@ struct TableStructureView: View {
} }
} }
_checkGroupStagesTeams()
do {
try dataStore.tournaments.addOrUpdate(instance: tournament)
} catch {
Logger.error(error)
}
dismiss()
}
private func _checkGroupStagesTeams() {
if groupStageCount == 0 { if groupStageCount == 0 {
let teams = tournament.unsortedTeams().filter({ $0.inGroupStage() }) let teams = tournament.unsortedTeams().filter({ $0.inGroupStage() })
teams.forEach { team in teams.forEach { team in
@ -382,12 +393,6 @@ struct TableStructureView: View {
Logger.error(error) Logger.error(error)
} }
} }
do {
try dataStore.tournaments.addOrUpdate(instance: tournament)
} catch {
Logger.error(error)
}
dismiss()
} }
private func _save(rebuildEverything: Bool = false) { private func _save(rebuildEverything: Bool = false) {
@ -413,6 +418,8 @@ struct TableStructureView: View {
tournament.buildGroupStages() tournament.buildGroupStages()
} }
_checkGroupStagesTeams()
try dataStore.tournaments.addOrUpdate(instance: tournament) try dataStore.tournaments.addOrUpdate(instance: tournament)
dismiss() dismiss()

Loading…
Cancel
Save