Files
ersatztv/ErsatzTV/Pages/SequentialPlayoutEditor.razor
T

122 lines
4.3 KiB
Plaintext

@page "/playouts/sequential/{Id:int}"
@using ErsatzTV.Application.Channels
@using ErsatzTV.Application.Playouts
@using ErsatzTV.Application.Scheduling
@implements IDisposable
@inject NavigationManager NavigationManager
@inject ISnackbar Snackbar
@inject IMediator Mediator
@inject IEntityLocker EntityLocker;
@inject ILogger<SequentialPlayoutEditor> Logger
<MudForm 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" Class="ml-6" OnClick="@(_ => SaveChanges())" StartIcon="@Icons.Material.Filled.Save">
Save Sequential Schedule
</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">@_channelName - Sequential Schedule</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>Sequential Schedule</MudText>
</div>
@if (_playout is not null)
{
<MudTextField @bind-Value="@_playout.ScheduleFile" For="@(() => _playout.ScheduleFile)"/>
}
</MudStack>
<MudText Typo="Typo.h5" Class="mt-10 mb-2">Maintenance</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>Playout Items and History</MudText>
</div>
<MudButton Disabled="@EntityLocker.IsPlayoutLocked(Id)" Variant="Variant.Filled" Color="Color.Error" OnClick="@(_ => EraseItems(eraseHistory: true))" StartIcon="@Icons.Material.Filled.Delete">
Erase Items and History
</MudButton>
</MudStack>
</MudContainer>
</div>
</MudForm>
@code {
private CancellationTokenSource _cts;
private PlayoutNameViewModel _playout;
[Parameter]
public int Id { get; set; }
private string _channelName;
public void Dispose()
{
_cts?.Cancel();
_cts?.Dispose();
}
protected override async Task OnParametersSetAsync()
{
_cts?.Cancel();
_cts?.Dispose();
_cts = new CancellationTokenSource();
var token = _cts.Token;
try
{
Option<string> maybeName = await Mediator.Send(new GetChannelNameByPlayoutId(Id), token);
if (maybeName.IsNone)
{
NavigationManager.NavigateTo("playouts");
return;
}
foreach (string name in maybeName)
{
_channelName = name;
}
Option<PlayoutNameViewModel> maybePlayout = await Mediator.Send(new GetPlayoutById(Id), token);
foreach (PlayoutNameViewModel playout in maybePlayout)
{
_playout = playout;
}
}
catch (OperationCanceledException)
{
// do nothing
}
}
private async Task EraseItems(bool eraseHistory)
{
IRequest request = eraseHistory ? new ErasePlayoutHistory(Id) : new ErasePlayoutItems(Id);
await Mediator.Send(request, _cts.Token);
string message = eraseHistory ? "Erased playout items and history" : "Erased playout items";
Snackbar.Add(message, Severity.Info);
}
private async Task SaveChanges()
{
if (_playout is null)
{
return;
}
Either<BaseError, PlayoutNameViewModel> result =
await Mediator.Send(new UpdateSequentialPlayout(_playout.PlayoutId, _playout.ScheduleFile), _cts.Token);
result.Match(
_ => { Snackbar.Add($"Saved sequential schedule for playout {_channelName}", Severity.Success); },
error =>
{
Snackbar.Add($"Unexpected error saving sequential schedule: {error.Value}", Severity.Error);
Logger.LogError("Unexpected error saving sequential schedule: {Error}", error.Value);
});
}
}