Skip to content

Commit

Permalink
Done the auth, cp, logs and sidebar for #72
Browse files Browse the repository at this point in the history
  • Loading branch information
tidusjar committed Apr 14, 2016
1 parent 7888912 commit 7c7142c
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 135 deletions.
11 changes: 11 additions & 0 deletions PlexRequests.UI/Content/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'>" +
"<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'>" +
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,23 +24,24 @@
// 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;
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<ISettingsService<PlexRequestSettings>>().GetSettings();
var sb = new StringBuilder();
var assetLocation = settings.BaseUrl;
var assetLocation = GetBaseUrl();

var content = GetContentUrl(assetLocation);

Expand All @@ -64,9 +65,8 @@ public static IHtmlString LoadAssets(this HtmlHelpers helper)

public static IHtmlString LoadSearchAssets(this HtmlHelpers helper)
{
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings();
var sb = new StringBuilder();
var assetLocation = settings.BaseUrl;
var assetLocation = GetBaseUrl();

var content = GetContentUrl(assetLocation);

Expand All @@ -77,9 +77,8 @@ public static IHtmlString LoadSearchAssets(this HtmlHelpers helper)

public static IHtmlString LoadRequestAssets(this HtmlHelpers helper)
{
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings();
var sb = new StringBuilder();
var assetLocation = settings.BaseUrl;
var assetLocation = GetBaseUrl();

var content = GetContentUrl(assetLocation);

Expand All @@ -90,9 +89,8 @@ public static IHtmlString LoadRequestAssets(this HtmlHelpers helper)

public static IHtmlString LoadLogsAssets(this HtmlHelpers helper)
{
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings();
var sb = new StringBuilder();
var assetLocation = settings.BaseUrl;
var assetLocation = GetBaseUrl();

var content = GetContentUrl(assetLocation);

Expand All @@ -101,10 +99,46 @@ public static IHtmlString LoadLogsAssets(this HtmlHelpers helper)

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}";
}
}
}
2 changes: 1 addition & 1 deletion PlexRequests.UI/PlexRequests.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Bootstrapper.cs" />
<Compile Include="Helpers\AssetHelper.cs" />
<Compile Include="Helpers\BaseUrlHelper.cs" />
<Compile Include="Helpers\HeadphonesSender.cs" />
<Compile Include="Helpers\ServiceLocator.cs" />
<Compile Include="Helpers\StringHelper.cs" />
Expand Down
27 changes: 21 additions & 6 deletions PlexRequests.UI/Views/Admin/Authentication.cshtml
Original file line number Diff line number Diff line change
@@ -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">
<form class="form-horizontal" method="POST" action="/admin/authentication" id="mainForm">
<form class="form-horizontal" method="POST" action="@formAction" id="mainForm">
<fieldset>
<legend>Authentication Settings</legend>

Expand Down Expand Up @@ -100,21 +109,24 @@
<script>
$(function () {
var base = '@Html.GetBaseUrl()';
if ($('#PlexAuthToken')) {
loadUserList();
}
$('#refreshUsers').click(function () {
$('#refreshUsers').click(function (e) {
e.preventDefault();
loadUserList();
});
$('#requestToken').click(function (e) {
e.preventDefault();
var url = createBaseUrl(base, "admin/requestauth");
var $form = $("#mainForm");
$.ajax({
type: $form.prop("method"),
url: "requestauth",
url: url,
data: $form.serialize(),
dataType: "json",
success: function (response) {
Expand All @@ -136,9 +148,12 @@
function loadUserList() {
$('#users').html("");
var url = "admin/getusers";
url = createBaseUrl(base, url);
$.ajax({
type: "Get",
url: "getusers",
url: url,
dataType: "json",
success: function (response) {
if (response.length > 1) {
Expand Down
18 changes: 13 additions & 5 deletions PlexRequests.UI/Views/Admin/CouchPotato.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@Html.Partial("_Sidebar")
@using PlexRequests.UI.Helpers
@Html.Partial("_Sidebar")
@{
int port;
if (Model.Port == 0)
Expand Down Expand Up @@ -108,15 +109,19 @@
<script>
$(function() {
var baseUrl = '@Html.GetBaseUrl()';
@if (!string.IsNullOrEmpty(Model.ProfileId))
{
<text>
var qualitySelected = '@Model.ProfileId';
var $form = $("#mainForm");
var url = 'cpprofiles';

This comment has been minimized.

Copy link
@tidusjar

tidusjar Apr 14, 2016

Member

Todo. Need to include admin.

url = createBaseUrl(baseUrl, url);
$.ajax({
type: $form.prop("method"),
data: $form.serialize(),
url: "cpprofiles",
url: url,
dataType: "json",
success: function(response) {
response.list.forEach(function(result) {
Expand All @@ -139,10 +144,12 @@
$('#getProfiles').click(function (e) {
e.preventDefault();
var $form = $("#mainForm");
var url = "admin/cpprofiles";
url = createBaseUrl(baseUrl, url);
$.ajax({
type: $form.prop("method"),
data: $form.serialize(),
url: "cpprofiles",
url: url,
dataType: "json",
success: function (response) {
response.list.forEach(function (result) {
Expand All @@ -159,10 +166,11 @@
$('#testCp').click(function (e) {
e.preventDefault();
var $form = $("#mainForm");
var url = createBaseUrl(baseUrl,"/test/cp");
url = createBaseUrl(baseUrl, url);
$.ajax({
type: $form.prop("method"),
url: "/test/cp",
url: url,
data: $form.serialize(),
dataType: "json",
success: function (response) {
Expand Down
21 changes: 17 additions & 4 deletions PlexRequests.UI/Views/Admin/Logs.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@
@Html.Partial("_Sidebar")
@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">
<fieldset>
<legend>Logs</legend>

<form method="post" id="mainForm" action="/admin/loglevel">
<form method="post" id="mainForm" action="@formAction">
<div class="form-group">
<label for="logLevel" class="control-label">Log Level</label>
<div id="logLevel">
Expand Down Expand Up @@ -45,9 +53,12 @@

<script>
$(function () {
var baseUrl = '@Html.GetBaseUrl()';
var logsUrl = "/admin/loadlogs";
var url = createBaseUrl(baseUrl, logsUrl);
$('#example').DataTable({
"ajax": "/admin/loadlogs",
"ajax": url,
"columns": [
{ "data": "message" },
{ "data": "logger" },
Expand All @@ -58,9 +69,11 @@
});
var logUrl = "/admin/loglevel";
logUrl = createBaseUrl(baseUrl, logUrl);
$.ajax({
type: "get",
url: "/admin/loglevel",
url: logUrl,
dataType: "json",
success: function (response) {
$("#select > option").each(function (level) {
Expand Down
Loading

0 comments on commit 7c7142c

Please sign in to comment.