diff --git a/ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateSchedule.cs b/ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateSchedule.cs index f85db7545..52a48999c 100644 --- a/ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateSchedule.cs +++ b/ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateSchedule.cs @@ -6,4 +6,11 @@ public record ReplacePlayoutAlternateSchedule( int ProgramScheduleId, List DaysOfWeek, List DaysOfMonth, - List MonthsOfYear); + List MonthsOfYear, + bool LimitToDateRange, + int StartMonth, + int StartDay, + int? StartYear, + int EndMonth, + int EndDay, + int? EndYear); diff --git a/ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateScheduleItemsHandler.cs b/ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateScheduleItemsHandler.cs index afa64cd5e..0cf6490a6 100644 --- a/ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateScheduleItemsHandler.cs +++ b/ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateScheduleItemsHandler.cs @@ -9,23 +9,13 @@ using Microsoft.Extensions.Logging; namespace ErsatzTV.Application.Playouts; -public class ReplacePlayoutAlternateScheduleItemsHandler : - IRequestHandler> +public class ReplacePlayoutAlternateScheduleItemsHandler( + IDbContextFactory dbContextFactory, + ChannelWriter channel, + ILogger logger) + : + IRequestHandler> { - private readonly ChannelWriter _channel; - private readonly IDbContextFactory _dbContextFactory; - private readonly ILogger _logger; - - public ReplacePlayoutAlternateScheduleItemsHandler( - IDbContextFactory dbContextFactory, - ChannelWriter channel, - ILogger logger) - { - _dbContextFactory = dbContextFactory; - _channel = channel; - _logger = logger; - } - public async Task> Handle( ReplacePlayoutAlternateScheduleItems request, CancellationToken cancellationToken) @@ -34,7 +24,7 @@ public class ReplacePlayoutAlternateScheduleItemsHandler : try { - await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); + await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); Option maybePlayout = await dbContext.Playouts .Include(p => p.ProgramSchedule) @@ -76,7 +66,7 @@ public class ReplacePlayoutAlternateScheduleItemsHandler : ProgramScheduleAlternate[] existing = playout.ProgramScheduleAlternates.ToArray(); - var incoming = request.Items.Except(new[] { highest }).ToList(); + var incoming = request.Items.Except([highest]).ToList(); var toAdd = incoming.Filter(x => existing.All(e => e.Id != x.Id)).ToList(); var toRemove = existing.Filter(e => incoming.All(m => m.Id != e.Id)).ToList(); @@ -94,7 +84,14 @@ public class ReplacePlayoutAlternateScheduleItemsHandler : ProgramScheduleId = add.ProgramScheduleId, DaysOfWeek = add.DaysOfWeek, DaysOfMonth = add.DaysOfMonth, - MonthsOfYear = add.MonthsOfYear + MonthsOfYear = add.MonthsOfYear, + LimitToDateRange = add.LimitToDateRange, + StartMonth = add.StartMonth, + StartDay = add.StartDay, + StartYear = add.StartYear, + EndMonth = add.EndMonth, + EndDay = add.EndDay, + EndYear = add.EndYear }); } @@ -107,6 +104,13 @@ public class ReplacePlayoutAlternateScheduleItemsHandler : ex.DaysOfWeek = update.DaysOfWeek; ex.DaysOfMonth = update.DaysOfMonth; ex.MonthsOfYear = update.MonthsOfYear; + ex.LimitToDateRange = update.LimitToDateRange; + ex.StartMonth = update.StartMonth; + ex.StartDay = update.StartDay; + ex.StartYear = update.StartYear; + ex.EndMonth = update.EndMonth; + ex.EndDay = update.EndDay; + ex.EndYear = update.EndYear; } } @@ -142,13 +146,13 @@ public class ReplacePlayoutAlternateScheduleItemsHandler : if (existingScheduleMap.TryGetValue(dayToCheck, out ProgramSchedule existingValue) && existingValue.Id != schedule.Id) { - _logger.LogInformation( + logger.LogInformation( "Alternate schedule change detected for day {Day}, schedule {One} => {Two}; will refresh playout", dayToCheck, existingValue.Name, schedule.Name); - await _channel.WriteAsync( + await channel.WriteAsync( new BuildPlayout(request.PlayoutId, PlayoutBuildMode.Refresh), cancellationToken); @@ -162,7 +166,7 @@ public class ReplacePlayoutAlternateScheduleItemsHandler : } catch (Exception ex) { - _logger.LogError(ex, "Error saving alternate schedule items"); + logger.LogError(ex, "Error saving alternate schedule items"); return BaseError.New(ex.Message); } } diff --git a/ErsatzTV.Application/Playouts/Mapper.cs b/ErsatzTV.Application/Playouts/Mapper.cs index 2ed5ad890..9376effdd 100644 --- a/ErsatzTV.Application/Playouts/Mapper.cs +++ b/ErsatzTV.Application/Playouts/Mapper.cs @@ -33,7 +33,14 @@ internal static class Mapper programScheduleAlternate.ProgramScheduleId, programScheduleAlternate.DaysOfWeek, programScheduleAlternate.DaysOfMonth, - programScheduleAlternate.MonthsOfYear); + programScheduleAlternate.MonthsOfYear, + programScheduleAlternate.LimitToDateRange, + programScheduleAlternate.StartMonth, + programScheduleAlternate.StartDay, + programScheduleAlternate.StartYear, + programScheduleAlternate.EndMonth, + programScheduleAlternate.EndDay, + programScheduleAlternate.EndYear); internal static PlayoutHistoryViewModel ProjectToViewModel(PlayoutHistory playoutHistory) => new( diff --git a/ErsatzTV.Application/Playouts/PlayoutAlternateScheduleViewModel.cs b/ErsatzTV.Application/Playouts/PlayoutAlternateScheduleViewModel.cs index e34db130a..b7972868a 100644 --- a/ErsatzTV.Application/Playouts/PlayoutAlternateScheduleViewModel.cs +++ b/ErsatzTV.Application/Playouts/PlayoutAlternateScheduleViewModel.cs @@ -6,4 +6,11 @@ public record PlayoutAlternateScheduleViewModel( int ProgramScheduleId, ICollection DaysOfWeek, ICollection DaysOfMonth, - ICollection MonthsOfYear); + ICollection MonthsOfYear, + bool LimitToDateRange, + int StartMonth, + int StartDay, + int? StartYear, + int EndMonth, + int EndDay, + int? EndYear); diff --git a/ErsatzTV.Application/Playouts/Queries/GetPlayoutAlternateSchedulesHandler.cs b/ErsatzTV.Application/Playouts/Queries/GetPlayoutAlternateSchedulesHandler.cs index ed5df9bde..81505743d 100644 --- a/ErsatzTV.Application/Playouts/Queries/GetPlayoutAlternateSchedulesHandler.cs +++ b/ErsatzTV.Application/Playouts/Queries/GetPlayoutAlternateSchedulesHandler.cs @@ -40,7 +40,14 @@ public class GetPlayoutAlternateSchedulesHandler(IDbContextFactory db Index = result.Map(i => i.Index).DefaultIfEmpty().Max() + 1, DaysOfMonth = AlternateScheduleSelector.AllDaysOfMonth(), DaysOfWeek = AlternateScheduleSelector.AllDaysOfWeek(), - MonthsOfYear = AlternateScheduleSelector.AllMonthsOfYear() + MonthsOfYear = AlternateScheduleSelector.AllMonthsOfYear(), + LimitToDateRange = false, + StartMonth = 1, + StartDay = 1, + StartYear = null, + EndMonth = 1, + EndDay = 1, + EndYear = null }; result.Add(ProjectToViewModel(psa)); diff --git a/ErsatzTV/Pages/PlayoutAlternateSchedulesEditor.razor b/ErsatzTV/Pages/PlayoutAlternateSchedulesEditor.razor index cdc401c43..41b279a18 100644 --- a/ErsatzTV/Pages/PlayoutAlternateSchedulesEditor.razor +++ b/ErsatzTV/Pages/PlayoutAlternateSchedulesEditor.razor @@ -107,6 +107,70 @@ } + +
+ Limit to Date Range +
+ +
+ +
+ Start Day +
+ + @foreach (int month in Enumerable.Range(1, 12)) + { + @_dtf.GetMonthName(month) + } + +
+ +
+ + @foreach (int day in Enumerable.Range(1, 31)) + { + @day.ToString() + } + +
+ +
+ + @foreach (int year in Enumerable.Range(DateTime.Today.Year, 50)) + { + @year.ToString() + } + +
+ +
+ End Day +
+ + @foreach (int month in Enumerable.Range(1, 12)) + { + @_dtf.GetMonthName(month) + } + +
+ +
+ + @foreach (int day in Enumerable.Range(1, 31)) + { + @day.ToString() + } + +
+ +
+ + @foreach (int year in Enumerable.Range(DateTime.Today.Year, 50)) + { + @year.ToString() + } + +
Days of the Week @@ -212,7 +276,14 @@ ProgramSchedule = _schedules.Find(vm => vm.Id == item.ProgramScheduleId), DaysOfWeek = item.DaysOfWeek.OrderBy(x => ((int)x + 6) % 7).ToList(), DaysOfMonth = item.DaysOfMonth.ToList(), - MonthsOfYear = item.MonthsOfYear.ToList() + MonthsOfYear = item.MonthsOfYear.ToList(), + LimitToDateRange = item.LimitToDateRange, + StartMonth = item.StartMonth, + StartDay = item.StartDay, + StartYear = item.StartYear, + EndMonth = item.EndMonth, + EndDay = item.EndDay, + EndYear = item.EndYear }; private void SelectWeekdays() @@ -246,7 +317,14 @@ ProgramSchedule = _schedules.Head(), DaysOfWeek = AlternateScheduleSelector.AllDaysOfWeek(), DaysOfMonth = AlternateScheduleSelector.AllDaysOfMonth(), - MonthsOfYear = AlternateScheduleSelector.AllMonthsOfYear() + MonthsOfYear = AlternateScheduleSelector.AllMonthsOfYear(), + LimitToDateRange = false, + StartMonth = 1, + StartDay = 1, + StartYear = null, + EndMonth = 1, + EndDay = 1, + EndYear = null }; _items.Add(item); @@ -281,7 +359,14 @@ item.ProgramSchedule.Id, item.DaysOfWeek, item.DaysOfMonth, - item.MonthsOfYear)).ToList(); + item.MonthsOfYear, + item.LimitToDateRange, + item.StartMonth, + item.StartDay, + item.StartYear, + item.EndMonth, + item.EndDay, + item.EndYear)).ToList(); Seq errorMessages = await Mediator.Send(new ReplacePlayoutAlternateScheduleItems(Id, items), _cts.Token) .Map(e => e.LeftToSeq()); diff --git a/ErsatzTV/ViewModels/PlayoutAlternateScheduleEditViewModel.cs b/ErsatzTV/ViewModels/PlayoutAlternateScheduleEditViewModel.cs index 590de5f25..d7789f290 100644 --- a/ErsatzTV/ViewModels/PlayoutAlternateScheduleEditViewModel.cs +++ b/ErsatzTV/ViewModels/PlayoutAlternateScheduleEditViewModel.cs @@ -10,4 +10,33 @@ public class PlayoutAlternateScheduleEditViewModel public List DaysOfWeek { get; set; } public List DaysOfMonth { get; set; } public List MonthsOfYear { get; set; } + public bool LimitToDateRange { get; set; } + + public int StartMonth + { + get => field == 0 ? 1 : field; + set; + } + + public int StartDay + { + get => field == 0 ? 1 : field; + set; + } + + public int? StartYear { get; set; } + + public int EndMonth + { + get => field == 0 ? 12 : field; + set; + } + + public int EndDay + { + get => field == 0 ? 31 : field; + set; + } + + public int? EndYear { get; set; } } diff --git a/ErsatzTV/ViewModels/PlayoutTemplateEditViewModel.cs b/ErsatzTV/ViewModels/PlayoutTemplateEditViewModel.cs index 9b6909396..33d9f82da 100644 --- a/ErsatzTV/ViewModels/PlayoutTemplateEditViewModel.cs +++ b/ErsatzTV/ViewModels/PlayoutTemplateEditViewModel.cs @@ -7,10 +7,6 @@ namespace ErsatzTV.ViewModels; public class PlayoutTemplateEditViewModel { - private int _endDay; - private int _endMonth; - private int _startDay; - private int _startMonth; public int Id { get; set; } public int Index { get; set; } public TemplateViewModel Template { get; set; } @@ -25,28 +21,28 @@ public class PlayoutTemplateEditViewModel public int StartMonth { - get => _startMonth == 0 ? 1 : _startMonth; - set => _startMonth = value; + get => field == 0 ? 1 : field; + set; } public int StartDay { - get => _startDay == 0 ? 1 : _startDay; - set => _startDay = value; + get => field == 0 ? 1 : field; + set; } public int? StartYear { get; set; } public int EndMonth { - get => _endMonth == 0 ? 12 : _endMonth; - set => _endMonth = value; + get => field == 0 ? 12 : field; + set; } public int EndDay { - get => _endDay == 0 ? 31 : _endDay; - set => _endDay = value; + get => field == 0 ? 31 : field; + set; } public int? EndYear { get; set; }