mirror of https://github.com/ErsatzTV/ErsatzTV.git
10 changed files with 157 additions and 18 deletions
@ -1,4 +1,4 @@
@@ -1,4 +1,4 @@
|
||||
namespace ErsatzTV.Application.Playouts |
||||
{ |
||||
public record PlayoutChannelViewModel(int Id, string Name); |
||||
public record PlayoutChannelViewModel(int Id, int Number, string Name); |
||||
} |
||||
|
||||
@ -0,0 +1,75 @@
@@ -0,0 +1,75 @@
|
||||
@page "/playouts/add" |
||||
@using ErsatzTV.Application.ProgramSchedules |
||||
@using ErsatzTV.Application.ProgramSchedules.Queries |
||||
@using ErsatzTV.Application.Channels |
||||
@using ErsatzTV.Application.Channels.Queries |
||||
@inject NavigationManager NavigationManager |
||||
@inject ILogger<PlayoutEditor> Logger |
||||
@inject ISnackbar Snackbar |
||||
@inject IMediator Mediator |
||||
|
||||
<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> |
||||
|
||||
@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()); |
||||
_programSchedules = await Mediator.Send(new GetAllProgramSchedules()); |
||||
} |
||||
|
||||
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}".ToLowerInvariant().Contains(value ?? string.Empty)).AsTask(); |
||||
|
||||
private Task<IEnumerable<ProgramScheduleViewModel>> SearchProgramSchedules(string value) => |
||||
_programSchedules.Filter(c => c.Name.ToLowerInvariant().StartsWith(value ?? string.Empty)).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); |
||||
Logger.LogError("Unexpected error saving playout: {Error}", error.Value); |
||||
}, |
||||
() => NavigationManager.NavigateTo("/playouts")); |
||||
} |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,14 @@
@@ -0,0 +1,14 @@
|
||||
using ErsatzTV.ViewModels; |
||||
using FluentValidation; |
||||
|
||||
namespace ErsatzTV.Validators |
||||
{ |
||||
public class PlayoutEditViewModelValidator : AbstractValidator<PlayoutEditViewModel> |
||||
{ |
||||
public PlayoutEditViewModelValidator() |
||||
{ |
||||
RuleFor(p => p.Channel).NotNull(); |
||||
RuleFor(p => p.ProgramSchedule).NotNull(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
using ErsatzTV.Application.Channels; |
||||
using ErsatzTV.Application.Playouts.Commands; |
||||
using ErsatzTV.Application.ProgramSchedules; |
||||
using ErsatzTV.Core.Domain; |
||||
|
||||
namespace ErsatzTV.ViewModels |
||||
{ |
||||
public class PlayoutEditViewModel |
||||
{ |
||||
public ChannelViewModel Channel { get; set; } |
||||
public ProgramScheduleViewModel ProgramSchedule { get; set; } |
||||
|
||||
public CreatePlayout ToCreate() => |
||||
new CreatePlayout(Channel.Id, ProgramSchedule.Id, ProgramSchedulePlayoutType.Flood); |
||||
} |
||||
} |
||||
Loading…
Reference in new issue