@page "/channels" @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 @inject IDialogService _dialog @inject IMediator _mediator Channels Number Logo Name Language Mode FFmpeg Profile @context.Number @if (!string.IsNullOrWhiteSpace(context.Logo)) { } @context.Name @context.PreferredLanguageCode @GetStreamingMode(context.StreamingMode) @if (context.StreamingMode != StreamingMode.HttpLiveStreamingDirect) { @_ffmpegProfiles.Find(p => p.Id == context.FFmpegProfileId)?.Name }
Add Channel
@code { private MudTable _table; private List _ffmpegProfiles; private int _rowsPerPage; protected override async Task OnParametersSetAsync() { _ffmpegProfiles = await _mediator.Send(new GetAllFFmpegProfiles()); _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) { var parameters = new DialogParameters { { "EntityType", "channel" }, { "EntityName", channel.Name } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = _dialog.Show("Delete Channel", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled) { await _mediator.Send(new DeleteChannel(channel.Id)); await _table.ReloadServerData(); } } private async Task> ServerReload(TableState state) { await _mediator.Send(new SaveConfigElementByKey(ConfigElementKey.ChannelsPageSize, state.PageSize.ToString())); List channels = await _mediator.Send(new GetAllChannels()); IOrderedEnumerable sorted = channels.OrderBy(c => decimal.Parse(c.Number)); CultureInfo[] allCultures = CultureInfo.GetCultures(CultureTypes.NeutralCultures); var processedChannels = new List(); foreach (ChannelViewModel channel in sorted) { Option maybeCultureInfo = allCultures.Find( ci => string.Equals( ci.ThreeLetterISOLanguageName, channel.PreferredLanguageCode, StringComparison.OrdinalIgnoreCase)); maybeCultureInfo.Match( cultureInfo => processedChannels.Add(channel with { PreferredLanguageCode = cultureInfo.EnglishName }), () => processedChannels.Add(channel)); } // TODO: properly page this data return new TableData { TotalItems = channels.Count, Items = processedChannels.Skip(state.Page * state.PageSize).Take(state.PageSize) }; } private static string GetStreamingMode(StreamingMode streamingMode) => streamingMode switch { StreamingMode.HttpLiveStreamingDirect => "HLS Direct", StreamingMode.HttpLiveStreamingSegmenter => "HLS Segmenter", StreamingMode.TransportStreamHybrid => "MPEG-TS", _ => "MPEG-TS (Legacy)" }; }