mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-15 01:32:55 -07:00
Added Pushbullet notifications #8
This commit is contained in:
parent
b9a886d5dc
commit
f046c5d39b
20 changed files with 534 additions and 61 deletions
|
@ -73,6 +73,7 @@ namespace PlexRequests.UI
|
|||
container.Register<ISettingsService<PlexSettings>, SettingsServiceV2<PlexSettings>>();
|
||||
container.Register<ISettingsService<SonarrSettings>, SettingsServiceV2<SonarrSettings>>();
|
||||
container.Register<ISettingsService<EmailNotificationSettings>, SettingsServiceV2<EmailNotificationSettings>>();
|
||||
container.Register<ISettingsService<PushbulletNotificationSettings>, SettingsServiceV2<PushbulletNotificationSettings>>();
|
||||
container.Register<IRepository<RequestedModel>, GenericRepository<RequestedModel>>();
|
||||
container.Register<IRequestService, RequestService>();
|
||||
|
||||
|
@ -81,6 +82,7 @@ namespace PlexRequests.UI
|
|||
container.Register<IIntervals, UpdateInterval>();
|
||||
|
||||
container.Register<ICouchPotatoApi, CouchPotatoApi>();
|
||||
container.Register<IPushbulletApi, PushbulletApi>();
|
||||
|
||||
container.Register<ISonarrApi, SonarrApi>();
|
||||
//container.Register<ISonarrApi, MockSonarrApi>();
|
||||
|
@ -125,6 +127,13 @@ namespace PlexRequests.UI
|
|||
{
|
||||
NotificationService.Subscribe(new EmailMessageNotification(emailSettingsService));
|
||||
}
|
||||
|
||||
var pushbulletService = container.Resolve<ISettingsService<PushbulletNotificationSettings>>();
|
||||
var pushbulletSettings = pushbulletService.GetSettings();
|
||||
if (pushbulletSettings.Enabled)
|
||||
{
|
||||
NotificationService.Subscribe(new PushbulletNotification(container.Resolve<IPushbulletApi>(), container.Resolve<ISettingsService<PushbulletNotificationSettings>>()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,6 +36,7 @@ using Nancy.Validation;
|
|||
|
||||
using NLog;
|
||||
|
||||
using PlexRequests.Api;
|
||||
using PlexRequests.Api.Interfaces;
|
||||
using PlexRequests.Core;
|
||||
using PlexRequests.Core.SettingModels;
|
||||
|
@ -54,8 +55,10 @@ namespace PlexRequests.UI.Modules
|
|||
private ISettingsService<PlexSettings> PlexService { get; }
|
||||
private ISettingsService<SonarrSettings> SonarrService { get; }
|
||||
private ISettingsService<EmailNotificationSettings> EmailService { get; }
|
||||
private ISettingsService<PushbulletNotificationSettings> PushbulletService { get; }
|
||||
private IPlexApi PlexApi { get; }
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
private PushbulletApi PushbulletApi { get; }
|
||||
|
||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||
public AdminModule(ISettingsService<PlexRequestSettings> rpService,
|
||||
|
@ -65,7 +68,9 @@ namespace PlexRequests.UI.Modules
|
|||
ISettingsService<SonarrSettings> sonarr,
|
||||
ISonarrApi sonarrApi,
|
||||
ISettingsService<EmailNotificationSettings> email,
|
||||
IPlexApi plexApi) : base("admin")
|
||||
IPlexApi plexApi,
|
||||
ISettingsService<PushbulletNotificationSettings> pbSettings,
|
||||
PushbulletApi pbApi) : base("admin")
|
||||
{
|
||||
RpService = rpService;
|
||||
CpService = cpService;
|
||||
|
@ -75,6 +80,8 @@ namespace PlexRequests.UI.Modules
|
|||
SonarrApi = sonarrApi;
|
||||
EmailService = email;
|
||||
PlexApi = plexApi;
|
||||
PushbulletService = pbSettings;
|
||||
PushbulletApi = pbApi;
|
||||
|
||||
#if !DEBUG
|
||||
this.RequiresAuthentication();
|
||||
|
@ -104,6 +111,9 @@ namespace PlexRequests.UI.Modules
|
|||
Get["/emailnotification"] = _ => EmailNotifications();
|
||||
Post["/emailnotification"] = _ => SaveEmailNotifications();
|
||||
Get["/status"] = _ => Status();
|
||||
|
||||
Get["/pushbulletnotification"] = _ => PushbulletNotifications();
|
||||
Post["/pushbulletnotification"] = _ => SavePushbulletNotifications();
|
||||
}
|
||||
|
||||
private Negotiator Authentication()
|
||||
|
@ -318,5 +328,31 @@ namespace PlexRequests.UI.Modules
|
|||
var status = checker.GetStatus();
|
||||
return View["Status", status];
|
||||
}
|
||||
|
||||
private Negotiator PushbulletNotifications()
|
||||
{
|
||||
var settings = PushbulletService.GetSettings();
|
||||
return View["PushbulletNotifications", settings];
|
||||
}
|
||||
|
||||
private Response SavePushbulletNotifications()
|
||||
{
|
||||
var settings = this.Bind<PushbulletNotificationSettings>();
|
||||
var valid = this.Validate(settings);
|
||||
if (!valid.IsValid)
|
||||
{
|
||||
return Response.AsJson(valid.SendJsonError());
|
||||
}
|
||||
Log.Trace(settings.DumpJson());
|
||||
|
||||
var result = PushbulletService.SaveSettings(settings);
|
||||
|
||||
NotificationService.Subscribe(new PushbulletNotification(PushbulletApi, PushbulletService));
|
||||
|
||||
Log.Info("Saved email settings, result: {0}", result);
|
||||
return Response.AsJson(result
|
||||
? new JsonResponseModel { Result = true, Message = "Successfully Updated the Settings for Pushbullet Notifications!" }
|
||||
: new JsonResponseModel { Result = false, Message = "Could not update the settings, take a look at the logs." });
|
||||
}
|
||||
}
|
||||
}
|
|
@ -161,6 +161,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="Bootstrapper.cs" />
|
||||
<Compile Include="Helpers\ValidationHelper.cs" />
|
||||
<Compile Include="Validators\PushbulletSettingsValidator.cs" />
|
||||
<Compile Include="Validators\EmailNotificationSettingsValidator.cs" />
|
||||
<Compile Include="Validators\CouchPotatoValidator.cs" />
|
||||
<Compile Include="Validators\PlexValidator.cs" />
|
||||
|
@ -316,6 +317,9 @@
|
|||
<Content Include="Views\Admin\Status.cshtml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="Views\Admin\PushbulletNotifications.cshtml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<None Include="Web.Debug.config">
|
||||
<DependentUpon>web.config</DependentUpon>
|
||||
</None>
|
||||
|
|
40
PlexRequests.UI/Validators/PushbulletSettingsValidator.cs
Normal file
40
PlexRequests.UI/Validators/PushbulletSettingsValidator.cs
Normal file
|
@ -0,0 +1,40 @@
|
|||
#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 PushbulletSettingsValidator : AbstractValidator<PushbulletNotificationSettings>
|
||||
{
|
||||
public PushbulletSettingsValidator()
|
||||
{
|
||||
RuleFor(request => request.AccessToken).NotEmpty().WithMessage("You must specify a Access Token.");
|
||||
}
|
||||
}
|
||||
}
|
74
PlexRequests.UI/Views/Admin/PushbulletNotifications.cshtml
Normal file
74
PlexRequests.UI/Views/Admin/PushbulletNotifications.cshtml
Normal file
|
@ -0,0 +1,74 @@
|
|||
@Html.Partial("_Sidebar")
|
||||
|
||||
<div class="col-sm-8 col-sm-push-1">
|
||||
<form class="form-horizontal" method="POST" id="mainForm">
|
||||
<fieldset>
|
||||
<legend>Pushbullet Notifications</legend>
|
||||
|
||||
<div class="form-group">
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
@if (Model.Enabled)
|
||||
{
|
||||
<input type="checkbox" id="Enabled" name="Enabled" checked="checked"><text>Enabled</text>
|
||||
}
|
||||
else
|
||||
{
|
||||
<input type="checkbox" id="Enabled" name="Enabled"><text>Enabled</text>
|
||||
}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="AccessToken" class="control-label">Access Token</label>
|
||||
<small class="control-label">You can get this by navigating to <a href="https://www.pushbullet.com/#settings">Pushbullet</a></small>
|
||||
<div class="">
|
||||
<input type="text" class="form-control form-control-custom " id="AccessToken" name="AccessToken" value="@Model.AccessToken">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="DeviceIdentifier" class="control-label">Device Identifier</label>
|
||||
<small class="control-label">This is optional, if left blank we will send a Push notification to all devices.</small>
|
||||
<div class="">
|
||||
<input type="text" class="form-control form-control-custom " id="DeviceIdentifier" name="DeviceIdentifier" value="@Model.DeviceIdentifier">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<div>
|
||||
<button id="save" type="submit" class="btn btn-primary-outline">Submit</button>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
$(function () {
|
||||
|
||||
$('#save').click(function (e) {
|
||||
e.preventDefault();
|
||||
|
||||
var $form = $("#mainForm");
|
||||
$.ajax({
|
||||
type: $form.prop("method"),
|
||||
data: $form.serialize(),
|
||||
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>
|
Loading…
Add table
Add a link
Reference in a new issue