@page "/playouts" @using ErsatzTV.Application.Playouts @using ErsatzTV.Application.Playouts.Commands @using ErsatzTV.Application.Playouts.Queries @using ErsatzTV.Application.Configuration.Commands @using ErsatzTV.Application.Configuration.Queries @inject IDialogService _dialog @inject IMediator _mediator Playouts Channel Schedule @* Playout Type *@ @context.ChannelNumber - @context.ChannelName @context.ScheduleName @* @context.ProgramSchedulePlayoutType *@
Add Playout @if (_selectedPlayoutId != null) { Playout Detail Start Media Item Duration @context.Start.ToString("G") @context.Title @context.Duration }
@code { private MudTable _table; private MudTable _detailTable; private int _rowsPerPage; private int _detailRowsPerPage; private int? _selectedPlayoutId; protected override async Task OnParametersSetAsync() { _rowsPerPage = await _mediator.Send(new GetConfigElementByKey(ConfigElementKey.PlayoutsPageSize)) .Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10)); _detailRowsPerPage = await _mediator.Send(new GetConfigElementByKey(ConfigElementKey.PlayoutsDetailPageSize)) .Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10)); } private async Task PlayoutSelected(PlayoutNameViewModel playout) { _selectedPlayoutId = playout.PlayoutId; await _detailTable.ReloadServerData(); } private async Task DeletePlayout(PlayoutNameViewModel playout) { var parameters = new DialogParameters { { "EntityType", "playout" }, { "EntityName", $"{playout.ScheduleName} on {playout.ChannelNumber} - {playout.ChannelName}" } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = _dialog.Show("Delete Playout", parameters, options); DialogResult result = await dialog.Result; if (!result.Cancelled) { await _mediator.Send(new DeletePlayout(playout.PlayoutId)); await _table.ReloadServerData(); if (_selectedPlayoutId == playout.PlayoutId) { _selectedPlayoutId = null; } } } private async Task RebuildPlayout(PlayoutNameViewModel playout) { await _mediator.Send(new BuildPlayout(playout.PlayoutId, true)); await _table.ReloadServerData(); if (_selectedPlayoutId == playout.PlayoutId) { await PlayoutSelected(playout); } } private async Task ScheduleRebuild(PlayoutNameViewModel playout) { var parameters = new DialogParameters { { "PlayoutId", playout.PlayoutId }, { "ChannelName", playout.ChannelName }, { "ScheduleName", playout.ScheduleName }, { "DailyRebuildTime", playout.DailyRebuildTime } }; var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; IDialogReference dialog = _dialog.Show("Schedule Playout Rebuild", parameters, options); await dialog.Result; } private async Task> ServerReload(TableState state) { await _mediator.Send(new SaveConfigElementByKey(ConfigElementKey.PlayoutsPageSize, state.PageSize.ToString())); List playouts = await _mediator.Send(new GetAllPlayouts()); IOrderedEnumerable sorted = playouts.OrderBy(p => decimal.Parse(p.ChannelNumber)); // TODO: properly page this data return new TableData { TotalItems = playouts.Count, Items = sorted.Skip(state.Page * state.PageSize).Take(state.PageSize) }; } private async Task> DetailServerReload(TableState state) { await _mediator.Send(new SaveConfigElementByKey(ConfigElementKey.PlayoutsDetailPageSize, state.PageSize.ToString())); if (_selectedPlayoutId.HasValue) { PagedPlayoutItemsViewModel data = await _mediator.Send(new GetPlayoutItemsById(_selectedPlayoutId.Value, state.Page, state.PageSize)); return new TableData { TotalItems = data.TotalCount, Items = data.Page }; } return new TableData { TotalItems = 0 }; } }