Browse Source

save channels table page size (#244)

* save channel table page size

* update changelog
pull/245/head
Jason Dove 5 years ago committed by GitHub
parent
commit
10c422a3eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      CHANGELOG.md
  2. 1
      ErsatzTV.Core/Domain/ConfigElementKey.cs
  3. 33
      ErsatzTV/Pages/Channels.razor

1
CHANGELOG.md

@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- Support `(Part #)` name suffixes for multi-part episode grouping
- Support multi-episode files in local libraries
- Save Channels table page size
### Fixed
- Fix search result crashes due to missing season metadata

1
ErsatzTV.Core/Domain/ConfigElementKey.cs

@ -14,6 +14,7 @@ @@ -14,6 +14,7 @@
public static ConfigElementKey FFmpegPreferredLanguageCode => new("ffmpeg.preferred_language_code");
public static ConfigElementKey SearchIndexVersion => new("search_index.version");
public static ConfigElementKey HDHRTunerCount => new("hdhr.tuner_count");
public static ConfigElementKey ChannelsPageSize => new("pages.channels.page_size");
public static ConfigElementKey CollectionsPageSize => new("pages.collections.page_size");
public static ConfigElementKey LibraryRefreshInterval => new("scanner.library_refresh_interval");
}

33
ErsatzTV/Pages/Channels.razor

@ -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);
_channels = new List<ChannelViewModel>();
var processedChannels = 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 => _channels.Add(channel with { PreferredLanguageCode = cultureInfo.EnglishName }),
() => _channels.Add(channel));
cultureInfo => processedChannels.Add(channel with { PreferredLanguageCode = cultureInfo.EnglishName }),
() => processedChannels.Add(channel));
}
// TODO: properly page this data
return new TableData<ChannelViewModel>
{
TotalItems = channels.Count,
Items = processedChannels.Skip(state.Page * state.PageSize).Take(state.PageSize)
};
}
}
Loading…
Cancel
Save