This commit is contained in:
tidusjar 2016-06-23 08:50:44 +01:00
commit 2aee84d36d
6 changed files with 178 additions and 164 deletions

View file

@ -24,6 +24,8 @@
// 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;
using System.Linq; using System.Linq;
using NLog; using NLog;
@ -86,8 +88,18 @@ namespace PlexRequests.Services.Jobs
// we do not want to set here... // we do not want to set here...
public int[] QueuedIds() public int[] QueuedIds()
{ {
var movies = Cache.Get<CouchPotatoMovies>(CacheKeys.CouchPotatoQueued); try
return movies?.movies?.Select(x => x.info.tmdb_id).ToArray() ?? new int[] { }; {
var movies = Cache.Get<CouchPotatoMovies>(CacheKeys.CouchPotatoQueued);
var items = movies?.movies?.Select(x => x.info?.tmdb_id).Cast<int>().ToArray();
return items ?? new int[] { };
}
catch (Exception e)
{
Log.Error(e);
return new int[] {};
}
} }
public void Execute(IJobExecutionContext context) public void Execute(IJobExecutionContext context)

View file

@ -120,8 +120,8 @@ namespace PlexRequests.Services.Notification
{ {
var message = new MimeMessage var message = new MimeMessage
{ {
Body = new TextPart("plain") { Text = $"Hello! The user '{model.User}' has requested the {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" }, Body = new TextPart("plain") { Text = $"Hello! The user '{model.User}' has requested the {model.RequestType.GetString()?.ToLower()} '{model.Title}'! Please log in to approve this request. Request Date: {model.DateTime.ToString("f")}" },
Subject = $"Plex Requests: New {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} request for {model.Title}!" Subject = $"Plex Requests: New {model.RequestType.GetString()?.ToLower()} request for {model.Title}!"
}; };
message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender)); message.From.Add(new MailboxAddress(settings.EmailSender, settings.EmailSender));
message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail)); message.To.Add(new MailboxAddress(settings.RecipientEmail, settings.RecipientEmail));

View file

@ -105,8 +105,8 @@ namespace PlexRequests.Services.Notification
private async Task PushNewRequestAsync(NotificationModel model, PushbulletNotificationSettings settings) private async Task PushNewRequestAsync(NotificationModel model, PushbulletNotificationSettings settings)
{ {
var message = $"The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} '{model.Title}' has been requested by user: {model.User}"; var message = $"The {model.RequestType.GetString()?.ToLower()} '{model.Title}' has been requested by user: {model.User}";
var pushTitle = $"Plex Requests: The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} {model.Title} has been requested!"; var pushTitle = $"Plex Requests: The {model.RequestType.GetString()?.ToLower()} {model.Title} has been requested!";
await Push(settings, message, pushTitle); await Push(settings, message, pushTitle);
} }

View file

@ -105,7 +105,7 @@ namespace PlexRequests.Services.Notification
private async Task PushNewRequestAsync(NotificationModel model, PushoverNotificationSettings settings) private async Task PushNewRequestAsync(NotificationModel model, PushoverNotificationSettings settings)
{ {
var message = $"Plex Requests: The {RequestTypeDisplay.Get(model.RequestType)?.ToLower()} '{model.Title}' has been requested by user: {model.User}"; var message = $"Plex Requests: The {model.RequestType.GetString()?.ToLower()} '{model.Title}' has been requested by user: {model.User}";
await Push(settings, message); await Push(settings, message);
} }

View file

@ -80,7 +80,7 @@ namespace PlexRequests.Store
public static class RequestTypeDisplay public static class RequestTypeDisplay
{ {
public static string Get(RequestType type) public static string GetString(this RequestType type)
{ {
switch (type) switch (type)
{ {

View file

@ -1,157 +1,159 @@
@using Nancy.Security @using Nancy.Security
@using Nancy.Session @using Nancy.Session
@using PlexRequests.UI.Helpers @using PlexRequests.UI.Helpers
@using PlexRequests.UI.Models @using PlexRequests.UI.Models
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase @inherits Nancy.ViewEngines.Razor.NancyRazorViewBase
@{ @{
var baseUrl = Html.GetBaseUrl(); var baseUrl = Html.GetBaseUrl();
var url = string.Empty; var url = string.Empty;
if (!string.IsNullOrEmpty(baseUrl.ToHtmlString())) if (!string.IsNullOrEmpty(baseUrl.ToHtmlString()))
{ {
url = "/" + baseUrl.ToHtmlString(); url = "/" + baseUrl.ToHtmlString();
} }
} }
<html> <html>
<div hidden="hidden" id="baseUrl">@baseUrl.ToHtmlString()</div> <div hidden="hidden" id="baseUrl">@baseUrl.ToHtmlString()</div>
<head> <head>
<title>Plex Requests</title> <title>Plex Requests</title>
<!-- Styles --> <!-- Styles -->
<meta name="viewport" content="width=device-width, initial-scale=1"> <meta name="viewport" content="width=device-width, initial-scale=1">
@Html.LoadAnalytics() @Html.LoadAnalytics()
@Html.LoadAssets() @Html.LoadAssets()
</head> </head>
<body> <body>
<nav class="navbar navbar-default"> <nav class="navbar navbar-default">
<div class="container-fluid"> <div class="container-fluid">
<div class="navbar-header"> <div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span> <span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
<span class="icon-bar"></span> <span class="icon-bar"></span>
</button> </button>
<a class="navbar-brand" href="@url/search">Plex Requests</a> <a class="navbar-brand" href="@url/search">Plex Requests</a>
</div> </div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav"> <ul class="nav navbar-nav">
@Html.GetNavbarUrl(Context, "/search", "Search", "search") @Html.GetNavbarUrl(Context, "/search", "Search", "search")
@Html.GetNavbarUrl(Context, "/requests", "Requests", "plus-circle") @Html.GetNavbarUrl(Context, "/requests", "Requests", "plus-circle")
@Html.GetNavbarUrl(Context, "/issues", "Issues", "exclamation", "<span id=\"issueCount\"></span>") @Html.GetNavbarUrl(Context, "/issues", "Issues", "exclamation", "<span id=\"issueCount\"></span>")
@if (Context.CurrentUser.IsAuthenticated()) // TODO replace with IsAdmin
</ul> {
<ul class="nav navbar-nav navbar-right"> <li><a href="https://www.paypal.me/PlexRequestsNet" target="_blank"><i class="fa fa-heart" style="color: red"></i> Donate</a></li>
}
</ul>
@if (!Context.CurrentUser.IsAuthenticated()) // TODO replace with IsAdmin <ul class="nav navbar-nav navbar-right">
{
<li><a href="@url/login?redirect=@Context.Request.Path"><i class="fa fa-user"></i> Admin</a></li> @if (!Context.CurrentUser.IsAuthenticated()) // TODO replace with IsAdmin
} {
else
{ <li><a href="@url/login?redirect=@Context.Request.Path"><i class="fa fa-user"></i> Admin</a></li>
<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> else
<ul class="dropdown-menu" role="menu"> {
<li><a href="@url/admin"><i class="fa fa-cog"></i> Settings</a></li> <li class="dropdown">
<li><a href="@url/changepassword"><i class="fa fa-key"></i> Change password</a></li> <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>
<li class="divider"></li> <ul class="dropdown-menu" role="menu">
<li><a href="https://www.paypal.me/PlexRequestsNet" target="_blank"><i class="fa fa-heart" style="color:red"></i> Donate!</a></li> <li><a href="@url/admin"><i class="fa fa-cog"></i> Settings</a></li>
<li class="divider"></li> <li><a href="@url/changepassword"><i class="fa fa-key"></i> Change password</a></li>
<li><a href="@url/logout"><i class="fa fa-sign-out"></i> Logout</a></li>
</ul> <li class="divider"></li>
</li> <li><a href="@url/logout"><i class="fa fa-sign-out"></i> Logout</a></li>
} </ul>
@if (Context.Request.Session[SessionKeys.UsernameKey] != null) </li>
{ }
<li><a href="@url/userlogin/logout"><i class="fa fa-sign-out"></i> Logout</a></li> @if (Context.Request.Session[SessionKeys.UsernameKey] != null)
} {
</ul> <li><a href="@url/userlogin/logout"><i class="fa fa-sign-out"></i> Logout</a></li>
</div> }
</div> </ul>
<div id="updateAvailable" hidden="hidden"></div> </div>
</nav> </div>
<div id="updateAvailable" hidden="hidden"></div>
<div class="container"> </nav>
@RenderBody()
</div> <div class="container">
<div class="scroll-top-wrapper "> @RenderBody()
<span class="scroll-top-inner"> </div>
<i class="fa fa-2x fa-arrow-circle-up"></i> <div class="scroll-top-wrapper ">
</span> <span class="scroll-top-inner">
</div> <i class="fa fa-2x fa-arrow-circle-up"></i>
</body> </span>
</html> </div>
<script> </body>
</html>
$(function () { <script>
var urlBase = '@Html.GetBaseUrl()'; $(function () {
// Check for update var urlBase = '@Html.GetBaseUrl()';
var url = createBaseUrl(urlBase, '/updatechecker');
$.ajax({ // Check for update
type: "GET", var url = createBaseUrl(urlBase, '/updatechecker');
url: url, $.ajax({
dataType: "json", type: "GET",
success: function (response) { url: url,
if (response.updateAvailable) { dataType: "json",
var status = createBaseUrl(urlBase, '/admin/status'); success: function (response) {
$('#updateAvailable').html("<i class='fa fa-cloud-download' aria-hidden='true'></i> There is a new update available! Click <a style='color: white' href='" + status + "'>Here!</a>"); if (response.updateAvailable) {
$('#updateAvailable').removeAttr("hidden"); var status = createBaseUrl(urlBase, '/admin/status');
$('body').addClass('update-available'); $('#updateAvailable').html("<i class='fa fa-cloud-download' aria-hidden='true'></i> There is a new update available! Click <a style='color: white' href='" + status + "'>Here!</a>");
} $('#updateAvailable').removeAttr("hidden");
}, $('body').addClass('update-available');
error: function (e) { }
console.log(e); },
} error: function (e) {
}); console.log(e);
// End Check for update }
});
// End Check for update
// Scroller
$(document).on('scroll', function () {
// Scroller
if ($(window).scrollTop() > 100) { $(document).on('scroll', function () {
$('.scroll-top-wrapper').addClass('show');
} else { if ($(window).scrollTop() > 100) {
$('.scroll-top-wrapper').removeClass('show'); $('.scroll-top-wrapper').addClass('show');
} } else {
}); $('.scroll-top-wrapper').removeClass('show');
}
$('.scroll-top-wrapper').on('click', scrollToTop); });
// End Scroller
$('.scroll-top-wrapper').on('click', scrollToTop);
// End Scroller
// Get Issue count
var issueUrl = createBaseUrl(urlBase, '/issues/issuecount');
$.ajax({ // Get Issue count
type: "GET", var issueUrl = createBaseUrl(urlBase, '/issues/issuecount');
url: issueUrl, $.ajax({
dataType: "json", type: "GET",
success: function (response) { url: issueUrl,
if (response) { dataType: "json",
if(response > 0) success: function (response) {
$('#issueCount').addClass("badge"); if (response) {
$('#issueCount').html(+response); if (response > 0)
} $('#issueCount').addClass("badge");
}, $('#issueCount').html(+response);
error: function (e) { }
console.log(e); },
} error: function (e) {
}); console.log(e);
// End issue count }
});
// End issue count
});
function scrollToTop() { });
verticalOffset = typeof (verticalOffset) != 'undefined' ? verticalOffset : 0;
element = $('body'); function scrollToTop() {
offset = element.offset(); verticalOffset = typeof (verticalOffset) != 'undefined' ? verticalOffset : 0;
offsetTop = offset.top; element = $('body');
$('html, body').animate({ scrollTop: offsetTop }, 500, 'linear'); offset = element.offset();
} offsetTop = offset.top;
$('html, body').animate({ scrollTop: offsetTop }, 500, 'linear');
}
</script> </script>