@ -143,7 +143,56 @@ struct PlanningSettingsView: View {
}
}
let allMatches = tournament . allMatches ( )
_smartView ( )
}
. headerProminence ( . increased )
. onAppear {
do {
try self . tournamentStore . matchSchedulers . addOrUpdate ( instance : matchScheduler )
} catch {
Logger . error ( error )
}
}
. overlay ( alignment : . bottom ) {
if schedulingDone {
if issueFound {
Label ( " Horaires mis à jour " , systemImage : " xmark.circle.fill " )
. toastFormatted ( )
. deferredRendering ( for : . seconds ( 2 ) )
} else {
Label ( " Horaires mis à jour " , systemImage : " checkmark.circle.fill " )
. toastFormatted ( )
. deferredRendering ( for : . seconds ( 2 ) )
}
}
if deletingDone {
Label ( " Tous les horaires ont été supprimés " , systemImage : " clock.badge.xmark " )
. toastFormatted ( )
. deferredRendering ( for : . seconds ( 2 ) )
}
if deletingDateMatchesDone {
Label ( " Horaires des matchs supprimés " , systemImage : " clock.badge.xmark " )
. toastFormatted ( )
. deferredRendering ( for : . seconds ( 2 ) )
}
}
. onChange ( of : tournament . startDate ) {
_save ( )
}
. onChange ( of : tournament . courtCount ) {
matchScheduler . courtsAvailable = Set ( tournament . courtsAvailable ( ) )
_save ( )
}
. onChange ( of : tournament . dayDuration ) {
_save ( )
}
}
@ ViewBuilder
private func _smartView ( ) -> some View {
let allMatches = tournament . allMatches ( ) . filter ( { $0 . hasEnded ( ) = = false && $0 . hasStarted ( ) = = false } )
let allGroupStages = tournament . allGroupStages ( )
let allRounds = tournament . allRounds ( )
let matchesWithDate = allMatches . filter ( { $0 . startDate != nil } )
@ -156,7 +205,7 @@ struct PlanningSettingsView: View {
let groupStagesWithDate = allGroupStages . filter ( { $0 . startDate != nil } )
let roundsWithDate = allRounds . filter ( { $0 . startDate != nil } )
if matchesWithDate . isEmpty = = false || groupStagesWithDate . isEmpty = = false || round sWithDate . isEmpty = = false {
if matchesWithDate . isEmpty = = false {
Section {
RowButtonView ( " Supprimer les horaires des matches " , role : . destructive ) {
do {
@ -172,9 +221,44 @@ struct PlanningSettingsView: View {
}
}
} footer : {
Text ( " Garde les horaires définis pour les poules et les manches. " )
Text ( " Supprime les horaires des matchs restants non démarrés. Garde les horaires définis pour les poules et les manches du tableau. " )
}
}
if groupStagesWithDate . isEmpty = = false {
Section {
RowButtonView ( " Supprimer les horaires des poules " , role : . destructive ) {
do {
deletingDone = false
allGroupStages . forEach ( { $0 . startDate = nil } )
try self . tournamentStore . groupStages . addOrUpdate ( contentOfs : allGroupStages )
deletingDone = true
} catch {
Logger . error ( error )
}
}
}
}
if roundsWithDate . isEmpty = = false {
Section {
RowButtonView ( " Supprimer les horaires du tableau " , role : . destructive ) {
do {
deletingDone = false
allRounds . forEach ( { $0 . startDate = nil } )
try self . tournamentStore . rounds . addOrUpdate ( contentOfs : allRounds )
deletingDone = true
} catch {
Logger . error ( error )
}
}
} footer : {
Text ( " Supprime les horaires définis pour les manches du tableau. " )
}
}
if matchesWithDate . isEmpty = = false && groupStagesWithDate . isEmpty = = false && roundsWithDate . isEmpty = = false {
Section {
RowButtonView ( " Supprimer tous les horaires " , role : . destructive ) {
do {
@ -195,8 +279,38 @@ struct PlanningSettingsView: View {
Logger . error ( error )
}
}
} footer : {
Text ( " Supprime les horaires des matchs restants non démarrés, les horaires définis pour les poules et les manches du tableau. " )
}
}
#if DEBUG
Section {
RowButtonView ( " Supprimer tous les horaires " , role : . destructive ) {
do {
deletingDone = false
tournament . allMatches ( ) . forEach ( {
$0 . startDate = nil
$0 . endDate = nil
$0 . confirmed = false
} )
try self . tournamentStore . matches . addOrUpdate ( contentOfs : tournament . allMatches ( ) )
allGroupStages . forEach ( { $0 . startDate = nil } )
try self . tournamentStore . groupStages . addOrUpdate ( contentOfs : allGroupStages )
allRounds . forEach ( { $0 . startDate = nil } )
try self . tournamentStore . rounds . addOrUpdate ( contentOfs : allRounds )
deletingDone = true
} catch {
Logger . error ( error )
}
}
} footer : {
Text ( " Supprime les horaires des matchs, les horaires définis pour les poules et les manches du tableau. " )
}
#endif
Section {
if groupStagesWithDate . isEmpty = = false {
@ -220,50 +334,6 @@ struct PlanningSettingsView: View {
Text ( " Padel Club programmera tous les matchs de votre tournoi en fonction de différents paramètres, " ) + Text ( " tout en tenant compte des horaires que vous avez fixé. " ) . underline ( )
}
}
. headerProminence ( . increased )
. onAppear {
do {
try self . tournamentStore . matchSchedulers . addOrUpdate ( instance : matchScheduler )
} catch {
Logger . error ( error )
}
}
. overlay ( alignment : . bottom ) {
if schedulingDone {
if issueFound {
Label ( " Horaires mis à jour " , systemImage : " xmark.circle.fill " )
. toastFormatted ( )
. deferredRendering ( for : . seconds ( 2 ) )
} else {
Label ( " Horaires mis à jour " , systemImage : " checkmark.circle.fill " )
. toastFormatted ( )
. deferredRendering ( for : . seconds ( 2 ) )
}
}
if deletingDone {
Label ( " Tous les horaires ont été supprimés " , systemImage : " clock.badge.xmark " )
. toastFormatted ( )
. deferredRendering ( for : . seconds ( 2 ) )
}
if deletingDateMatchesDone {
Label ( " Horaires des matchs supprimés " , systemImage : " clock.badge.xmark " )
. toastFormatted ( )
. deferredRendering ( for : . seconds ( 2 ) )
}
}
. onChange ( of : tournament . startDate ) {
_save ( )
}
. onChange ( of : tournament . courtCount ) {
matchScheduler . courtsAvailable = Set ( tournament . courtsAvailable ( ) )
_save ( )
}
. onChange ( of : tournament . dayDuration ) {
_save ( )
}
}
@ ViewBuilder
private func _optionsView ( ) -> some View {