mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 08:16:05 -07:00
#221 delete requests per category
This commit is contained in:
parent
96352e14ee
commit
217ce391e0
10 changed files with 169 additions and 8 deletions
|
@ -41,5 +41,6 @@ namespace PlexRequests.Core
|
||||||
RequestedModel Get(int id);
|
RequestedModel Get(int id);
|
||||||
IEnumerable<RequestedModel> GetAll();
|
IEnumerable<RequestedModel> GetAll();
|
||||||
bool BatchUpdate(List<RequestedModel> model);
|
bool BatchUpdate(List<RequestedModel> model);
|
||||||
|
bool BatchDelete(List<RequestedModel> model);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -107,5 +107,11 @@ namespace PlexRequests.Core
|
||||||
var entities = model.Select(m => new RequestBlobs { Type = m.Type, Content = ByteConverterHelper.ReturnBytes(m), ProviderId = m.ProviderId, Id = m.Id }).ToList();
|
var entities = model.Select(m => new RequestBlobs { Type = m.Type, Content = ByteConverterHelper.ReturnBytes(m), ProviderId = m.ProviderId, Id = m.Id }).ToList();
|
||||||
return Repo.UpdateAll(entities);
|
return Repo.UpdateAll(entities);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool BatchDelete(List<RequestedModel> model)
|
||||||
|
{
|
||||||
|
var entities = model.Select(m => new RequestBlobs { Type = m.Type, Content = ByteConverterHelper.ReturnBytes(m), ProviderId = m.ProviderId, Id = m.Id }).ToList();
|
||||||
|
return Repo.DeleteAll(entities);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -53,6 +53,8 @@ namespace PlexRequests.Store.Repository
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
bool Delete(RequestBlobs entity);
|
bool Delete(RequestBlobs entity);
|
||||||
|
|
||||||
|
bool DeleteAll(IEnumerable<RequestBlobs> entity);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the specified entity.
|
/// Updates the specified entity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -122,5 +122,20 @@ namespace PlexRequests.Store.Repository
|
||||||
}
|
}
|
||||||
return result.All(x => true);
|
return result.All(x => true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool DeleteAll(IEnumerable<RequestBlobs> entity)
|
||||||
|
{
|
||||||
|
ResetCache();
|
||||||
|
var result = new HashSet<bool>();
|
||||||
|
using (var db = Db.DbConnection())
|
||||||
|
{
|
||||||
|
db.Open();
|
||||||
|
foreach (var e in entity)
|
||||||
|
{
|
||||||
|
result.Add(db.Delete(e));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result.All(x => true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,10 @@ hr {
|
||||||
.btn {
|
.btn {
|
||||||
border-radius: 0.25rem !important; }
|
border-radius: 0.25rem !important; }
|
||||||
|
|
||||||
|
.btn-group-separated .btn,
|
||||||
|
.btn-group-separated .btn + .btn {
|
||||||
|
margin-left: 3px; }
|
||||||
|
|
||||||
.multiSelect {
|
.multiSelect {
|
||||||
background-color: #4e5d6c; }
|
background-color: #4e5d6c; }
|
||||||
|
|
||||||
|
|
2
PlexRequests.UI/Content/base.min.css
vendored
2
PlexRequests.UI/Content/base.min.css
vendored
File diff suppressed because one or more lines are too long
|
@ -46,6 +46,11 @@ hr {
|
||||||
border-radius: .25rem $i;
|
border-radius: .25rem $i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.btn-group-separated .btn,
|
||||||
|
.btn-group-separated .btn + .btn {
|
||||||
|
margin-left: 3px;
|
||||||
|
}
|
||||||
|
|
||||||
.multiSelect {
|
.multiSelect {
|
||||||
background-color: $form-color;
|
background-color: $form-color;
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,9 @@ $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||||
var $tvl = $('#tvList');
|
var $tvl = $('#tvList');
|
||||||
var $musicL = $('#musicList');
|
var $musicL = $('#musicList');
|
||||||
|
|
||||||
$('.approve-category').hide();
|
$('.approve-category,.delete-category').hide();
|
||||||
if (target === "#TvShowTab") {
|
if (target === "#TvShowTab") {
|
||||||
$('#approveTVShows').show();
|
$('#approveTVShows,#deleteTVShows').show();
|
||||||
if ($ml.mixItUp('isLoaded')) {
|
if ($ml.mixItUp('isLoaded')) {
|
||||||
activeState = $ml.mixItUp('getState');
|
activeState = $ml.mixItUp('getState');
|
||||||
$ml.mixItUp('destroy');
|
$ml.mixItUp('destroy');
|
||||||
|
@ -55,7 +55,7 @@ $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||||
$tvl.mixItUp(mixItUpConfig(activeState)); // init or reinit
|
$tvl.mixItUp(mixItUpConfig(activeState)); // init or reinit
|
||||||
}
|
}
|
||||||
if (target === "#MoviesTab") {
|
if (target === "#MoviesTab") {
|
||||||
$('#approveMovies').show();
|
$('#approveMovies,#deleteMovies').show();
|
||||||
if ($tvl.mixItUp('isLoaded')) {
|
if ($tvl.mixItUp('isLoaded')) {
|
||||||
activeState = $tvl.mixItUp('getState');
|
activeState = $tvl.mixItUp('getState');
|
||||||
$tvl.mixItUp('destroy');
|
$tvl.mixItUp('destroy');
|
||||||
|
@ -69,7 +69,7 @@ $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target === "#MusicTab") {
|
if (target === "#MusicTab") {
|
||||||
$('#approveMusic').show();
|
$('#approveMusic,#deleteMusic').show();
|
||||||
if ($tvl.mixItUp('isLoaded')) {
|
if ($tvl.mixItUp('isLoaded')) {
|
||||||
activeState = $tvl.mixItUp('getState');
|
activeState = $tvl.mixItUp('getState');
|
||||||
$tvl.mixItUp('destroy');
|
$tvl.mixItUp('destroy');
|
||||||
|
@ -124,7 +124,7 @@ $('#approveTVShows').click(function (e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadingButton(buttonId, "success");
|
loadingButton(buttonId, "warning");
|
||||||
var url = createBaseUrl(base, '/approval/approvealltvshows');
|
var url = createBaseUrl(base, '/approval/approvealltvshows');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: 'post',
|
type: 'post',
|
||||||
|
@ -140,6 +140,72 @@ $('#approveTVShows').click(function (e) {
|
||||||
console.log(e);
|
console.log(e);
|
||||||
generateNotify("Something went wrong!", "danger");
|
generateNotify("Something went wrong!", "danger");
|
||||||
},
|
},
|
||||||
|
complete: function (e) {
|
||||||
|
finishLoading(buttonId, "warning", origHtml);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#deleteMovies').click(function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!confirm("Are you sure you want to delete all TV show requests?")) return;
|
||||||
|
|
||||||
|
var buttonId = e.target.id;
|
||||||
|
var origHtml = $(this).html();
|
||||||
|
|
||||||
|
if ($('#' + buttonId).text() === " Loading...") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadingButton(buttonId, "warning");
|
||||||
|
|
||||||
|
var url = createBaseUrl(base, '/approval/deleteallmovies');
|
||||||
|
$.ajax({
|
||||||
|
type: 'post',
|
||||||
|
url: url,
|
||||||
|
dataType: "json",
|
||||||
|
success: function (response) {
|
||||||
|
if (checkJsonResponse(response)) {
|
||||||
|
generateNotify("Success! All Movie requests deleted!", "success");
|
||||||
|
movieLoad();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (e) {
|
||||||
|
console.log(e);
|
||||||
|
generateNotify("Something went wrong!", "danger");
|
||||||
|
},
|
||||||
|
complete: function (e) {
|
||||||
|
finishLoading(buttonId, "warning", origHtml);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
$('#deleteTVShows').click(function (e) {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!confirm("Are you sure you want to delete all TV show requests?")) return;
|
||||||
|
|
||||||
|
var buttonId = e.target.id;
|
||||||
|
var origHtml = $(this).html();
|
||||||
|
|
||||||
|
if ($('#' + buttonId).text() === " Loading...") {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
loadingButton(buttonId, "success");
|
||||||
|
var url = createBaseUrl(base, '/approval/deletealltvshows');
|
||||||
|
$.ajax({
|
||||||
|
type: 'post',
|
||||||
|
url: url,
|
||||||
|
dataType: "json",
|
||||||
|
success: function (response) {
|
||||||
|
if (checkJsonResponse(response)) {
|
||||||
|
generateNotify("Success! All TV Show requests deleted!", "success");
|
||||||
|
tvLoad();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error: function (e) {
|
||||||
|
console.log(e);
|
||||||
|
generateNotify("Something went wrong!", "danger");
|
||||||
|
},
|
||||||
complete: function (e) {
|
complete: function (e) {
|
||||||
finishLoading(buttonId, "success", origHtml);
|
finishLoading(buttonId, "success", origHtml);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,8 @@ namespace PlexRequests.UI.Modules
|
||||||
Post["/approveall"] = x => ApproveAll();
|
Post["/approveall"] = x => ApproveAll();
|
||||||
Post["/approveallmovies"] = x => ApproveAllMovies();
|
Post["/approveallmovies"] = x => ApproveAllMovies();
|
||||||
Post["/approvealltvshows"] = x => ApproveAllTVShows();
|
Post["/approvealltvshows"] = x => ApproveAllTVShows();
|
||||||
|
Post["/deleteallmovies"] = x => DeleteAllMovies();
|
||||||
|
Post["/deletealltvshows"] = x => DeleteAllTVShows();
|
||||||
}
|
}
|
||||||
|
|
||||||
private IRequestService Service { get; }
|
private IRequestService Service { get; }
|
||||||
|
@ -274,6 +276,27 @@ namespace PlexRequests.UI.Modules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Response DeleteAllMovies()
|
||||||
|
{
|
||||||
|
|
||||||
|
var requests = Service.GetAll().Where(x => x.Type == RequestType.Movie);
|
||||||
|
var requestedModels = requests as RequestedModel[] ?? requests.ToArray();
|
||||||
|
if (!requestedModels.Any())
|
||||||
|
{
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = "There are no movie requests to delete. Please refresh." });
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return DeleteRequests(requestedModels);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Fatal(e);
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something bad happened, please check the logs!" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Response ApproveAllTVShows()
|
private Response ApproveAllTVShows()
|
||||||
{
|
{
|
||||||
var requests = Service.GetAll().Where(x => x.CanApprove && x.Type == RequestType.TvShow);
|
var requests = Service.GetAll().Where(x => x.CanApprove && x.Type == RequestType.TvShow);
|
||||||
|
@ -294,6 +317,27 @@ namespace PlexRequests.UI.Modules
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Response DeleteAllTVShows()
|
||||||
|
{
|
||||||
|
|
||||||
|
var requests = Service.GetAll().Where(x => x.Type == RequestType.TvShow);
|
||||||
|
var requestedModels = requests as RequestedModel[] ?? requests.ToArray();
|
||||||
|
if (!requestedModels.Any())
|
||||||
|
{
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = "There are no tv show requests to delete. Please refresh." });
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return DeleteRequests(requestedModels);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Fatal(e);
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something bad happened, please check the logs!" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Approves all.
|
/// Approves all.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -319,6 +363,22 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Response DeleteRequests(RequestedModel[] requestedModels)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var result = Service.BatchDelete(requestedModels.ToList());
|
||||||
|
return Response.AsJson(result
|
||||||
|
? new JsonResponseModel { Result = true }
|
||||||
|
: new JsonResponseModel { Result = false, Message = "We could not delete all of the requests. Please try again or check the logs." });
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Fatal(e);
|
||||||
|
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something bad happened, please check the logs!" });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Response UpdateRequests(RequestedModel[] requestedModels)
|
private Response UpdateRequests(RequestedModel[] requestedModels)
|
||||||
{
|
{
|
||||||
var cpSettings = CpService.GetSettings();
|
var cpSettings = CpService.GetSettings();
|
||||||
|
@ -389,7 +449,6 @@ namespace PlexRequests.UI.Modules
|
||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
var result = Service.BatchUpdate(updatedRequests);
|
var result = Service.BatchUpdate(updatedRequests);
|
||||||
return Response.AsJson(result
|
return Response.AsJson(result
|
||||||
? new JsonResponseModel { Result = true }
|
? new JsonResponseModel { Result = true }
|
||||||
|
|
|
@ -35,19 +35,22 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-12">
|
<div class="col-sm-12">
|
||||||
<div class="pull-right">
|
<div class="pull-right">
|
||||||
<div class="btn-group">
|
<div class="btn-group btn-group-separated">
|
||||||
@if (Context.CurrentUser.IsAuthenticated()) //TODO replace with IsAdmin
|
@if (Context.CurrentUser.IsAuthenticated()) //TODO replace with IsAdmin
|
||||||
{
|
{
|
||||||
@if (Model.SearchForMovies)
|
@if (Model.SearchForMovies)
|
||||||
{
|
{
|
||||||
|
<button id="deleteMovies" class="btn btn-warning-outline delete-category" type="submit"><i class="fa fa-trash"></i> Delete Movies</button>
|
||||||
<button id="approveMovies" class="btn btn-success-outline approve-category" type="submit"><i class="fa fa-plus"></i> Approve Movies</button>
|
<button id="approveMovies" class="btn btn-success-outline approve-category" type="submit"><i class="fa fa-plus"></i> Approve Movies</button>
|
||||||
}
|
}
|
||||||
@if (Model.SearchForTvShows)
|
@if (Model.SearchForTvShows)
|
||||||
{
|
{
|
||||||
|
<button id="deleteTVShows" class="btn btn-warning-outline delete-category" type="submit" style="display: none;"><i class="fa fa-trash"></i> Delete TV Shows</button>
|
||||||
<button id="approveTVShows" class="btn btn-success-outline approve-category" type="submit" style="display: none;"><i class="fa fa-plus"></i> Approve TV Shows</button>
|
<button id="approveTVShows" class="btn btn-success-outline approve-category" type="submit" style="display: none;"><i class="fa fa-plus"></i> Approve TV Shows</button>
|
||||||
}
|
}
|
||||||
@if (Model.SearchForMusic)
|
@if (Model.SearchForMusic)
|
||||||
{
|
{
|
||||||
|
<button id="deleteMusics" class="btn btn-warning-outline delete-category" type="submit" style="display: none;"><i class="fa fa-trash"></i> Delete Music</button>
|
||||||
<button id="approveMusic" class="btn btn-success-outline approve-category" type="submit" style="display: none;"><i class="fa fa-plus"></i> Approve Music</button>
|
<button id="approveMusic" class="btn btn-success-outline approve-category" type="submit" style="display: none;"><i class="fa fa-plus"></i> Approve Music</button>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue