From 5843dee2a5f919025e6b92cef1cb8d7f35a35a79 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 29 Mar 2016 09:58:23 +0100 Subject: [PATCH] Added the settings page for #32 --- PlexRequests.Core/PlexRequests.Core.csproj | 1 + .../SettingModels/HeadphonesSettings.cs | 58 +++++++ PlexRequests.UI/Bootstrapper.cs | 1 + PlexRequests.UI/Modules/AdminModule.cs | 37 +++- .../Modules/ApplicationTesterModule.cs | 6 + PlexRequests.UI/PlexRequests.UI.csproj | 3 + PlexRequests.UI/Views/Admin/Headphones.cshtml | 162 ++++++++++++++++++ PlexRequests.UI/Views/Admin/_Sidebar.cshtml | 8 + 8 files changed, 275 insertions(+), 1 deletion(-) create mode 100644 PlexRequests.Core/SettingModels/HeadphonesSettings.cs create mode 100644 PlexRequests.UI/Views/Admin/Headphones.cshtml diff --git a/PlexRequests.Core/PlexRequests.Core.csproj b/PlexRequests.Core/PlexRequests.Core.csproj index a1e0538f7..13a1e74ec 100644 --- a/PlexRequests.Core/PlexRequests.Core.csproj +++ b/PlexRequests.Core/PlexRequests.Core.csproj @@ -74,6 +74,7 @@ + diff --git a/PlexRequests.Core/SettingModels/HeadphonesSettings.cs b/PlexRequests.Core/SettingModels/HeadphonesSettings.cs new file mode 100644 index 000000000..0da4971d7 --- /dev/null +++ b/PlexRequests.Core/SettingModels/HeadphonesSettings.cs @@ -0,0 +1,58 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CouchPotatoSettings.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion + +using System; +using Newtonsoft.Json; +using PlexRequests.Helpers; + +namespace PlexRequests.Core.SettingModels +{ + public class HeadphonesSettings : Settings + { + public string Enabled { get; set; } + public string Ip { get; set; } + public int Port { get; set; } + public int ApiKey { get; set; } + public bool Ssl { get; set; } + public string SubDir { get; set; } + + [JsonIgnore] + public Uri FullUri + { + get + { + if (!string.IsNullOrEmpty(SubDir)) + { + var formattedSubDir = Ip.ReturnUriWithSubDir(Port, Ssl, SubDir); + return formattedSubDir; + } + var formatted = Ip.ReturnUri(Port, Ssl); + return formatted; + } + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/Bootstrapper.cs b/PlexRequests.UI/Bootstrapper.cs index 5e4f24343..e65ea82bd 100644 --- a/PlexRequests.UI/Bootstrapper.cs +++ b/PlexRequests.UI/Bootstrapper.cs @@ -76,6 +76,7 @@ namespace PlexRequests.UI container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); container.Register, SettingsServiceV2>(); + container.Register, SettingsServiceV2>(); // Repo's container.Register, GenericRepository>(); diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index e8cd8961f..4009f1b5e 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -28,6 +28,8 @@ using System.Collections.Generic; using System.Dynamic; using System.Linq; +using System.Web.UI.HtmlControls; + using Humanizer; using MarkdownSharp; @@ -65,6 +67,7 @@ namespace PlexRequests.UI.Modules private ISettingsService EmailService { get; } private ISettingsService PushbulletService { get; } private ISettingsService PushoverService { get; } + private ISettingsService HeadphonesSerivce { get; } private IPlexApi PlexApi { get; } private ISonarrApi SonarrApi { get; } private IPushbulletApi PushbulletApi { get; } @@ -89,7 +92,8 @@ namespace PlexRequests.UI.Modules ISettingsService pushoverSettings, IPushoverApi pushoverApi, IRepository logsRepo, - INotificationService notify) : base("admin") + INotificationService notify, + ISettingsService headphones) : base("admin") { RpService = rpService; CpService = cpService; @@ -107,6 +111,7 @@ namespace PlexRequests.UI.Modules PushoverService = pushoverSettings; PushoverApi = pushoverApi; NotificationService = notify; + HeadphonesSerivce = headphones; #if !DEBUG this.RequiresAuthentication(); @@ -151,6 +156,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() @@ -509,5 +517,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 = HeadphonesSerivce.GetSettings(); + return View["Headphones", settings]; + } + + private Response SaveHeadphones() + { + var settings = this.Bind(); + + 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 = HeadphonesSerivce.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." }); + } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/ApplicationTesterModule.cs b/PlexRequests.UI/Modules/ApplicationTesterModule.cs index 98d2bd591..98884d2f1 100644 --- a/PlexRequests.UI/Modules/ApplicationTesterModule.cs +++ b/PlexRequests.UI/Modules/ApplicationTesterModule.cs @@ -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 + } } } \ No newline at end of file diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index b561ad36b..9a32ef2b3 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -371,6 +371,9 @@ Always + + Always + web.config diff --git a/PlexRequests.UI/Views/Admin/Headphones.cshtml b/PlexRequests.UI/Views/Admin/Headphones.cshtml new file mode 100644 index 000000000..30f45985f --- /dev/null +++ b/PlexRequests.UI/Views/Admin/Headphones.cshtml @@ -0,0 +1,162 @@ +@Html.Partial("_Sidebar") +@{ + int port; + if (Model.Port == 0) + { + port = 8081; + } + else + { + port = Model.Port; + } +} +
+
+
+ Headphones Settings +
+
+ +
+
+
+
+ +
+
+
+ +
+ +
+
+ +
+ + +
+ +
+
+ + +
+ +
+ +
+
+
+ +
+ +
+
+ + +
+
+ +
+
+ + +
+
+ +
+
+ + + + +
+
+ +
+
+
+
+
+ + + + \ No newline at end of file diff --git a/PlexRequests.UI/Views/Admin/_Sidebar.cshtml b/PlexRequests.UI/Views/Admin/_Sidebar.cshtml index efb8ce36b..e6d21e3fc 100644 --- a/PlexRequests.UI/Views/Admin/_Sidebar.cshtml +++ b/PlexRequests.UI/Views/Admin/_Sidebar.cshtml @@ -52,6 +52,14 @@ { SickRage } + @if (Context.Request.Path == "/admin/headphones") + { + Headphones + } + else + { + Headphones + } @if (Context.Request.Path == "/admin/emailnotification") {