Browse Source

add button to reset all playouts (#1927)

pull/1928/head
Jason Dove 9 months ago committed by GitHub
parent
commit
c0a14ba81c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 3
      CHANGELOG.md
  2. 3
      ErsatzTV.Application/Playouts/Commands/ResetAllPlayouts.cs
  3. 40
      ErsatzTV.Application/Playouts/Commands/ResetAllPlayoutsHandler.cs
  4. 13
      ErsatzTV/Pages/Playouts.razor

3
CHANGELOG.md

@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
## [Unreleased] ## [Unreleased]
### Added
- Add `Reset All Playouts` button to top of playouts page
### Changed ### Changed
- **BREAKING CHANGE**: Change channel identifiers used in XMLTV to work around bad behavior in Plex - **BREAKING CHANGE**: Change channel identifiers used in XMLTV to work around bad behavior in Plex

3
ErsatzTV.Application/Playouts/Commands/ResetAllPlayouts.cs

@ -0,0 +1,3 @@
namespace ErsatzTV.Application.Playouts;
public record ResetAllPlayouts : IRequest;

40
ErsatzTV.Application/Playouts/Commands/ResetAllPlayoutsHandler.cs

@ -0,0 +1,40 @@
using System.Threading.Channels;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Interfaces.Locking;
using ErsatzTV.Core.Scheduling;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace ErsatzTV.Application.Playouts;
public class ResetAllPlayoutsHandler(
IEntityLocker locker,
ChannelWriter<IBackgroundServiceRequest> channel,
IDbContextFactory<TvContext> dbContextFactory)
: IRequestHandler<ResetAllPlayouts>
{
public async Task Handle(ResetAllPlayouts request, CancellationToken cancellationToken)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
foreach (Playout playout in await dbContext.Playouts.ToListAsync(cancellationToken))
{
switch (playout.ProgramSchedulePlayoutType)
{
case ProgramSchedulePlayoutType.Flood:
case ProgramSchedulePlayoutType.Block:
case ProgramSchedulePlayoutType.Yaml:
if (!locker.IsPlayoutLocked(playout.Id))
{
await channel.WriteAsync(new BuildPlayout(playout.Id, PlayoutBuildMode.Reset), cancellationToken);
}
break;
case ProgramSchedulePlayoutType.ExternalJson:
case ProgramSchedulePlayoutType.None:
default:
// external json cannot be reset
continue;
}
}
}
}

13
ErsatzTV/Pages/Playouts.razor

@ -28,6 +28,9 @@
Add External Json Playout Add External Json Playout
</MudButton> </MudButton>
</MudTooltip> </MudTooltip>
<MudButton Class="ml-3" Variant="Variant.Filled" Color="Color.Warning" StartIcon="@Icons.Material.Filled.Refresh" OnClick="@ResetAllPlayouts">
Reset All Playouts
</MudButton>
</div> </div>
<MudTable Hover="true" <MudTable Hover="true"
Dense="true" Dense="true"
@ -274,7 +277,7 @@
IDialogReference dialog = await Dialog.ShowAsync<EditExternalJsonFileDialog>("Edit External Json File", parameters, options); IDialogReference dialog = await Dialog.ShowAsync<EditExternalJsonFileDialog>("Edit External Json File", parameters, options);
DialogResult result = await dialog.Result; DialogResult result = await dialog.Result;
if (!result.Canceled) if (result is { Canceled: false })
{ {
await Mediator.Send(new UpdateExternalJsonPlayout(playout.PlayoutId, result.Data as string ?? playout.ExternalJsonFile), _cts.Token); await Mediator.Send(new UpdateExternalJsonPlayout(playout.PlayoutId, result.Data as string ?? playout.ExternalJsonFile), _cts.Token);
if (_table != null) if (_table != null)
@ -293,7 +296,7 @@
IDialogReference dialog = await Dialog.ShowAsync<DeleteDialog>("Delete Playout", parameters, options); IDialogReference dialog = await Dialog.ShowAsync<DeleteDialog>("Delete Playout", parameters, options);
DialogResult result = await dialog.Result; DialogResult result = await dialog.Result;
if (!result.Canceled) if (result is { Canceled: false })
{ {
await Mediator.Send(new DeletePlayout(playout.PlayoutId), _cts.Token); await Mediator.Send(new DeletePlayout(playout.PlayoutId), _cts.Token);
if (_table != null) if (_table != null)
@ -308,6 +311,12 @@
} }
} }
private async Task ResetAllPlayouts()
{
_selectedPlayoutId = null;
await Mediator.Send(new ResetAllPlayouts(), _cts.Token);
}
private async Task ResetPlayout(PlayoutNameViewModel playout) private async Task ResetPlayout(PlayoutNameViewModel playout)
{ {
await WorkerChannel.WriteAsync(new BuildPlayout(playout.PlayoutId, PlayoutBuildMode.Reset), _cts.Token); await WorkerChannel.WriteAsync(new BuildPlayout(playout.PlayoutId, PlayoutBuildMode.Reset), _cts.Token);

Loading…
Cancel
Save