mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
5.0 KiB
131 lines
5.0 KiB
@page "/media/sources/local" |
|
@using ErsatzTV.Application.Libraries |
|
@implements IDisposable |
|
@inject IDialogService Dialog |
|
@inject IMediator Mediator |
|
@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"> |
|
<MudButton Variant="Variant.Filled" Color="Color.Primary" Class="ml-6" StartIcon="@Icons.Material.Filled.Add" Href="media/sources/local/add"> |
|
Add Local Library |
|
</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">Local Libraries</MudText> |
|
<MudDivider Class="mb-6"/> |
|
<MudTable Hover="true" Items="_libraries" Dense="true"> |
|
<ColGroup> |
|
<MudHidden Breakpoint="Breakpoint.Xs"> |
|
<col/> |
|
<col/> |
|
<col style="width: 120px;"/> |
|
</MudHidden> |
|
</ColGroup> |
|
<HeaderContent> |
|
<MudTh>Name</MudTh> |
|
<MudTh>Media Kind</MudTh> |
|
<MudTh/> |
|
</HeaderContent> |
|
<RowTemplate> |
|
<MudTd DataLabel="Name">@context.Name</MudTd> |
|
<MudTd DataLabel="Media Kind">@StringForMediaKind(context.MediaKind)</MudTd> |
|
<MudTd> |
|
<div style="align-items: center; display: flex;"> |
|
<MudTooltip Text="Edit Library"> |
|
<MudIconButton Icon="@Icons.Material.Filled.Edit" |
|
Disabled="@Locker.IsLibraryLocked(context.Id)" |
|
Href="@($"media/sources/local/{context.Id}/edit")"> |
|
</MudIconButton> |
|
</MudTooltip> |
|
<MudTooltip Text="Delete Library"> |
|
<MudIconButton Icon="@Icons.Material.Filled.Delete" |
|
Disabled="@Locker.IsLibraryLocked(context.Id)" |
|
OnClick="@(() => DeleteLibrary(context))"> |
|
</MudIconButton> |
|
</MudTooltip> |
|
</div> |
|
</MudTd> |
|
</RowTemplate> |
|
</MudTable> |
|
</MudContainer> |
|
</div> |
|
</MudForm> |
|
|
|
@code { |
|
private CancellationTokenSource _cts; |
|
|
|
private IList<LocalLibraryViewModel> _libraries; |
|
|
|
protected override void OnInitialized() => Locker.OnLibraryChanged += LockChanged; |
|
|
|
protected override async Task OnParametersSetAsync() |
|
{ |
|
_cts?.Cancel(); |
|
_cts?.Dispose(); |
|
_cts = new CancellationTokenSource(); |
|
var token = _cts.Token; |
|
|
|
try |
|
{ |
|
await LoadLibraries(token); |
|
} |
|
catch (OperationCanceledException) |
|
{ |
|
// do nothing |
|
} |
|
} |
|
|
|
private async Task LoadLibraries(CancellationToken cancellationToken) |
|
{ |
|
_libraries = await Mediator.Send(new GetAllLocalLibraries(), cancellationToken); |
|
} |
|
|
|
private void LockChanged(object sender, EventArgs e) => |
|
InvokeAsync(StateHasChanged); |
|
|
|
private async Task DeleteLibrary(LocalLibraryViewModel library) |
|
{ |
|
using var cts = new CancellationTokenSource(); |
|
|
|
int count = await Mediator.Send(new CountMediaItemsByLibrary(library.Id), cts.Token); |
|
var parameters = new DialogParameters |
|
{ |
|
{ "EntityType", "library" }, |
|
{ "EntityName", library.Name }, |
|
{ "DetailText", $"This library contains {count} media items." }, |
|
{ "DetailHighlight", count.ToString() } |
|
}; |
|
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; |
|
|
|
IDialogReference dialog = await Dialog.ShowAsync<DeleteDialog>("Delete Library", parameters, options); |
|
DialogResult result = await dialog.Result; |
|
if (result is { Canceled: false }) |
|
{ |
|
await Mediator.Send(new DeleteLocalLibrary(library.Id), cts.Token); |
|
await LoadLibraries(cts.Token); |
|
} |
|
} |
|
|
|
private static string StringForMediaKind(LibraryMediaKind mediaKind) => |
|
mediaKind switch |
|
{ |
|
LibraryMediaKind.Movies => "Movies", |
|
LibraryMediaKind.Shows => "Shows", |
|
LibraryMediaKind.MusicVideos => "Music Videos", |
|
LibraryMediaKind.OtherVideos => "Other Videos", |
|
LibraryMediaKind.Songs => "Songs", |
|
LibraryMediaKind.Images => "Images", |
|
LibraryMediaKind.RemoteStreams => "Remote Streams", |
|
_ => "Unknown" |
|
}; |
|
|
|
void IDisposable.Dispose() |
|
{ |
|
Locker.OnLibraryChanged -= LockChanged; |
|
|
|
_cts?.Cancel(); |
|
_cts?.Dispose(); |
|
} |
|
}
|
|
|