@ -2,6 +2,8 @@
@@ -2,6 +2,8 @@
@using ErsatzTV.Application.Channels
@using ErsatzTV.Application.Channels.Commands
@using ErsatzTV.Application.Channels.Queries
@using ErsatzTV.Application.Configuration.Commands
@using ErsatzTV.Application.Configuration.Queries
@using ErsatzTV.Application.FFmpegProfiles
@using ErsatzTV.Application.FFmpegProfiles.Queries
@using System.Globalization
@ -9,7 +11,10 @@
@@ -9,7 +11,10 @@
@inject IMediator _mediator
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
<MudTable Hover="true" Items="_channels">
<MudTable Hover="true"
@bind-RowsPerPage="@_rowsPerPage"
ServerData="@(new Func<TableState, Task<TableData<ChannelViewModel>>>(ServerReload))"
@ref="_table">
<ToolBarContent>
<MudText Typo="Typo.h6">Channels</MudText>
</ToolBarContent>
@ -77,13 +82,16 @@
@@ -77,13 +82,16 @@
</MudContainer>
@code {
private List<ChannelViewModel> _channels ;
private MudTable<ChannelViewModel> _table ;
private List<FFmpegProfileViewModel> _ffmpegProfiles;
private int _rowsPerPage;
protected override async Task OnParametersSetAsync()
{
_ffmpegProfiles = await _mediator.Send(new GetAllFFmpegProfiles());
await LoadChannelsAsync();
_rowsPerPage = await _mediator.Send(new GetConfigElementByKey(ConfigElementKey.ChannelsPageSize))
.Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10));
}
private async Task DeleteChannelAsync(ChannelViewModel channel)
@ -96,17 +104,19 @@
@@ -96,17 +104,19 @@
if (!result.Cancelled)
{
await _mediator.Send(new DeleteChannel(channel.Id));
await LoadChannelsAsync ();
await _table.ReloadServerData ();
}
}
private async Task LoadChannelsAsync( )
private async Task<TableData<ChannelViewModel>> ServerReload(TableState state )
{
await _mediator.Send(new SaveConfigElementByKey(ConfigElementKey.ChannelsPageSize, state.PageSize.ToString()));
List<ChannelViewModel> channels = await _mediator.Send(new GetAllChannels());
IOrderedEnumerable<ChannelViewModel> sorted = channels.OrderBy(c => decimal.Parse(c.Number));
CultureInfo[] allCultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures);
_c hannels = new List<ChannelViewModel>();
var processedC hannels = new List<ChannelViewModel>();
foreach (ChannelViewModel channel in sorted)
{
Option<CultureInfo> maybeCultureInfo = allCultures.Find(
@ -116,9 +126,16 @@
@@ -116,9 +126,16 @@
StringComparison.OrdinalIgnoreCase));
maybeCultureInfo.Match(
cultureInfo => _c hannels.Add(channel with { PreferredLanguageCode = cultureInfo.EnglishName }),
() => _c hannels.Add(channel));
cultureInfo => processedC hannels.Add(channel with { PreferredLanguageCode = cultureInfo.EnglishName }),
() => processedC hannels.Add(channel));
}
// TODO: properly page this data
return new TableData<ChannelViewModel>
{
TotalItems = channels.Count,
Items = processedChannels.Skip(state.Page * state.PageSize).Take(state.PageSize)
};
}
}