* add template playout kind * add template scheduler count * implement pad to next * only allow resetting template playouts * update changelog
132 lines
4.8 KiB
Plaintext
132 lines
4.8 KiB
Plaintext
@page "/playouts/add"
|
|
@page "/playouts/add/{kind}"
|
|
@using ErsatzTV.Application.Channels
|
|
@using ErsatzTV.Application.ProgramSchedules
|
|
@implements IDisposable
|
|
@inject NavigationManager NavigationManager
|
|
@inject ILogger<PlayoutEditor> Logger
|
|
@inject ISnackbar Snackbar
|
|
@inject IMediator Mediator
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<MudText Typo="Typo.h4" Class="mb-4">
|
|
@switch (Kind)
|
|
{
|
|
case PlayoutKind.ExternalJson:
|
|
<span>Add External Json Playout</span>
|
|
break;
|
|
case PlayoutKind.Template:
|
|
<span>Add Template Playout</span>
|
|
break;
|
|
case PlayoutKind.Block:
|
|
<span>Add Block Playout</span>
|
|
break;
|
|
default:
|
|
<span>Add Playout</span>
|
|
break;
|
|
}
|
|
</MudText>
|
|
<div style="max-width: 400px;">
|
|
<EditForm EditContext="_editContext" OnSubmit="@HandleSubmitAsync">
|
|
<FluentValidationValidator/>
|
|
<MudCard>
|
|
<MudCardContent>
|
|
<MudSelect T="ChannelViewModel"
|
|
Label="Channel"
|
|
@bind-value="_model.Channel"
|
|
HelperText="Disabled channels already have a playout">
|
|
@foreach (ChannelViewModel channel in _channels)
|
|
{
|
|
<MudSelectItem Disabled="@(channel.PlayoutCount > 0)" Value="@channel">
|
|
@($"{channel.Number} - {channel.Name}")
|
|
</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
@switch (Kind)
|
|
{
|
|
case PlayoutKind.ExternalJson:
|
|
<MudTextField Label="External Json File" @bind-Value="_model.ExternalJsonFile" For="@(() => _model.ExternalJsonFile)"/>
|
|
break;
|
|
case PlayoutKind.Template:
|
|
<MudTextField Label="Template File" @bind-Value="_model.TemplateFile" For="@(() => _model.TemplateFile)"/>
|
|
break;
|
|
default:
|
|
<MudSelect Class="mt-3"
|
|
T="ProgramScheduleViewModel"
|
|
Label="Schedule"
|
|
@bind-value="_model.ProgramSchedule">
|
|
@foreach (ProgramScheduleViewModel schedule in _programSchedules)
|
|
{
|
|
<MudSelectItem Value="@schedule">@schedule.Name</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
break;
|
|
}
|
|
</MudCardContent>
|
|
<MudCardActions>
|
|
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Primary">
|
|
Add Playout
|
|
</MudButton>
|
|
</MudCardActions>
|
|
</MudCard>
|
|
</EditForm>
|
|
</div>
|
|
</MudContainer>
|
|
|
|
@code {
|
|
private readonly CancellationTokenSource _cts = new();
|
|
|
|
private readonly PlayoutEditViewModel _model = new();
|
|
private List<ChannelViewModel> _channels = [];
|
|
private List<ProgramScheduleViewModel> _programSchedules = [];
|
|
|
|
private EditContext _editContext;
|
|
private ValidationMessageStore _messageStore;
|
|
|
|
[Parameter]
|
|
public string Kind { get; set; }
|
|
|
|
public void Dispose()
|
|
{
|
|
_cts.Cancel();
|
|
_cts.Dispose();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
_model.Kind = Kind;
|
|
|
|
_channels = await Mediator.Send(new GetAllChannels(), _cts.Token)
|
|
.Map(list => list.OrderBy(vm => decimal.Parse(vm.Number)).ToList());
|
|
|
|
if (string.IsNullOrWhiteSpace(Kind))
|
|
{
|
|
_programSchedules = await Mediator.Send(new GetAllProgramSchedules(), _cts.Token)
|
|
.Map(list => list.OrderBy(vm => vm.Name).ToList());
|
|
}
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
_editContext = new EditContext(_model);
|
|
_messageStore = new ValidationMessageStore(_editContext);
|
|
}
|
|
|
|
private async Task HandleSubmitAsync()
|
|
{
|
|
_messageStore.Clear();
|
|
if (_editContext.Validate())
|
|
{
|
|
Seq<BaseError> errorMessage = (await Mediator.Send(_model.ToCreate(), _cts.Token)).LeftToSeq();
|
|
|
|
errorMessage.HeadOrNone().Match(
|
|
error =>
|
|
{
|
|
Snackbar.Add(error.Value, Severity.Error);
|
|
Logger.LogError("Unexpected error saving playout: {Error}", error.Value);
|
|
},
|
|
() => NavigationManager.NavigateTo("/playouts"));
|
|
}
|
|
}
|
|
|
|
} |