Browse Source

add option to stop scheduling before or after block duration end (#1563)

pull/1564/head
Jason Dove 1 year ago committed by GitHub
parent
commit
88fac0de04
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      ErsatzTV.Application/Scheduling/BlockViewModel.cs
  2. 5
      ErsatzTV.Application/Scheduling/Commands/PreviewBlockPlayoutHandler.cs
  3. 8
      ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItems.cs
  4. 1
      ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItemsHandler.cs
  5. 2
      ErsatzTV.Application/Scheduling/Mapper.cs
  6. 1
      ErsatzTV.Core/Domain/Scheduling/Block.cs
  7. 7
      ErsatzTV.Core/Domain/Scheduling/BlockStopScheduling.cs
  8. 12
      ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs
  9. 4910
      ErsatzTV.Infrastructure.MySql/Migrations/20240116185109_Add_BlockStopScheduling.Designer.cs
  10. 29
      ErsatzTV.Infrastructure.MySql/Migrations/20240116185109_Add_BlockStopScheduling.cs
  11. 3
      ErsatzTV.Infrastructure.MySql/Migrations/TvContextModelSnapshot.cs
  12. 4908
      ErsatzTV.Infrastructure.Sqlite/Migrations/20240116184306_Add_BlockStopScheduling.Designer.cs
  13. 29
      ErsatzTV.Infrastructure.Sqlite/Migrations/20240116184306_Add_BlockStopScheduling.cs
  14. 3
      ErsatzTV.Infrastructure.Sqlite/Migrations/TvContextModelSnapshot.cs
  15. 11
      ErsatzTV/Pages/BlockEditor.razor
  16. 5
      ErsatzTV/ViewModels/BlockItemsEditViewModel.cs

4
ErsatzTV.Application/Scheduling/BlockViewModel.cs

@ -1,3 +1,5 @@ @@ -1,3 +1,5 @@
using ErsatzTV.Core.Domain.Scheduling;
namespace ErsatzTV.Application.Scheduling;
public record BlockViewModel(int Id, string Name, int Minutes);
public record BlockViewModel(int Id, string Name, int Minutes, BlockStopScheduling StopScheduling);

5
ErsatzTV.Application/Scheduling/Commands/PreviewBlockPlayoutHandler.cs

@ -93,9 +93,10 @@ public class PreviewBlockPlayoutHandler( @@ -93,9 +93,10 @@ public class PreviewBlockPlayoutHandler(
private static Block MapToBlock(ReplaceBlockItems request) =>
new()
{
Minutes = request.Minutes,
Name = request.Name,
Items = request.Items.Map(MapToBlockItem).ToList(),
Minutes = request.Minutes,
StopScheduling = request.StopScheduling,
Items = request.Items.Map(MapToBlockItem).ToList()
};
private static BlockItem MapToBlockItem(int id, ReplaceBlockItem request) =>

8
ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItems.cs

@ -1,6 +1,12 @@ @@ -1,6 +1,12 @@
using ErsatzTV.Core;
using ErsatzTV.Core.Domain.Scheduling;
namespace ErsatzTV.Application.Scheduling;
public record ReplaceBlockItems(int BlockId, string Name, int Minutes, List<ReplaceBlockItem> Items)
public record ReplaceBlockItems(
int BlockId,
string Name,
int Minutes,
BlockStopScheduling StopScheduling,
List<ReplaceBlockItem> Items)
: IRequest<Either<BaseError, List<BlockItemViewModel>>>;

1
ErsatzTV.Application/Scheduling/Commands/ReplaceBlockItemsHandler.cs

@ -26,6 +26,7 @@ public class ReplaceBlockItemsHandler(IDbContextFactory<TvContext> dbContextFact @@ -26,6 +26,7 @@ public class ReplaceBlockItemsHandler(IDbContextFactory<TvContext> dbContextFact
{
block.Name = request.Name;
block.Minutes = request.Minutes;
block.StopScheduling = request.StopScheduling;
block.DateUpdated = DateTime.UtcNow;
dbContext.RemoveRange(block.Items);

2
ErsatzTV.Application/Scheduling/Mapper.cs

@ -9,7 +9,7 @@ internal static class Mapper @@ -9,7 +9,7 @@ internal static class Mapper
new(blockGroup.Id, blockGroup.Name, blockGroup.Blocks.Count);
internal static BlockViewModel ProjectToViewModel(Block block) =>
new(block.Id, block.Name, block.Minutes);
new(block.Id, block.Name, block.Minutes, block.StopScheduling);
internal static BlockItemViewModel ProjectToViewModel(BlockItem blockItem) =>
new(

1
ErsatzTV.Core/Domain/Scheduling/Block.cs

@ -7,6 +7,7 @@ public class Block @@ -7,6 +7,7 @@ public class Block
public BlockGroup BlockGroup { get; set; }
public string Name { get; set; }
public int Minutes { get; set; }
public BlockStopScheduling StopScheduling { get; set; }
public ICollection<BlockItem> Items { get; set; }
public ICollection<TemplateItem> TemplateItems { get; set; }
public ICollection<PlayoutHistory> PlayoutHistory { get; set; }

7
ErsatzTV.Core/Domain/Scheduling/BlockStopScheduling.cs

@ -0,0 +1,7 @@ @@ -0,0 +1,7 @@
namespace ErsatzTV.Core.Domain.Scheduling;
public enum BlockStopScheduling
{
AfterDurationEnd = 0,
BeforeDurationEnd = 1
}

12
ErsatzTV.Core/Scheduling/BlockScheduling/BlockPlayoutBuilder.cs

@ -137,6 +137,18 @@ public class BlockPlayoutBuilder( @@ -137,6 +137,18 @@ public class BlockPlayoutBuilder(
BlockKey = JsonConvert.SerializeObject(effectiveBlock.BlockKey)
};
if (effectiveBlock.Block.StopScheduling is BlockStopScheduling.BeforeDurationEnd
&& playoutItem.FinishOffset > blockFinish)
{
Logger.LogDebug(
"Current time {Time} for block {Block} would go beyond block finish {Finish}; will not schedule more items",
currentTime,
effectiveBlock.Block.Name,
blockFinish);
break;
}
playout.Items.Add(playoutItem);
// create a playout history record

4910
ErsatzTV.Infrastructure.MySql/Migrations/20240116185109_Add_BlockStopScheduling.Designer.cs generated

File diff suppressed because it is too large Load Diff

29
ErsatzTV.Infrastructure.MySql/Migrations/20240116185109_Add_BlockStopScheduling.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ErsatzTV.Infrastructure.MySql.Migrations
{
/// <inheritdoc />
public partial class Add_BlockStopScheduling : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "StopScheduling",
table: "Block",
type: "int",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "StopScheduling",
table: "Block");
}
}
}

3
ErsatzTV.Infrastructure.MySql/Migrations/TvContextModelSnapshot.cs

@ -1841,6 +1841,9 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations @@ -1841,6 +1841,9 @@ namespace ErsatzTV.Infrastructure.MySql.Migrations
b.Property<string>("Name")
.HasColumnType("varchar(255)");
b.Property<int>("StopScheduling")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("BlockGroupId");

4908
ErsatzTV.Infrastructure.Sqlite/Migrations/20240116184306_Add_BlockStopScheduling.Designer.cs generated

File diff suppressed because it is too large Load Diff

29
ErsatzTV.Infrastructure.Sqlite/Migrations/20240116184306_Add_BlockStopScheduling.cs

@ -0,0 +1,29 @@ @@ -0,0 +1,29 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ErsatzTV.Infrastructure.Sqlite.Migrations
{
/// <inheritdoc />
public partial class Add_BlockStopScheduling : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "StopScheduling",
table: "Block",
type: "INTEGER",
nullable: false,
defaultValue: 0);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "StopScheduling",
table: "Block");
}
}
}

3
ErsatzTV.Infrastructure.Sqlite/Migrations/TvContextModelSnapshot.cs

@ -1839,6 +1839,9 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations @@ -1839,6 +1839,9 @@ namespace ErsatzTV.Infrastructure.Sqlite.Migrations
b.Property<string>("Name")
.HasColumnType("TEXT");
b.Property<int>("StopScheduling")
.HasColumnType("INTEGER");
b.HasKey("Id");
b.HasIndex("BlockGroupId");

11
ErsatzTV/Pages/BlockEditor.razor

@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
@using ErsatzTV.Application.MediaItems
@using ErsatzTV.Application.Scheduling
@using ErsatzTV.Application.Search
@using ErsatzTV.Core.Domain.Scheduling
@implements IDisposable
@inject NavigationManager NavigationManager
@inject ILogger<BlockEditor> Logger
@ -32,6 +33,13 @@ @@ -32,6 +33,13 @@
</MudSelect>
</MudItem>
</MudGrid>
<MudSelect T="BlockStopScheduling"
@bind-Value="_block.StopScheduling"
For="@(() => _block.StopScheduling)"
Label="Stop scheduling block items">
<MudSelectItem Value="BlockStopScheduling.BeforeDurationEnd">Before Duration End</MudSelectItem>
<MudSelectItem Value="BlockStopScheduling.AfterDurationEnd">After Duration End</MudSelectItem>
</MudSelect>
</MudCardContent>
</MudCard>
</div>
@ -293,6 +301,7 @@ @@ -293,6 +301,7 @@
{
Name = block.Name,
Minutes = block.Minutes,
StopScheduling = block.StopScheduling,
Items = []
};
@ -468,7 +477,7 @@ @@ -468,7 +477,7 @@
_block.Minutes = _durationHours * 60 + _durationMinutes;
return new ReplaceBlockItems(Id, _block.Name, _block.Minutes, items);
return new ReplaceBlockItems(Id, _block.Name, _block.Minutes, _block.StopScheduling, items);
}
private async Task PreviewPlayout()

5
ErsatzTV/ViewModels/BlockItemsEditViewModel.cs

@ -1,8 +1,11 @@ @@ -1,8 +1,11 @@
namespace ErsatzTV.ViewModels;
using ErsatzTV.Core.Domain.Scheduling;
namespace ErsatzTV.ViewModels;
public class BlockItemsEditViewModel
{
public string Name { get; set; }
public int Minutes { get; set; }
public BlockStopScheduling StopScheduling { get; set; }
public List<BlockItemEditViewModel> Items { get; set; }
}

Loading…
Cancel
Save