136 lines
4.7 KiB
Plaintext
136 lines
4.7 KiB
Plaintext
@typeparam TViewModel
|
|
@typeparam TSecrets
|
|
@implements IDisposable
|
|
@using ErsatzTV.Core.Interfaces.MediaSources
|
|
@typeparam TMediaSource
|
|
@inject IMediator _mediator
|
|
@inject IDialogService _dialog
|
|
@inject IEntityLocker _locker
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<MudTable Hover="true" Dense="true" Items="_mediaSources">
|
|
<ToolBarContent>
|
|
<MudText Typo="Typo.h6">@Name Media Sources</MudText>
|
|
</ToolBarContent>
|
|
<ColGroup>
|
|
<col/>
|
|
<col/>
|
|
<col style="width: 120px;"/>
|
|
</ColGroup>
|
|
<HeaderContent>
|
|
<MudTh>Name</MudTh>
|
|
<MudTh>Address</MudTh>
|
|
<MudTh/>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Name">@context.Name</MudTd>
|
|
<MudTd DataLabel="Address">@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))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Edit Libraries">
|
|
<MudIconButton Icon="@Icons.Material.Filled.VideoLibrary"
|
|
Link="@($"media/sources/{Name.ToLowerInvariant()}/{context.Id}/libraries")">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
<MudTooltip Text="Edit Path Replacements">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Folder"
|
|
Link="@($"media/sources/{Name.ToLowerInvariant()}/{context.Id}/paths")">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
</div>
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
@if (_mediaSources.Any())
|
|
{
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Error"
|
|
OnClick="@(_ => Disconnect())"
|
|
Class="mt-4">
|
|
Disconnect @Name
|
|
</MudButton>
|
|
}
|
|
else
|
|
{
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Primary"
|
|
Link="@($"media/sources/{Name.ToLowerInvariant()}/edit")"
|
|
Class="mt-4">
|
|
Connect @Name
|
|
</MudButton>
|
|
}
|
|
|
|
@if (_mediaSources.Any() && !_isAuthorized)
|
|
{
|
|
<MudButton Variant="Variant.Filled"
|
|
Color="Color.Secondary"
|
|
Link="@($"media/sources/{Name.ToLowerInvariant()}/edit")"
|
|
Class="ml-4 mt-4">
|
|
Fix @Name Connection
|
|
</MudButton>
|
|
}
|
|
|
|
</MudContainer>
|
|
|
|
@code {
|
|
private readonly CancellationTokenSource _cts = new();
|
|
|
|
[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, Task> RefreshLibrariesCommand { get; set; }
|
|
|
|
[Parameter]
|
|
public IRemoteMediaSourceSecretStore<TSecrets> SecretStore { get; set; }
|
|
|
|
private List<TViewModel> _mediaSources = new();
|
|
|
|
private bool _isAuthorized;
|
|
|
|
public void Dispose()
|
|
{
|
|
_cts.Cancel();
|
|
_cts.Dispose();
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync() => await LoadMediaSources();
|
|
|
|
private async Task LoadMediaSources()
|
|
{
|
|
_isAuthorized = await SecretStore.ReadSecrets()
|
|
.Map(secrets => !string.IsNullOrWhiteSpace(secrets.Address) && !string.IsNullOrWhiteSpace(secrets.ApiKey));
|
|
_mediaSources = await _mediator.Send(GetAllMediaSourcesCommand, _cts.Token);
|
|
}
|
|
|
|
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.Canceled)
|
|
{
|
|
if (_locker.LockRemoteMediaSource<TMediaSource>())
|
|
{
|
|
await _mediator.Send(DisconnectCommand, _cts.Token);
|
|
await LoadMediaSources();
|
|
}
|
|
}
|
|
}
|
|
|
|
private async Task RefreshLibraries(int mediaSourceId) => await RefreshLibrariesCommand(mediaSourceId);
|
|
|
|
} |