allow approving all requests by category

pull/110/head
Drewster727 9 years ago
parent 3d944b32a8
commit e1b8293fdd

@ -20,8 +20,7 @@ var mixItUpDefault = {
}
};
movieLoad();
tvLoad();
initLoad();
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
@ -51,7 +50,17 @@ $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
});
// Approve all
$('#approveAll').click(function () {
$('#approveAll').click(function (e) {
e.preventDefault();
var buttonId = e.target.id;
var origHtml = $(this).html();
if ($('#' + buttonId).text() === " Loading...") {
return;
}
loadingButton(buttonId, "success");
$.ajax({
type: 'post',
url: '/approval/approveall',
@ -59,11 +68,75 @@ $('#approveAll').click(function () {
success: function (response) {
if (checkJsonResponse(response)) {
generateNotify("Success! All requests approved!", "success");
initLoad();
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
},
complete: function (e) {
finishLoading(buttonId, "success", origHtml)
}
});
});
$('#approveMovies').click(function (e) {
e.preventDefault();
var buttonId = e.target.id;
var origHtml = $(this).html();
if ($('#' + buttonId).text() === " Loading...") {
return;
}
loadingButton(buttonId, "success");
$.ajax({
type: 'post',
url: '/approval/approveallmovies',
dataType: "json",
success: function (response) {
if (checkJsonResponse(response)) {
generateNotify("Success! All Movie requests approved!", "success");
movieLoad();
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
},
complete: function (e) {
finishLoading(buttonId, "success", origHtml)
}
});
});
$('#approveTVShows').click(function (e) {
e.preventDefault();
var buttonId = e.target.id;
var origHtml = $(this).html();
if ($('#' + buttonId).text() === " Loading...") {
return;
}
loadingButton(buttonId, "success");
$.ajax({
type: 'post',
url: '/approval/approvealltvshows',
dataType: "json",
success: function (response) {
if (checkJsonResponse(response)) {
generateNotify("Success! All TV Show requests approved!", "success");
tvLoad();
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
},
complete: function (e) {
finishLoading(buttonId, "success", origHtml)
}
});
});
@ -321,29 +394,44 @@ function mixItUpConfig(activeState) {
return conf;
};
function initLoad() {
movieLoad();
tvLoad();
}
function movieLoad() {
$("#movieList").html("");
var $ml = $('#movieList');
if ($ml.mixItUp('isLoaded')) {
activeState = $ml.mixItUp('getState');
$ml.mixItUp('destroy');
}
$ml.html("");
$.ajax("/requests/movies/").success(function (results) {
results.forEach(function (result) {
var context = buildRequestContext(result, "movie");
var html = searchTemplate(context);
$("#movieList").append(html);
$ml.append(html);
});
$('#movieList').mixItUp(mixItUpConfig());
$ml.mixItUp(mixItUpConfig());
});
};
function tvLoad() {
$("#tvList").html("");
var $tvl = $('#tvList');
if ($tvl.mixItUp('isLoaded')) {
activeState = $tvl.mixItUp('getState');
$tvl.mixItUp('destroy');
}
$tvl.html("");
$.ajax("/requests/tvshows/").success(function (results) {
results.forEach(function (result) {
var context = buildRequestContext(result, "tv");
var html = searchTemplate(context);
$("#tvList").append(html);
$tvl.append(html);
});
$('#tvList').mixItUp(mixItUpConfig());
$tvl.mixItUp(mixItUpConfig());
});
};
@ -374,16 +462,4 @@ function buildRequestContext(result, type) {
};
return context;
}
function startFilter(elementId) {
$('#' + element).mixItUp({
load: {
filter: activeState.activeFilter || 'all',
sort: activeState.activeSort || 'default:asc'
},
layout: {
display: 'block'
}
});
}

@ -61,6 +61,8 @@ namespace PlexRequests.UI.Modules
Post["/approve"] = parameters => Approve((int)Request.Form.requestid);
Post["/approveall"] = x => ApproveAll();
Post["/approveallmovies"] = x => ApproveAllMovies();
Post["/approvealltvshows"] = x => ApproveAllTVShows();
}
private IRequestService Service { get; }
@ -216,6 +218,56 @@ namespace PlexRequests.UI.Modules
});
}
private Response ApproveAllMovies()
{
if (!Context.CurrentUser.IsAuthenticated())
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "You are not an Admin, so you cannot approve any requests." });
}
var requests = Service.GetAll().Where(x => x.Approved == false && 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 approve. Please refresh." });
}
try
{
return UpdateRequests(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()
{
if (!Context.CurrentUser.IsAuthenticated())
{
return Response.AsJson(new JsonResponseModel { Result = false, Message = "You are not an Admin, so you cannot approve any requests." });
}
var requests = Service.GetAll().Where(x => x.Approved == false && 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 approve. Please refresh." });
}
try
{
return UpdateRequests(requestedModels);
}
catch (Exception e)
{
Log.Fatal(e);
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something bad happened, please check the logs!" });
}
}
/// <summary>
/// Approves all.
/// </summary>
@ -234,16 +286,28 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(new JsonResponseModel { Result = false, Message = "There are no requests to approve. Please refresh." });
}
var cpSettings = CpService.GetSettings();
try
{
return UpdateRequests(requestedModels);
}
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)
{
var cpSettings = CpService.GetSettings();
var updatedRequests = new List<RequestedModel>();
foreach (var r in requestedModels)
{
if (r.Type == RequestType.Movie)
{
var result = SendMovie(cpSettings, r, CpApi);
if (result)
var res = SendMovie(cpSettings, r, CpApi);
if (res)
{
r.Approved = true;
updatedRequests.Add(r);
@ -260,8 +324,8 @@ namespace PlexRequests.UI.Modules
var sonarr = SonarrSettings.GetSettings();
if (sr.Enabled)
{
var result = sender.SendToSickRage(sr, r);
if (result?.result == "success")
var res = sender.SendToSickRage(sr, r);
if (res?.result == "success")
{
r.Approved = true;
updatedRequests.Add(r);
@ -269,14 +333,14 @@ namespace PlexRequests.UI.Modules
else
{
Log.Error("Could not approve and send the TV {0} to SickRage!", r.Title);
Log.Error("SickRage Message: {0}", result?.message);
Log.Error("SickRage Message: {0}", res?.message);
}
}
if (sonarr.Enabled)
{
var result = sender.SendToSonarr(sonarr, r);
if (result != null)
var res = sender.SendToSonarr(sonarr, r);
if (res != null)
{
r.Approved = true;
updatedRequests.Add(r);
@ -288,20 +352,10 @@ namespace PlexRequests.UI.Modules
}
}
}
try
{
var result = Service.BatchUpdate(updatedRequests); return Response.AsJson(result
var result = Service.BatchUpdate(updatedRequests);
return Response.AsJson(result
? new JsonResponseModel { Result = true }
: new JsonResponseModel { Result = false, Message = "We could not approve 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 bool SendMovie(CouchPotatoSettings settings, RequestedModel r, ICouchPotatoApi cp)

@ -5,6 +5,8 @@
@if (Context.CurrentUser.IsAuthenticated())
{
<button id="approveAll" class="btn btn-success-outline" type="submit"><i class="fa fa-plus"></i> Approve All</button>
<button id="approveMovies" class="btn btn-success-outline" type="submit"><i class="fa fa-plus"></i> Approve Movies</button>
<button id="approveTVShows" class="btn btn-success-outline" type="submit"><i class="fa fa-plus"></i> Approve TV Shows</button>
<br />
<br />
}

Loading…
Cancel
Save