@ -8,60 +8,64 @@
@@ -8,60 +8,64 @@
@inject ISnackbar Snackbar
@inject IMediator Mediator
<MudForm @bind-IsValid="@_success" Style="max-height: 100%">
<MudPaper Square="true" Style="display: flex; height: 64px; min-height: 64px; width: 100%; z-index: 100; align-items: center">
<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="ml-8" OnClick="HandleSubmitAsync" StartIcon="@(IsEdit ? Icons.Material.Filled.Save : Icons.Material.Filled.Add)">@(IsEdit ? "Save Schedule" : "Add Schedule")</MudButton>
</MudPaper>
<div class="d-flex flex-column" style="height: 100vh; overflow-x: auto">
<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"
<MudText Typo="Typo.h5" Class="mb-2">Schedule</MudText>
<MudDivider Class="mb-6"/>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex justify-md-end">
<MudText>Name</MudText>
</div>
<MudTextField @bind-Value="_model.Name" For="@(() => _model.Name)" Required="true" RequiredError="Schedule name is required!" />
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex justify-md-end">
<MudText>Keep Multi-Part Episodes Together</MudText>
</div>
<MudCheckBox @bind-Value="@_model.KeepMultiPartEpisodesTogether" For="@(() => _model.KeepMultiPartEpisodesTogether)" Dense="true">
<MudText Typo="Typo.caption" Style="font-weight: normal">Group multi-part episodes when shuffling</MudText>
</MudCheckBox>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex justify-md-end">
<MudText>Treat Collections As Shows</MudText>
</div>
<MudCheckBox @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>
For="@(() => _model.TreatCollectionsAsShows)" Dense="true">
<MudText Typo="Typo.caption" Style="font-weight: normal">This is useful for multi-part crossover episodes</MudText>
</MudCheckBox>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex justify-md-end">
<MudText>Shuffle Schedule Items</MudText>
</div>
<MudCheckBox @bind-Value="@_model.ShuffleScheduleItems" For="@(() => _model.ShuffleScheduleItems)" Dense="true">
<MudText Typo="Typo.caption" Style="font-weight: normal">Note: this disables fixed start times and flood mode</MudText>
</MudCheckBox>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex justify-md-end">
<MudText>Random Start Point</MudText>
</div>
<MudCheckBox @bind-Value="@_model.RandomStartPoint" For="@(() => _model.RandomStartPoint)" Dense="true" />
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex justify-md-end">
<MudText>Fixed Start Time Behavior</MudText>
</div>
<MudSelect @bind-Value="@_model.FixedStartTimeBehavior" For="@(() => _model.FixedStartTimeBehavior)">
<MudSelectItem Value="FixedStartTimeBehavior.Strict">Strict - Wait For Exact Start Time</MudSelectItem>
<MudSelectItem Value="FixedStartTimeBehavior.Flexible">Flexible - Start As Soon As Possible</MudSelectItem>
</MudSelect>
</MudStack>
</MudContainer>
</div>
</MudForm>
@code {
private readonly CancellationTokenSource _cts = new();
@ -70,8 +74,7 @@
@@ -70,8 +74,7 @@
public int Id { get; set; }
private readonly ProgramScheduleEditViewModel _model = new();
private EditContext _editContext;
private ValidationMessageStore _messageStore;
private bool _success;
public void Dispose()
{
@ -103,18 +106,11 @@
@@ -103,18 +106,11 @@
}
}
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())
if (_success)
{
Either<BaseError, EntityIdResult> result = IsEdit
? await Mediator.Send(_model.ToUpdate(), _cts.Token).MapT(r => r as EntityIdResult)