Stream custom live channels using your own media
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.
 
 

104 lines
4.0 KiB

@page "/schedules/{Id:int}"
@page "/schedules/add"
@using ErsatzTV.Application.ProgramSchedules
@using ErsatzTV.Application.ProgramSchedules.Queries
@inject NavigationManager _navigationManager
@inject ILogger<ScheduleEditor> _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">@(IsEdit ? "Edit Schedule" : "Add Schedule")</MudText>
<EditForm EditContext="_editContext" OnSubmit="@HandleSubmitAsync">
<FluentValidator/>
<MudCard>
<MudCardContent>
<MudTextField Label="Name" @bind-Value="_model.Name" For="@(() => _model.Name)"/>
<MudElement HtmlTag="div" Class="mt-3">
<MudCheckBox Label="Keep Multi-Part Episodes Together"
@bind-Checked="@_model.KeepMultiPartEpisodesTogether"
For="@(() => _model.KeepMultiPartEpisodesTogether)"/>
</MudElement>
<MudElement HtmlTag="div" Class="mt-3">
<MudTooltip Text="This is useful for multi-part crossover episodes">
<MudCheckBox Label="Treat Collections As Shows*"
@bind-Checked="@_model.TreatCollectionsAsShows"
Disabled="@(_model.KeepMultiPartEpisodesTogether == false)"
For="@(() => _model.TreatCollectionsAsShows)"/>
</MudTooltip>
</MudElement>
</MudCardContent>
<MudCardActions>
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Primary">
@(IsEdit ? "Save Changes" : "Add Schedule")
</MudButton>
</MudCardActions>
</MudCard>
</EditForm>
</div>
</MudContainer>
@code {
[Parameter]
public int Id { get; set; }
private readonly ProgramScheduleEditViewModel _model = new();
private EditContext _editContext;
private ValidationMessageStore _messageStore;
protected override async Task OnParametersSetAsync()
{
if (IsEdit)
{
Option<ProgramScheduleViewModel> maybeProgramSchedule = await _mediator.Send(new GetProgramScheduleById(Id));
maybeProgramSchedule.Match(
viewModel =>
{
_model.Id = viewModel.Id;
_model.Name = viewModel.Name;
_model.KeepMultiPartEpisodesTogether = viewModel.KeepMultiPartEpisodesTogether;
_model.TreatCollectionsAsShows = viewModel.TreatCollectionsAsShows;
},
() => _navigationManager.NavigateTo("404"));
}
else
{
_model.Name = "New Schedule";
}
}
protected override void OnInitialized()
{
_editContext = new EditContext(_model);
_messageStore = new ValidationMessageStore(_editContext);
}
private bool IsEdit => Id > 0;
private async Task HandleSubmitAsync()
{
_messageStore.Clear();
if (_editContext.Validate())
{
Either<BaseError, EntityIdResult> result = IsEdit ?
await _mediator.Send(_model.ToUpdate()).MapT(r => r as EntityIdResult) :
await _mediator.Send(_model.ToCreate()).MapT(r => r as EntityIdResult);
result.Match(
programSchedule =>
{
string destination = IsEdit ? "/schedules" : $"/schedules/{programSchedule.Id}/items";
_navigationManager.NavigateTo(destination);
},
error =>
{
_snackbar.Add(error.Value, Severity.Error);
_logger.LogError("Unexpected error saving schedule: {Error}", error.Value);
});
}
}
}