points for championship assimilation
online_payment
Raz 7 months ago
parent 902578d660
commit f72e98df8b
  1. 12
      PadelClub.xcodeproj/project.pbxproj
  2. 13
      PadelClub/Data/Tournament.swift
  3. 72
      PadelClub/Views/Tournament/Screen/TournamentRankView.swift

@ -3666,7 +3666,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.11;
MARKETING_VERSION = 1.2.12;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -3711,7 +3711,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.11;
MARKETING_VERSION = 1.2.12;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -3829,7 +3829,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.11;
MARKETING_VERSION = 1.2.12;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -3874,7 +3874,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.11;
MARKETING_VERSION = 1.2.12;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -3918,7 +3918,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.11;
MARKETING_VERSION = 1.2.12;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub.beta;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
@ -3960,7 +3960,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.2.11;
MARKETING_VERSION = 1.2.12;
PRODUCT_BUNDLE_IDENTIFIER = app.padelclub.beta;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";

@ -1228,6 +1228,19 @@ defer {
return rankings
}
func refreshPointsEarned(assimilationLevel: TournamentLevel? = nil) {
guard let tournamentStore = self.tournamentStore else { return }
let tournamentLevel = assimilationLevel ?? tournamentLevel
let unsortedTeams = unsortedTeams()
unsortedTeams.forEach { team in
if let finalRanking = team.finalRanking {
team.pointsEarned = isAnimation() ? nil : tournamentLevel.points(for: finalRanking - 1, count: teamCount)
}
}
tournamentStore.teamRegistrations.addOrUpdate(contentOfs: unsortedTeams)
}
func lockRegistration() {
closedRegistrationDate = Date()

@ -15,18 +15,14 @@ struct TournamentRankView: View {
@State private var rankings: [Int: [TeamRegistration]] = [:]
@State private var calculating = false
@State private var selectedTeam: TeamRegistration?
@State private var assimilationSelection: TournamentLevel?
var tournamentStore: TournamentStore? {
return self.tournament.tournamentStore
}
var isEditingTeam: Binding<Bool> {
Binding {
selectedTeam != nil
} set: { value in
}
var tournamentLevel: TournamentLevel {
assimilationSelection ?? tournament.tournamentLevel
}
var hideRankings: Binding<Bool> {
@ -70,6 +66,10 @@ struct TournamentRankView: View {
} label: {
Text("Assimilation")
}
.disabled(calculating)
.onChange(of: assimilationSelection) {
_refreshPointsEarned()
}
}
//affiche l'onglet sur le site, car sur le broadcast c'est dispo automatiquement de toute façon
@ -134,9 +134,7 @@ struct TournamentRankView: View {
if calculating == false && rankingsCalculated && teamsRanked.isEmpty == false {
Section {
ForEach(teamsRanked) { team in
if let key = team.finalRanking {
TeamRankCellView(team: team, key: key)
}
TeamRankCellView(team: team, tournamentLevel: tournamentLevel)
}
}
}
@ -149,30 +147,6 @@ struct TournamentRankView: View {
Logger.error(error)
}
}
.alert("Position", isPresented: isEditingTeam) {
if let selectedTeam {
@Bindable var team = selectedTeam
TextField("Position", value: $team.finalRanking, format: .number)
.keyboardType(.numberPad)
.multilineTextAlignment(.trailing)
.frame(maxWidth: .infinity)
Button("Valider") {
selectedTeam.pointsEarned = tournament.isAnimation() ? nil : tournament.tournamentLevel.points(for: selectedTeam.finalRanking! - 1, count: tournament.teamCount)
do {
try self.tournamentStore?.teamRegistrations.addOrUpdate(instance: selectedTeam)
} catch {
Logger.error(error)
}
self.selectedTeam = nil
}
Button("Annuler", role: .cancel) {
self.selectedTeam = nil
}
}
}
.onAppear {
let rankingPublished = tournament.selectedSortedTeams().anySatisfy({ $0.finalRanking != nil })
if rankingPublished == false {
@ -196,18 +170,23 @@ struct TournamentRankView: View {
@EnvironmentObject var dataStore: DataStore
@Environment(\.editMode) private var editMode
@Environment(Tournament.self) var tournament: Tournament
@State private var editedKey: Int = 0
@State private var isEditingTeam: Bool = false
@Bindable var team: TeamRegistration
@State var key: Int
var key: Int {
team.finalRanking ?? 0
}
let tournamentLevel: TournamentLevel
var body: some View {
VStack {
if editMode?.wrappedValue.isEditing == true {
if key > 1 {
FooterButtonView("monter") {
key -= 1
team.finalRanking = key
team.pointsEarned = tournament.isAnimation() ? nil : tournament.tournamentLevel.points(for: key - 1, count: tournament.teamCount)
team.finalRanking = key - 1
team.pointsEarned = tournament.isAnimation() ? nil : tournamentLevel.points(for: key - 1, count: tournament.teamCount)
do {
try self.tournament.tournamentStore?.teamRegistrations.addOrUpdate(instance: team)
} catch {
@ -218,6 +197,7 @@ struct TournamentRankView: View {
}
Button {
editedKey = key
isEditingTeam = true
} label: {
HStack {
@ -293,7 +273,7 @@ struct TournamentRankView: View {
if tournament.isAnimation() == false && key > 0 {
VStack(alignment: .trailing) {
HStack(alignment: .lastTextBaseline, spacing: 0.0) {
Text(tournament.tournamentLevel.points(for: key - 1, count: tournament.teamCount).formatted(.number.sign(strategy: .always())))
Text(tournamentLevel.points(for: key - 1, count: tournament.teamCount).formatted(.number.sign(strategy: .always())))
Text("pts").font(.caption)
}
}
@ -306,9 +286,8 @@ struct TournamentRankView: View {
if editMode?.wrappedValue.isEditing == true {
FooterButtonView("descendre") {
key += 1
team.finalRanking = key
team.pointsEarned = tournament.isAnimation() ? nil : tournament.tournamentLevel.points(for: key - 1, count: tournament.teamCount)
team.finalRanking = key + 1
team.pointsEarned = tournament.isAnimation() ? nil : tournamentLevel.points(for: key - 1, count: tournament.teamCount)
do {
try self.tournament.tournamentStore?.teamRegistrations.addOrUpdate(instance: team)
@ -319,13 +298,14 @@ struct TournamentRankView: View {
}
}
.alert("Position", isPresented: $isEditingTeam) {
TextField("Position", value: $team.finalRanking, format: .number)
TextField("Position", value: $editedKey, format: .number)
.keyboardType(.numberPad)
.multilineTextAlignment(.trailing)
.frame(maxWidth: .infinity)
Button("Valider") {
team.pointsEarned = tournament.isAnimation() ? nil : tournament.tournamentLevel.points(for: key - 1, count: tournament.teamCount)
team.finalRanking = editedKey
team.pointsEarned = tournament.isAnimation() ? nil : tournamentLevel.points(for: editedKey - 1, count: tournament.teamCount)
do {
try self.tournament.tournamentStore?.teamRegistrations.addOrUpdate(instance: team)
} catch {
@ -333,7 +313,7 @@ struct TournamentRankView: View {
}
isEditingTeam = false
}
}.disabled(editedKey < 1)
Button("Annuler", role: .cancel) {
isEditingTeam = false
@ -342,6 +322,10 @@ struct TournamentRankView: View {
}
}
private func _refreshPointsEarned() {
tournament.refreshPointsEarned(assimilationLevel: assimilationSelection)
}
private func _calculateRankings() async {
await MainActor.run {
calculating = true

Loading…
Cancel
Save