Browse Source

add date range editing to classic (alternate) schedules

pull/2757/head
Jason Dove 7 months ago
parent
commit
61cdc0be94
No known key found for this signature in database
  1. 9
      ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateSchedule.cs
  2. 44
      ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateScheduleItemsHandler.cs
  3. 9
      ErsatzTV.Application/Playouts/Mapper.cs
  4. 9
      ErsatzTV.Application/Playouts/PlayoutAlternateScheduleViewModel.cs
  5. 9
      ErsatzTV.Application/Playouts/Queries/GetPlayoutAlternateSchedulesHandler.cs
  6. 91
      ErsatzTV/Pages/PlayoutAlternateSchedulesEditor.razor
  7. 29
      ErsatzTV/ViewModels/PlayoutAlternateScheduleEditViewModel.cs
  8. 20
      ErsatzTV/ViewModels/PlayoutTemplateEditViewModel.cs

9
ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateSchedule.cs

@ -6,4 +6,11 @@ public record ReplacePlayoutAlternateSchedule( @@ -6,4 +6,11 @@ public record ReplacePlayoutAlternateSchedule(
int ProgramScheduleId,
List<DayOfWeek> DaysOfWeek,
List<int> DaysOfMonth,
List<int> MonthsOfYear);
List<int> MonthsOfYear,
bool LimitToDateRange,
int StartMonth,
int StartDay,
int? StartYear,
int EndMonth,
int EndDay,
int? EndYear);

44
ErsatzTV.Application/Playouts/Commands/ReplacePlayoutAlternateScheduleItemsHandler.cs

@ -9,23 +9,13 @@ using Microsoft.Extensions.Logging; @@ -9,23 +9,13 @@ using Microsoft.Extensions.Logging;
namespace ErsatzTV.Application.Playouts;
public class ReplacePlayoutAlternateScheduleItemsHandler :
IRequestHandler<ReplacePlayoutAlternateScheduleItems, Either<BaseError, Unit>>
{
private readonly ChannelWriter<IBackgroundServiceRequest> _channel;
private readonly IDbContextFactory<TvContext> _dbContextFactory;
private readonly ILogger<ReplacePlayoutAlternateScheduleItemsHandler> _logger;
public ReplacePlayoutAlternateScheduleItemsHandler(
public class ReplacePlayoutAlternateScheduleItemsHandler(
IDbContextFactory<TvContext> dbContextFactory,
ChannelWriter<IBackgroundServiceRequest> channel,
ILogger<ReplacePlayoutAlternateScheduleItemsHandler> logger)
{
_dbContextFactory = dbContextFactory;
_channel = channel;
_logger = logger;
}
:
IRequestHandler<ReplacePlayoutAlternateScheduleItems, Either<BaseError, Unit>>
{
public async Task<Either<BaseError, Unit>> Handle(
ReplacePlayoutAlternateScheduleItems request,
CancellationToken cancellationToken)
@ -34,7 +24,7 @@ public class ReplacePlayoutAlternateScheduleItemsHandler : @@ -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<Playout> maybePlayout = await dbContext.Playouts
.Include(p => p.ProgramSchedule)
@ -76,7 +66,7 @@ public class ReplacePlayoutAlternateScheduleItemsHandler : @@ -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 : @@ -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 : @@ -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 : @@ -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 : @@ -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);
}
}

9
ErsatzTV.Application/Playouts/Mapper.cs

@ -33,7 +33,14 @@ internal static class Mapper @@ -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(

9
ErsatzTV.Application/Playouts/PlayoutAlternateScheduleViewModel.cs

@ -6,4 +6,11 @@ public record PlayoutAlternateScheduleViewModel( @@ -6,4 +6,11 @@ public record PlayoutAlternateScheduleViewModel(
int ProgramScheduleId,
ICollection<DayOfWeek> DaysOfWeek,
ICollection<int> DaysOfMonth,
ICollection<int> MonthsOfYear);
ICollection<int> MonthsOfYear,
bool LimitToDateRange,
int StartMonth,
int StartDay,
int? StartYear,
int EndMonth,
int EndDay,
int? EndYear);

9
ErsatzTV.Application/Playouts/Queries/GetPlayoutAlternateSchedulesHandler.cs

@ -40,7 +40,14 @@ public class GetPlayoutAlternateSchedulesHandler(IDbContextFactory<TvContext> db @@ -40,7 +40,14 @@ public class GetPlayoutAlternateSchedulesHandler(IDbContextFactory<TvContext> 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));

91
ErsatzTV/Pages/PlayoutAlternateSchedulesEditor.razor

@ -107,6 +107,70 @@ @@ -107,6 +107,70 @@
}
</MudSelect>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex">
<MudText>Limit to Date Range</MudText>
</div>
<MudCheckBox T="bool" @bind-Value="_selectedItem.LimitToDateRange" Dense="true"/>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex">
<MudText>Start Day</MudText>
</div>
<MudSelect T="int" @bind-Value="_selectedItem.StartMonth" Disabled="@(!_selectedItem.LimitToDateRange)">
@foreach (int month in Enumerable.Range(1, 12))
{
<MudSelectItem Value="@month">@_dtf.GetMonthName(month)</MudSelectItem>
}
</MudSelect>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex"></div>
<MudSelect T="int" @bind-Value="_selectedItem.StartDay" Disabled="@(!_selectedItem.LimitToDateRange)">
@foreach (int day in Enumerable.Range(1, 31))
{
<MudSelectItem Value="@day">@day.ToString()</MudSelectItem>
}
</MudSelect>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex"></div>
<MudSelect T="int?" @bind-Value="_selectedItem.StartYear" Disabled="@(!_selectedItem.LimitToDateRange)" Clearable="true">
@foreach (int year in Enumerable.Range(DateTime.Today.Year, 50))
{
<MudSelectItem T="int?" Value="@year">@year.ToString()</MudSelectItem>
}
</MudSelect>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex">
<MudText>End Day</MudText>
</div>
<MudSelect T="int" @bind-Value="_selectedItem.EndMonth" Disabled="@(!_selectedItem.LimitToDateRange)">
@foreach (int month in Enumerable.Range(1, 12))
{
<MudSelectItem Value="@month">@_dtf.GetMonthName(month)</MudSelectItem>
}
</MudSelect>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex"></div>
<MudSelect T="int" @bind-Value="_selectedItem.EndDay" Disabled="@(!_selectedItem.LimitToDateRange)">
@foreach (int day in Enumerable.Range(1, 31))
{
<MudSelectItem Value="@day">@day.ToString()</MudSelectItem>
}
</MudSelect>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex"></div>
<MudSelect T="int?" @bind-Value="_selectedItem.EndYear" Disabled="@(!_selectedItem.LimitToDateRange)" Clearable="true">
@foreach (int year in Enumerable.Range(DateTime.Today.Year, 50))
{
<MudSelectItem T="int?" Value="@year">@year.ToString()</MudSelectItem>
}
</MudSelect>
</MudStack>
<MudStack Row="true" Breakpoint="Breakpoint.SmAndDown" Class="form-field-stack gap-md-8 mb-5">
<div class="d-flex">
<MudText>Days of the Week</MudText>
@ -212,7 +276,14 @@ @@ -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 @@ @@ -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 @@ @@ -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<BaseError> errorMessages = await Mediator.Send(new ReplacePlayoutAlternateScheduleItems(Id, items), _cts.Token)
.Map(e => e.LeftToSeq());

29
ErsatzTV/ViewModels/PlayoutAlternateScheduleEditViewModel.cs

@ -10,4 +10,33 @@ public class PlayoutAlternateScheduleEditViewModel @@ -10,4 +10,33 @@ public class PlayoutAlternateScheduleEditViewModel
public List<DayOfWeek> DaysOfWeek { get; set; }
public List<int> DaysOfMonth { get; set; }
public List<int> 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; }
}

20
ErsatzTV/ViewModels/PlayoutTemplateEditViewModel.cs

@ -7,10 +7,6 @@ namespace ErsatzTV.ViewModels; @@ -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 @@ -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; }

Loading…
Cancel
Save