multistore
Razmig Sarkissian 2 years ago
parent 0540943b26
commit 0b098b5b3b
  1. 2
      PadelClub/Data/Match.swift
  2. 13
      PadelClub/Data/MatchScheduler.swift
  3. 5
      PadelClub/Data/Tournament.swift
  4. 19
      PadelClub/Views/Club/CourtView.swift
  5. 2
      PadelClub/Views/GroupStage/Shared/GroupStageTeamReplacementView.swift
  6. 41
      PadelClub/Views/Planning/CourtAvailabilitySettingsView.swift
  7. 4
      PadelClub/Views/Planning/PlanningSettingsView.swift

@ -269,7 +269,7 @@ class Match: ModelObject, Storable {
}
func roundTitle() -> String? {
if groupStage != nil { return "Poule" }
if groupStage != nil { return groupStageObject?.groupStageTitle() }
else if let roundObject { return roundObject.roundTitle() }
else { return nil }
}

@ -111,7 +111,7 @@ class MatchScheduler : ModelObject, Storable {
return lastDate
}
func groupStageDispatcher(numberOfCourtsAvailablePerRotation: Int, groupStages: [GroupStage], startingDate: Date?) -> GroupStageMatchDispatcher {
func groupStageDispatcher(numberOfCourtsAvailablePerRotation: Int, groupStages: [GroupStage], startingDate: Date) -> GroupStageMatchDispatcher {
let _groupStages = groupStages
@ -156,7 +156,16 @@ class MatchScheduler : ModelObject, Storable {
(0..<numberOfCourtsAvailablePerRotation).forEach { courtIndex in
//print(mt.map { ($0.bracket!.index.intValue, counts[$0.bracket!.index.intValue]) })
if let first = rotationMatches.first(where: { match in
teamsPerRotation[rotationIndex]!.allSatisfy({ match.containsTeamId($0) == false }) == true
let estimatedDuration = match.matchFormat.getEstimatedDuration(additionalEstimationDuration)
let timeIntervalToAdd = (Double(rotationIndex)) * Double(estimatedDuration) * 60
let rotationStartDate: Date = startingDate.addingTimeInterval(timeIntervalToAdd)
let courtsUnavailable = courtsUnavailable(startDate: rotationStartDate, duration: match.matchFormat.getEstimatedDuration(additionalEstimationDuration))
if courtIndex >= numberOfCourtsAvailablePerRotation - courtsUnavailable {
return false
} else {
return teamsPerRotation[rotationIndex]!.allSatisfy({ match.containsTeamId($0) == false }) == true
}
}) {
let timeMatch = GroupStageTimeMatch(matchID: first.id, rotationIndex: rotationIndex, courtIndex: courtIndex, groupIndex: first.groupStageObject!.index)
slots.append(timeMatch)

@ -363,8 +363,9 @@ class Tournament : ModelObject, Storable {
}
func seeds() -> [TeamRegistration] {
let seeds = max(teamCount - groupStageCount * teamsPerGroupStage, 0)
return Array(selectedSortedTeams().prefix(seeds))
let selectedSortedTeams = selectedSortedTeams()
let seeds = max(selectedSortedTeams.count - groupStageCount * teamsPerGroupStage, 0)
return Array(selectedSortedTeams.prefix(seeds))
}
func availableSeeds() -> [TeamRegistration] {

@ -25,9 +25,24 @@ struct CourtView: View {
.keyboardType(.alphabet)
.multilineTextAlignment(.trailing)
.frame(maxWidth: .infinity)
.onSubmit {
court.name = name
if name.isEmpty {
court.name = nil
}
try? dataStore.courts.addOrUpdate(instance: court)
}
} label: {
Text("Nom du terrain")
}
} footer: {
if court.name?.isEmpty == false {
FooterButtonView("nom par défaut") {
name = ""
court.name = nil
try? dataStore.courts.addOrUpdate(instance: court)
}
}
}
Section {
@ -39,10 +54,6 @@ struct CourtView: View {
}
}
}
.onChange(of: name) {
court.name = name
try? dataStore.courts.addOrUpdate(instance: court)
}
.onChange(of: [court.indoor, court.exitAllowed]) {
try? dataStore.courts.addOrUpdate(instance: court)
}

@ -72,6 +72,8 @@ struct GroupStageTeamReplacementView: View {
}
.labelsHidden()
.pickerStyle(.inline)
} header: {
Text("Remplacer")
} footer: {
Text("Remplacement de l'équipe ou d'un joueur particulier")
}

@ -33,24 +33,7 @@ struct CourtAvailabilitySettingsView: View {
if let dates = courtsUnavailability[key] {
Section {
ForEach(dates) { dateInterval in
HStack {
VStack(alignment: .leading, spacing: 0) {
Text(dateInterval.startDate.localizedTime()).font(.largeTitle)
Text(dateInterval.startDate.localizedDay()).font(.caption)
}
Spacer()
VStack {
Image(systemName: "arrowshape.forward.fill")
.tint(.master)
Text("indisponible").foregroundStyle(.red).font(.caption)
}
Spacer()
VStack(alignment: .trailing, spacing: 0) {
Text(dateInterval.endDate.localizedTime()).font(.largeTitle)
Text(dateInterval.endDate.localizedDay()).font(.caption)
}
}
.contextMenu(menuItems: {
Menu {
Button("dupliquer") {
let duplicatedDateInterval = DateInterval(event: event.id, courtIndex: (courtIndex+1)%tournament.courtCount, startDate: dateInterval.startDate, endDate: dateInterval.endDate)
try? dataStore.dateIntervals.addOrUpdate(instance: duplicatedDateInterval)
@ -65,7 +48,25 @@ struct CourtAvailabilitySettingsView: View {
Button("effacer", role: .destructive) {
try? dataStore.dateIntervals.delete(instance: dateInterval)
}
})
} label: {
HStack {
VStack(alignment: .leading, spacing: 0) {
Text(dateInterval.startDate.localizedTime()).font(.largeTitle)
Text(dateInterval.startDate.localizedDay()).font(.caption)
}
Spacer()
VStack {
Image(systemName: "arrowshape.forward.fill")
.tint(.master)
Text("indisponible").foregroundStyle(.red).font(.caption)
}
Spacer()
VStack(alignment: .trailing, spacing: 0) {
Text(dateInterval.endDate.localizedTime()).font(.largeTitle)
Text(dateInterval.endDate.localizedDay()).font(.caption)
}
}
}
.swipeActions {
Button(role: .destructive) {
try? dataStore.dateIntervals.delete(instance: dateInterval)
@ -95,6 +96,8 @@ struct CourtAvailabilitySettingsView: View {
Text("Vous pouvez précisez l'indisponibilité d'une ou plusieurs terrains, que ce soit pour une journée entière ou un créneau précis.")
} actions: {
RowButtonView("Ajouter une indisponibilité", systemImage: "plus.circle.fill") {
startDate = tournament.startDate
endDate = tournament.startDate.addingTimeInterval(5400)
showingPopover = true
}
}

@ -42,15 +42,13 @@ struct PlanningSettingsView: View {
}
} header: {
Text("Démarrage et durée du tournoi")
} footer: {
Text("todo: Expliquer ce que ca fait")
}
Section {
TournamentFieldsManagerView(localizedStringKey: "Terrains maximum", count: $tournament.courtCount)
if tournament.groupStages().isEmpty == false {
TournamentFieldsManagerView(localizedStringKey: "Terrains par poule", count: $groupStageCourtCount, max: tournament.maximumCourtsPerGroupSage())
TournamentFieldsManagerView(localizedStringKey: "Nombre de poule en même temps", count: $groupStageCourtCount, max: tournament.groupStageCount)
}
if let event = tournament.eventObject() {

Loading…
Cancel
Save