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.
132 lines
4.8 KiB
132 lines
4.8 KiB
@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.Yaml: |
|
<span>Add YAML 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.Yaml: |
|
<MudTextField Label="YAML File" @bind-Value="_model.YamlFile" For="@(() => _model.YamlFile)"/> |
|
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")); |
|
} |
|
} |
|
|
|
} |