* add template playout kind * add template scheduler count * implement pad to next * only allow resetting template playouts * update changelog
408 lines
18 KiB
Plaintext
408 lines
18 KiB
Plaintext
@page "/playouts"
|
|
@using ErsatzTV.Application.Configuration
|
|
@using ErsatzTV.Application.Playouts
|
|
@using ErsatzTV.Core.Scheduling
|
|
@implements IDisposable
|
|
@inject IDialogService Dialog
|
|
@inject IMediator Mediator
|
|
@inject ChannelWriter<IBackgroundServiceRequest> WorkerChannel
|
|
@inject IEntityLocker EntityLocker;
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<div>
|
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Href="playouts/add">
|
|
Add Playout
|
|
</MudButton>
|
|
<MudTooltip Text="This feature is experimental">
|
|
<MudButton Class="ml-3" Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Warning" Href="@($"playouts/add/{PlayoutKind.Block}")">
|
|
Add Block Playout
|
|
</MudButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="This feature is experimental">
|
|
<MudButton Class="ml-3" Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Warning" Href="@($"playouts/add/{PlayoutKind.Template}")">
|
|
Add Template Playout
|
|
</MudButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="This feature is experimental">
|
|
<MudButton Class="ml-3" Variant="Variant.Filled" Color="Color.Primary" StartIcon="@Icons.Material.Filled.Warning" Href="@($"playouts/add/{PlayoutKind.ExternalJson}")">
|
|
Add External Json Playout
|
|
</MudButton>
|
|
</MudTooltip>
|
|
</div>
|
|
<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/>
|
|
<col style="width: 225px;"/>
|
|
</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">
|
|
@switch (context.PlayoutType)
|
|
{
|
|
case ProgramSchedulePlayoutType.Block:
|
|
<span>Block</span>
|
|
break;
|
|
case ProgramSchedulePlayoutType.Template:
|
|
<span>Template</span>
|
|
break;
|
|
case ProgramSchedulePlayoutType.ExternalJson:
|
|
<span>External Json</span>
|
|
break;
|
|
default:
|
|
<span></span>
|
|
break;
|
|
}
|
|
</MudTd>
|
|
<MudTd>
|
|
<div style="align-items: center; display: flex;">
|
|
<div style="align-items: center; display: flex; height: 48px; justify-content: center; width: 48px;">
|
|
@if (EntityLocker.IsPlayoutLocked(context.PlayoutId))
|
|
{
|
|
<MudProgressCircular Color="Color.Primary" Size="Size.Small" Indeterminate="true"/>
|
|
}
|
|
</div>
|
|
@if (context.PlayoutType == ProgramSchedulePlayoutType.Flood)
|
|
{
|
|
if (context.ProgressMode is ChannelProgressMode.OnDemand)
|
|
{
|
|
<MudTooltip Text="Alternate Schedules are not supported with On Demand progress">
|
|
<MudIconButton Icon="@Icons.Material.Filled.EditCalendar"
|
|
Disabled="true">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
}
|
|
else
|
|
{
|
|
<MudTooltip Text="Edit Alternate Schedules">
|
|
<MudIconButton Icon="@Icons.Material.Filled.EditCalendar"
|
|
Disabled="@EntityLocker.IsPlayoutLocked(context.PlayoutId)"
|
|
Href="@($"playouts/{context.PlayoutId}/alternate-schedules")">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
}
|
|
|
|
<MudTooltip Text="Reset Playout">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh"
|
|
Disabled="@EntityLocker.IsPlayoutLocked(context.PlayoutId)"
|
|
OnClick="@(_ => ResetPlayout(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Schedule Reset">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Update"
|
|
Disabled="@EntityLocker.IsPlayoutLocked(context.PlayoutId)"
|
|
OnClick="@(_ => ScheduleReset(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
}
|
|
else if (context.PlayoutType == ProgramSchedulePlayoutType.ExternalJson)
|
|
{
|
|
<MudTooltip Text="Edit External Json File">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit"
|
|
Disabled="@EntityLocker.IsPlayoutLocked(context.PlayoutId)"
|
|
OnClick="@(_ => EditExternalJsonFile(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<div style="width: 48px"></div>
|
|
<div style="width: 48px"></div>
|
|
}
|
|
else if (context.PlayoutType == ProgramSchedulePlayoutType.Template)
|
|
{
|
|
<MudTooltip Text="Edit Template File">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit"
|
|
Disabled="@EntityLocker.IsPlayoutLocked(context.PlayoutId)"
|
|
OnClick="@(_ => EditTemplateFile(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Reset Playout">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh"
|
|
Disabled="@EntityLocker.IsPlayoutLocked(context.PlayoutId)"
|
|
OnClick="@(_ => ResetPlayout(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<div style="width: 48px"></div>
|
|
}
|
|
else if (context.PlayoutType == ProgramSchedulePlayoutType.Block)
|
|
{
|
|
<MudTooltip Text="Edit Playout">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit"
|
|
Disabled="@EntityLocker.IsPlayoutLocked(context.PlayoutId)"
|
|
Href="@($"playouts/block/{context.PlayoutId}")">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Reset Playout">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh"
|
|
Disabled="@EntityLocker.IsPlayoutLocked(context.PlayoutId)"
|
|
OnClick="@(_ => ResetPlayout(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<div style="width: 48px"></div>
|
|
}
|
|
<MudTooltip Text="Delete Playout">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Delete"
|
|
Disabled="@EntityLocker.IsPlayoutLocked(context.PlayoutId)"
|
|
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-Value="@ShowFiller" Color="Color.Secondary" Label="Show Filler"/>
|
|
</ToolBarContent>
|
|
<HeaderContent>
|
|
<MudTh>Start</MudTh>
|
|
<MudTh>Finish</MudTh>
|
|
<MudTh>Media Item</MudTh>
|
|
<MudTh>Duration</MudTh>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Start">@context.Start.ToString("G")</MudTd>
|
|
<MudTd DataLabel="Finish">@context.Finish.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 = 10;
|
|
private int _detailRowsPerPage = 10;
|
|
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()
|
|
{
|
|
EntityLocker.OnPlayoutChanged -= ReloadDetailsIfNeeded;
|
|
|
|
_cts.Cancel();
|
|
_cts.Dispose();
|
|
}
|
|
|
|
protected override void OnInitialized() => EntityLocker.OnPlayoutChanged += ReloadDetailsIfNeeded;
|
|
|
|
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)
|
|
{
|
|
// only show details for flood, block and template playouts
|
|
_selectedPlayoutId = playout.PlayoutType is ProgramSchedulePlayoutType.Flood or ProgramSchedulePlayoutType.Block or ProgramSchedulePlayoutType.Template
|
|
? playout.PlayoutId
|
|
: null;
|
|
|
|
if (_detailTable != null)
|
|
{
|
|
await _detailTable.ReloadServerData();
|
|
}
|
|
}
|
|
|
|
private async Task EditExternalJsonFile(PlayoutNameViewModel playout)
|
|
{
|
|
var parameters = new DialogParameters { { "ExternalJsonFile", $"{playout.ExternalJsonFile}" } };
|
|
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraLarge };
|
|
|
|
IDialogReference dialog = await Dialog.ShowAsync<EditExternalJsonFileDialog>("Edit External Json File", parameters, options);
|
|
DialogResult result = await dialog.Result;
|
|
if (!result.Canceled)
|
|
{
|
|
await Mediator.Send(new UpdateExternalJsonPlayout(playout.PlayoutId, result.Data as string ?? playout.ExternalJsonFile), _cts.Token);
|
|
if (_table != null)
|
|
{
|
|
await _table.ReloadServerData();
|
|
}
|
|
|
|
_selectedPlayoutId = null;
|
|
}
|
|
}
|
|
|
|
private async Task EditTemplateFile(PlayoutNameViewModel playout)
|
|
{
|
|
var parameters = new DialogParameters { { "TemplateFile", $"{playout.TemplateFile}" } };
|
|
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraLarge };
|
|
|
|
IDialogReference dialog = await Dialog.ShowAsync<EditTemplateFileDialog>("Edit Template File", parameters, options);
|
|
DialogResult result = await dialog.Result;
|
|
if (!result.Canceled)
|
|
{
|
|
await Mediator.Send(new UpdateTemplatePlayout(playout.PlayoutId, result.Data as string ?? playout.TemplateFile), _cts.Token);
|
|
if (_table != null)
|
|
{
|
|
await _table.ReloadServerData();
|
|
}
|
|
|
|
_selectedPlayoutId = null;
|
|
}
|
|
}
|
|
|
|
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 void ReloadDetailsIfNeeded(object sender, int playoutId)
|
|
{
|
|
if (playoutId == _selectedPlayoutId && _detailTable is not null)
|
|
{
|
|
await InvokeAsync(() => _detailTable.ReloadServerData());
|
|
}
|
|
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
|
|
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 };
|
|
}
|
|
|
|
} |