mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
4.1 KiB
91 lines
4.1 KiB
@page "/settings/playout" |
|
@using ErsatzTV.Application.Configuration |
|
@implements IDisposable |
|
@inject IMediator Mediator |
|
@inject ISnackbar Snackbar |
|
@inject ILogger<PlayoutSettings> Logger |
|
|
|
<MudForm @ref="_form" @bind-IsValid="@_playoutSuccess" Style="max-height: 100%"> |
|
<MudPaper Square="true" Style="display: flex; height: 64px; min-height: 64px; width: 100%; z-index: 100; align-items: center"> |
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" OnClick="@(_ => SavePlayoutSettings())" Class="ml-6" StartIcon="@Icons.Material.Filled.Save">Save Settings</MudButton> |
|
</MudPaper> |
|
<div class="d-flex flex-column" style="height: 100vh; overflow-x: auto"> |
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8"> |
|
<MudText Typo="Typo.h5" Class="mb-2">Playout</MudText> |
|
<MudDivider Class="mb-6"/> |
|
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5"> |
|
<div class="d-flex"> |
|
<MudText>Days To Build</MudText> |
|
</div> |
|
<MudTextField @bind-Value="_playoutSettings.DaysToBuild" Validation="@(new Func<int, string>(ValidatePlayoutDaysToBuild))" Required="true" RequiredError="Playout days to build is required!" Adornment="Adornment.End" AdornmentText="days"/> |
|
</MudStack> |
|
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5"> |
|
<div class="d-flex"> |
|
<MudText>Skip Missing Items</MudText> |
|
</div> |
|
<MudCheckBox @bind-Value="_playoutSettings.SkipMissingItems" Dense="true"> |
|
<MudText Typo="Typo.caption" Style="font-weight: normal">Controls whether file-not-found or unavailable items should be included in playouts</MudText> |
|
</MudCheckBox> |
|
</MudStack> |
|
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5"> |
|
<div class="d-flex"> |
|
<MudText>Scripted Schedule Timeout</MudText> |
|
</div> |
|
<MudTextField @bind-Value="_playoutSettings.ScriptedScheduleTimeoutSeconds" Validation="@(new Func<int, string>(ValidateScriptedScheduleTimeoutSeconds))" Required="true" RequiredError="Scripted schedule timeout is required!" Adornment="Adornment.End" AdornmentText="seconds"/> |
|
</MudStack> |
|
</MudContainer> |
|
</div> |
|
</MudForm> |
|
|
|
@code { |
|
private CancellationTokenSource _cts; |
|
|
|
private MudForm _form; |
|
private bool _playoutSuccess; |
|
private PlayoutSettingsViewModel _playoutSettings = new(); |
|
|
|
public void Dispose() |
|
{ |
|
_cts?.Cancel(); |
|
_cts?.Dispose(); |
|
} |
|
|
|
protected override async Task OnParametersSetAsync() |
|
{ |
|
_cts?.Cancel(); |
|
_cts?.Dispose(); |
|
_cts = new CancellationTokenSource(); |
|
var token = _cts.Token; |
|
|
|
try |
|
{ |
|
_playoutSettings = await Mediator.Send(new GetPlayoutSettings(), token); |
|
_playoutSuccess = _playoutSettings.DaysToBuild > 0 && _playoutSettings.ScriptedScheduleTimeoutSeconds >= 10; |
|
} |
|
catch (OperationCanceledException) |
|
{ |
|
// do nothing |
|
} |
|
} |
|
|
|
private static string ValidatePlayoutDaysToBuild(int daysToBuild) => daysToBuild <= 0 ? "Playout days to build must be greater than zero" : null; |
|
|
|
private static string ValidateScriptedScheduleTimeoutSeconds(int seconds) => seconds < 10 ? "Scripted schedule timeout seconds must be at least 10" : null; |
|
|
|
private async Task SavePlayoutSettings() |
|
{ |
|
await _form.ValidateAsync(); |
|
if (_playoutSuccess) |
|
{ |
|
Either<BaseError, Unit> result = await Mediator.Send(new UpdatePlayoutSettings(_playoutSettings), _cts.Token); |
|
result.Match( |
|
Left: error => |
|
{ |
|
Snackbar.Add(error.Value, Severity.Error); |
|
Logger.LogError("Unexpected error saving playout settings: {Error}", error.Value); |
|
}, |
|
Right: _ => Snackbar.Add("Successfully saved playout settings", Severity.Success)); |
|
} |
|
} |
|
|
|
}
|
|
|