Merge pull request #579 from tidusjar/dev

Dev to master
pull/580/head
Jamie 8 years ago committed by GitHub
commit 4a29a0a89d

@ -60,6 +60,9 @@ namespace PlexRequests.Core.SettingModels
public bool DisableTvRequestsBySeason { get; set; }
public bool SendRecentlyAddedEmail { get; set; }
public string CustomDonationUrl { get; set; }
public bool EnableCustomDonationUrl { get; set; }
public string CustomDonationMessage { get; set; }
/// <summary>
/// The CSS name of the theme we want
/// </summary>

@ -48,13 +48,14 @@ namespace PlexRequests.Services.Jobs
public class RecentlyAdded : IJob, IRecentlyAdded
{
public RecentlyAdded(IPlexApi api, ISettingsService<PlexSettings> plexSettings, ISettingsService<EmailNotificationSettings> email,
ISettingsService<ScheduledJobsSettings> scheduledService, IJobRecord rec)
ISettingsService<ScheduledJobsSettings> scheduledService, IJobRecord rec, ISettingsService<PlexRequestSettings> plexRequest)
{
JobRecord = rec;
Api = api;
PlexSettings = plexSettings;
EmailSettings = email;
ScheduledJobsSettings = scheduledService;
PlexRequestSettings = plexRequest;
}
private IPlexApi Api { get; }
@ -62,6 +63,7 @@ namespace PlexRequests.Services.Jobs
private readonly TheMovieDbApi _movieApi = new TheMovieDbApi();
private ISettingsService<PlexSettings> PlexSettings { get; }
private ISettingsService<EmailNotificationSettings> EmailSettings { get; }
private ISettingsService<PlexRequestSettings> PlexRequestSettings { get; }
private ISettingsService<ScheduledJobsSettings> ScheduledJobsSettings { get; }
private IJobRecord JobRecord { get; }
@ -71,14 +73,19 @@ namespace PlexRequests.Services.Jobs
{
try
{
var settings = PlexRequestSettings.GetSettings();
if (!settings.SendRecentlyAddedEmail)
{
return;
}
var jobs = JobRecord.GetJobs();
var thisJob =
jobs.FirstOrDefault(
x => x.Name.Equals(JobNames.RecentlyAddedEmail, StringComparison.CurrentCultureIgnoreCase));
var settings = ScheduledJobsSettings.GetSettings();
var jobSettings = ScheduledJobsSettings.GetSettings();
if (thisJob?.LastRun > DateTime.Now.AddHours(-settings.RecentlyAdded))
if (thisJob?.LastRun > DateTime.Now.AddHours(-jobSettings.RecentlyAdded))
{
return;
}
@ -147,14 +154,19 @@ namespace PlexRequests.Services.Jobs
sb.AppendFormat("<a href=\"https://www.imdb.com/title/{0}/\"><h3 style=\"font-family: sans-serif; font-weight: normal; margin: 0; Margin-bottom: 15px;\">{1} {2}</p></a>",
info.ImdbId, info.Title, info.ReleaseDate?.ToString("yyyy") ?? string.Empty);
sb.AppendFormat("<p style=\"font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;\">Genre: {0}</p>", string.Join(", ", info.Genres.Select(x => x.Name.ToString()).ToArray()));
if (info.Genres.Any())
{
sb.AppendFormat(
"<p style=\"font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;\">Genre: {0}</p>",
string.Join(", ", info.Genres.Select(x => x.Name.ToString()).ToArray()));
}
sb.AppendFormat("<p style=\"font-family: sans-serif; font-size: 14px; font-weight: normal; margin: 0; Margin-bottom: 15px;\">{0}</p>", info.Overview);
sb.Append("<td");
sb.Append("</tr>");
sb.Append("<hr>");
sb.Append("<br>");
sb.Append("<br>");
sb.Append("</tr>");
}
sb.Append("</table><br/><br/>");
@ -192,10 +204,10 @@ namespace PlexRequests.Services.Jobs
string.IsNullOrEmpty(parentMetaData.Directory.Summary) ? info.summary : parentMetaData.Directory.Summary); // Episode Summary
sb.Append("<td");
sb.Append("</tr>");
sb.Append("<hr>");
sb.Append("<br>");
sb.Append("<br>");
sb.Append("</tr>");
}
sb.Append("</table><br/><br/>");
}

@ -64,9 +64,12 @@ namespace PlexRequests.UI.Modules
var redirectPath = string.IsNullOrEmpty(baseUrl) ? "~/userlogin" : $"~/{baseUrl}/userlogin";
return Session[SessionKeys.UsernameKey] == null
? Context.GetRedirect(redirectPath)
: null;
if (Session[SessionKeys.UsernameKey] == null && Context?.CurrentUser == null)
{
return Context.GetRedirect(redirectPath);
}
return null;
}
}
}

@ -0,0 +1,52 @@
using System;
using System.Threading.Tasks;
using Nancy;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using PlexRequests.Core;
using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers;
using PlexRequests.UI.Models;
namespace PlexRequests.UI.Modules
{
public class DonationLinkModule : BaseAuthModule
{
public DonationLinkModule(ICacheProvider provider, ISettingsService<PlexRequestSettings> pr) : base("customDonation", pr)
{
Cache = provider;
Get["/", true] = async (x, ct) => await GetCustomDonationUrl(pr);
}
private ICacheProvider Cache { get; }
private static Logger Log = LogManager.GetCurrentClassLogger();
private async Task<Response> GetCustomDonationUrl(ISettingsService<PlexRequestSettings> pr)
{
PlexRequestSettings settings = await pr.GetSettingsAsync();
try
{
if (settings.EnableCustomDonationUrl)
{
return Response.AsJson(new { url = settings.CustomDonationUrl, message = settings.CustomDonationMessage });
}
else
{
return Response.AsJson(new { url = settings.CustomDonationUrl, message = settings.CustomDonationMessage });
}
}
catch (Exception e)
{
Log.Warn("Exception Thrown when attempting to check the custom donation url");
Log.Warn(e);
return Response.AsJson(new { url = settings.CustomDonationUrl, message = settings.CustomDonationMessage });
}
}
}
}

@ -65,8 +65,8 @@ namespace PlexRequests.UI.Modules
{
if (!string.IsNullOrEmpty(Username) || IsAdmin)
{
var uri = Linker.BuildRelativeUri(Context, "SearchIndex");
return Response.AsRedirect(uri.ToString());
var url = Linker.BuildRelativeUri(Context, "SearchIndex").ToString();
return Response.AsRedirect(url);
}
var settings = await AuthService.GetSettingsAsync();
return View["Index", settings];

@ -248,6 +248,7 @@
<Compile Include="Modules\BaseModule.cs" />
<Compile Include="Modules\BetaModule.cs" />
<Compile Include="Modules\CultureModule.cs" />
<Compile Include="Modules\DonationLinkModule.cs" />
<Compile Include="Modules\IssuesModule.cs" />
<Compile Include="Modules\LandingPageModule.cs" />
<Compile Include="Modules\RequestsBetaModule.cs" />

@ -443,4 +443,7 @@
<data name="Search_ViewInPlex" xml:space="preserve">
<value>View In Plex</value>
</data>
<data name="Custom_Donation_Default" xml:space="preserve">
<value>Donate to Library Maintainer</value>
</data>
</root>

@ -114,6 +114,15 @@ namespace PlexRequests.UI.Resources {
}
}
/// <summary>
/// Looks up a localized string similar to Donate to Library Maintainer.
/// </summary>
public static string Custom_Donation_Default {
get {
return ResourceManager.GetString("Custom_Donation_Default", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Issue.
/// </summary>

@ -273,10 +273,38 @@
}
</div>
</div>
<div class="form-group">
<div class="checkbox">
@if (Model.EnableCustomDonationUrl)
{
<input type="checkbox" id="EnableCustomDonationUrl" name="EnableCustomDonationUrl" checked="checked">
<label for="EnableCustomDonationUrl">Enable custom donation link</label>
}
else
{
<input type="checkbox" id="EnableCustomDonationUrl" name="EnableCustomDonationUrl"><label for="EnableCustomDonationUrl">Enable custom donation link</label>
}
</div>
</div>
<div class="form-group">
<label for="CustomDonationUrl" class="control-label">Custom Donation URL</label>
<div>
<input type="text" class="form-control-custom form-control " id="CustomDonationUrl" name="CustomDonationUrl" placeholder="http://example.com" value="@Model.CustomDonationUrl">
</div>
</div>
<div class="form-group">
<label for="CustomDonationMessage" class="control-label">Donation Button Message</label>
<div>
<input type="text" class="form-control-custom form-control " id="CustomDonationMessage" name="CustomDonationMessage" placeholder="Donation button message" value="@Model.CustomDonationMessage">
</div>
</div>
<p class="form-group">A comma separated list of users whose requests do not require approval (These users also do not have a request limit).</p>
<p class="form-group">A comma separated list of users whose requests do not require approval (These users also do not have a request limit).</p>
<div class="form-group">
<label for="NoApprovalUsers" class="control-label">Approval White listed Users</label>
<div>

@ -1,6 +1,7 @@
@using Nancy.Security
@using Nancy.Session
@using Nancy;
@using PlexRequests.Core.SettingModels
@using PlexRequests.UI.Helpers
@using PlexRequests.UI.Models
@using PlexRequests.UI.Resources
@ -38,10 +39,11 @@
{
<li><a id="donate" href="https://www.paypal.me/PlexRequestsNet" target="_blank"><i class="fa fa-heart" style="color: red"></i> @UI.Layout_Donate</a></li>
}
<li id="customDonate" style="display: none"><a id="customDonateHref" href="https://www.paypal.me/PlexRequestsNet" target="_blank"><i class="fa fa-heart" style="color: yellow;"></i> <span id="donationText">@UI.Custom_Donation_Default</span></a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
@if (!Context.CurrentUser.IsAuthenticated() && Context.Request.Session[SessionKeys.UsernameKey] == null) // TODO replace with IsAdmin
{
@ -91,5 +93,28 @@
</ul>
</div>
</div>
<script>
var base = '@Html.GetBaseUrl()';
var url = createBaseUrl(base, '/customDonation');
$.ajax({
url: url,
success: function (result) {
console.log("we win + " + result.url);
if (result.url && result.url != "donationLinkError") {
$("#customDonate").show();
var donateLink = $("#customDonateHref");
var donationText = $("#donationText");
donateLink.attr("href", result.url);
if(result.message) {
donationText.text(result.message);
}
}
},
error: function(xhr, status, error) {
console.log("error " + error);
$("#customDonate").hide();
}
});
</script>
<div id="updateAvailable" hidden="hidden"></div>
</nav>
Loading…
Cancel
Save