Browse Source

add empty trash button (#739)

pull/740/head
Jason Dove 4 years ago committed by GitHub
parent
commit
ff1a7b376f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      CHANGELOG.md
  2. 5
      ErsatzTV.Application/Maintenance/Commands/EmptyTrash.cs
  3. 55
      ErsatzTV.Application/Maintenance/Commands/EmptyTrashHandler.cs
  4. 28
      ErsatzTV/Pages/Trash.razor

3
CHANGELOG.md

@ -14,6 +14,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). @@ -14,6 +14,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix bug where filler would behave as if it were configured to pad even though a different mode was selected
- Fix bug where mid-roll count filler would skip scheduling the final chapter in an episode
### Added
- Add `Empty Trash` button to `Trash` page
## [0.5.0-beta] - 2022-04-13
### Fixed
- Fix `HLS Segmenter` bug where it would drift off of the schedule if a playout was changed while the segmenter was running

5
ErsatzTV.Application/Maintenance/Commands/EmptyTrash.cs

@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
using ErsatzTV.Core;
namespace ErsatzTV.Application.Maintenance;
public record EmptyTrash : IRequest<Either<BaseError, Unit>>;

55
ErsatzTV.Application/Maintenance/Commands/EmptyTrashHandler.cs

@ -0,0 +1,55 @@ @@ -0,0 +1,55 @@
using ErsatzTV.Core;
using ErsatzTV.Core.Interfaces.Repositories;
using ErsatzTV.Core.Interfaces.Search;
using ErsatzTV.Core.Search;
using ErsatzTV.Infrastructure.Search;
namespace ErsatzTV.Application.Maintenance;
public class EmptyTrashHandler : IRequestHandler<EmptyTrash, Either<BaseError, Unit>>
{
private readonly IMediaItemRepository _mediaItemRepository;
private readonly ISearchIndex _searchIndex;
public EmptyTrashHandler(
IMediaItemRepository mediaItemRepository,
ISearchIndex searchIndex)
{
_mediaItemRepository = mediaItemRepository;
_searchIndex = searchIndex;
}
public async Task<Either<BaseError, Unit>> Handle(
EmptyTrash request,
CancellationToken cancellationToken)
{
string[] types =
{
SearchIndex.MovieType,
SearchIndex.ShowType,
SearchIndex.SeasonType,
SearchIndex.EpisodeType,
SearchIndex.MusicVideoType,
SearchIndex.OtherVideoType,
SearchIndex.SongType,
SearchIndex.ArtistType
};
var ids = new List<int>();
foreach (string type in types)
{
SearchResult result = await _searchIndex.Search($"type:{type} AND (state:FileNotFound)", 0, 0);
ids.AddRange(result.Items.Map(i => i.Id));
}
Either<BaseError, Unit> deleteResult = await _mediaItemRepository.DeleteItems(ids);
if (deleteResult.IsRight)
{
await _searchIndex.RemoveItems(ids);
_searchIndex.Commit();
}
return deleteResult;
}
}

28
ErsatzTV/Pages/Trash.razor

@ -74,6 +74,17 @@ @@ -74,6 +74,17 @@
{
<MudText>Nothing to see here...</MudText>
}
else
{
<div style="margin-left: auto">
<MudButton Variant="Variant.Filled"
Color="Color.Error"
StartIcon="@Icons.Material.Filled.DeleteForever"
OnClick="@(_ => EmptyTrash())">
Empty Trash
</MudButton>
</div>
}
}
</div>
</MudPaper>
@ -560,4 +571,21 @@ @@ -560,4 +571,21 @@
}
}
private async Task EmptyTrash()
{
int count = _movies.Count + _shows.Count + _seasons.Count + _episodes.Count + _artists.Count +
_musicVideos.Count + _otherVideos.Count + _songs.Count;
var parameters = new DialogParameters { { "EntityType", count.ToString() }, { "EntityName", "missing items" } };
var options = new DialogOptions { CloseButton = true, MaxWidth = MaxWidth.ExtraSmall };
IDialogReference dialog = Dialog.Show<DeleteFromDatabaseDialog>("Delete From Database", parameters, options);
DialogResult result = await dialog.Result;
if (!result.Cancelled)
{
await Mediator.Send(new EmptyTrash(), CancellationToken);
await RefreshData();
}
}
}
Loading…
Cancel
Save