BaseUrl is finally finished! #72

pull/158/head
tidusjar 9 years ago
parent 47dc543b09
commit 67c968e886

@ -40,5 +40,7 @@ namespace PlexRequests.Core
public const string CouchPotatoQualityProfiles = "CouchPotatoQualityProfiles";
public const string CouchPotatoQueued = "CouchPotatoQueued";
public const string GetBaseUrl = "GetBaseUrl";
}
}

@ -11,7 +11,7 @@ var searchTemplate = Handlebars.compile(searchSource);
var albumTemplate = Handlebars.compile(albumSource);
var movieTimer = 0;
var tvimer = 0;
var base = $('#baseUrl').val();
var base = $('#baseUrl').text();
var mixItUpDefault = {
animation: { enable: true },
@ -381,16 +381,20 @@ $(document).on("click", ".change", function (e) {
generateNotify("Success! Availibility changed.", "info");
var button = $("button[custom-availibility='" + buttonId + "']");
var icon = $('#availableIcon' + buttonId);
var approvedIcon = $("#"+buttonId + "notapproved");
if (response.available) {
button.text("Mark Unavailable");
button.val("false");
button.prop("class", "btn btn-sm btn-info-outline change");
icon.prop("class", "fa fa-check");
approvedIcon.prop("class", "fa fa-check");
} else {
button.text("Mark Available");
button.prop("class", "btn btn-sm btn-success-outline change");
icon.prop("class", "fa fa-times");
approvedIcon.prop("class", "fa fa-times");
button.val("true");
}
}

@ -5,6 +5,8 @@
return opts.inverse(this);
});
$(function () {
var searchSource = $("#search-template").html();
@ -12,6 +14,8 @@ $(function () {
var searchTemplate = Handlebars.compile(searchSource);
var musicTemplate = Handlebars.compile(musicSource);
var base = $('#baseUrl').text();
var searchTimer = 0;
// fix for selecting a default tab
@ -21,7 +25,7 @@ $(function () {
}
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
focusSearch($($(e.target).attr('href')))
focusSearch($($(e.target).attr('href')));
});
focusSearch($('li.active a', '#nav-tabs').first().attr('href'));
@ -172,15 +176,18 @@ $(function () {
function movieSearch() {
var query = $("#movieSearchContent").val();
query ? getMovies("/search/movie/" + query) : resetMovies();
var url = createBaseUrl(base, '/search/movie/');
query ? getMovies(url + query) : resetMovies();
}
function moviesComingSoon() {
getMovies("/search/movie/upcoming");
var url = createBaseUrl(base, '/search/movie/upcoming');
getMovies(url);
}
function moviesInTheaters() {
getMovies("/search/movie/playing");
var url = createBaseUrl(base, '/search/movie/playing');
getMovies(url);
}
function getMovies(url) {
@ -209,7 +216,9 @@ $(function () {
function tvSearch() {
var query = $("#tvSearchContent").val();
query ? getTvShows("/search/tv/" + query) : resetTvShows();
var url = createBaseUrl(base, '/search/tv/');
query ? getTvShows(url + query) : resetTvShows();
}
function getTvShows(url) {
@ -236,8 +245,9 @@ $(function () {
}
function musicSearch() {
var url = createBaseUrl(base, '/search/music/');
var query = $("#musicSearchContent").val();
query ? getMusic("/search/music/" + query) : resetMusic();
query ? getMusic(url + query) : resetMusic();
}
function getMusic(url) {
@ -266,7 +276,9 @@ $(function () {
}
function getCoverArt(artistId) {
$.ajax("/search/music/coverart/" + artistId).success(function (result) {
var url = createBaseUrl(base, '/search/music/coverart/');
$.ajax(url + artistId).success(function (result) {
if (result) {
$('#' + artistId + "imageDiv").html(" <img class='img-responsive' src='" + result + "' width='150' alt='poster'>");
}

@ -32,12 +32,20 @@ using Nancy.ViewEngines.Razor;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
namespace PlexRequests.UI.Helpers
{
public static class BaseUrlHelper
{
private static ServiceLocator Locator => ServiceLocator.Instance;
static BaseUrlHelper()
{
Locator = ServiceLocator.Instance;
Cache = Locator.Resolve<ICacheProvider>();
}
private static ICacheProvider Cache { get; }
private static ServiceLocator Locator { get; }
public static IHtmlString LoadAssets(this HtmlHelpers helper)
{
var sb = new StringBuilder();
@ -120,16 +128,40 @@ namespace PlexRequests.UI.Helpers
return helper.Raw(returnString);
}
public static IHtmlString GetNavbarUrl(this HtmlHelpers helper, NancyContext context, string url, string title, string fontIcon)
{
var returnString = string.Empty;
var content = GetLinkUrl(GetBaseUrl());
if (!string.IsNullOrEmpty(content))
{
url = $"/{content}{url}";
}
if (context.Request.Path == url)
{
returnString = $"<li class=\"active\"><a href=\"{url}\"><i class=\"fa fa-{fontIcon}\"></i> {title}</a></li>";
}
else
{
returnString = $"<li><a href=\"{url}\"><i class=\"fa fa-{fontIcon}\"></i> {title}</a></li>";
}
return helper.Raw(returnString);
}
public static IHtmlString GetBaseUrl(this HtmlHelpers helper)
{
return helper.Raw(GetBaseUrl());
}
private static string GetBaseUrl()
{
var returnValue = Cache.GetOrSet(CacheKeys.GetBaseUrl, () =>
{
var settings = Locator.Resolve<ISettingsService<PlexRequestSettings>>().GetSettings();
var assetLocation = settings.BaseUrl;
return assetLocation;
});
return returnValue;
}
private static string GetLinkUrl(string assetLocation)

@ -44,11 +44,7 @@ namespace PlexRequests.UI.Helpers
}
public T Resolve<T>() where T : class
{
if (Container != null)
{
return Container.Resolve<T>();
}
return null;
return Container?.Resolve<T>();
}
}
}

@ -595,6 +595,11 @@ namespace PlexRequests.UI.Modules
private Response GetCpProfiles()
{
var settings = this.Bind<CouchPotatoSettings>();
var valid = this.Validate(settings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
var profiles = CpApi.GetProfiles(settings.FullUri, settings.ApiKey);
// set the cache

@ -29,12 +29,13 @@ using System;
using Nancy;
using Nancy.ModelBinding;
using Nancy.Security;
using Nancy.Validation;
using NLog;
using PlexRequests.Api.Interfaces;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.UI.Helpers;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules
@ -73,6 +74,11 @@ namespace PlexRequests.UI.Modules
private Response CouchPotatoTest()
{
var couchPotatoSettings = this.Bind<CouchPotatoSettings>();
var valid = this.Validate(couchPotatoSettings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
try
{
var status = CpApi.GetStatus(couchPotatoSettings.FullUri, couchPotatoSettings.ApiKey);
@ -97,6 +103,11 @@ namespace PlexRequests.UI.Modules
private Response SonarrTest()
{
var sonarrSettings = this.Bind<SonarrSettings>();
var valid = this.Validate(sonarrSettings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
try
{
var status = SonarrApi.SystemStatus(sonarrSettings.ApiKey, sonarrSettings.FullUri);
@ -121,6 +132,11 @@ namespace PlexRequests.UI.Modules
private Response PlexTest()
{
var plexSettings = this.Bind<PlexSettings>();
var valid = this.Validate(plexSettings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
var settings = AuthSettings.GetSettings();
if (settings?.PlexAuthToken == null)
{
@ -150,7 +166,11 @@ namespace PlexRequests.UI.Modules
private Response SickRageTest()
{
var sickRageSettings = this.Bind<SickRageSettings>();
var valid = this.Validate(sickRageSettings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
try
{
var status = SickRageApi.Ping(sickRageSettings.ApiKey, sickRageSettings.FullUri);
@ -175,6 +195,11 @@ namespace PlexRequests.UI.Modules
private Response HeadphonesTest()
{
var settings = this.Bind<HeadphonesSettings>();
var valid = this.Validate(settings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
try
{
var result = HeadphonesApi.GetVersion(settings.ApiKey, settings.FullUri);

@ -75,6 +75,11 @@ namespace PlexRequests.UI.Modules
}
Session[SessionKeys.UsernameKey] = username;
Session[SessionKeys.ClientDateTimeOffsetKey] = dtOffset;
if (!string.IsNullOrEmpty(BaseUrl))
{
return this.LoginAndRedirect(userId.Value, expiry, $"/{BaseUrl}");
}
return this.LoginAndRedirect(userId.Value, expiry);
};

@ -178,6 +178,7 @@
<Compile Include="Models\SearchMusicViewModel.cs" />
<Compile Include="Models\SearchMovieViewModel.cs" />
<Compile Include="Modules\BaseModule.cs" />
<Compile Include="Validators\HeadphonesValidator.cs" />
<Compile Include="Validators\PushoverSettingsValidator.cs" />
<Compile Include="Validators\PushbulletSettingsValidator.cs" />
<Compile Include="Validators\EmailNotificationSettingsValidator.cs" />

@ -0,0 +1,42 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: SonarrValidator.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 FluentValidation;
using PlexRequests.Core.SettingModels;
namespace PlexRequests.UI.Validators
{
public class HeadphonesValidator : AbstractValidator<HeadphonesSettings>
{
public HeadphonesValidator()
{
RuleFor(request => request.Ip).NotEmpty().WithMessage("You must specify a IP/Host name.");
RuleFor(request => request.Port).NotEmpty().WithMessage("You must specify a Port.");
RuleFor(request => request.ApiKey).NotEmpty().WithMessage("You must specify a Api Key.");
}
}
}

@ -122,11 +122,11 @@
$('#requestToken').click(function (e) {
e.preventDefault();
var url = createBaseUrl(base, "admin/requestauth");
var url = createBaseUrl(base, "requestauth");
var $form = $("#mainForm");
$.ajax({
type: $form.prop("method"),
url: url,
url: "requestauth",
data: $form.serialize(),
dataType: "json",
success: function (response) {
@ -149,11 +149,11 @@
function loadUserList() {
$('#users').html("");
var url = "admin/getusers";
var url = "getusers";
url = createBaseUrl(base, url);
$.ajax({
type: "Get",
url: url,
url: "getusers",
dataType: "json",
success: function (response) {
if (response.length > 1) {

@ -116,7 +116,7 @@
<text>
var qualitySelected = '@Model.ProfileId';
var $form = $("#mainForm");
var url = 'cpprofiles';
var url = '/admin/cpprofiles';
url = createBaseUrl(baseUrl, url);
$.ajax({
type: $form.prop("method"),
@ -144,14 +144,17 @@
$('#getProfiles').click(function (e) {
e.preventDefault();
var $form = $("#mainForm");
var url = "admin/cpprofiles";
url = createBaseUrl(baseUrl, url);
var url = createBaseUrl(baseUrl, "/admin/cpprofiles");
$.ajax({
type: $form.prop("method"),
data: $form.serialize(),
url: url,
dataType: "json",
success: function (response) {
if (response.message) {
generateNotify(response.message, "warning");
return;
}
response.list.forEach(function (result) {
$("#select").append("<option value='" + result._id + "'>" + result.label + "</option>");
});
@ -167,7 +170,6 @@
e.preventDefault();
var $form = $("#mainForm");
var url = createBaseUrl(baseUrl,"/test/cp");
url = createBaseUrl(baseUrl, url);
$.ajax({
type: $form.prop("method"),
url: url,

@ -148,13 +148,18 @@
$('#testSickRage').click(function (e) {
e.preventDefault();
var qualityProfile = $("#profiles option:selected").val();
var $form = $("#mainForm");
var data = $form.serialize();
data = data + "&qualityProfile=" + qualityProfile;
var url = createBaseUrl(base, '/test/sickrage');
$.ajax({
type: $form.prop("method"),
url: url,
data: $form.serialize(),
data: data,
dataType: "json",
success: function (response) {
console.log(response);

@ -224,16 +224,22 @@
}
});
});
var base = '@Html.GetBaseUrl()';
$('#testSonarr').click(function (e) {
e.preventDefault();
var qualityProfile = $("#profiles option:selected").val();
var $form = $("#mainForm");
var data = $form.serialize();
data = data + "&qualityProfile=" + qualityProfile;
var url = createBaseUrl(base, '/test/sonarr');
$.ajax({
type: $form.prop("method"),
url: url,
data: $form.serialize(),
data: data,
dataType: "json",
success: function (response) {
console.log(response);

@ -411,7 +411,6 @@
</div>
</div>
</div>
<div id="baseUrl" value="@Html.GetBaseUrl()"></div>
@Html.LoadRequestAssets()

@ -1,4 +1,12 @@
@using PlexRequests.UI.Helpers
@{
var baseUrl = Html.GetBaseUrl();
var url = string.Empty;
if (!string.IsNullOrEmpty(baseUrl.ToHtmlString()))
{
url = "/" + baseUrl.ToHtmlString();
}
}
<div>
<h1>Search</h1>
<h4>Want to watch something that is not currently on Plex?! No problem! Just search for it below and request it!</h4>
@ -123,7 +131,7 @@
<p>{{overview}}</p>
</div>
<div class="col-sm-2 col-sm-push-3">
<form method="POST" action="/search/request/{{type}}" id="form{{id}}">
<form method="POST" action="@url/search/request/{{type}}" id="form{{id}}">
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" />
{{#if_eq available true}}
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Available</button>
@ -188,7 +196,7 @@
<p>{{overview}}</p>
</div>
<div class="col-sm-2 col-sm-push-3">
<form method="POST" action="/search/request/{{type}}" id="form{{id}}">
<form method="POST" action="@url/search/request/{{type}}" id="form{{id}}">
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" />
{{#if_eq available true}}
<button style="text-align: right" class="btn btn-success-outline disabled" disabled><i class="fa fa-check"></i> Available</button>

@ -3,11 +3,21 @@
@using PlexRequests.UI.Helpers
@using PlexRequests.UI.Models
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase
@{
var baseUrl = Html.GetBaseUrl();
var url = string.Empty;
if (!string.IsNullOrEmpty(baseUrl.ToHtmlString()))
{
url = "/" + baseUrl.ToHtmlString();
}
}
<html>
<div hidden="hidden" id="baseUrl">@baseUrl.ToHtmlString()</div>
<head>
<title>Plex Requests</title>
<!-- Styles -->
<meta name="viewport" content="width=device-width, initial-scale=1">
@Html.LoadAssets()
</head>
<body>
@ -22,53 +32,36 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/search">Plex Requests</a>
<a class="navbar-brand" href="@url/search">Plex Requests</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
@if (Context.Request.Path == "/search")
{
<li class="active"><a href="/search"><i class="fa fa-search"></i> Search</a></li>
}
else
{
<li><a href="/search"><i class="fa fa-search"></i> Search</a></li>
}
@if (Context.Request.Path == "/requests")
{
<li class="active"><a href="/requests"><i class="fa fa-plus-circle"></i> Requests</a></li>
}
else
{
<li><a href="/requests"><i class="fa fa-plus-circle"></i> Requests</a></li>
}
@Html.GetNavbarUrl(Context, "/search", "Search", "search")
@Html.GetNavbarUrl(Context, "/requests", "Requests", "plus-circle")
</ul>
<ul class="nav navbar-nav navbar-right">
@if (!Context.CurrentUser.IsAuthenticated())
{
<li><a href="/login"><i class="fa fa-user"></i> Admin</a></li>
<li><a href="@url/login"><i class="fa fa-user"></i> Admin</a></li>
}
else
{
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-user"></i> Admin <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li><a href="/admin"><i class="fa fa-cog"></i> Settings</a></li>
<li><a href="/changepassword"><i class="fa fa-key"></i> Change password</a></li>
<li><a href="@url/admin"><i class="fa fa-cog"></i> Settings</a></li>
<li><a href="@url/changepassword"><i class="fa fa-key"></i> Change password</a></li>
<li class="divider"></li>
<li><a href="/logout"><i class="fa fa-sign-out"></i> Logout</a></li>
<li><a href="@url/logout"><i class="fa fa-sign-out"></i> Logout</a></li>
</ul>
</li>
}
@if (Context.Request.Session[SessionKeys.UsernameKey] != null)
{
<li><a href="/userlogin/logout"><i class="fa fa-sign-out"></i> Logout</a></li>
<li><a href="@url/userlogin/logout"><i class="fa fa-sign-out"></i> Logout</a></li>
}
</ul>
</div>

Loading…
Cancel
Save