Done the auth, cp, logs and sidebar for #72

pull/158/head
tidusjar 9 years ago
parent 7888912c2d
commit 7c7142c8b5

@ -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 = "<div class='no-search-results'>" + var noResultsHtml = "<div class='no-search-results'>" +
"<i class='fa fa-film no-search-results-icon'></i><div class='no-search-results-text'>Sorry, we didn't find any results!</div></div>"; "<i class='fa fa-film no-search-results-icon'></i><div class='no-search-results-text'>Sorry, we didn't find any results!</div></div>";
var noResultsMusic = "<div class='no-search-results'>" + var noResultsMusic = "<div class='no-search-results'>" +

@ -1,7 +1,7 @@
#region Copyright #region Copyright
// /************************************************************************ // /************************************************************************
// Copyright (c) 2016 Jamie Rees // Copyright (c) 2016 Jamie Rees
// File: AssetHelper.cs // File: BaseUrlHelper.cs
// Created By: Jamie Rees // Created By: Jamie Rees
// //
// Permission is hereby granted, free of charge, to any person obtaining // 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. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/ // ************************************************************************/
#endregion #endregion
using System.Text;
using System.IO;
using System.Text;
using Nancy;
using Nancy.ViewEngines.Razor; using Nancy.ViewEngines.Razor;
using PlexRequests.Core; using PlexRequests.Core;
@ -33,14 +35,13 @@ using PlexRequests.Core.SettingModels;
namespace PlexRequests.UI.Helpers namespace PlexRequests.UI.Helpers
{ {
public static class AssetHelper public static class BaseUrlHelper
{ {
private static ServiceLocator Locator => ServiceLocator.Instance; private static ServiceLocator Locator => ServiceLocator.Instance;
public static IHtmlString LoadAssets(this HtmlHelpers helper) public static IHtmlString LoadAssets(this HtmlHelpers helper)
{ {
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings();
var sb = new StringBuilder(); var sb = new StringBuilder();
var assetLocation = settings.BaseUrl; var assetLocation = GetBaseUrl();
var content = GetContentUrl(assetLocation); var content = GetContentUrl(assetLocation);
@ -64,9 +65,8 @@ namespace PlexRequests.UI.Helpers
public static IHtmlString LoadSearchAssets(this HtmlHelpers helper) public static IHtmlString LoadSearchAssets(this HtmlHelpers helper)
{ {
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings();
var sb = new StringBuilder(); var sb = new StringBuilder();
var assetLocation = settings.BaseUrl; var assetLocation = GetBaseUrl();
var content = GetContentUrl(assetLocation); var content = GetContentUrl(assetLocation);
@ -77,9 +77,8 @@ namespace PlexRequests.UI.Helpers
public static IHtmlString LoadRequestAssets(this HtmlHelpers helper) public static IHtmlString LoadRequestAssets(this HtmlHelpers helper)
{ {
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings();
var sb = new StringBuilder(); var sb = new StringBuilder();
var assetLocation = settings.BaseUrl; var assetLocation = GetBaseUrl();
var content = GetContentUrl(assetLocation); var content = GetContentUrl(assetLocation);
@ -90,9 +89,8 @@ namespace PlexRequests.UI.Helpers
public static IHtmlString LoadLogsAssets(this HtmlHelpers helper) public static IHtmlString LoadLogsAssets(this HtmlHelpers helper)
{ {
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings();
var sb = new StringBuilder(); var sb = new StringBuilder();
var assetLocation = settings.BaseUrl; var assetLocation = GetBaseUrl();
var content = GetContentUrl(assetLocation); var content = GetContentUrl(assetLocation);
@ -101,10 +99,46 @@ namespace PlexRequests.UI.Helpers
return helper.Raw(sb.ToString()); 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 = $"<a class=\"list-group-item active\" href=\"{url}\">{title}</a>";
}
else
{
returnString = $"<a class=\"list-group-item\" href=\"{url}\">{title}</a>";
}
return helper.Raw(returnString);
}
public static IHtmlString GetBaseUrl(this HtmlHelpers helper)
{
return helper.Raw(GetBaseUrl());
}
private static string GetBaseUrl()
{
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().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}";
} }
} }
} }

@ -164,7 +164,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Bootstrapper.cs" /> <Compile Include="Bootstrapper.cs" />
<Compile Include="Helpers\AssetHelper.cs" /> <Compile Include="Helpers\BaseUrlHelper.cs" />
<Compile Include="Helpers\HeadphonesSender.cs" /> <Compile Include="Helpers\HeadphonesSender.cs" />
<Compile Include="Helpers\ServiceLocator.cs" /> <Compile Include="Helpers\ServiceLocator.cs" />
<Compile Include="Helpers\StringHelper.cs" /> <Compile Include="Helpers\StringHelper.cs" />

@ -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;
}
}
<div class="col-sm-8 col-sm-push-1"> <div class="col-sm-8 col-sm-push-1">
<form class="form-horizontal" method="POST" action="/admin/authentication" id="mainForm"> <form class="form-horizontal" method="POST" action="@formAction" id="mainForm">
<fieldset> <fieldset>
<legend>Authentication Settings</legend> <legend>Authentication Settings</legend>
@ -100,21 +109,24 @@
<script> <script>
$(function () { $(function () {
var base = '@Html.GetBaseUrl()';
if ($('#PlexAuthToken')) { if ($('#PlexAuthToken')) {
loadUserList(); loadUserList();
} }
$('#refreshUsers').click(function () { $('#refreshUsers').click(function (e) {
e.preventDefault(); e.preventDefault();
loadUserList(); loadUserList();
}); });
$('#requestToken').click(function (e) { $('#requestToken').click(function (e) {
e.preventDefault(); e.preventDefault();
var url = createBaseUrl(base, "admin/requestauth");
var $form = $("#mainForm"); var $form = $("#mainForm");
$.ajax({ $.ajax({
type: $form.prop("method"), type: $form.prop("method"),
url: "requestauth", url: url,
data: $form.serialize(), data: $form.serialize(),
dataType: "json", dataType: "json",
success: function (response) { success: function (response) {
@ -136,9 +148,12 @@
function loadUserList() { function loadUserList() {
$('#users').html("");
var url = "admin/getusers";
url = createBaseUrl(base, url);
$.ajax({ $.ajax({
type: "Get", type: "Get",
url: "getusers", url: url,
dataType: "json", dataType: "json",
success: function (response) { success: function (response) {
if (response.length > 1) { if (response.length > 1) {

@ -1,4 +1,5 @@
@Html.Partial("_Sidebar") @using PlexRequests.UI.Helpers
@Html.Partial("_Sidebar")
@{ @{
int port; int port;
if (Model.Port == 0) if (Model.Port == 0)
@ -108,15 +109,19 @@
<script> <script>
$(function() { $(function() {
var baseUrl = '@Html.GetBaseUrl()';
@if (!string.IsNullOrEmpty(Model.ProfileId)) @if (!string.IsNullOrEmpty(Model.ProfileId))
{ {
<text> <text>
var qualitySelected = '@Model.ProfileId'; var qualitySelected = '@Model.ProfileId';
var $form = $("#mainForm"); var $form = $("#mainForm");
var url = 'cpprofiles';
url = createBaseUrl(baseUrl, url);
$.ajax({ $.ajax({
type: $form.prop("method"), type: $form.prop("method"),
data: $form.serialize(), data: $form.serialize(),
url: "cpprofiles", url: url,
dataType: "json", dataType: "json",
success: function(response) { success: function(response) {
response.list.forEach(function(result) { response.list.forEach(function(result) {
@ -139,10 +144,12 @@
$('#getProfiles').click(function (e) { $('#getProfiles').click(function (e) {
e.preventDefault(); e.preventDefault();
var $form = $("#mainForm"); var $form = $("#mainForm");
var url = "admin/cpprofiles";
url = createBaseUrl(baseUrl, url);
$.ajax({ $.ajax({
type: $form.prop("method"), type: $form.prop("method"),
data: $form.serialize(), data: $form.serialize(),
url: "cpprofiles", url: url,
dataType: "json", dataType: "json",
success: function (response) { success: function (response) {
response.list.forEach(function (result) { response.list.forEach(function (result) {
@ -159,10 +166,11 @@
$('#testCp').click(function (e) { $('#testCp').click(function (e) {
e.preventDefault(); e.preventDefault();
var $form = $("#mainForm"); var $form = $("#mainForm");
var url = createBaseUrl(baseUrl,"/test/cp");
url = createBaseUrl(baseUrl, url);
$.ajax({ $.ajax({
type: $form.prop("method"), type: $form.prop("method"),
url: "/test/cp", url: url,
data: $form.serialize(), data: $form.serialize(),
dataType: "json", dataType: "json",
success: function (response) { success: function (response) {

@ -2,11 +2,19 @@
@Html.Partial("_Sidebar") @Html.Partial("_Sidebar")
@Html.LoadLogsAssets() @Html.LoadLogsAssets()
@{
var baseUrl = Html.GetBaseUrl();
var formAction = "/admin/loglevel";
if (!string.IsNullOrEmpty(baseUrl.ToHtmlString()))
{
formAction = "/" + baseUrl.ToHtmlString() + formAction;
}
}
<div class="col-sm-8 col-sm-push-1"> <div class="col-sm-8 col-sm-push-1">
<fieldset> <fieldset>
<legend>Logs</legend> <legend>Logs</legend>
<form method="post" id="mainForm" action="@formAction">
<form method="post" id="mainForm" action="/admin/loglevel">
<div class="form-group"> <div class="form-group">
<label for="logLevel" class="control-label">Log Level</label> <label for="logLevel" class="control-label">Log Level</label>
<div id="logLevel"> <div id="logLevel">
@ -45,9 +53,12 @@
<script> <script>
$(function () { $(function () {
var baseUrl = '@Html.GetBaseUrl()';
var logsUrl = "/admin/loadlogs";
var url = createBaseUrl(baseUrl, logsUrl);
$('#example').DataTable({ $('#example').DataTable({
"ajax": "/admin/loadlogs", "ajax": url,
"columns": [ "columns": [
{ "data": "message" }, { "data": "message" },
{ "data": "logger" }, { "data": "logger" },
@ -58,9 +69,11 @@
}); });
var logUrl = "/admin/loglevel";
logUrl = createBaseUrl(baseUrl, logUrl);
$.ajax({ $.ajax({
type: "get", type: "get",
url: "/admin/loglevel", url: logUrl,
dataType: "json", dataType: "json",
success: function (response) { success: function (response) {
$("#select > option").each(function (level) { $("#select > option").each(function (level) {

@ -1,108 +1,17 @@
<div class="col-lg-3 col-md-3 col-sm-4"> @using PlexRequests.UI.Helpers
<div class="col-lg-3 col-md-3 col-sm-4">
<div class="list-group table-of-contents"> <div class="list-group table-of-contents">
@if (Context.Request.Path == "/admin") @Html.GetSidebarUrl(Context, "/admin", "Plex Request")
{ @Html.GetSidebarUrl(Context, "/admin/authentication", "Authentication")
<a class="list-group-item active" href="/admin">Plex Request</a> @Html.GetSidebarUrl(Context, "/admin/plex", "Plex")
} @Html.GetSidebarUrl(Context, "/admin/couchpotato", "CouchPotato")
else @Html.GetSidebarUrl(Context, "/admin/sonarr", "Sonarr")
{ @Html.GetSidebarUrl(Context, "/admin/sickrage", "SickRage")
<a class="list-group-item" href="/admin">Plex Request</a> @Html.GetSidebarUrl(Context, "/admin/headphones", "Headphones (Beta)")
} @Html.GetSidebarUrl(Context, "/admin/emailnotification", "Email Notifications")
@if (Context.Request.Path == "/admin/authentication") @Html.GetSidebarUrl(Context, "/admin/pushbulletnotification", "Pushbullet Notifications")
{ @Html.GetSidebarUrl(Context, "/admin/pushovernotification", "Pushover Notifications")
@Html.GetSidebarUrl(Context, "/admin/logs", "Logs")
<a class="list-group-item active" href="/admin/authentication">Authentication</a> @Html.GetSidebarUrl(Context, "/admin/status", "Status")
}
else
{
<a class="list-group-item" href="/admin/authentication">Authentication</a>
}
@if (Context.Request.Path == "/admin/plex")
{
<a class="list-group-item active" href="/admin/plex">Plex</a>
}
else
{
<a class="list-group-item" href="/admin/plex">Plex</a>
}
@if (Context.Request.Path == "/admin/couchpotato")
{
<a class="list-group-item active" href="/admin/couchpotato">CouchPotato</a>
}
else
{
<a class="list-group-item" href="/admin/couchpotato">CouchPotato</a>
}
@if (Context.Request.Path == "/admin/sonarr")
{
<a class="list-group-item active" href="/admin/sonarr">Sonarr</a>
}
else
{
<a class="list-group-item" href="/admin/sonarr">Sonarr</a>
}
@if (Context.Request.Path == "/admin/sickrage")
{
<a class="list-group-item active" href="/admin/sickrage">SickRage</a>
}
else
{
<a class="list-group-item" href="/admin/sickrage">SickRage</a>
}
@if (Context.Request.Path == "/admin/headphones")
{
<a class="list-group-item active" href="/admin/headphones">Headphones (Beta)</a>
}
else
{
<a class="list-group-item" href="/admin/headphones">Headphones (Beta)</a>
}
@if (Context.Request.Path == "/admin/emailnotification")
{
<a class="list-group-item active" href="/admin/emailnotification">Email Notifications</a>
}
else
{
<a class="list-group-item" href="/admin/emailnotification">Email Notifications</a>
}
@if (Context.Request.Path == "/admin/pushbulletnotification")
{
<a class="list-group-item active" href="/admin/pushbulletnotification">Pushbullet Notifications</a>
}
else
{
<a class="list-group-item" href="/admin/pushbulletnotification">Pushbullet Notifications</a>
}
@if (Context.Request.Path == "/admin/pushovernotification")
{
<a class="list-group-item active" href="/admin/pushovernotification">Pushover Notifications</a>
}
else
{
<a class="list-group-item" href="/admin/pushovernotification">Pushover Notifications</a>
}
@if (Context.Request.Path == "/admin/logs")
{
<a class="list-group-item active" href="/admin/logs">Logs</a>
}
else
{
<a class="list-group-item" href="/admin/logs">Logs</a>
}
@if (Context.Request.Path == "/admin/status")
{
<a class="list-group-item active" href="/admin/status">Status</a>
}
else
{
<a class="list-group-item" href="/admin/status">Status</a>
}
</div> </div>
</div> </div>
Loading…
Cancel
Save