online_reg
Raz 10 months ago
parent b92e5cec63
commit 945f9ddf29
  1. 5
      PadelClub/Data/TeamRegistration.swift
  2. 68
      PadelClub/Views/Team/EditingTeamView.swift
  3. 110
      PadelClub/Views/Tournament/Screen/InscriptionManagerView.swift

@ -43,6 +43,11 @@ final class TeamRegistration: ModelObject, Storable {
players().anySatisfy({ $0.source == .onlineRegistration }) players().anySatisfy({ $0.source == .onlineRegistration })
} }
func unrankedOrUnknown() -> Bool {
players().anySatisfy({ $0.source == nil })
}
func isOutOfTournament() -> Bool { func isOutOfTournament() -> Bool {
walkOut walkOut
} }

@ -22,6 +22,8 @@ struct EditingTeamView: View {
@State private var registrationDate : Date @State private var registrationDate : Date
@State private var name: String @State private var name: String
@FocusState private var focusedField: TeamRegistration.CodingKeys? @FocusState private var focusedField: TeamRegistration.CodingKeys?
@State private var presentOnlineRegistrationWarning: Bool = false
@State private var currentWaitingList: TeamRegistration?
var messageSentFailed: Binding<Bool> { var messageSentFailed: Binding<Bool> {
Binding { Binding {
@ -43,6 +45,22 @@ struct EditingTeamView: View {
_registrationDate = State(wrappedValue: team.registrationDate ?? Date()) _registrationDate = State(wrappedValue: team.registrationDate ?? Date())
} }
private func _resetTeam() {
self.currentWaitingList = tournament.waitingListSortedTeams().filter({ $0.hasRegisteredOnline() }).first
team.resetPositions()
team.wildCardGroupStage = false
team.walkOut = false
team.wildCardBracket = false
}
private func _checkOnlineRegistrationWarning() {
guard let currentWaitingList else { return }
let selectedSortedTeams = tournament.selectedSortedTeams().map({ $0.id })
if selectedSortedTeams.contains(currentWaitingList.id) {
presentOnlineRegistrationWarning = true
}
}
var body: some View { var body: some View {
List { List {
Section { Section {
@ -101,15 +119,9 @@ struct EditingTeamView: View {
Toggle(isOn: .init(get: { Toggle(isOn: .init(get: {
return team.wildCardBracket return team.wildCardBracket
}, set: { value in }, set: { value in
team.resetPositions() _resetTeam()
team.wildCardGroupStage = false
team.walkOut = false
team.wildCardBracket = value team.wildCardBracket = value
do { _save()
try tournamentStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
})) { })) {
Text("Wildcard Tableau") Text("Wildcard Tableau")
} }
@ -117,15 +129,9 @@ struct EditingTeamView: View {
Toggle(isOn: .init(get: { Toggle(isOn: .init(get: {
return team.wildCardGroupStage return team.wildCardGroupStage
}, set: { value in }, set: { value in
team.resetPositions() _resetTeam()
team.wildCardBracket = false
team.walkOut = false
team.wildCardGroupStage = value team.wildCardGroupStage = value
do { _save()
try tournamentStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
})) { })) {
Text("Wildcard Poule") Text("Wildcard Poule")
} }
@ -133,15 +139,9 @@ struct EditingTeamView: View {
Toggle(isOn: .init(get: { Toggle(isOn: .init(get: {
return team.walkOut return team.walkOut
}, set: { value in }, set: { value in
team.resetPositions() _resetTeam()
team.wildCardBracket = false
team.wildCardGroupStage = false
team.walkOut = value team.walkOut = value
do { _save()
try tournamentStore.teamRegistrations.addOrUpdate(instance: team)
} catch {
Logger.error(error)
}
})) { })) {
Text("Forfait") Text("Forfait")
} }
@ -199,12 +199,9 @@ struct EditingTeamView: View {
Section { Section {
RowButtonView("Effacer l'équipe", role: .destructive, systemImage: "trash") { RowButtonView("Effacer l'équipe", role: .destructive, systemImage: "trash") {
_resetTeam()
team.deleteTeamScores() team.deleteTeamScores()
do { _save()
try tournamentStore.teamRegistrations.delete(instance: team)
} catch {
Logger.error(error)
}
dismiss() dismiss()
} }
} footer: { } footer: {
@ -213,6 +210,19 @@ struct EditingTeamView: View {
} }
} }
} }
.alert("Attention", isPresented: $presentOnlineRegistrationWarning, actions: {
if let currentWaitingList {
Button("Prévenir") {
}
Button("OK") {
self.currentWaitingList = nil
}
}
}, message: {
Text("Cette équipe, inscrite en ligne, rentre dans votre sélection suite à la modification que vous venez de faire, voulez-vous les prévenir ?")
})
.navigationBarBackButtonHidden(focusedField != nil) .navigationBarBackButtonHidden(focusedField != nil)
.toolbar(content: { .toolbar(content: {
if focusedField != nil { if focusedField != nil {

@ -53,11 +53,87 @@ struct InscriptionManagerView: View {
@State private var refreshResult: String? = nil @State private var refreshResult: String? = nil
@State private var refreshInProgress: Bool = false @State private var refreshInProgress: Bool = false
@State private var refreshStatus: Bool? @State private var refreshStatus: Bool?
@State private var showLegendView: Bool = false
var tournamentStore: TournamentStore { var tournamentStore: TournamentStore {
return self.tournament.tournamentStore return self.tournament.tournamentStore
} }
enum LegendPositionTip: Int, Identifiable, CaseIterable {
var id: Int { self.rawValue }
case groupStage
case bracket
func legendDescriptionLabel() -> String {
return ""
}
var isActive: Bool {
switch self {
case .groupStage:
return true
case .bracket:
return true
}
}
var color: Color {
switch self {
case .groupStage:
return .red
case .bracket:
return .green
}
}
var hideColorVariation: Bool {
switch self {
case .groupStage:
return true
case .bracket:
return true
}
}
}
enum LegendInscriptionTip: Int, Identifiable, CaseIterable {
var id: Int { self.rawValue }
case groupStage
case bracket
func legendDescriptionLabel() -> String {
return ""
}
var isActive: Bool {
switch self {
case .groupStage:
return true
case .bracket:
return true
}
}
var color: Color {
switch self {
case .groupStage:
return .red
case .bracket:
return .green
}
}
var hideColorVariation: Bool {
switch self {
case .groupStage:
return true
case .bracket:
return true
}
}
}
enum SortingMode: Int, Identifiable, CaseIterable { enum SortingMode: Int, Identifiable, CaseIterable {
var id: Int { self.rawValue } var id: Int { self.rawValue }
case registrationDate case registrationDate
@ -592,6 +668,8 @@ struct InscriptionManagerView: View {
} }
} }
let isImported = teams.anySatisfy({ $0.isImported() })
if teams.isEmpty == false { if teams.isEmpty == false {
if compactMode { if compactMode {
Section { Section {
@ -602,13 +680,19 @@ struct InscriptionManagerView: View {
.environment(tournament) .environment(tournament)
} label: { } label: {
TeamRowView(team: team) TeamRowView(team: team)
if isImported && team.isImported() == false {
Text("ne provient pas du fichier beach-padel").foregroundStyle(.red)
}
} }
.swipeActions(edge: .trailing, allowsFullSwipe: true) { .swipeActions(edge: .trailing, allowsFullSwipe: true) {
if tournament.enableOnlineRegistration == false { if tournament.enableOnlineRegistration == false {
_teamDeleteButtonView(team) _teamDeleteButtonView(team)
} }
} }
.listRowView(isActive: true, color: team.initialRoundColor() ?? tournament.cutLabelColor(index: teamIndex, teamCount: filterMode == .waiting ? 0 : selectedSortedTeams.count), hideColorVariation: true) .listRowView(isActive: team.hasRegisteredOnline(), color: .master, hideColorVariation: true)
.listRowView(isActive: team.unrankedOrUnknown(), color: .logoYellow, hideColorVariation: true)
.listRowView(isActive: isImported && team.isImported() == false, color: .red, hideColorVariation: false)
.listRowView(isActive: true, color: team.initialRoundColor() ?? tournament.cutLabelColor(index: teamIndex, teamCount: filterMode == .waiting ? 0 : selectedSortedTeams.count), hideColorVariation: true, alignment: .trailing)
} }
} header: { } header: {
if filterMode == .all && walkoutTeams.isEmpty == false { if filterMode == .all && walkoutTeams.isEmpty == false {
@ -616,8 +700,32 @@ struct InscriptionManagerView: View {
} else { } else {
Text("\(teams.count.formatted()) équipe\(teams.count.pluralSuffix)") Text("\(teams.count.formatted()) équipe\(teams.count.pluralSuffix)")
} }
} footer: {
FooterButtonView("Légende") {
showLegendView = true
}
} }
.headerProminence(.increased) .headerProminence(.increased)
.sheet(isPresented: $showLegendView) {
List {
Section {
ForEach(LegendInscriptionTip.allCases) { legend in
Text(legend.legendDescriptionLabel())
.listRowView(isActive: legend.isActive, color: legend.color, hideColorVariation: legend.hideColorVariation)
}
} header: {
Text("Statut de l'inscription")
}
Section {
ForEach(LegendPositionTip.allCases) { legend in
Text(legend.legendDescriptionLabel())
.listRowView(isActive: legend.isActive, color: legend.color, hideColorVariation: legend.hideColorVariation, alignment: .trailing)
}
} header: {
Text("Statut de la position dans le tournoi")
}
}
}
} else { } else {
ForEach(teams) { team in ForEach(teams) { team in
let teamIndex = team.index(in: sortedTeams) let teamIndex = team.index(in: sortedTeams)

Loading…
Cancel
Save