#96 Finished adding test functionality to notifications

pull/110/head
Drewster727 9 years ago
parent 9742b42fdf
commit 3d41445f6f

@ -145,9 +145,11 @@ namespace PlexRequests.UI.Modules
Get["/pushbulletnotification"] = _ => PushbulletNotifications();
Post["/pushbulletnotification"] = _ => SavePushbulletNotifications();
Post["/testpushbulletnotification"] = _ => TestPushbulletNotifications();
Get["/pushovernotification"] = _ => PushoverNotifications();
Post["/pushovernotification"] = _ => SavePushoverNotifications();
Post["/testpushovernotification"] = _ => TestPushoverNotifications();
Get["/logs"] = _ => Logs();
Get["/loglevel"] = _ => GetLogLevels();
@ -377,6 +379,11 @@ namespace PlexRequests.UI.Modules
private Response TestEmailNotifications()
{
var settings = this.Bind<EmailNotificationSettings>();
var valid = this.Validate(settings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
var notificationModel = new NotificationModel
{
NotificationType = NotificationType.Test,
@ -455,6 +462,24 @@ namespace PlexRequests.UI.Modules
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}
private Response TestPushbulletNotifications()
{
var settings = this.Bind<PushbulletNotificationSettings>();
var valid = this.Validate(settings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
var notificationModel = new NotificationModel
{
NotificationType = NotificationType.Test,
DateTime = DateTime.Now
};
NotificationService.Publish(notificationModel, settings);
Log.Info("Sent pushbullet notification test");
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Pushbullet Notification!" });
}
private Negotiator PushoverNotifications()
{
var settings = PushoverService.GetSettings();
@ -487,6 +512,24 @@ namespace PlexRequests.UI.Modules
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
}
private Response TestPushoverNotifications()
{
var settings = this.Bind<PushoverNotificationSettings>();
var valid = this.Validate(settings);
if (!valid.IsValid)
{
return Response.AsJson(valid.SendJsonError());
}
var notificationModel = new NotificationModel
{
NotificationType = NotificationType.Test,
DateTime = DateTime.Now
};
NotificationService.Publish(notificationModel, settings);
Log.Info("Sent pushover notification test");
return Response.AsJson(new JsonResponseModel { Result = true, Message = "Successfully sent a test Pushover Notification!" });
}
private Response GetCpProfiles()
{
var settings = this.Bind<CouchPotatoSettings>();

@ -36,6 +36,12 @@
</div>
</div>
<div class="form-group">
<div>
<button id="testPushbullet" type="submit" class="btn btn-primary-outline">Test</button>
</div>
</div>
<div class="form-group">
<div>
<button id="save" type="submit" class="btn btn-primary-outline">Submit</button>
@ -70,5 +76,28 @@
}
});
});
$('#testPushbullet').click(function (e) {
e.preventDefault();
var $form = $("#mainForm");
$.ajax({
type: $form.prop("method"),
data: $form.serialize(),
url: '/admin/testpushbulletnotification',
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>

@ -36,6 +36,12 @@
</div>
</div>
<div class="form-group">
<div>
<button id="testPushover" type="submit" class="btn btn-primary-outline">Test</button>
</div>
</div>
<div class="form-group">
<div>
<button id="save" type="submit" class="btn btn-primary-outline">Submit</button>
@ -70,5 +76,28 @@
}
});
});
$('#testPushover').click(function (e) {
e.preventDefault();
var $form = $("#mainForm");
$.ajax({
type: $form.prop("method"),
data: $form.serialize(),
url: '/admin/testpushovernotification',
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>
Loading…
Cancel
Save