245 lines
9.6 KiB
Plaintext
245 lines
9.6 KiB
Plaintext
@page "/playouts"
|
|
@using ErsatzTV.Application.Playouts
|
|
@using ErsatzTV.Application.Configuration
|
|
@using ErsatzTV.Core.Scheduling
|
|
@implements IDisposable
|
|
@inject IDialogService _dialog
|
|
@inject IMediator _mediator
|
|
@inject ChannelWriter<IBackgroundServiceRequest> WorkerChannel;
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Link="playouts/add">
|
|
Add Playout
|
|
</MudButton>
|
|
<MudTable Hover="true"
|
|
Dense="true"
|
|
Class="mt-4"
|
|
SelectedItemChanged="@(async (PlayoutNameViewModel x) => await PlayoutSelected(x))"
|
|
@bind-RowsPerPage="@_rowsPerPage"
|
|
ServerData="@(new Func<TableState, Task<TableData<PlayoutNameViewModel>>>(ServerReload))"
|
|
@ref="_table">
|
|
<ToolBarContent>
|
|
<MudText Typo="Typo.h6">Playouts</MudText>
|
|
</ToolBarContent>
|
|
<ColGroup>
|
|
<col/>
|
|
<col/>
|
|
<col style="width: 180px;"/>
|
|
</ColGroup>
|
|
<HeaderContent>
|
|
<MudTh>
|
|
<MudTableSortLabel SortBy="new Func<PlayoutViewModel, object>(x => decimal.Parse(x.Channel.Number))">
|
|
Channel
|
|
</MudTableSortLabel>
|
|
</MudTh>
|
|
<MudTh>
|
|
<MudTableSortLabel SortBy="new Func<PlayoutViewModel, object>(x => x.ProgramSchedule.Name)">
|
|
Default Schedule
|
|
</MudTableSortLabel>
|
|
</MudTh>
|
|
@* <MudTh>Playout Type</MudTh> *@
|
|
<MudTh/>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Channel">@context.ChannelNumber - @context.ChannelName</MudTd>
|
|
<MudTd DataLabel="Schedule">@context.ScheduleName</MudTd>
|
|
@* <MudTd DataLabel="Playout Type">@context.ProgramSchedulePlayoutType</MudTd> *@
|
|
<MudTd>
|
|
<div style="align-items: center; display: flex;">
|
|
<MudTooltip Text="Edit Alternate Schedules">
|
|
<MudIconButton Icon="@Icons.Material.Filled.EditCalendar"
|
|
Link="@($"playouts/{context.PlayoutId}/alternate-schedules")">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Reset Playout">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh"
|
|
OnClick="@(_ => ResetPlayout(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Schedule Reset">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Update"
|
|
OnClick="@(_ => ScheduleReset(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Delete Playout">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
|
OnClick="@(_ => DeletePlayout(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
</div>
|
|
</MudTd>
|
|
</RowTemplate>
|
|
<PagerContent>
|
|
<MudTablePager/>
|
|
</PagerContent>
|
|
</MudTable>
|
|
|
|
@if (_selectedPlayoutId != null)
|
|
{
|
|
<MudTable Class="mt-8"
|
|
Hover="true"
|
|
Dense="true"
|
|
@bind-RowsPerPage="@_detailRowsPerPage"
|
|
ServerData="@(new Func<TableState, Task<TableData<PlayoutItemViewModel>>>(DetailServerReload))"
|
|
@ref="_detailTable">
|
|
<ToolBarContent>
|
|
<MudText Typo="Typo.h6">Playout Detail</MudText>
|
|
<MudSwitch T="bool" Class="ml-6" @bind-Checked="@ShowFiller" Color="Color.Secondary" Label="Show Filler"/>
|
|
</ToolBarContent>
|
|
<HeaderContent>
|
|
<MudTh>Start</MudTh>
|
|
<MudTh>Media Item</MudTh>
|
|
<MudTh>Duration</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Start">@context.Start.ToString("G")</MudTd>
|
|
<MudTd DataLabel="Media Item">@context.Title</MudTd>
|
|
<MudTd DataLabel="Duration">@context.Duration</MudTd>
|
|
</RowTemplate>
|
|
<PagerContent>
|
|
<MudTablePager/>
|
|
</PagerContent>
|
|
</MudTable>
|
|
}
|
|
</MudContainer>
|
|
|
|
@code {
|
|
private readonly CancellationTokenSource _cts = new();
|
|
|
|
private MudTable<PlayoutNameViewModel> _table;
|
|
private MudTable<PlayoutItemViewModel> _detailTable;
|
|
private int _rowsPerPage;
|
|
private int _detailRowsPerPage;
|
|
private int? _selectedPlayoutId;
|
|
private bool _showFiller;
|
|
|
|
private bool ShowFiller
|
|
{
|
|
get => _showFiller;
|
|
set
|
|
{
|
|
if (_showFiller != value)
|
|
{
|
|
_showFiller = value;
|
|
if (_detailTable != null && _selectedPlayoutId != null)
|
|
{
|
|
_detailTable.ReloadServerData();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
_cts.Cancel();
|
|
_cts.Dispose();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
_rowsPerPage = await _mediator.Send(new GetConfigElementByKey(ConfigElementKey.PlayoutsPageSize), _cts.Token)
|
|
.Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10));
|
|
_detailRowsPerPage = await _mediator.Send(new GetConfigElementByKey(ConfigElementKey.PlayoutsDetailPageSize), _cts.Token)
|
|
.Map(maybeRows => maybeRows.Match(ce => int.TryParse(ce.Value, out int rows) ? rows : 10, () => 10));
|
|
_showFiller = await _mediator.Send(new GetConfigElementByKey(ConfigElementKey.PlayoutsDetailShowFiller), _cts.Token)
|
|
.Map(maybeShow => maybeShow.Match(ce => bool.TryParse(ce.Value, out bool show) && show, () => false));
|
|
}
|
|
|
|
private async Task PlayoutSelected(PlayoutNameViewModel playout)
|
|
{
|
|
_selectedPlayoutId = playout.PlayoutId;
|
|
if (_detailTable != null)
|
|
{
|
|
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 = await _dialog.ShowAsync<DeleteDialog>("Delete Playout", parameters, options);
|
|
DialogResult result = await dialog.Result;
|
|
if (!result.Canceled)
|
|
{
|
|
await _mediator.Send(new DeletePlayout(playout.PlayoutId), _cts.Token);
|
|
if (_table != null)
|
|
{
|
|
await _table.ReloadServerData();
|
|
}
|
|
if (_selectedPlayoutId == playout.PlayoutId)
|
|
{
|
|
_selectedPlayoutId = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task ResetPlayout(PlayoutNameViewModel playout)
|
|
{
|
|
await WorkerChannel.WriteAsync(new BuildPlayout(playout.PlayoutId, PlayoutBuildMode.Reset), _cts.Token);
|
|
if (_table != null)
|
|
{
|
|
await _table.ReloadServerData();
|
|
}
|
|
if (_selectedPlayoutId == playout.PlayoutId)
|
|
{
|
|
await PlayoutSelected(playout);
|
|
}
|
|
}
|
|
|
|
private async Task ScheduleReset(PlayoutNameViewModel playout)
|
|
{
|
|
var parameters = new DialogParameters
|
|
{
|
|
{ "PlayoutId", playout.PlayoutId },
|
|
{ "ChannelName", playout.ChannelName },
|
|
{ "ScheduleName", playout.ScheduleName },
|
|
{ "DailyResetTime", playout.DailyRebuildTime }
|
|
};
|
|
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall };
|
|
|
|
IDialogReference dialog = await _dialog.ShowAsync<SchedulePlayoutReset>("Schedule Playout Reset", parameters, options);
|
|
await dialog.Result;
|
|
|
|
if (_table != null)
|
|
{
|
|
await _table.ReloadServerData();
|
|
}
|
|
}
|
|
|
|
private async Task<TableData<PlayoutNameViewModel>> ServerReload(TableState state)
|
|
{
|
|
await _mediator.Send(new SaveConfigElementByKey(ConfigElementKey.PlayoutsPageSize, state.PageSize.ToString()), _cts.Token);
|
|
|
|
List<PlayoutNameViewModel> playouts = await _mediator.Send(new GetAllPlayouts(), _cts.Token);
|
|
IOrderedEnumerable<PlayoutNameViewModel> sorted = playouts.OrderBy(p => decimal.Parse(p.ChannelNumber));
|
|
|
|
// TODO: properly page this data
|
|
return new TableData<PlayoutNameViewModel>
|
|
{
|
|
TotalItems = playouts.Count,
|
|
Items = sorted.Skip(state.Page * state.PageSize).Take(state.PageSize)
|
|
};
|
|
}
|
|
|
|
private async Task<TableData<PlayoutItemViewModel>> DetailServerReload(TableState state)
|
|
{
|
|
await _mediator.Send(new SaveConfigElementByKey(ConfigElementKey.PlayoutsDetailPageSize, state.PageSize.ToString()), _cts.Token);
|
|
await _mediator.Send(new SaveConfigElementByKey(ConfigElementKey.PlayoutsDetailShowFiller, _showFiller.ToString()), _cts.Token);
|
|
|
|
if (_selectedPlayoutId.HasValue)
|
|
{
|
|
PagedPlayoutItemsViewModel data =
|
|
await _mediator.Send(new GetFuturePlayoutItemsById(_selectedPlayoutId.Value, _showFiller, state.Page, state.PageSize), _cts.Token);
|
|
return new TableData<PlayoutItemViewModel>
|
|
{
|
|
TotalItems = data.TotalCount,
|
|
Items = data.Page
|
|
};
|
|
}
|
|
|
|
return new TableData<PlayoutItemViewModel> { TotalItems = 0 };
|
|
}
|
|
|
|
} |