mirror of https://github.com/ErsatzTV/ErsatzTV.git
4 changed files with 1 additions and 150 deletions
@ -1,9 +0,0 @@
@@ -1,9 +0,0 @@
|
||||
using System.Threading.Tasks; |
||||
using ErsatzTV.Core; |
||||
using LanguageExt; |
||||
using MediatR; |
||||
|
||||
namespace ErsatzTV.Application.MediaSources.Commands |
||||
{ |
||||
public record DeleteLocalMediaSource(int LocalMediaSourceId) : IRequest<Either<BaseError, Task>>; |
||||
} |
||||
@ -1,38 +0,0 @@
@@ -1,38 +0,0 @@
|
||||
using System.Linq; |
||||
using System.Threading; |
||||
using System.Threading.Tasks; |
||||
using ErsatzTV.Core; |
||||
using ErsatzTV.Core.Domain; |
||||
using ErsatzTV.Core.Interfaces.Repositories; |
||||
using LanguageExt; |
||||
using MediatR; |
||||
|
||||
namespace ErsatzTV.Application.MediaSources.Commands |
||||
{ |
||||
public class |
||||
DeleteLocalMediaSourceHandler : IRequestHandler<DeleteLocalMediaSource, Either<BaseError, Task>> |
||||
{ |
||||
private readonly IMediaSourceRepository _mediaSourceRepository; |
||||
|
||||
public DeleteLocalMediaSourceHandler(IMediaSourceRepository mediaSourceRepository) => |
||||
_mediaSourceRepository = mediaSourceRepository; |
||||
|
||||
public async Task<Either<BaseError, Task>> Handle( |
||||
DeleteLocalMediaSource request, |
||||
CancellationToken cancellationToken) => |
||||
(await MediaSourceMustExist(request)) |
||||
.Map(DoDeletion) |
||||
.ToEither<Task>(); |
||||
|
||||
private async Task DoDeletion(LocalMediaSource mediaSource) => |
||||
await _mediaSourceRepository.Delete(mediaSource.Id); |
||||
|
||||
private async Task<Validation<BaseError, LocalMediaSource>> MediaSourceMustExist( |
||||
DeleteLocalMediaSource deleteMediaSource) => |
||||
(await _mediaSourceRepository.Get(deleteMediaSource.LocalMediaSourceId)) |
||||
.OfType<LocalMediaSource>() |
||||
.HeadOrNone() |
||||
.ToValidation<BaseError>( |
||||
$"Local media source {deleteMediaSource.LocalMediaSourceId} does not exist."); |
||||
} |
||||
} |
||||
@ -1,102 +0,0 @@
@@ -1,102 +0,0 @@
|
||||
@using ErsatzTV.Application.MediaSources |
||||
@using ErsatzTV.Application.MediaSources.Commands |
||||
@using ErsatzTV.Application.MediaSources.Queries |
||||
@implements IDisposable |
||||
@inject IDialogService Dialog |
||||
@inject IMediator Mediator |
||||
@inject IEntityLocker Locker |
||||
@inject ChannelWriter<IBackgroundServiceRequest> Channel |
||||
|
||||
<MudTable Hover="true" Items="_mediaSources" Dense="true"> |
||||
<ToolBarContent> |
||||
<MudText Typo="Typo.h6">Local Media Sources</MudText> |
||||
</ToolBarContent> |
||||
<ColGroup> |
||||
<col/> |
||||
<col style="width: 120px;"/> |
||||
</ColGroup> |
||||
<HeaderContent> |
||||
<MudTh>Folder</MudTh> |
||||
<MudTh/> |
||||
</HeaderContent> |
||||
<RowTemplate> |
||||
<MudTd DataLabel="Folder">@context.Folder</MudTd> |
||||
<MudTd> |
||||
<div style="align-items: center; display: flex;"> |
||||
@if (Locker.IsLibraryLocked(context.Id)) |
||||
{ |
||||
<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 |
||||
{ |
||||
<MudTooltip Text="Scan Media Source"> |
||||
<MudIconButton Icon="@Icons.Material.Filled.Refresh" |
||||
Disabled="@Locker.IsLibraryLocked(context.Id)" |
||||
OnClick="@(_ => ScanMediaSource(context))"> |
||||
</MudIconButton> |
||||
</MudTooltip> |
||||
} |
||||
<MudTooltip Text="Delete Media Source"> |
||||
<MudIconButton Icon="@Icons.Material.Filled.Delete" |
||||
Disabled="@Locker.IsLibraryLocked(context.Id)" |
||||
OnClick="@(_ => DeleteMediaSource(context))"> |
||||
</MudIconButton> |
||||
</MudTooltip> |
||||
</div> |
||||
</MudTd> |
||||
</RowTemplate> |
||||
</MudTable> |
||||
@* <MudButton Variant="Variant.Filled" Color="Color.Primary" Link="/media/sources/local/add" Class="mt-4"> *@ |
||||
@* Add Local Media Source *@ |
||||
@* </MudButton> *@ |
||||
|
||||
@code { |
||||
private IList<LocalMediaSourceViewModel> _mediaSources; |
||||
|
||||
protected override void OnInitialized() => |
||||
Locker.OnLibraryChanged += LockChanged; |
||||
|
||||
protected override async Task OnParametersSetAsync() => await LoadMediaSources(); |
||||
|
||||
private async Task LoadMediaSources() => |
||||
_mediaSources = await Mediator.Send(new GetAllMediaSources()).Map(list => list.OfType<LocalMediaSourceViewModel>().ToList()); |
||||
|
||||
private async Task DeleteMediaSource(LocalMediaSourceViewModel mediaSource) |
||||
{ |
||||
int count = await Mediator.Send(new CountMediaItemsById(mediaSource.Id)); |
||||
|
||||
var parameters = new DialogParameters |
||||
{ |
||||
{ "EntityType", "media source" }, |
||||
{ "EntityName", mediaSource.Folder }, |
||||
{ "DetailText", $"This media source contains {count} media items." }, |
||||
{ "DetailHighlight", count.ToString() } |
||||
}; |
||||
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall }; |
||||
|
||||
IDialogReference dialog = Dialog.Show<DeleteDialog>("Delete Media Source", parameters, options); |
||||
DialogResult result = await dialog.Result; |
||||
if (!result.Cancelled) |
||||
{ |
||||
await Mediator.Send(new DeleteLocalMediaSource(mediaSource.Id)); |
||||
await LoadMediaSources(); |
||||
} |
||||
} |
||||
|
||||
private async Task ScanMediaSource(LocalMediaSourceViewModel mediaSource) |
||||
{ |
||||
if (Locker.LockLibrary(mediaSource.Id)) |
||||
{ |
||||
await Channel.WriteAsync(new ForceScanLocalLibrary(mediaSource.Id)); |
||||
StateHasChanged(); |
||||
} |
||||
} |
||||
|
||||
private void LockChanged(object sender, EventArgs e) => |
||||
InvokeAsync(StateHasChanged); |
||||
|
||||
void IDisposable.Dispose() => Locker.OnLibraryChanged -= LockChanged; |
||||
|
||||
} |
||||
Loading…
Reference in new issue