174 lines
6.3 KiB
Plaintext
174 lines
6.3 KiB
Plaintext
@typeparam TViewModel
|
|
@typeparam TSecrets
|
|
@implements IDisposable
|
|
@using ErsatzTV.Core.Interfaces.MediaSources
|
|
@typeparam TMediaSource
|
|
@inject IMediator Mediator
|
|
@inject IDialogService Dialog
|
|
@inject IEntityLocker Locker
|
|
|
|
<MudForm Style="max-height: 100%">
|
|
<MudPaper Square="true" Style="display: flex; height: 64px; min-height: 64px; width: 100%; z-index: 100; align-items: center">
|
|
@if (_mediaSources.Any())
|
|
{
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Error"
|
|
OnClick="@(_ => Disconnect())"
|
|
Class="ml-8">
|
|
Disconnect @Name
|
|
</MudButton>
|
|
}
|
|
else
|
|
{
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Primary"
|
|
Href="@($"media/sources/{Name.ToLowerInvariant()}/edit")"
|
|
Class="ml-8">
|
|
Connect @Name
|
|
</MudButton>
|
|
}
|
|
|
|
@if (_mediaSources.Any())
|
|
{
|
|
@if (CanEdit)
|
|
{
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Secondary"
|
|
Href="@($"media/sources/{Name.ToLowerInvariant()}/edit")"
|
|
Class="ml-4">
|
|
Edit @Name Connection
|
|
</MudButton>
|
|
}
|
|
else if (!_isAuthorized)
|
|
{
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Secondary"
|
|
Href="@($"media/sources/{Name.ToLowerInvariant()}/edit")"
|
|
Class="ml-4">
|
|
Fix @Name Connection
|
|
</MudButton>
|
|
}
|
|
}
|
|
</MudPaper>
|
|
<div class="d-flex flex-column" style="height: 100vh; overflow-x: auto">
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<MudText Typo="Typo.h5" Class="mb-2">@Name Media Sources</MudText>
|
|
<MudDivider Class="mb-6"/>
|
|
<MudTable Hover="true" Dense="true" Items="_mediaSources">
|
|
<ColGroup>
|
|
<MudHidden Breakpoint="Breakpoint.Xs">
|
|
<col/>
|
|
<col/>
|
|
<col style="width: 120px;"/>
|
|
</MudHidden>
|
|
</ColGroup>
|
|
<HeaderContent>
|
|
<MudTh>Name</MudTh>
|
|
<MudTh>Address</MudTh>
|
|
<MudTh/>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd>@context.Name</MudTd>
|
|
<MudTd Style="overflow-wrap: anywhere;">@context.Address</MudTd>
|
|
<MudTd>
|
|
<div style="align-items: center; display: flex;">
|
|
<MudTooltip Text="Refresh Libraries">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh"
|
|
Disabled="@(Locker.IsRemoteMediaSourceLocked<TMediaSource>())"
|
|
OnClick="@(_ => RefreshLibraries(context.Id, _cts?.Token ?? CancellationToken.None))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Edit Libraries">
|
|
<MudIconButton Icon="@Icons.Material.Filled.VideoLibrary"
|
|
Href="@($"media/sources/{Name.ToLowerInvariant()}/{context.Id}/libraries")">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Edit Path Replacements">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Folder"
|
|
Href="@($"media/sources/{Name.ToLowerInvariant()}/{context.Id}/paths")">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
</div>
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
</MudContainer>
|
|
</div>
|
|
</MudForm>
|
|
|
|
@code {
|
|
private CancellationTokenSource _cts;
|
|
|
|
[Parameter]
|
|
public string Name { get; set; }
|
|
|
|
[Parameter]
|
|
public IRequest<List<TViewModel>> GetAllMediaSourcesCommand { get; set; }
|
|
|
|
[Parameter]
|
|
public IRequest<Either<BaseError, Unit>> DisconnectCommand { get; set; }
|
|
|
|
[Parameter]
|
|
public Func<int, CancellationToken, Task> RefreshLibrariesCommand { get; set; }
|
|
|
|
[Parameter]
|
|
public IRemoteMediaSourceSecretStore<TSecrets> SecretStore { get; set; }
|
|
|
|
[Parameter]
|
|
public bool CanEdit { get; set; }
|
|
|
|
private List<TViewModel> _mediaSources = [];
|
|
|
|
private bool _isAuthorized;
|
|
|
|
public void Dispose()
|
|
{
|
|
_cts?.Cancel();
|
|
_cts?.Dispose();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync()
|
|
{
|
|
_cts?.Cancel();
|
|
_cts?.Dispose();
|
|
_cts = new CancellationTokenSource();
|
|
var token = _cts.Token;
|
|
|
|
try
|
|
{
|
|
await LoadMediaSources(token);
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
// do nothing
|
|
}
|
|
}
|
|
|
|
private async Task LoadMediaSources(CancellationToken cancellationToken)
|
|
{
|
|
_isAuthorized = await SecretStore.ReadSecrets()
|
|
.Map(secrets => !string.IsNullOrWhiteSpace(secrets.Address) && !string.IsNullOrWhiteSpace(secrets.ApiKey));
|
|
_mediaSources = await Mediator.Send(GetAllMediaSourcesCommand, cancellationToken);
|
|
}
|
|
|
|
private async Task Disconnect()
|
|
{
|
|
var parameters = new DialogParameters { { "Name", Name } };
|
|
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.Small };
|
|
IDialogReference dialog = await Dialog.ShowAsync<DisconnectRemoteMediaSourceDialog>($"Disconnect {Name}", parameters, options);
|
|
DialogResult result = await dialog.Result;
|
|
if (result is { Canceled: false })
|
|
{
|
|
if (Locker.LockRemoteMediaSource<TMediaSource>())
|
|
{
|
|
await Mediator.Send(DisconnectCommand, _cts.Token);
|
|
await LoadMediaSources(_cts.Token);
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task RefreshLibraries(int mediaSourceId, CancellationToken cancellationToken) =>
|
|
await RefreshLibrariesCommand(mediaSourceId, cancellationToken);
|
|
|
|
}
|