144 lines
5.4 KiB
Plaintext
144 lines
5.4 KiB
Plaintext
@page "/media/libraries"
|
|
@using MediatR.Courier
|
|
@using ErsatzTV.Application.Libraries
|
|
@using ErsatzTV.Application.Libraries.Queries
|
|
@using ErsatzTV.Application.MediaSources.Commands
|
|
@using ErsatzTV.Application.Plex.Commands
|
|
@using ErsatzTV.Core.Metadata
|
|
@using System.Threading
|
|
@implements IDisposable
|
|
@inject IMediator Mediator
|
|
@inject IEntityLocker Locker
|
|
@inject ChannelWriter<IBackgroundServiceRequest> WorkerChannel
|
|
@inject ChannelWriter<IPlexBackgroundServiceRequest> PlexWorkerChannel
|
|
@inject ICourier Courier
|
|
|
|
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="pt-8">
|
|
<MudTable Hover="true" Items="_libraries" Dense="true">
|
|
<ToolBarContent>
|
|
<MudText Typo="Typo.h6">Libraries</MudText>
|
|
</ToolBarContent>
|
|
<ColGroup>
|
|
<col/>
|
|
<col/>
|
|
<col/>
|
|
<col style="width: 240px;"/>
|
|
</ColGroup>
|
|
<HeaderContent>
|
|
<MudTh>Library Kind</MudTh>
|
|
<MudTh>Name</MudTh>
|
|
<MudTh>Media Kind</MudTh>
|
|
<MudTh/>
|
|
</HeaderContent>
|
|
<RowTemplate>
|
|
<MudTd DataLabel="Library Kind">@context.LibraryKind</MudTd>
|
|
<MudTd DataLabel="Name">@context.Name</MudTd>
|
|
<MudTd DataLabel="Media Kind">@context.MediaKind</MudTd>
|
|
<MudTd>
|
|
<div style="align-items: center; display: flex;">
|
|
@if (Locker.IsLibraryLocked(context.Id))
|
|
{
|
|
<div style="width: 48px">
|
|
@if (_progressByLibrary[context.Id] > 0)
|
|
{
|
|
<MudText Color="Color.Primary">
|
|
@($"{_progressByLibrary[context.Id]} %")
|
|
</MudText>
|
|
}
|
|
</div>
|
|
<div style="align-items: center; display: flex; height: 48px; justify-content: center; width: 48px;">
|
|
<MudProgressCircular Color="Color.Primary" Size="Size.Small" Indeterminate="true"/>
|
|
</div>
|
|
}
|
|
else
|
|
{
|
|
<div style="width: 48px"></div>
|
|
<MudTooltip Text="Scan Library">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Refresh"
|
|
Disabled="@Locker.IsLibraryLocked(context.Id)"
|
|
OnClick="@(_ => ScanLibrary(context))">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
}
|
|
<MudTooltip Text="Search Library">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Search"
|
|
Link="@($"/search?query=library_name%3a%22{Uri.EscapeDataString(context.Name)}%22")">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
@if (context is LocalLibraryViewModel)
|
|
{
|
|
<MudTooltip Text="Edit Library">
|
|
<MudIconButton Icon="@Icons.Material.Filled.Edit"
|
|
Disabled="@Locker.IsLibraryLocked(context.Id)"
|
|
Link="@($"/media/libraries/local/{context.Id}")">
|
|
</MudIconButton>
|
|
</MudTooltip>
|
|
}
|
|
</div>
|
|
</MudTd>
|
|
</RowTemplate>
|
|
</MudTable>
|
|
</MudContainer>
|
|
|
|
@code {
|
|
private IList<LibraryViewModel> _libraries;
|
|
private Dictionary<int, int> _progressByLibrary;
|
|
|
|
protected override void OnInitialized()
|
|
{
|
|
Locker.OnLibraryChanged += LockChanged;
|
|
Courier.Subscribe<LibraryScanProgress>(HandleScanProgress);
|
|
}
|
|
|
|
protected override async Task OnParametersSetAsync() => await LoadLibraries();
|
|
|
|
private async Task LoadLibraries()
|
|
{
|
|
_libraries = await Mediator.Send(new GetAllLibraries());
|
|
_progressByLibrary = _libraries.ToDictionary(vm => vm.Id, _ => 0);
|
|
}
|
|
|
|
private async Task ScanLibrary(LibraryViewModel library)
|
|
{
|
|
if (Locker.LockLibrary(library.Id))
|
|
{
|
|
switch (library)
|
|
{
|
|
case LocalLibraryViewModel:
|
|
await WorkerChannel.WriteAsync(new ForceScanLocalLibrary(library.Id));
|
|
break;
|
|
case PlexLibraryViewModel:
|
|
await PlexWorkerChannel.WriteAsync(new ForceSynchronizePlexLibraryById(library.Id));
|
|
break;
|
|
}
|
|
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
|
|
private void LockChanged(object sender, EventArgs e) =>
|
|
InvokeAsync(StateHasChanged);
|
|
|
|
private async Task HandleScanProgress(LibraryScanProgress libraryScanProgress, CancellationToken cancellationToken)
|
|
{
|
|
try
|
|
{
|
|
if (_progressByLibrary != null && _progressByLibrary.ContainsKey(libraryScanProgress.LibraryId))
|
|
{
|
|
_progressByLibrary[libraryScanProgress.LibraryId] = (int) (libraryScanProgress.Progress * 100);
|
|
await InvokeAsync(StateHasChanged);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// ignore
|
|
}
|
|
}
|
|
|
|
void IDisposable.Dispose()
|
|
{
|
|
Locker.OnLibraryChanged -= LockChanged;
|
|
Courier.UnSubscribe<LibraryScanProgress>(HandleScanProgress);
|
|
}
|
|
|
|
} |