From 66bede34f4b5ca5e1a30a3fe932cb8be309182c5 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 6 Jun 2016 17:19:56 +0100 Subject: [PATCH] Settings done for #298 --- PlexRequests.UI/Modules/AdminModule.cs | 18 ++++++++- PlexRequests.UI/Modules/LandingPageModule.cs | 12 ++++++ PlexRequests.UI/Modules/SearchModule.cs | 11 ----- .../Views/Admin/LandingPage.cshtml | 40 ++++++++----------- 4 files changed, 45 insertions(+), 36 deletions(-) diff --git a/PlexRequests.UI/Modules/AdminModule.cs b/PlexRequests.UI/Modules/AdminModule.cs index 4852adc42..451a3ea3c 100644 --- a/PlexRequests.UI/Modules/AdminModule.cs +++ b/PlexRequests.UI/Modules/AdminModule.cs @@ -191,7 +191,7 @@ namespace PlexRequests.UI.Modules Post["/slacknotification"] = _ => SaveSlackNotifications(); Get["/landingpage", true] = async (x,ct) => await LandingPage(); - Post["/landingpage"] = _ => SaveSlackNotifications(); + Post["/landingpage", true] = async (x, ct) => await SaveLandingPage(); } private Negotiator Authentication() @@ -819,5 +819,21 @@ namespace PlexRequests.UI.Modules return View["LandingPage", settings]; } + + private async Task SaveLandingPage() + { + var settings = this.Bind(); + + if (settings.Enabled && settings.EnabledNoticeTime && string.IsNullOrEmpty(settings.NoticeMessage)) + { + return Response.AsJson(new JsonResponseModel { Result = false, Message = "If you are going to enabled the notice, then we need a message!"}); + } + + var result = await LandingSettings.SaveSettingsAsync(settings); + + return Response.AsJson(result + ? new JsonResponseModel { Result = true } + : new JsonResponseModel { Result = false, Message = "Could not save to Db Please check the logs"}); + } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/LandingPageModule.cs b/PlexRequests.UI/Modules/LandingPageModule.cs index 1905ebf9a..c84b7c4fd 100644 --- a/PlexRequests.UI/Modules/LandingPageModule.cs +++ b/PlexRequests.UI/Modules/LandingPageModule.cs @@ -24,6 +24,10 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion +using System.Threading.Tasks; + +using Nancy.Responses.Negotiation; + using PlexRequests.Core; using PlexRequests.Core.SettingModels; @@ -34,8 +38,16 @@ namespace PlexRequests.UI.Modules public LandingPageModule(ISettingsService settingsService, ISettingsService landing) : base("landing", settingsService) { LandingSettings = landing; + + Get["/", true] = async (x, ct) => await Index(); } private ISettingsService LandingSettings { get; } + + private async Task Index() + { + var model = await LandingSettings.GetSettingsAsync(); + return View["Index", model]; + } } } \ No newline at end of file diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 9b3ea90cc..c6bd8b748 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -352,8 +352,6 @@ namespace PlexRequests.UI.Modules viewTv.Add(viewT); } - Log.Trace("Returning TV Show results: "); - Log.Trace(viewTv.DumpJson()); return Response.AsJson(viewTv); } @@ -788,12 +786,6 @@ namespace PlexRequests.UI.Modules var img = GetMusicBrainzCoverArt(albumInfo.id); - Log.Trace("Album Details:"); - Log.Trace(albumInfo.DumpJson()); - Log.Trace("CoverArt Details:"); - Log.Trace(img.DumpJson()); - - var model = new RequestedModel { Title = albumInfo.title, @@ -816,9 +808,6 @@ namespace PlexRequests.UI.Modules Log.Debug("We don't require approval OR the user is in the whitelist"); var hpSettings = HeadphonesService.GetSettings(); - Log.Trace("Headphone Settings:"); - Log.Trace(hpSettings.DumpJson()); - if (!hpSettings.Enabled) { await RequestService.AddRequestAsync(model); diff --git a/PlexRequests.UI/Views/Admin/LandingPage.cshtml b/PlexRequests.UI/Views/Admin/LandingPage.cshtml index 2ddad25d6..26d587c22 100644 --- a/PlexRequests.UI/Views/Admin/LandingPage.cshtml +++ b/PlexRequests.UI/Views/Admin/LandingPage.cshtml @@ -1,13 +1,6 @@ @using PlexRequests.UI.Helpers @Html.Partial("_Sidebar") -@{ - var baseUrl = Html.GetBaseUrl(); - var formAction = "/admin"; - if (!string.IsNullOrEmpty(baseUrl.ToHtmlString())) - { - formAction = "/" + baseUrl.ToHtmlString() + formAction; - } -} +
@@ -70,7 +63,7 @@
-
+
@@ -80,7 +73,7 @@
-
+
@@ -103,14 +96,24 @@ \ No newline at end of file