137 lines
6.0 KiB
Plaintext
137 lines
6.0 KiB
Plaintext
@page "/schedules/{Id:int}"
|
|
@page "/schedules/add"
|
|
@using ErsatzTV.Application.ProgramSchedules
|
|
@using ErsatzTV.Core.Scheduling
|
|
@implements IDisposable
|
|
@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">
|
|
<FluentValidationValidator/>
|
|
<MudCard>
|
|
<MudCardContent>
|
|
<MudTextField Label="Name" @bind-Value="_model.Name" For="@(() => _model.Name)"/>
|
|
<MudElement HtmlTag="div" Class="mt-3">
|
|
<MudTooltip Text="Always schedule multi-part episodes chronologically when shuffling">
|
|
<MudCheckBox Label="Keep Multi-Part Episodes Together"
|
|
@bind-Value="@_model.KeepMultiPartEpisodesTogether"
|
|
For="@(() => _model.KeepMultiPartEpisodesTogether)"/>
|
|
</MudTooltip>
|
|
</MudElement>
|
|
<MudElement HtmlTag="div" Class="mt-3">
|
|
<MudTooltip Text="This is useful for multi-part crossover episodes">
|
|
<MudCheckBox Label="Treat Collections As Shows*"
|
|
@bind-Value="@_model.TreatCollectionsAsShows"
|
|
Disabled="@(_model.KeepMultiPartEpisodesTogether == false)"
|
|
For="@(() => _model.TreatCollectionsAsShows)"/>
|
|
</MudTooltip>
|
|
</MudElement>
|
|
<MudElement HtmlTag="div" Class="mt-3">
|
|
<MudTooltip Text="Note: this disables fixed start times and flood mode">
|
|
<MudCheckBox Label="Shuffle Schedule Items"
|
|
@bind-Value="@_model.ShuffleScheduleItems"
|
|
For="@(() => _model.ShuffleScheduleItems)"/>
|
|
</MudTooltip>
|
|
</MudElement>
|
|
<MudElement HtmlTag="div" Class="mt-3">
|
|
<MudCheckBox Label="Random Start Point"
|
|
@bind-Value="@_model.RandomStartPoint"
|
|
For="@(() => _model.RandomStartPoint)"/>
|
|
</MudElement>
|
|
<MudElement HtmlTag="div" Class="mt-3">
|
|
<MudSelect Label="Fixed Start Time Behavior"
|
|
@bind-Value="@_model.FixedStartTimeBehavior"
|
|
For="@(() => _model.FixedStartTimeBehavior)">
|
|
<MudSelectItem Value="FixedStartTimeBehavior.Strict">Strict - Always Wait For Exact Start Time</MudSelectItem>
|
|
<MudSelectItem Value="FixedStartTimeBehavior.Flexible">Flexible - Start As Soon As Possible After Start Time</MudSelectItem>
|
|
</MudSelect>
|
|
</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 {
|
|
private readonly CancellationTokenSource _cts = new();
|
|
|
|
[Parameter]
|
|
public int Id { get; set; }
|
|
|
|
private readonly ProgramScheduleEditViewModel _model = new();
|
|
private EditContext _editContext;
|
|
private ValidationMessageStore _messageStore;
|
|
|
|
public void Dispose()
|
|
{
|
|
_cts.Cancel();
|
|
_cts.Dispose();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
if (IsEdit)
|
|
{
|
|
Option<ProgramScheduleViewModel> maybeProgramSchedule = await Mediator.Send(new GetProgramScheduleById(Id), _cts.Token);
|
|
maybeProgramSchedule.Match(
|
|
viewModel =>
|
|
{
|
|
_model.Id = viewModel.Id;
|
|
_model.Name = viewModel.Name;
|
|
_model.ShuffleScheduleItems = viewModel.ShuffleScheduleItems;
|
|
_model.KeepMultiPartEpisodesTogether = viewModel.KeepMultiPartEpisodesTogether;
|
|
_model.TreatCollectionsAsShows = viewModel.TreatCollectionsAsShows;
|
|
_model.RandomStartPoint = viewModel.RandomStartPoint;
|
|
_model.FixedStartTimeBehavior = viewModel.FixedStartTimeBehavior;
|
|
},
|
|
() => 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(), _cts.Token).MapT(r => r as EntityIdResult)
|
|
: await Mediator.Send(_model.ToCreate(), _cts.Token).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);
|
|
});
|
|
}
|
|
}
|
|
|
|
} |