Browse Source

add playout via ui

pull/1/head
Jason Dove 5 years ago
parent
commit
32f4bfcf08
  1. 2
      ErsatzTV.Application/Playouts/Mapper.cs
  2. 2
      ErsatzTV.Application/Playouts/PlayoutChannelViewModel.cs
  3. 4
      ErsatzTV/Pages/MediaCollectionItemsEditor.razor
  4. 6
      ErsatzTV/Pages/MediaCollections.razor
  5. 75
      ErsatzTV/Pages/PlayoutEditor.razor
  6. 45
      ErsatzTV/Pages/Playouts.razor
  7. 7
      ErsatzTV/Pages/ScheduleItemsEditor.razor
  8. 4
      ErsatzTV/Shared/MediaItemTable.razor
  9. 14
      ErsatzTV/Validators/PlayoutEditViewModelValidator.cs
  10. 16
      ErsatzTV/ViewModels/PlayoutEditViewModel.cs

2
ErsatzTV.Application/Playouts/Mapper.cs

@ -16,7 +16,7 @@ namespace ErsatzTV.Application.Playouts @@ -16,7 +16,7 @@ namespace ErsatzTV.Application.Playouts
new(GetDisplayTitle(playoutItem.MediaItem), playoutItem.Start, GetDisplayDuration(playoutItem.MediaItem));
private static PlayoutChannelViewModel Project(Channel channel) =>
new(channel.Id, channel.Name);
new(channel.Id, channel.Number, channel.Name);
private static PlayoutProgramScheduleViewModel Project(ProgramSchedule programSchedule) =>
new(programSchedule.Id, programSchedule.Name);

2
ErsatzTV.Application/Playouts/PlayoutChannelViewModel.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
namespace ErsatzTV.Application.Playouts
{
public record PlayoutChannelViewModel(int Id, string Name);
public record PlayoutChannelViewModel(int Id, int Number, string Name);
}

4
ErsatzTV/Pages/MediaCollectionItemsEditor.razor

@ -87,10 +87,10 @@ @@ -87,10 +87,10 @@
return new TableData<MediaItem> { TotalItems = _totalItems, Items = _pagedData };
}
private void OnSearch(string text)
private async Task OnSearch(string text)
{
_searchString = text;
_table.ReloadServerData();
await _table.ReloadServerData();
}
private async Task AddResultsAsync()

6
ErsatzTV/Pages/MediaCollections.razor

@ -79,7 +79,7 @@ @@ -79,7 +79,7 @@
if (!result.Cancelled)
{
await Mediator.Send(new DeleteSimpleMediaCollection(mediaCollection.Id));
_table.ReloadServerData();
await _table.ReloadServerData();
}
}
}
@ -95,10 +95,10 @@ @@ -95,10 +95,10 @@
return new TableData<MediaCollectionSummaryViewModel> { TotalItems = _totalItems, Items = _pagedData };
}
private void OnSearch(string text)
private async Task OnSearch(string text)
{
_searchString = text;
_table.ReloadServerData();
await _table.ReloadServerData();
}
}

75
ErsatzTV/Pages/PlayoutEditor.razor

@ -0,0 +1,75 @@ @@ -0,0 +1,75 @@
@page "/playouts/add"
@using ErsatzTV.Application.ProgramSchedules
@using ErsatzTV.Application.ProgramSchedules.Queries
@using ErsatzTV.Application.Channels
@using ErsatzTV.Application.Channels.Queries
@inject NavigationManager NavigationManager
@inject ILogger<PlayoutEditor> Logger
@inject ISnackbar Snackbar
@inject IMediator Mediator
<div style="max-width: 400px;">
<MudText Typo="Typo.h4" Class="mb-4">Add Playout</MudText>
<EditForm EditContext="_editContext" OnSubmit="@HandleSubmitAsync">
<FluentValidator/>
<MudCard>
<MudCardContent>
<MudAutocomplete T="ChannelViewModel" Label="Channel" @bind-value="_model.Channel" SearchFunc="@SearchChannels" ToStringFunc="@(c => c is null ? null : $"{c.Number} - {c.Name}")"/>
<MudAutocomplete Class="mt-3" T="ProgramScheduleViewModel" Label="Schedule" @bind-value="_model.ProgramSchedule" SearchFunc="@SearchProgramSchedules" ToStringFunc="@(s => s?.Name)"/>
</MudCardContent>
<MudCardActions>
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Primary">
Add Playout
</MudButton>
</MudCardActions>
</MudCard>
</EditForm>
</div>
@code {
private readonly PlayoutEditViewModel _model = new();
private List<ChannelViewModel> _channels;
private List<ProgramScheduleViewModel> _programSchedules;
private EditContext _editContext;
private ValidationMessageStore _messageStore;
protected override async Task OnParametersSetAsync()
{
_channels = await Mediator.Send(new GetAllChannels());
_programSchedules = await Mediator.Send(new GetAllProgramSchedules());
}
protected override void OnInitialized()
{
_editContext = new EditContext(_model);
_messageStore = new ValidationMessageStore(_editContext);
}
private Task<IEnumerable<ChannelViewModel>> SearchChannels(string value) =>
_channels.Filter(c => $"{c.Number} - {c.Name}".ToLowerInvariant().Contains(value ?? string.Empty)).AsTask();
private Task<IEnumerable<ProgramScheduleViewModel>> SearchProgramSchedules(string value) =>
_programSchedules.Filter(c => c.Name.ToLowerInvariant().StartsWith(value ?? string.Empty)).AsTask();
private async Task HandleSubmitAsync()
{
_messageStore.Clear();
if (_editContext.Validate())
{
Seq<BaseError> errorMessage = (await Mediator.Send(_model.ToCreate())).LeftToSeq();
errorMessage.HeadOrNone().Match(
error =>
{
Snackbar.Add(error.Value);
Logger.LogError("Unexpected error saving playout: {Error}", error.Value);
},
() => NavigationManager.NavigateTo("/playouts"));
}
}
}

45
ErsatzTV/Pages/Playouts.razor

@ -1,25 +1,40 @@ @@ -1,25 +1,40 @@
@page "/playouts"
@using ErsatzTV.Application.Playouts
@using ErsatzTV.Application.Playouts.Commands
@using ErsatzTV.Application.Playouts.Queries
@inject IDialogService Dialog
@inject IMediator Mediator
<MudTable Hover="true" Items="_playouts" SelectedItemChanged="@(async (PlayoutViewModel x) => await PlayoutSelected(x))">
<MudTable Hover="true" Dense="true" Items="_playouts" SelectedItemChanged="@(async (PlayoutViewModel x) => await PlayoutSelected(x))">
<ToolBarContent>
<MudText Typo="Typo.h6">Playouts</MudText>
</ToolBarContent>
<ColGroup>
<col/>
<col/>
<col/>
<col style="width: 60px;"/>
</ColGroup>
<HeaderContent>
<MudTh>Id</MudTh>
<MudTh>Channel</MudTh>
<MudTh>Schedule</MudTh>
<MudTh>Playout Type</MudTh>
@* <MudTh>Playout Type</MudTh> *@
<MudTh/>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Id">@context.Id</MudTd>
<MudTd DataLabel="Channel">@context.Channel.Name</MudTd>
<MudTd DataLabel="Channel">@context.Channel.Number - @context.Channel.Name</MudTd>
<MudTd DataLabel="Schedule">@context.ProgramSchedule.Name</MudTd>
<MudTd DataLabel="Playout Type">@context.ProgramSchedulePlayoutType</MudTd>
@* <MudTd DataLabel="Playout Type">@context.ProgramSchedulePlayoutType</MudTd> *@
<MudTd>
<MudIconButton Icon="@Icons.Material.Filled.Delete" OnClick="@(_ => DeletePlayout(context))"></MudIconButton>
</MudTd>
</RowTemplate>
</MudTable>
<MudButton Variant="Variant.Filled" Color="Color.Primary" Link="/playouts/add" Class="mt-4">
Add Playout
</MudButton>
@if (_selectedPlayoutItems != null)
{
@ -47,10 +62,28 @@ @@ -47,10 +62,28 @@
private List<PlayoutViewModel> _playouts;
private List<PlayoutItemViewModel> _selectedPlayoutItems;
protected override async Task OnParametersSetAsync() =>
_playouts = await Mediator.Send(new GetAllPlayouts());
protected override Task OnParametersSetAsync() =>
LoadAllPlayouts();
private async Task PlayoutSelected(PlayoutViewModel playout) =>
_selectedPlayoutItems = await Mediator.Send(new GetPlayoutItemsById(playout.Id));
private async Task DeletePlayout(PlayoutViewModel playout)
{
var parameters = new DialogParameters { { "EntityType", "playout" }, { "EntityName", $"{playout.ProgramSchedule.Name} on {playout.Channel.Number} - {playout.Channel.Name}" } };
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall };
IDialogReference dialog = Dialog.Show<DeleteDialog>("Delete Media Collection", parameters, options);
DialogResult result = await dialog.Result;
if (!result.Cancelled)
{
await Mediator.Send(new DeletePlayout(playout.Id));
await LoadAllPlayouts();
}
}
private async Task LoadAllPlayouts() =>
_playouts = await Mediator.Send(new GetAllPlayouts());
}

7
ErsatzTV/Pages/ScheduleItemsEditor.razor

@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
@using ErsatzTV.Application.ProgramSchedules.Commands
@using ErsatzTV.Application.ProgramSchedules.Queries
@inject NavigationManager NavigationManager
@inject ILogger<ChannelEditor> Logger
@inject ILogger<ScheduleItemsEditor> Logger
@inject ISnackbar Snackbar
@inject IMediator Mediator
@ -74,7 +74,7 @@ @@ -74,7 +74,7 @@
}
</MudSelect>
<MudTextField Class="mt-3" Label="Start Time" @bind-Value="@_selectedItem.StartTime" For="@(() => _selectedItem.StartTime)" Disabled="@(_selectedItem.StartType == StartType.Dynamic)"/>
<MudAutocomplete T="MediaCollectionViewModel" Label="Media Collection" @bind-value="_selectedItem.MediaCollection" SearchFunc="@SearchMediaCollections" ToStringFunc="@(c => c?.Name)"/>
<MudAutocomplete Class="mt-3" T="MediaCollectionViewModel" Label="Media Collection" @bind-value="_selectedItem.MediaCollection" SearchFunc="@SearchMediaCollections" ToStringFunc="@(c => c?.Name)"/>
<MudSelect Class="mt-3" Label="Playout Mode" @bind-Value="@_selectedItem.PlayoutMode" For="@(() => _selectedItem.PlayoutMode)">
@foreach (PlayoutMode playoutMode in Enum.GetValues<PlayoutMode>())
{
@ -169,7 +169,8 @@ @@ -169,7 +169,8 @@
_schedule.Items.Remove(item);
}
private async Task<IEnumerable<MediaCollectionViewModel>> SearchMediaCollections(string value) => _mediaCollections.Filter(c => c.Name.StartsWith(value));
private Task<IEnumerable<MediaCollectionViewModel>> SearchMediaCollections(string value) =>
_mediaCollections.Filter(c => c.Name.ToLowerInvariant().StartsWith(value ?? string.Empty)).AsTask();
private async Task SaveChanges()
{

4
ErsatzTV/Shared/MediaItemTable.razor

@ -49,10 +49,10 @@ @@ -49,10 +49,10 @@
return new TableData<AggregateMediaItemViewModel> { TotalItems = _totalItems, Items = _pagedData };
}
private void OnSearch(string text)
private async Task OnSearch(string text)
{
_searchString = text;
_table.ReloadServerData();
await _table.ReloadServerData();
}
private class MediaItemAggregate

14
ErsatzTV/Validators/PlayoutEditViewModelValidator.cs

@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
using ErsatzTV.ViewModels;
using FluentValidation;
namespace ErsatzTV.Validators
{
public class PlayoutEditViewModelValidator : AbstractValidator<PlayoutEditViewModel>
{
public PlayoutEditViewModelValidator()
{
RuleFor(p => p.Channel).NotNull();
RuleFor(p => p.ProgramSchedule).NotNull();
}
}
}

16
ErsatzTV/ViewModels/PlayoutEditViewModel.cs

@ -0,0 +1,16 @@ @@ -0,0 +1,16 @@
using ErsatzTV.Application.Channels;
using ErsatzTV.Application.Playouts.Commands;
using ErsatzTV.Application.ProgramSchedules;
using ErsatzTV.Core.Domain;
namespace ErsatzTV.ViewModels
{
public class PlayoutEditViewModel
{
public ChannelViewModel Channel { get; set; }
public ProgramScheduleViewModel ProgramSchedule { get; set; }
public CreatePlayout ToCreate() =>
new CreatePlayout(Channel.Id, ProgramSchedule.Id, ProgramSchedulePlayoutType.Flood);
}
}
Loading…
Cancel
Save