From 334a6f3d8e77bf54547c6f846f894e0472fbf4c5 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 14 Mar 2016 13:39:52 +0000 Subject: [PATCH] added settings page for #8 --- PlexRequests.UI/Bootstrapper.cs | 1 + PlexRequests.UI/Modules/AdminModule.cs | 28 +++++- PlexRequests.UI/PlexRequests.UI.csproj | 3 + PlexRequests.UI/Startup.cs | 7 +- .../Views/Admin/EmailNotifications.cshtml | 92 +++++++++++++++++++ PlexRequests.UI/Views/Admin/_Sidebar.cshtml | 10 +- 6 files changed, 136 insertions(+), 5 deletions(-) create mode 100644 PlexRequests.UI/Views/Admin/EmailNotifications.cshtml diff --git a/PlexRequests.UI/Bootstrapper.cs b/PlexRequests.UI/Bootstrapper.cs index ab0a5bfd8..4eee11c67 100644 --- a/PlexRequests.UI/Bootstrapper.cs +++ b/PlexRequests.UI/Bootstrapper.cs @@ -71,6 +71,7 @@ namespace PlexRequests.UI container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); container.Register, GenericRepository>(); container.Register(); diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index 13bf1afef..184bdcc85 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -51,6 +51,7 @@ namespace PlexRequests.UI.Modules private ISettingsService AuthService { get; set; } private ISettingsService PlexService { get; set; } private ISettingsService SonarrService { get; set; } + private ISettingsService EmailService { get; set; } private ISonarrApi SonarrApi { get; set; } private static Logger Log = LogManager.GetCurrentClassLogger(); @@ -59,7 +60,8 @@ namespace PlexRequests.UI.Modules ISettingsService auth , ISettingsService plex, ISettingsService sonarr, - ISonarrApi sonarrApi) : base("admin") + ISonarrApi sonarrApi, + ISettingsService email) : base("admin") { RpService = rpService; CpService = cpService; @@ -67,10 +69,11 @@ namespace PlexRequests.UI.Modules PlexService = plex; SonarrService = sonarr; SonarrApi = sonarrApi; + EmailService = email; -//#if !DEBUG +#if !DEBUG this.RequiresAuthentication(); -//#endif +#endif Get["/"] = _ => Admin(); Get["/authentication"] = _ => Authentication(); @@ -92,6 +95,9 @@ namespace PlexRequests.UI.Modules Post["/sonarr"] = _ => SaveSonarr(); Post["/sonarrprofiles"] = _ => GetSonarrQualityProfiles(); + + Get["/emailnotification"] = _ => EmailNotifications(); + Post["/emailnotification"] = _ => SaveEmailNotifications(); } private Negotiator Authentication() @@ -239,5 +245,21 @@ namespace PlexRequests.UI.Modules return Response.AsJson(profiles); } + + private Negotiator EmailNotifications() + { + var settings = EmailService.GetSettings(); + return View["EmailNotifications",settings]; + } + + private Response SaveEmailNotifications() + { + var settings = this.Bind(); + Log.Trace(settings.DumpJson()); + + var result = EmailService.SaveSettings(settings); + Log.Info("Saved email settings, result: {0}", result); + return Context.GetRedirect("~/admin/emailnotification"); + } } } \ No newline at end of file diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index c2700c5aa..036f695a7 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -296,6 +296,9 @@ Always + + Always + web.config diff --git a/PlexRequests.UI/Startup.cs b/PlexRequests.UI/Startup.cs index 28a918fd7..60a00ac37 100644 --- a/PlexRequests.UI/Startup.cs +++ b/PlexRequests.UI/Startup.cs @@ -26,6 +26,9 @@ #endregion using System; using FluentScheduler; + +using NLog; + using Owin; using PlexRequests.UI.Jobs; using TaskFactory = FluentScheduler.TaskFactory; @@ -34,6 +37,8 @@ namespace PlexRequests.UI { public class Startup { + + private static Logger Log = LogManager.GetCurrentClassLogger(); public void Configuration(IAppBuilder app) { try @@ -44,7 +49,7 @@ namespace PlexRequests.UI } catch (Exception exception) { - Console.WriteLine(exception.Message); + Log.Fatal(exception); throw; } diff --git a/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml b/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml new file mode 100644 index 000000000..d0560a863 --- /dev/null +++ b/PlexRequests.UI/Views/Admin/EmailNotifications.cshtml @@ -0,0 +1,92 @@ +@Html.Partial("_Sidebar") +@{ + int port; + if (Model.EmailPort == 0) + { + port = 25; + } + else + { + port = Model.EmailPort; + } +} +
+
+
+ Email Notifications + +
+
+ +
+
+
+ +
+ +
+
+ +
+ + +
+ +
+
+ + +
+ +
+ +
+
+ +
+
+ +
+
+ +
+ +
+ +
+
+ +
+ +
+ +
+
+ + +
+
+ +
+
+
+
+
diff --git a/PlexRequests.UI/Views/Admin/_Sidebar.cshtml b/PlexRequests.UI/Views/Admin/_Sidebar.cshtml index 642eced41..f414c0769 100644 --- a/PlexRequests.UI/Views/Admin/_Sidebar.cshtml +++ b/PlexRequests.UI/Views/Admin/_Sidebar.cshtml @@ -43,8 +43,16 @@ else { Sonarr Settings - } @*Sickbeard Settings*@ + + @if (Context.Request.Path == "/admin/emailnotification") + { + Email Notifications + } + else + { + Email Notifications + } \ No newline at end of file