Browse Source

improve classic scheduling context display

pull/2819/head
Jason Dove 6 months ago
parent
commit
a98428495e
No known key found for this signature in database
  1. 3
      ErsatzTV.Application/ProgramSchedules/Queries/ProcessSchedulingContext.cs
  2. 94
      ErsatzTV.Application/ProgramSchedules/Queries/ProcessSchedulingContextHandler.cs
  3. 2
      ErsatzTV.Core/Scheduling/ClassicSchedulingContext.cs
  4. 4
      ErsatzTV.Core/Scheduling/PlayoutModeSchedulerBase.cs
  5. 13
      ErsatzTV/Pages/Playouts.razor
  6. 7
      ErsatzTV/Shared/SchedulingContextDialog.razor

3
ErsatzTV.Application/ProgramSchedules/Queries/ProcessSchedulingContext.cs

@ -0,0 +1,3 @@ @@ -0,0 +1,3 @@
namespace ErsatzTV.Application.ProgramSchedules;
public record ProcessSchedulingContext(string SerializedContext) : IRequest<Option<string>>;

94
ErsatzTV.Application/ProgramSchedules/Queries/ProcessSchedulingContextHandler.cs

@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using ErsatzTV.Core.Domain;
using ErsatzTV.Core.Scheduling;
using ErsatzTV.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
using JsonSerializer = System.Text.Json.JsonSerializer;
namespace ErsatzTV.Application.ProgramSchedules;
public class ProcessSchedulingContextHandler(IDbContextFactory<TvContext> dbContextFactory)
: IRequestHandler<ProcessSchedulingContext, Option<string>>
{
private static readonly JsonSerializerOptions Options = new()
{
Converters = { new JsonStringEnumConverter() },
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
WriteIndented = true
};
public async Task<Option<string>> Handle(ProcessSchedulingContext request, CancellationToken cancellationToken)
{
if (string.IsNullOrEmpty(request.SerializedContext))
{
return Option<string>.None;
}
var classicContext = JsonConvert.DeserializeObject<ClassicSchedulingContext>(request.SerializedContext);
if (classicContext is not null)
{
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
string scheduleName = await dbContext.ProgramSchedules
.Where(s => s.Id == classicContext.ScheduleId)
.Select(s => s.Name)
.SingleOrDefaultAsync(cancellationToken);
var scheduleItem = await dbContext.ProgramScheduleItems
.AsNoTracking()
.AsSplitQuery()
.Include(si => si.SmartCollection)
.Include(si => si.Collection)
.Include(si => si.MultiCollection)
.Include(si => si.RerunCollection)
.Include(si => si.Playlist)
.SingleOrDefaultAsync(s => s.Id == classicContext.ItemId, cancellationToken);
ClassicContextScheduleItem item;
if (scheduleItem is not null)
{
string collectionName = scheduleItem.CollectionType switch
{
CollectionType.SmartCollection => scheduleItem.SmartCollection.Name,
CollectionType.Collection => scheduleItem.Collection.Name,
CollectionType.MultiCollection => scheduleItem.MultiCollection.Name,
CollectionType.RerunRerun or CollectionType.RerunFirstRun => scheduleItem.RerunCollection.Name,
CollectionType.Playlist => scheduleItem.Playlist.Name,
_ => null
};
item = new ClassicContextScheduleItem(scheduleItem.Id, scheduleItem.CollectionType, collectionName);
}
else
{
item = new ClassicContextScheduleItem(classicContext.ItemId, null, null);
}
var context = new ClassicContext(
new ContextScheduler("Classic", classicContext.Scheduler),
new ClassicContextSchedule(classicContext.ScheduleId, scheduleName ?? string.Empty),
item,
new ContextEnumerator(classicContext.Enumerator, classicContext.Seed, classicContext.Index));
return JsonSerializer.Serialize(context, Options);
}
return request.SerializedContext;
}
private sealed record ClassicContext(
ContextScheduler Scheduler,
ClassicContextSchedule Schedule,
ClassicContextScheduleItem ScheduleItem,
ContextEnumerator Enumerator);
private sealed record ContextScheduler(string Type, string Mode);
private sealed record ClassicContextSchedule(int Id, string Name);
private sealed record ClassicContextScheduleItem(int Id, CollectionType? CollectionType, string CollectionName);
private sealed record ContextEnumerator(string Name, int Seed, int Index);
}

2
ErsatzTV.Core/Scheduling/SchedulingContext.cs → ErsatzTV.Core/Scheduling/ClassicSchedulingContext.cs

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
namespace ErsatzTV.Core.Scheduling;
public record SchedulingContext(
public record ClassicSchedulingContext(
string Scheduler,
int ScheduleId,
int ItemId,

4
ErsatzTV.Core/Scheduling/PlayoutModeSchedulerBase.cs

@ -20,7 +20,7 @@ public abstract class PlayoutModeSchedulerBase<T>(ILogger logger) : IPlayoutMode @@ -20,7 +20,7 @@ public abstract class PlayoutModeSchedulerBase<T>(ILogger logger) : IPlayoutMode
{
Converters = { new JsonStringEnumConverter() },
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
WriteIndented = true
WriteIndented = false
};
private readonly Random _random = new();
@ -914,7 +914,7 @@ public abstract class PlayoutModeSchedulerBase<T>(ILogger logger) : IPlayoutMode @@ -914,7 +914,7 @@ public abstract class PlayoutModeSchedulerBase<T>(ILogger logger) : IPlayoutMode
protected string GetSchedulingContext(ProgramScheduleItem scheduleItem, IMediaCollectionEnumerator enumerator)
{
var context = new SchedulingContext(
var context = new ClassicSchedulingContext(
SchedulingContextName,
scheduleItem.ProgramScheduleId,
scheduleItem.Id,

13
ErsatzTV/Pages/Playouts.razor

@ -2,6 +2,7 @@ @@ -2,6 +2,7 @@
@using System.Globalization
@using ErsatzTV.Application.Configuration
@using ErsatzTV.Application.Playouts
@using ErsatzTV.Application.ProgramSchedules
@using ErsatzTV.Core.Notifications
@using ErsatzTV.Core.Scheduling
@using MediatR.Courier
@ -521,10 +522,14 @@ @@ -521,10 +522,14 @@
private async Task ShowSchedulingContext(PlayoutItemViewModel item)
{
var parameters = new DialogParameters { { "PlayoutItem", item } };
var options = new DialogOptions { CloseButton = true, CloseOnEscapeKey = true, MaxWidth = MaxWidth.Medium, FullWidth = true };
IDialogReference dialog = await Dialog.ShowAsync<SchedulingContextDialog>(item.Title, parameters, options);
DialogResult _ = await dialog.Result;
Option<string> maybeResults = await Mediator.Send(new ProcessSchedulingContext(item.SchedulingContext), _cts.Token);
foreach (string result in maybeResults)
{
var parameters = new DialogParameters { { "Context", result } };
var options = new DialogOptions { CloseButton = true, CloseOnEscapeKey = true, MaxWidth = MaxWidth.Medium, FullWidth = true };
IDialogReference dialog = await Dialog.ShowAsync<SchedulingContextDialog>(item.Title, parameters, options);
DialogResult _ = await dialog.Result;
}
}
}

7
ErsatzTV/Shared/SchedulingContextDialog.razor

@ -1,5 +1,4 @@ @@ -1,5 +1,4 @@
@using ErsatzTV.Application.Playouts
@inject IJSRuntime JsRuntime
@inject IJSRuntime JsRuntime
<div>
<MudDialog>
@ -25,7 +24,7 @@ @@ -25,7 +24,7 @@
IMudDialogInstance MudDialog { get; set; }
[Parameter]
public PlayoutItemViewModel PlayoutItem { get; set; }
public string Context { get; set; }
private string _info;
private ElementReference _infoView;
@ -34,7 +33,7 @@ @@ -34,7 +33,7 @@
{
try
{
_info = PlayoutItem.SchedulingContext;
_info = Context;
}
catch (Exception ex)
{

Loading…
Cancel
Save