main
Razmig Sarkissian 4 weeks ago
parent 6c634399d7
commit b41e8064d7
  1. 2
      PadelClub/Views/Calling/BracketCallingView.swift
  2. 1
      PadelClub/Views/Calling/CallMessageCustomizationView.swift
  3. 52
      PadelClub/Views/Planning/PlanningView.swift
  4. 21
      PadelClub/Views/Tournament/Screen/TableStructureView.swift

@ -106,7 +106,7 @@ struct BracketCallingView: View {
ForEach(filteredRounds()) { round in
let seeds = seeds(forRoundIndex: round.index)
let startDate = round.startDate ?? round.playedMatches().first?.startDate
let startDate = ([round.startDate] + round.playedMatches().map { $0.startDate }).compacted().min()
let callSeeds = seeds.filter({ tournament.isStartDateIsDifferentThanCallDate($0, expectedSummonDate: startDate) == false })
if seeds.isEmpty == false {
Section {

@ -236,7 +236,6 @@ struct CallMessageCustomizationView: View {
let hasBeenCreated: Bool = eventClub.hasBeenCreated(by: StoreCenter.main.userId)
Section {
TextField("Nom du club", text: $customClubName, axis: .vertical)
.lineLimit(2)
.autocorrectionDisabled()
.focused($focusedField, equals: .clubName)
.onSubmit {

@ -728,9 +728,6 @@ struct PlanningView: View {
}
}
private func _eventCourtCount() -> Int { timeSlots.first?.value.first?.currentTournament()?.eventObject()?.eventCourtCount() ?? 2
}
private func _save() {
let groupByTournaments = allMatches.grouped { match in
match.currentTournament()
@ -749,16 +746,27 @@ struct PlanningView: View {
Button("Tirer au sort") {
_removeCourts()
let eventCourtCount = _eventCourtCount()
for slot in timeSlots {
var courtsAvailable = Array(0...eventCourtCount)
let matches = slot.value
matches.forEach { match in
if let rand = courtsAvailable.randomElement() {
var courtsByTournament: [String: Set<Int>] = [:]
for match in matches {
if let tournament = match.currentTournament(),
let available = tournament.matchScheduler()?.courtsAvailable {
courtsByTournament[tournament.id, default: []].formUnion(available)
}
}
for match in matches {
guard let tournament = match.currentTournament() else { continue }
// Get current set of available courts for this tournament id
guard var courts = courtsByTournament[tournament.id], !courts.isEmpty else { continue }
// Pick a random court
if let rand = courts.randomElement() {
match.courtIndex = rand
courtsAvailable.remove(elements: [rand])
// Remove from local copy and assign back into the dictionary
courts.remove(rand)
courtsByTournament[tournament.id] = courts
}
}
}
@ -768,16 +776,27 @@ struct PlanningView: View {
Button("Fixer par ordre croissant") {
_removeCourts()
let eventCourtCount = _eventCourtCount()
for slot in timeSlots {
var courtsAvailable = Array(0..<eventCourtCount)
let matches = slot.value.sorted(by: \.computedOrder)
var courtsByTournament: [String: Set<Int>] = [:]
for match in matches {
if let tournament = match.currentTournament(),
let available = tournament.matchScheduler()?.courtsAvailable {
courtsByTournament[tournament.id, default: []].formUnion(available.sorted())
}
}
for i in 0..<matches.count {
if !courtsAvailable.isEmpty {
let court = courtsAvailable.removeFirst()
guard let tournament = matches[i].currentTournament() else { continue }
// Get current set of available courts for this tournament id
guard var courts = courtsByTournament[tournament.id]?.sorted(), !courts.isEmpty else { continue }
if courts.isEmpty == false {
let court = courts.removeFirst()
matches[i].courtIndex = court
// Remove from local copy and assign back into the dictionary
courtsByTournament[tournament.id] = Set(courts)
}
}
}
@ -984,3 +1003,4 @@ extension EnvironmentValues {
set { self[EnableMoveKey.self] = newValue }
}
}

@ -352,12 +352,28 @@ struct TableStructureView: View {
await _save(rebuildEverything: true)
}
}
Section {
RowButtonView("Remise-à-zéro", role: .destructive) {
_reset()
}
}
Section {
RowButtonView("Retirer toutes les équipes de poules", role: .destructive) {
tournament.unsortedTeams().forEach {
$0.resetGroupeStagePosition()
}
}
}
Section {
RowButtonView("Retirer toutes les équipes du tableau", role: .destructive) {
tournament.unsortedTeams().forEach {
$0.resetBracketPosition()
}
}
}
}
}
.focused($stepperFieldIsFocused)
@ -505,6 +521,9 @@ struct TableStructureView: View {
}
private func _reset() {
tournament.unsortedTeams().forEach {
$0.resetPositions()
}
tournament.removeWildCards()
tournament.deleteGroupStages()
tournament.deleteStructure()

Loading…
Cancel
Save