79 lines
3.2 KiB
Plaintext
79 lines
3.2 KiB
Plaintext
@page "/playouts/add"
|
|
@using ErsatzTV.Application.Channels
|
|
@using ErsatzTV.Application.Channels.Queries
|
|
@using ErsatzTV.Application.ProgramSchedules
|
|
@using ErsatzTV.Application.ProgramSchedules.Queries
|
|
@inject NavigationManager _navigationManager
|
|
@inject ILogger<PlayoutEditor> _logger
|
|
@inject ISnackbar _snackbar
|
|
@inject IMediator _mediator
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<div style="max-width: 400px;">
|
|
<MudText Typo="Typo.h4" Class="mb-4">Add Playout</MudText>
|
|
|
|
<EditForm EditContext="_editContext" OnSubmit="@HandleSubmitAsync">
|
|
<FluentValidator/>
|
|
<MudCard>
|
|
<MudCardContent>
|
|
<MudAutocomplete T="ChannelViewModel" Label="Channel" @bind-value="_model.Channel" SearchFunc="@SearchChannels" ToStringFunc="@(c => c is null ? null : $"{c.Number} - {c.Name}")"/>
|
|
<MudAutocomplete Class="mt-3" T="ProgramScheduleViewModel" Label="Schedule" @bind-value="_model.ProgramSchedule" SearchFunc="@SearchProgramSchedules" ToStringFunc="@(s => s?.Name)"/>
|
|
</MudCardContent>
|
|
<MudCardActions>
|
|
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Primary">
|
|
Add Playout
|
|
</MudButton>
|
|
</MudCardActions>
|
|
</MudCard>
|
|
</EditForm>
|
|
</div>
|
|
</MudContainer>
|
|
|
|
@code {
|
|
|
|
private readonly PlayoutEditViewModel _model = new();
|
|
private List<ChannelViewModel> _channels;
|
|
private List<ProgramScheduleViewModel> _programSchedules;
|
|
|
|
private EditContext _editContext;
|
|
private ValidationMessageStore _messageStore;
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
_channels = await _mediator.Send(new GetAllChannels())
|
|
.Map(list => list.OrderBy(vm => decimal.Parse(vm.Number)).ToList());
|
|
_programSchedules = await _mediator.Send(new GetAllProgramSchedules())
|
|
.Map(list => list.OrderBy(vm => vm.Name).ToList());
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
_editContext = new EditContext(_model);
|
|
_messageStore = new ValidationMessageStore(_editContext);
|
|
}
|
|
|
|
private Task<IEnumerable<ChannelViewModel>> SearchChannels(string value) =>
|
|
_channels.Filter(c => $"{c.Number} - {c.Name}".Contains(value ?? string.Empty, StringComparison.OrdinalIgnoreCase)).AsTask();
|
|
|
|
private Task<IEnumerable<ProgramScheduleViewModel>> SearchProgramSchedules(string value) =>
|
|
_programSchedules.Filter(c => c.Name.Contains(value ?? string.Empty, StringComparison.OrdinalIgnoreCase)).AsTask();
|
|
|
|
|
|
private async Task HandleSubmitAsync()
|
|
{
|
|
_messageStore.Clear();
|
|
if (_editContext.Validate())
|
|
{
|
|
Seq<BaseError> errorMessage = (await _mediator.Send(_model.ToCreate())).LeftToSeq();
|
|
|
|
errorMessage.HeadOrNone().Match(
|
|
error =>
|
|
{
|
|
_snackbar.Add(error.Value, Severity.Error);
|
|
_logger.LogError("Unexpected error saving playout: {Error}", error.Value);
|
|
},
|
|
() => _navigationManager.NavigateTo("/playouts"));
|
|
}
|
|
}
|
|
|
|
} |