From 7c7142c8b5401ec7aead1b4c2604446b413eb85d Mon Sep 17 00:00:00 2001 From: tidusjar Date: Thu, 14 Apr 2016 23:03:33 +0100 Subject: [PATCH] Done the auth, cp, logs and sidebar for #72 --- PlexRequests.UI/Content/site.js | 11 ++ .../{AssetHelper.cs => BaseUrlHelper.cs} | 62 ++++++--- PlexRequests.UI/PlexRequests.UI.csproj | 2 +- .../Views/Admin/Authentication.cshtml | 27 +++- .../Views/Admin/CouchPotato.cshtml | 18 ++- PlexRequests.UI/Views/Admin/Logs.cshtml | 21 +++- PlexRequests.UI/Views/Admin/_Sidebar.cshtml | 119 +++--------------- 7 files changed, 125 insertions(+), 135 deletions(-) rename PlexRequests.UI/Helpers/{AssetHelper.cs => BaseUrlHelper.cs} (76%) diff --git a/PlexRequests.UI/Content/site.js b/PlexRequests.UI/Content/site.js index e2784b315..e08d5835d 100644 --- a/PlexRequests.UI/Content/site.js +++ b/PlexRequests.UI/Content/site.js @@ -62,6 +62,17 @@ function finishLoading(elementId, originalCss, html) { } } +function createBaseUrl(base, url) { + if (base) { + if (url.charAt(0) === "/") { + url = "/" + base + url; + } else { + url = "/" + base + "/" + url; + } + } + return url; +} + var noResultsHtml = "
" + "
Sorry, we didn't find any results!
"; var noResultsMusic = "
" + diff --git a/PlexRequests.UI/Helpers/AssetHelper.cs b/PlexRequests.UI/Helpers/BaseUrlHelper.cs similarity index 76% rename from PlexRequests.UI/Helpers/AssetHelper.cs rename to PlexRequests.UI/Helpers/BaseUrlHelper.cs index 66aa2e48d..ddeb1fb7b 100644 --- a/PlexRequests.UI/Helpers/AssetHelper.cs +++ b/PlexRequests.UI/Helpers/BaseUrlHelper.cs @@ -1,7 +1,7 @@ #region Copyright // /************************************************************************ // Copyright (c) 2016 Jamie Rees -// File: AssetHelper.cs +// File: BaseUrlHelper.cs // Created By: Jamie Rees // // Permission is hereby granted, free of charge, to any person obtaining @@ -24,8 +24,10 @@ // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ************************************************************************/ #endregion -using System.Text; +using System.IO; +using System.Text; +using Nancy; using Nancy.ViewEngines.Razor; using PlexRequests.Core; @@ -33,14 +35,13 @@ using PlexRequests.Core.SettingModels; namespace PlexRequests.UI.Helpers { - public static class AssetHelper + public static class BaseUrlHelper { private static ServiceLocator Locator => ServiceLocator.Instance; public static IHtmlString LoadAssets(this HtmlHelpers helper) { - var settings = Locator.Resolve>().GetSettings(); var sb = new StringBuilder(); - var assetLocation = settings.BaseUrl; + var assetLocation = GetBaseUrl(); var content = GetContentUrl(assetLocation); @@ -64,9 +65,8 @@ namespace PlexRequests.UI.Helpers public static IHtmlString LoadSearchAssets(this HtmlHelpers helper) { - var settings = Locator.Resolve>().GetSettings(); var sb = new StringBuilder(); - var assetLocation = settings.BaseUrl; + var assetLocation = GetBaseUrl(); var content = GetContentUrl(assetLocation); @@ -77,9 +77,8 @@ namespace PlexRequests.UI.Helpers public static IHtmlString LoadRequestAssets(this HtmlHelpers helper) { - var settings = Locator.Resolve>().GetSettings(); var sb = new StringBuilder(); - var assetLocation = settings.BaseUrl; + var assetLocation = GetBaseUrl(); var content = GetContentUrl(assetLocation); @@ -90,9 +89,8 @@ namespace PlexRequests.UI.Helpers public static IHtmlString LoadLogsAssets(this HtmlHelpers helper) { - var settings = Locator.Resolve>().GetSettings(); var sb = new StringBuilder(); - var assetLocation = settings.BaseUrl; + var assetLocation = GetBaseUrl(); var content = GetContentUrl(assetLocation); @@ -101,10 +99,46 @@ namespace PlexRequests.UI.Helpers return helper.Raw(sb.ToString()); } - - private static string GetContentUrl(string assetLocation) + + public static IHtmlString GetSidebarUrl(this HtmlHelpers helper, NancyContext context, string url, string title) { - return string.IsNullOrEmpty(assetLocation) ? string.Empty : $"/{assetLocation}"; + var returnString = string.Empty; + var content = GetLinkUrl(GetBaseUrl()); + if (!string.IsNullOrEmpty(content)) + { + url = $"/{content}{url}"; + } + if (context.Request.Path == url) + { + returnString = $"{title}"; + } + else + { + returnString = $"{title}"; + } + + return helper.Raw(returnString); + } + + public static IHtmlString GetBaseUrl(this HtmlHelpers helper) + { + return helper.Raw(GetBaseUrl()); + } + + private static string GetBaseUrl() + { + var settings = Locator.Resolve>().GetSettings(); + var assetLocation = settings.BaseUrl; + return assetLocation; + } + + private static string GetLinkUrl(string assetLocation) + { + return string.IsNullOrEmpty(assetLocation) ? string.Empty : $"{assetLocation}"; + } + private static string GetContentUrl(string assetLocation) + { + return string.IsNullOrEmpty(assetLocation) ? string.Empty : $"/{assetLocation}"; } } } \ No newline at end of file diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index ec156d653..93a345ed1 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -164,7 +164,7 @@ - + diff --git a/PlexRequests.UI/Views/Admin/Authentication.cshtml b/PlexRequests.UI/Views/Admin/Authentication.cshtml index a703431b8..da2cea63f 100644 --- a/PlexRequests.UI/Views/Admin/Authentication.cshtml +++ b/PlexRequests.UI/Views/Admin/Authentication.cshtml @@ -1,7 +1,16 @@ -@Html.Partial("_Sidebar") - +@using PlexRequests.UI.Helpers +@Html.Partial("_Sidebar") + +@{ + var baseUrl = Html.GetBaseUrl(); + var formAction = "/admin/authentication"; + if (!string.IsNullOrEmpty(baseUrl.ToHtmlString())) + { + formAction = "/" + baseUrl.ToHtmlString() + formAction; + } +}
-
+
Authentication Settings @@ -100,21 +109,24 @@