From 1067b9afd715fdab46ff7073863b0fc77273521b Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Fri, 16 Dec 2016 08:50:27 +0000 Subject: [PATCH] #782 --- PlexRequests.Core/PlexRequests.Core.csproj | 1 + .../SettingModels/CustomizationSettings.cs | 39 ++++++++ PlexRequests.UI/Helpers/BaseUrlHelper.cs | 17 +++- .../Modules/Admin/CustomizationModule.cs | 72 +++++++++++++++ PlexRequests.UI/PlexRequests.UI.csproj | 4 + PlexRequests.UI/Views/Admin/Settings.cshtml | 22 ----- .../Views/Customization/Customization.cshtml | 89 +++++++++++++++++++ .../Views/Shared/Partial/_Head.cshtml | 8 +- .../Views/Shared/Partial/_Navbar.cshtml | 9 +- .../Views/Shared/Partial/_Sidebar.cshtml | 1 + 10 files changed, 237 insertions(+), 25 deletions(-) create mode 100644 PlexRequests.Core/SettingModels/CustomizationSettings.cs create mode 100644 PlexRequests.UI/Modules/Admin/CustomizationModule.cs create mode 100644 PlexRequests.UI/Views/Customization/Customization.cshtml diff --git a/PlexRequests.Core/PlexRequests.Core.csproj b/PlexRequests.Core/PlexRequests.Core.csproj index f2f79067b..20e3e74fe 100644 --- a/PlexRequests.Core/PlexRequests.Core.csproj +++ b/PlexRequests.Core/PlexRequests.Core.csproj @@ -122,6 +122,7 @@ + diff --git a/PlexRequests.Core/SettingModels/CustomizationSettings.cs b/PlexRequests.Core/SettingModels/CustomizationSettings.cs new file mode 100644 index 000000000..9c0d47a65 --- /dev/null +++ b/PlexRequests.Core/SettingModels/CustomizationSettings.cs @@ -0,0 +1,39 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: NewsletterSettings.cs +// Created By: Jim MacKenzie +// +// 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 + +namespace PlexRequests.Core.SettingModels +{ + public class CustomizationSettings : Settings + { + public string ApplicationName { get; set; } + + /// + /// The CSS name of the theme we want + /// + public string ThemeName { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/Helpers/BaseUrlHelper.cs b/PlexRequests.UI/Helpers/BaseUrlHelper.cs index 513dbd553..7541ca73b 100644 --- a/PlexRequests.UI/Helpers/BaseUrlHelper.cs +++ b/PlexRequests.UI/Helpers/BaseUrlHelper.cs @@ -66,7 +66,7 @@ namespace PlexRequests.UI.Helpers var assetLocation = GetBaseUrl(); var content = GetContentUrl(assetLocation); - var settings = GetSettings(); + var settings = GetCustomizationSettings(); if (string.IsNullOrEmpty(settings.ThemeName)) { settings.ThemeName = Themes.PlexTheme; @@ -328,6 +328,11 @@ namespace PlexRequests.UI.Helpers return helper.Raw(GetBaseUrl()); } + public static IHtmlString GetApplicationName(this HtmlHelpers helper) + { + return helper.Raw(GetCustomizationSettings().ApplicationName); + } + private static string GetBaseUrl() { return GetSettings().BaseUrl; @@ -343,6 +348,16 @@ namespace PlexRequests.UI.Helpers return returnValue; } + private static CustomizationSettings GetCustomizationSettings() + { + var returnValue = Cache.GetOrSet(CacheKeys.GetPlexRequestSettings, () => + { + var settings = Locator.Resolve>().GetSettings(); + return settings; + }); + return returnValue; + } + private static string GetLinkUrl(string assetLocation) { return string.IsNullOrEmpty(assetLocation) ? string.Empty : $"{assetLocation}"; diff --git a/PlexRequests.UI/Modules/Admin/CustomizationModule.cs b/PlexRequests.UI/Modules/Admin/CustomizationModule.cs new file mode 100644 index 000000000..be009396d --- /dev/null +++ b/PlexRequests.UI/Modules/Admin/CustomizationModule.cs @@ -0,0 +1,72 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: CustomizationModule.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.Threading.Tasks; +using Nancy; +using Nancy.ModelBinding; +using Nancy.Responses.Negotiation; +using PlexRequests.Core; +using PlexRequests.Core.SettingModels; +using PlexRequests.Helpers.Permissions; +using PlexRequests.UI.Models; +using ISecurityExtensions = PlexRequests.Core.ISecurityExtensions; + +namespace PlexRequests.UI.Modules.Admin +{ + public class CustomizationModule : BaseModule + { + public CustomizationModule(ISettingsService settingsService, ISettingsService cust, ISecurityExtensions security) : base("admin", settingsService, security) + { + Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx); + + Settings = cust; + + Get["/customization", true] = async (x,ct) => await Index(); + Post["/customization", true] = async (x,ct) => await Save(); + } + + private ISettingsService Settings { get; } + + private async Task Index() + { + var model = await Settings.GetSettingsAsync(); + + return View["customization", model]; + } + + private async Task Save() + { + var model = this.Bind(); + + var result = await Settings.SaveSettingsAsync(model); + + return Response.AsJson(result + ? new JsonResponseModel { Result = true } + : new JsonResponseModel { Result = false, Message = "We could not save to the database, please try again" }); + } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index e8489f12c..81263e146 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -244,6 +244,7 @@ + @@ -757,6 +758,9 @@ Always + + Always + web.config diff --git a/PlexRequests.UI/Views/Admin/Settings.cshtml b/PlexRequests.UI/Views/Admin/Settings.cshtml index 653e3d734..fb27fee20 100644 --- a/PlexRequests.UI/Views/Admin/Settings.cshtml +++ b/PlexRequests.UI/Views/Admin/Settings.cshtml @@ -19,18 +19,6 @@ { formAction = "/" + baseUrl.ToHtmlString() + formAction; } - var plexTheme = string.Empty; - var originalTheme = string.Empty; - - if (!string.IsNullOrEmpty(Model.ThemeName)) - { - plexTheme = Model.ThemeName.Equals(Themes.PlexTheme) ? "selected=\"selected\"" : string.Empty; - originalTheme = Model.ThemeName.Equals(Themes.OriginalTheme) ? "selected=\"selected\"" : string.Empty; - } - else - { - plexTheme = "selected=\"selected\""; - } }
@@ -69,16 +57,6 @@
- -
- -
- -
-
@Html.Checkbox(Model.SearchForMovies,"SearchForMovies","Search for Movies") diff --git a/PlexRequests.UI/Views/Customization/Customization.cshtml b/PlexRequests.UI/Views/Customization/Customization.cshtml new file mode 100644 index 000000000..d0e2d4720 --- /dev/null +++ b/PlexRequests.UI/Views/Customization/Customization.cshtml @@ -0,0 +1,89 @@ +@using PlexRequests.UI.Helpers +@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase +@Html.Partial("Shared/Partial/_Sidebar") +@{ + var plexTheme = string.Empty; + var originalTheme = string.Empty; + + if (!string.IsNullOrEmpty(Model.ThemeName)) + { + plexTheme = Model.ThemeName.Equals(Themes.PlexTheme) ? "selected=\"selected\"" : string.Empty; + originalTheme = Model.ThemeName.Equals(Themes.OriginalTheme) ? "selected=\"selected\"" : string.Empty; + } + else + { + plexTheme = "selected=\"selected\""; + } +} +
+ +
+ Customization Settings + + + +
+ + +
+ +
+
+ +
+ +
+ +
+
+ +
+
+ +
+
+ +
+ +
+ + + + \ No newline at end of file diff --git a/PlexRequests.UI/Views/Shared/Partial/_Head.cshtml b/PlexRequests.UI/Views/Shared/Partial/_Head.cshtml index a57044559..3524f3379 100644 --- a/PlexRequests.UI/Views/Shared/Partial/_Head.cshtml +++ b/PlexRequests.UI/Views/Shared/Partial/_Head.cshtml @@ -12,13 +12,19 @@ { url = "/" + baseUrl.ToHtmlString(); } + var title = UI.Layout_Title; + var customName = Html.GetApplicationName().ToHtmlString(); + if (!string.IsNullOrEmpty(customName)) + { + title = customName; + } } - @UI.Layout_Title + @title diff --git a/PlexRequests.UI/Views/Shared/Partial/_Navbar.cshtml b/PlexRequests.UI/Views/Shared/Partial/_Navbar.cshtml index 0f1a4b0c9..17149fc90 100644 --- a/PlexRequests.UI/Views/Shared/Partial/_Navbar.cshtml +++ b/PlexRequests.UI/Views/Shared/Partial/_Navbar.cshtml @@ -15,6 +15,13 @@ { url = "/" + baseUrl.ToHtmlString(); } + + var title = UI.Layout_Title; + var customName = Html.GetApplicationName().ToHtmlString(); + if (!string.IsNullOrEmpty(customName)) + { + title = customName; + } } @@ -28,7 +35,7 @@ - @UI.Layout_Title + @title