This commit is contained in:
Jamie.Rees 2016-10-20 12:06:46 +01:00
commit 171c64fe8e
11 changed files with 187 additions and 28 deletions

View file

@ -80,6 +80,7 @@ namespace PlexRequests.UI.Modules
private ISettingsService<PushbulletNotificationSettings> PushbulletService { get; }
private ISettingsService<PushoverNotificationSettings> PushoverService { get; }
private ISettingsService<HeadphonesSettings> HeadphonesService { get; }
private ISettingsService<NewletterSettings> NewsLetterService { get; }
private ISettingsService<LogSettings> LogService { get; }
private IPlexApi PlexApi { get; }
private ISonarrApi SonarrApi { get; }
@ -112,6 +113,7 @@ namespace PlexRequests.UI.Modules
PushbulletApi pbApi,
ICouchPotatoApi cpApi,
ISettingsService<PushoverNotificationSettings> pushoverSettings,
ISettingsService<NewletterSettings> newsletter,
IPushoverApi pushoverApi,
IRepository<LogEntity> logsRepo,
INotificationService notify,
@ -139,6 +141,7 @@ namespace PlexRequests.UI.Modules
PushoverApi = pushoverApi;
NotificationService = notify;
HeadphonesService = headphones;
NewsLetterService = newsletter;
LogService = logs;
Cache = cache;
SlackSettings = slackSettings;
@ -200,6 +203,9 @@ namespace PlexRequests.UI.Modules
Get["/headphones"] = _ => Headphones();
Post["/headphones"] = _ => SaveHeadphones();
Get["/newsletter"] = _ => Newsletter();
Post["/newsletter"] = _ => SaveNewsletter();
Post["/createapikey"] = x => CreateApiKey();
Post["/autoupdate"] = x => AutoUpdate();
@ -814,6 +820,33 @@ namespace PlexRequests.UI.Modules
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}
private Negotiator Newsletter()
{
var settings = NewsLetterService.GetSettings();
return View["NewsletterSettings", settings];
}
private Response SaveNewsletter()
{
var settings = this.Bind<NewletterSettings>();
var valid = this.Validate(settings);
if (!valid.IsValid)
{
var error = valid.SendJsonError();
Log.Info("Error validating Headphones settings, message: {0}", error.Message);
return Response.AsJson(error);
}
settings.SendRecentlyAddedEmail = settings.SendRecentlyAddedEmail;
var result = NewsLetterService.SaveSettings(settings);
Log.Info("Saved headphones settings, result: {0}", result);
return Response.AsJson(result
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Newsletter!" }
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}
private Response CreateApiKey()
{
this.RequiresClaims(UserClaims.Admin);

View file

@ -719,6 +719,7 @@
<Content Include="Views\Admin\NotificationSettings.cshtml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<None Include="Views\Admin\NewsletterSettings.cshtml" />
<None Include="Web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>

View file

@ -0,0 +1,76 @@
@using System.Linq
@using PlexRequests.Core.Models
@using PlexRequests.UI.Helpers
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<PlexRequests.Core.SettingModels.NewletterSettings>
@Html.Partial("_Sidebar")
<div class="col-sm-8 col-sm-push-1">
<form class="form-horizontal" method="POST" id="mainForm">
<fieldset>
<legend>Newsletter Settings</legend>
<!-- Email Nofication Section -->
<div class="form-group">
<div class="checkbox">
<small>Note: This will require you to setup your email notifications</small>
@if (Model.SendRecentlyAddedEmail)
{
<input type="checkbox" id="SendRecentlyAddedEmail" name="SendRecentlyAddedEmail" checked="checked"><label for="SendRecentlyAddedEmail">Send out a weekly email of recently added content to all your Plex 'Friends'</label>
}
else
{
<input type="checkbox" id="SendRecentlyAddedEmail" name="SendRecentlyAddedEmail"><label for="SendRecentlyAddedEmail">Send out a weekly email of recently added content to all your Plex 'Friends'</label>
}
</div>
<button id="recentlyAddedBtn" class="btn btn-primary-outline">Send test email to Admin</button>
</div>
<br/>
<br />
<div class="form-group">
<div>
<button type="submit" id="save" class="btn btn-primary-outline">Submit</button>
</div>
</div>
<!-- Email Nofication Section -->
</fieldset>
</form>
</div>
<script>
$(function () {
var base = '@Html.GetBaseUrl()';
$('#save').click(function (e) {
e.preventDefault();
var $form = $("#mainForm");
var data = $form.serialize();
$.ajax({
type: $form.prop("method"),
data: data,
url: $form.prop("action"),
dataType: "json",
success: function (response) {
if (response.result === true) {
generateNotify(response.message, "success");
} else {
generateNotify(response.message, "warning");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
});
</script>

View file

@ -74,27 +74,6 @@
</select>
</div>
</div>
<br/>
<br/>
<div class="form-group">
<div class="checkbox">
<small>Note: This will require you to setup your email notifications</small>
@if (Model.SendRecentlyAddedEmail)
{
<input type="checkbox" id="SendRecentlyAddedEmail" name="SendRecentlyAddedEmail" checked="checked"><label for="SendRecentlyAddedEmail">Send out a weekly email of recently added content to all your Plex 'Friends'</label>
}
else
{
<input type="checkbox" id="SendRecentlyAddedEmail" name="SendRecentlyAddedEmail"><label for="SendRecentlyAddedEmail">Send out a weekly email of recently added content to all your Plex 'Friends'</label>
}
</div>
</div>
<button id="recentlyAddedBtn" class="btn btn-primary-outline">Send test email to Admin</button>
<br/>
<br/>
<div class="form-group">
<div class="checkbox">

View file

@ -10,6 +10,7 @@
@Html.GetSidebarUrl(Context, "/admin/sonarr", "Sonarr")
@Html.GetSidebarUrl(Context, "/admin/sickrage", "SickRage")
@Html.GetSidebarUrl(Context, "/admin/headphones", "Headphones (Beta)")
@Html.GetSidebarUrl(Context, "/admin/newsletter", "Newsletter Settings")
@Html.GetSidebarUrl(Context, "/admin/emailnotification", "Email Notifications")
@Html.GetSidebarUrl(Context, "/admin/pushbulletnotification", "Pushbullet Notifications")
@Html.GetSidebarUrl(Context, "/admin/pushovernotification", "Pushover Notifications")