merge in tidusjar's dev changes, remove approve all, fix alignment on approve all category buttons

This commit is contained in:
Drewster727 2016-03-29 09:03:34 -05:00
commit dce5983720
26 changed files with 592 additions and 109 deletions

View file

@ -28,6 +28,8 @@
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Web.UI.HtmlControls;
using Humanizer;
using MarkdownSharp;
@ -66,6 +68,7 @@ namespace PlexRequests.UI.Modules
private ISettingsService<EmailNotificationSettings> EmailService { get; }
private ISettingsService<PushbulletNotificationSettings> PushbulletService { get; }
private ISettingsService<PushoverNotificationSettings> PushoverService { get; }
private ISettingsService<HeadphonesSettings> HeadphonesService { get; }
private IPlexApi PlexApi { get; }
private ISonarrApi SonarrApi { get; }
private IPushbulletApi PushbulletApi { get; }
@ -90,7 +93,8 @@ namespace PlexRequests.UI.Modules
ISettingsService<PushoverNotificationSettings> pushoverSettings,
IPushoverApi pushoverApi,
IRepository<LogEntity> logsRepo,
INotificationService notify) : base("admin")
INotificationService notify,
ISettingsService<HeadphonesSettings> headphones) : base("admin")
{
RpService = rpService;
CpService = cpService;
@ -108,6 +112,7 @@ namespace PlexRequests.UI.Modules
PushoverService = pushoverSettings;
PushoverApi = pushoverApi;
NotificationService = notify;
HeadphonesService = headphones;
#if !DEBUG
this.RequiresAuthentication();
@ -155,6 +160,9 @@ namespace PlexRequests.UI.Modules
Get["/loglevel"] = _ => GetLogLevels();
Post["/loglevel"] = _ => UpdateLogLevels(Request.Form.level);
Get["/loadlogs"] = _ => LoadLogs();
Get["/headphones"] = _ => Headphones();
Post["/headphones"] = _ => SaveHeadphones();
}
private Negotiator Authentication()
@ -567,5 +575,32 @@ namespace PlexRequests.UI.Modules
LoggingHelper.ReconfigureLogLevel(newLevel);
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"The new log level is now {newLevel}"});
}
private Negotiator Headphones()
{
var settings = HeadphonesService.GetSettings();
return View["Headphones", settings];
}
private Response SaveHeadphones()
{
var settings = this.Bind<HeadphonesSettings>();
var valid = this.Validate(settings);
if (!valid.IsValid)
{
var error = valid.SendJsonError();
Log.Info("Error validating Headphones settings, message: {0}", error.Message);
return Response.AsJson(error);
}
Log.Trace(settings.DumpJson());
var result = HeadphonesService.SaveSettings(settings);
Log.Info("Saved headphones settings, result: {0}", result);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Headphones!" }
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}
}
}

View file

@ -57,6 +57,7 @@ namespace PlexRequests.UI.Modules
Post["/sonarr"] = _ => SonarrTest();
Post["/plex"] = _ => PlexTest();
Post["/sickrage"] = _ => SickRageTest();
Post["/headphones"] = _ => HeadphonesTest();
}
@ -168,5 +169,10 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(new JsonResponseModel { Result = false, Message = message });
}
}
private Response HeadphonesTest()
{
throw new NotImplementedException(); //TODO
}
}
}

View file

@ -133,7 +133,7 @@ namespace PlexRequests.UI.Modules
return Response.AsJson(new JsonResponseModel
{
Result = false,
Message = "Could not add the series to Sonarr"
Message = result.ErrorMessage ?? "Could not add the series to Sonarr"
});
}
@ -340,7 +340,7 @@ namespace PlexRequests.UI.Modules
if (sonarr.Enabled)
{
var res = sender.SendToSonarr(sonarr, r);
if (res != null)
if (!string.IsNullOrEmpty(res?.title))
{
r.Approved = true;
updatedRequests.Add(r);
@ -348,15 +348,25 @@ namespace PlexRequests.UI.Modules
else
{
Log.Error("Could not approve and send the TV {0} to Sonarr!", r.Title);
Log.Error("Error message: {0}", res?.ErrorMessage);
}
}
}
}
var result = Service.BatchUpdate(updatedRequests);
try
{
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)
{

View file

@ -371,18 +371,19 @@ namespace PlexRequests.UI.Modules
if (sonarrSettings.Enabled)
{
var result = sender.SendToSonarr(sonarrSettings, model);
if (result != null)
if (result != null && !string.IsNullOrEmpty(result.title))
{
model.Approved = true;
Log.Debug("Adding tv to database requests (No approval required & Sonarr)");
RequestService.AddRequest(model);
var notify1 = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
NotificationService.Publish(notify1);
return Response.AsJson(new JsonResponseModel { Result = true, Message = $"{fullShowName} was successfully added!" });
}
var notify1 = new NotificationModel { Title = model.Title, User = model.RequestedBy, DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest };
NotificationService.Publish(notify1);
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Something went wrong adding the movie to Sonarr! Please check your settings." });
return Response.AsJson(new JsonResponseModel { Result = false, Message = result?.ErrorMessage ?? "Something went wrong adding the movie to Sonarr! Please check your settings." });
}