* rework alternate schedules editor * rework playout templates editor
112 lines
4.6 KiB
Plaintext
112 lines
4.6 KiB
Plaintext
@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 readonly CancellationTokenSource _cts = new();
|
|
|
|
private IList<LocalLibraryViewModel> _libraries;
|
|
|
|
protected override void OnInitialized() => Locker.OnLibraryChanged += LockChanged;
|
|
|
|
protected override async Task OnParametersSetAsync() => await LoadLibraries(_cts.Token);
|
|
|
|
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)
|
|
{
|
|
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",
|
|
_ => "Unknown"
|
|
};
|
|
|
|
void IDisposable.Dispose()
|
|
{
|
|
Locker.OnLibraryChanged -= LockChanged;
|
|
|
|
_cts.Cancel();
|
|
_cts.Dispose();
|
|
}
|
|
|
|
|
|
} |