@page "/media/rerun-collections"
@using ErsatzTV.Application.Configuration
@using ErsatzTV.Application.MediaCollections
@implements IDisposable
@inject IDialogService Dialog
@inject IMediator Mediator
Rerun Collections
@context.Name
@code {
private CancellationTokenSource _cts;
private MudTable _rerunCollectionsTable;
private int _rerunCollectionsRowsPerPage = 10;
private string _searchString;
public void Dispose()
{
_cts?.Cancel();
_cts?.Dispose();
}
protected override async Task OnParametersSetAsync()
{
_cts?.Cancel();
_cts?.Dispose();
_cts = new CancellationTokenSource();
var token = _cts.Token;
try
{
_rerunCollectionsRowsPerPage = await Mediator.Send(new GetConfigElementByKey(ConfigElementKey.RerunCollectionsPageSize), token)
.Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10));
}
catch (OperationCanceledException)
{
// do nothing
}
}
private async Task DeleteRerunCollection(RerunCollectionViewModel collection)
{
var parameters = new DialogParameters { { "EntityType", "rerun collection" }, { "EntityName", collection.Name } };
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall };
IDialogReference dialog = await Dialog.ShowAsync("Delete Rerun Collection", parameters, options);
DialogResult result = await dialog.Result;
if (result is { Canceled: false })
{
await Mediator.Send(new DeleteRerunCollection(collection.Id), _cts.Token);
if (_rerunCollectionsTable != null)
{
await _rerunCollectionsTable.ReloadServerData();
}
}
}
private async Task> ServerReloadRerunCollections(TableState state, CancellationToken cancellationToken)
{
await Mediator.Send(new SaveConfigElementByKey(ConfigElementKey.RerunCollectionsPageSize, state.PageSize.ToString()), cancellationToken);
PagedRerunCollectionsViewModel data = await Mediator.Send(new GetPagedRerunCollections(_searchString, state.Page, state.PageSize), cancellationToken);
return new TableData { TotalItems = data.TotalCount, Items = data.Page };
}
private void OnSearch(string query)
{
_searchString = query;
_rerunCollectionsTable.ReloadServerData();
}
}