mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Notification schema added to server side.
This commit is contained in:
parent
fea10997ad
commit
482cbc20a3
42
NzbDrone.Api/Notifications/NotificationSchemaModule.cs
Normal file
42
NzbDrone.Api/Notifications/NotificationSchemaModule.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using NzbDrone.Api.ClientSchema;
|
||||
using NzbDrone.Common.Reflection;
|
||||
using NzbDrone.Core.Annotations;
|
||||
using NzbDrone.Core.Notifications;
|
||||
using Omu.ValueInjecter;
|
||||
|
||||
namespace NzbDrone.Api.Notifications
|
||||
{
|
||||
public class NotificationSchemaModule : NzbDroneRestModule<NotificationResource>
|
||||
{
|
||||
private readonly INotificationService _notificationService;
|
||||
|
||||
public NotificationSchemaModule(INotificationService notificationService)
|
||||
: base("notification/schema")
|
||||
{
|
||||
_notificationService = notificationService;
|
||||
|
||||
GetResourceAll = GetAll;
|
||||
}
|
||||
|
||||
private List<NotificationResource> GetAll()
|
||||
{
|
||||
//Need to get all the possible Notification's same as we would for settiings (but keep them empty)
|
||||
|
||||
var notifications = _notificationService.Schema();
|
||||
|
||||
var result = new List<NotificationResource>(notifications.Count);
|
||||
|
||||
foreach (var notification in notifications)
|
||||
{
|
||||
var notificationResource = new NotificationResource();
|
||||
notificationResource.InjectFrom(notification);
|
||||
notificationResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
|
||||
|
||||
result.Add(notificationResource);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -119,6 +119,7 @@
|
||||
<Compile Include="Mapping\ResourceMappingException.cs" />
|
||||
<Compile Include="Mapping\ValueInjectorExtensions.cs" />
|
||||
<Compile Include="Missing\MissingModule.cs" />
|
||||
<Compile Include="Notifications\NotificationSchemaModule.cs" />
|
||||
<Compile Include="Notifications\NotificationModule.cs" />
|
||||
<Compile Include="Notifications\NotificationResource.cs" />
|
||||
<Compile Include="NzbDroneRestModule.cs" />
|
||||
|
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentAssertions;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Composition;
|
||||
using NzbDrone.Core.Lifecycle;
|
||||
using NzbDrone.Core.Notifications;
|
||||
using NzbDrone.Core.Notifications.Growl;
|
||||
using NzbDrone.Core.Notifications.Plex;
|
||||
using NzbDrone.Core.Notifications.Prowl;
|
||||
using NzbDrone.Core.Notifications.Smtp;
|
||||
using NzbDrone.Core.Notifications.Xbmc;
|
||||
using NzbDrone.Core.Test.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Test.NotificationTests
|
||||
{
|
||||
public class NotificationServiceFixture : DbTest<NotificationService, NotificationDefinition>
|
||||
{
|
||||
private List<INotification> _notifications;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_notifications = new List<INotification>();
|
||||
|
||||
_notifications.Add(new Xbmc(null, null));
|
||||
_notifications.Add(new PlexClient(null));
|
||||
_notifications.Add(new PlexServer(null));
|
||||
_notifications.Add(new Smtp(null));
|
||||
_notifications.Add(new Growl(null));
|
||||
_notifications.Add(new Prowl(null));
|
||||
|
||||
Mocker.SetConstant<IEnumerable<INotification>>(_notifications);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void getting_list_of_indexers_should_be_empty_by_default()
|
||||
{
|
||||
Mocker.SetConstant<INotificationRepository>(Mocker.Resolve<NotificationRepository>());
|
||||
|
||||
var notifications = Subject.All().ToList();
|
||||
notifications.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_be_able_to_get_schema_for_all_notifications()
|
||||
{
|
||||
Mocker.SetConstant<INotificationRepository>(Mocker.Resolve<NotificationRepository>());
|
||||
|
||||
Mocker.GetMock<IContainer>().Setup(s => s.Resolve(typeof (Xbmc)))
|
||||
.Returns(new Xbmc(null, null));
|
||||
|
||||
Mocker.GetMock<IContainer>().Setup(s => s.Resolve(typeof(PlexClient)))
|
||||
.Returns(new PlexClient(null));
|
||||
|
||||
Mocker.GetMock<IContainer>().Setup(s => s.Resolve(typeof(PlexServer)))
|
||||
.Returns(new PlexServer(null));
|
||||
|
||||
Mocker.GetMock<IContainer>().Setup(s => s.Resolve(typeof(Smtp)))
|
||||
.Returns(new Smtp(null));
|
||||
|
||||
Mocker.GetMock<IContainer>().Setup(s => s.Resolve(typeof(Growl)))
|
||||
.Returns(new Growl(null));
|
||||
|
||||
Mocker.GetMock<IContainer>().Setup(s => s.Resolve(typeof(Prowl)))
|
||||
.Returns(new Prowl(null));
|
||||
|
||||
var notifications = Subject.Schema().ToList();
|
||||
notifications.Should().NotBeEmpty();
|
||||
notifications.Should().NotContain(c => c.Settings == null);
|
||||
notifications.Should().NotContain(c => c.Instance == null);
|
||||
notifications.Should().NotContain(c => c.Name == null);
|
||||
notifications.Select(c => c.Name).Should().OnlyHaveUniqueItems();
|
||||
notifications.Select(c => c.Instance).Should().OnlyHaveUniqueItems();
|
||||
notifications.Select(c => c.Id).Should().OnlyHaveUniqueItems();
|
||||
}
|
||||
}
|
||||
}
|
@ -146,6 +146,7 @@
|
||||
<Compile Include="MediaFileTests\MediaFileRepositoryFixture.cs" />
|
||||
<Compile Include="MediaFileTests\EpisodeFileMoverFixture.cs" />
|
||||
<Compile Include="MetadataSourceTests\TracktProxyFixture.cs" />
|
||||
<Compile Include="NotificationTests\NotificationServiceFixture.cs" />
|
||||
<Compile Include="Qualities\QualityProfileRepositoryFixture.cs" />
|
||||
<Compile Include="RootFolderTests\FreeSpaceOnDrivesFixture.cs" />
|
||||
<Compile Include="Qualities\QualityFixture.cs" />
|
||||
|
@ -15,6 +15,7 @@ public interface INotificationService
|
||||
{
|
||||
List<Notification> All();
|
||||
Notification Get(int id);
|
||||
List<Notification> Schema();
|
||||
}
|
||||
|
||||
public class NotificationService
|
||||
@ -49,6 +50,32 @@ public Notification Get(int id)
|
||||
return ToNotification(_notificationRepository.Get(id));
|
||||
}
|
||||
|
||||
public List<Notification> Schema()
|
||||
{
|
||||
var notifications = new List<Notification>();
|
||||
|
||||
int i = 1;
|
||||
foreach (var notification in _notifications)
|
||||
{
|
||||
i++;
|
||||
var type = notification.GetType();
|
||||
|
||||
var newNotification = new Notification();
|
||||
newNotification.Instance = (INotification)_container.Resolve(type);
|
||||
newNotification.Id = i;
|
||||
newNotification.Name = notification.Name;
|
||||
|
||||
var instanceType = newNotification.Instance.GetType();
|
||||
var baseGenArgs = instanceType.BaseType.GetGenericArguments();
|
||||
newNotification.Settings = (INotifcationSettings) Activator.CreateInstance(baseGenArgs[0]);
|
||||
newNotification.Implementation = type.Name;
|
||||
|
||||
notifications.Add(newNotification);
|
||||
}
|
||||
|
||||
return notifications;
|
||||
}
|
||||
|
||||
private Notification ToNotification(NotificationDefinition definition)
|
||||
{
|
||||
var notification = new Notification();
|
||||
|
@ -4,7 +4,7 @@ define(['app', 'Series/EpisodeModel'], function () {
|
||||
url : NzbDrone.Constants.ApiRoot + '/calendar',
|
||||
model : NzbDrone.Series.EpisodeModel,
|
||||
comparator: function (model) {
|
||||
return model.get('start');
|
||||
return model.get('airDate');
|
||||
}
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user