* fix updating plex path replacements * fix adding/removing plex libraries * fix adding/removing plex servers * fix initial plex library sync after sign in * code cleanup
159 lines
6.7 KiB
Plaintext
159 lines
6.7 KiB
Plaintext
@page "/channels/{Id:int?}"
|
|
@page "/channels/add"
|
|
@using static LanguageExt.Prelude
|
|
@using ErsatzTV.Application.FFmpegProfiles
|
|
@using ErsatzTV.Application.FFmpegProfiles.Queries
|
|
@using ErsatzTV.Application.Images.Commands
|
|
@using ErsatzTV.Application.Channels
|
|
@using ErsatzTV.Application.Channels.Queries
|
|
@inject NavigationManager NavigationManager
|
|
@inject ILogger<ChannelEditor> Logger
|
|
@inject ISnackbar Snackbar
|
|
@inject IMediator Mediator
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<div style="max-width: 400px;">
|
|
<MudText Typo="Typo.h4" Class="mb-4">@(IsEdit ? "Edit Channel" : "Add Channel")</MudText>
|
|
|
|
<EditForm EditContext="_editContext" OnSubmit="@HandleSubmitAsync">
|
|
<FluentValidator/>
|
|
<MudCard>
|
|
<MudCardContent>
|
|
<MudTextField Label="Number" @bind-Value="_model.Number" For="@(() => _model.Number)" Immediate="true"/>
|
|
<MudTextField Class="mt-3" Label="Name" @bind-Value="_model.Name" For="@(() => _model.Name)"/>
|
|
<MudSelect Class="mt-3" Label="Streaming Mode" @bind-Value="_model.StreamingMode" For="@(() => _model.StreamingMode)">
|
|
@foreach (StreamingMode streamingMode in Enum.GetValues<StreamingMode>())
|
|
{
|
|
<MudSelectItem Value="@streamingMode">@streamingMode</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
<MudSelect Class="mt-3" Label="FFmpeg Profile" @bind-Value="_model.FFmpegProfileId" For="@(() => _model.FFmpegProfileId)"
|
|
Disabled="@(_model.StreamingMode != StreamingMode.TransportStream)">
|
|
@foreach (FFmpegProfileViewModel profile in _ffmpegProfiles)
|
|
{
|
|
<MudSelectItem Value="@profile.Id">@profile.Name</MudSelectItem>
|
|
}
|
|
</MudSelect>
|
|
<MudGrid Class="mt-3" Style="align-items: center" Justify="Justify.Center">
|
|
<MudItem xs="6">
|
|
<InputFile id="fileInput" OnChange="UploadLogo" hidden/>
|
|
@if (!string.IsNullOrWhiteSpace(_model.Logo))
|
|
{
|
|
<MudElement HtmlTag="img" src="@($"iptv/logos/{_model.Logo}")" Style="max-height: 50px"/>
|
|
}
|
|
</MudItem>
|
|
<MudItem xs="6">
|
|
<MudButton Class="ml-auto" HtmlTag="label"
|
|
Variant="Variant.Filled"
|
|
Color="Color.Primary"
|
|
StartIcon="@Icons.Material.Filled.CloudUpload"
|
|
for="fileInput">
|
|
Upload Logo
|
|
</MudButton>
|
|
</MudItem>
|
|
</MudGrid>
|
|
</MudCardContent>
|
|
<MudCardActions>
|
|
<MudButton ButtonType="ButtonType.Submit" Variant="Variant.Filled" Color="Color.Primary">
|
|
@(IsEdit ? "Save Changes" : "Add Channel")
|
|
</MudButton>
|
|
</MudCardActions>
|
|
</MudCard>
|
|
</EditForm>
|
|
</div>
|
|
</MudContainer>
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
|
public int? Id { get; set; }
|
|
|
|
private readonly ChannelEditViewModel _model = new();
|
|
private EditContext _editContext;
|
|
private ValidationMessageStore _messageStore;
|
|
|
|
private List<FFmpegProfileViewModel> _ffmpegProfiles;
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
await LoadFFmpegProfilesAsync();
|
|
|
|
if (Id.HasValue)
|
|
{
|
|
Option<ChannelViewModel> maybeChannel = await Mediator.Send(new GetChannelById(Id.Value));
|
|
maybeChannel.Match(
|
|
channelViewModel =>
|
|
{
|
|
_model.Id = channelViewModel.Id;
|
|
_model.Name = channelViewModel.Name;
|
|
_model.Number = channelViewModel.Number;
|
|
_model.FFmpegProfileId = channelViewModel.FFmpegProfileId;
|
|
_model.Logo = channelViewModel.Logo;
|
|
_model.StreamingMode = channelViewModel.StreamingMode;
|
|
},
|
|
() => NavigationManager.NavigateTo("404"));
|
|
}
|
|
else
|
|
{
|
|
FFmpegSettingsViewModel ffmpegSettings = await Mediator.Send(new GetFFmpegSettings());
|
|
|
|
// TODO: command for new channel
|
|
IEnumerable<int> channelNumbers = await Mediator.Send(new GetAllChannels())
|
|
.Map(list => list.Map(c => int.TryParse(c.Number.Split(".").Head(), out int result) ? result : 0));
|
|
int maxNumber = Optional(channelNumbers).Flatten().DefaultIfEmpty(0).Max();
|
|
_model.Number = (maxNumber + 1).ToString();
|
|
_model.Name = "New Channel";
|
|
_model.FFmpegProfileId = ffmpegSettings.DefaultFFmpegProfileId;
|
|
_model.StreamingMode = StreamingMode.TransportStream;
|
|
}
|
|
}
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
_editContext = new EditContext(_model);
|
|
_messageStore = new ValidationMessageStore(_editContext);
|
|
}
|
|
|
|
private bool IsEdit => Id.HasValue;
|
|
|
|
private async Task LoadFFmpegProfilesAsync() =>
|
|
_ffmpegProfiles = await Mediator.Send(new GetAllFFmpegProfiles());
|
|
|
|
private async Task HandleSubmitAsync()
|
|
{
|
|
_messageStore.Clear();
|
|
if (_editContext.Validate())
|
|
{
|
|
Seq<BaseError> errorMessage = IsEdit ?
|
|
(await Mediator.Send(_model.ToUpdate())).LeftToSeq() :
|
|
(await Mediator.Send(_model.ToCreate())).LeftToSeq();
|
|
|
|
errorMessage.HeadOrNone().Match(
|
|
error =>
|
|
{
|
|
Snackbar.Add(error.Value, Severity.Error);
|
|
Logger.LogError("Unexpected error saving channel: {Error}", error.Value);
|
|
},
|
|
() => NavigationManager.NavigateTo("/channels"));
|
|
}
|
|
}
|
|
|
|
private async Task UploadLogo(InputFileChangeEventArgs e)
|
|
{
|
|
var buffer = new byte[e.File.Size];
|
|
await e.File.OpenReadStream().ReadAsync(buffer);
|
|
Either<BaseError, string> maybeCacheFileName = await Mediator.Send(new SaveArtworkToDisk(buffer, ArtworkKind.Logo));
|
|
maybeCacheFileName.Match(
|
|
relativeFileName =>
|
|
{
|
|
_model.Logo = relativeFileName;
|
|
StateHasChanged();
|
|
},
|
|
error =>
|
|
{
|
|
Snackbar.Add($"Unexpected error saving channel logo: {error.Value}", Severity.Error);
|
|
Logger.LogError("Unexpected error saving channel logo: {Error}", error.Value);
|
|
});
|
|
}
|
|
|
|
} |