1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-09-19 07:52:33 +02:00

Cleaned up per comments

This commit is contained in:
Mark McDowall 2013-05-28 23:24:45 -07:00
parent 4d101cc6dc
commit af6e3ddb66
13 changed files with 41 additions and 36 deletions

View File

@ -7,7 +7,7 @@ namespace NzbDrone.Api.ClientSchema
{ {
public static class SchemaDeserializer public static class SchemaDeserializer
{ {
public static object DeserializeSchema(object model, List<Field> fields) public static T DeserializeSchema<T>(T model, List<Field> fields)
{ {
var properties = model.GetType().GetSimpleProperties(); var properties = model.GetType().GetSimpleProperties();

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Api.ClientSchema; using NzbDrone.Api.ClientSchema;
using NzbDrone.Api.REST;
using NzbDrone.Core.Indexers; using NzbDrone.Core.Indexers;
using Omu.ValueInjecter; using Omu.ValueInjecter;
@ -43,20 +44,22 @@ private IndexerResource Create(IndexerResource indexerResource)
i.Implementation.Equals(indexerResource.Implementation, i.Implementation.Equals(indexerResource.Implementation,
StringComparison.InvariantCultureIgnoreCase)); StringComparison.InvariantCultureIgnoreCase));
//TODO: How should be handle this error?
if (indexer == null) if (indexer == null)
{ {
throw new InvalidOperationException(); throw new BadRequestException("Invalid Notification Implementation");
} }
indexer.Name = indexerResource.Name; indexer.Name = indexerResource.Name;
indexer.Enable = indexerResource.Enable; indexer.Enable = indexerResource.Enable;
indexer.Settings = (IIndexerSetting)SchemaDeserializer.DeserializeSchema(indexer.Settings, indexerResource.Fields); indexer.Settings = SchemaDeserializer.DeserializeSchema(indexer.Settings, indexerResource.Fields);
indexer = _indexerService.Create(indexer); indexer = _indexerService.Create(indexer);
indexerResource.Id = indexer.Id;
return indexerResource; var responseResource = new IndexerResource();
responseResource.InjectFrom(indexer);
responseResource.Fields = SchemaBuilder.GenerateSchema(indexer.Settings);
return responseResource;
} }
} }
} }

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using NzbDrone.Api.ClientSchema; using NzbDrone.Api.ClientSchema;
using NzbDrone.Api.REST;
using NzbDrone.Core.Notifications; using NzbDrone.Core.Notifications;
using Omu.ValueInjecter; using Omu.ValueInjecter;
@ -46,16 +47,24 @@ private NotificationResource Create(NotificationResource notificationResource)
notification = _notificationService.Create(notification); notification = _notificationService.Create(notification);
notificationResource.Id = notification.Id; notificationResource.Id = notification.Id;
return notificationResource; var responseResource = new NotificationResource();
responseResource.InjectFrom(notification);
responseResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
return responseResource;
} }
private NotificationResource Update(NotificationResource notificationResource) private NotificationResource Update(NotificationResource notificationResource)
{ {
var notification = GetNotification(notificationResource); var notification = GetNotification(notificationResource);
notification.Id = notificationResource.Id; notification.Id = notificationResource.Id;
_notificationService.Update(notification); notification = _notificationService.Update(notification);
return notificationResource; var responseResource = new NotificationResource();
responseResource.InjectFrom(notification);
responseResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
return responseResource;
} }
private void DeleteNotification(int id) private void DeleteNotification(int id)
@ -70,16 +79,13 @@ private Notification GetNotification(NotificationResource notificationResource)
i.Implementation.Equals(notificationResource.Implementation, i.Implementation.Equals(notificationResource.Implementation,
StringComparison.InvariantCultureIgnoreCase)); StringComparison.InvariantCultureIgnoreCase));
//TODO: How should be handle this error?
if (notification == null) if (notification == null)
{ {
throw new InvalidOperationException(); throw new BadRequestException("Invalid Notification Implementation");
} }
notification.Name = notificationResource.Name; notification.InjectFrom(notificationResource);
notification.OnGrab = notificationResource.OnGrab; notification.Settings = SchemaDeserializer.DeserializeSchema(notification.Settings, notificationResource.Fields);
notificationResource.OnDownload = notificationResource.OnDownload;
notification.Settings = (INotifcationSettings)SchemaDeserializer.DeserializeSchema(notification.Settings, notificationResource.Fields);
return notification; return notification;
} }

View File

@ -54,7 +54,8 @@ protected Action<int> DeleteResource
{ {
ValidateId(options.Id); ValidateId(options.Id);
DeleteResource((int)options.Id); DeleteResource((int)options.Id);
return new Response { StatusCode = HttpStatusCode.OK };
return new object().AsResponse();
}; };
} }
} }

View File

@ -9,6 +9,7 @@
using NzbDrone.Common.Serializer; using NzbDrone.Common.Serializer;
using NzbDrone.Core.Download; using NzbDrone.Core.Download;
using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.MediaFiles.Events;
using Omu.ValueInjecter;
namespace NzbDrone.Core.Notifications namespace NzbDrone.Core.Notifications
{ {
@ -82,14 +83,9 @@ public List<Notification> Schema()
public Notification Create(Notification notification) public Notification Create(Notification notification)
{ {
var definition = new NotificationDefinition() var definition = new NotificationDefinition();
{ definition.InjectFrom(notification);
Name = notification.Name, definition.Settings = Json.Serialize(notification.Settings);
OnGrab = notification.OnGrab,
OnDownload = notification.OnDownload,
Implementation = notification.Implementation,
Settings = Json.Serialize(notification.Settings)
};
definition = _notificationRepository.Insert(definition); definition = _notificationRepository.Insert(definition);
notification.Id = definition.Id; notification.Id = definition.Id;
@ -100,11 +96,7 @@ public Notification Create(Notification notification)
public Notification Update(Notification notification) public Notification Update(Notification notification)
{ {
var definition = _notificationRepository.Get(notification.Id); var definition = _notificationRepository.Get(notification.Id);
definition.InjectFrom(notification);
definition.Name = notification.Name;
definition.OnGrab = notification.OnGrab;
definition.OnDownload = notification.OnDownload;
definition.Implementation = notification.Implementation;
definition.Settings = Json.Serialize(notification.Settings); definition.Settings = Json.Serialize(notification.Settings);
_notificationRepository.Update(definition); _notificationRepository.Update(definition);

View File

@ -151,6 +151,9 @@
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NLog.2.0.1.2\lib\net40\NLog.dll</HintPath> <HintPath>..\packages\NLog.2.0.1.2\lib\net40\NLog.dll</HintPath>
</Reference> </Reference>
<Reference Include="Omu.ValueInjecter">
<HintPath>..\packages\valueinjecter.2.3.3\lib\net35\Omu.ValueInjecter.dll</HintPath>
</Reference>
<Reference Include="Prowlin, Version=0.9.4456.26422, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Prowlin, Version=0.9.4456.26422, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion> <SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Prowlin.0.9.4456.26422\lib\net40\Prowlin.dll</HintPath> <HintPath>..\packages\Prowlin.0.9.4456.26422\lib\net40\Prowlin.dll</HintPath>

View File

@ -8,4 +8,5 @@
<package id="NLog" version="2.0.1.2" targetFramework="net40" /> <package id="NLog" version="2.0.1.2" targetFramework="net40" />
<package id="Prowlin" version="0.9.4456.26422" targetFramework="net40" /> <package id="Prowlin" version="0.9.4456.26422" targetFramework="net40" />
<package id="RestSharp" version="104.1" targetFramework="net40" /> <package id="RestSharp" version="104.1" targetFramework="net40" />
<package id="valueinjecter" version="2.3.3" targetFramework="net40" />
</packages> </packages>

View File

@ -56,6 +56,7 @@ define(['app', 'Calendar/CalendarItemView'], function () {
NzbDrone.Calendar.CalendarCollectionView.Instance = this; NzbDrone.Calendar.CalendarCollectionView.Instance = this;
}, },
getEvents : function (start, end, callback) { getEvents : function (start, end, callback) {
var bbView = NzbDrone.Calendar.CalendarCollectionView.Instance; var bbView = NzbDrone.Calendar.CalendarCollectionView.Instance;

View File

@ -26,7 +26,7 @@ define(['app', 'Series/SeriesModel', 'Series/Delete/DeleteSeriesView', 'Quality/
this.model.save(); this.model.save();
this.trigger('saved'); this.trigger('saved');
this.$el.parent().modal('hide'); NzbDrone.modalRegion.closeModal();
}, },
removeSeries: function () { removeSeries: function () {

View File

@ -29,7 +29,7 @@ define([
}); });
context.indexerCollection.add(context.model); context.indexerCollection.add(context.model);
context.$el.parent().modal('hide'); NzbDrone.modalRegion.closeModal();
}, },
error: function () { error: function () {

View File

@ -11,12 +11,10 @@ define(['app', 'Settings/Notifications/Model'], function () {
removeNotification: function () { removeNotification: function () {
var self = this; var self = this;
//Success is not getting triggered: http://stackoverflow.com/questions/6988873/backbone-model-destroy-not-triggering-success-function-on-success
this.model.destroy({ this.model.destroy({
wait : true, wait : true,
success: function (model) { success: function (model) {
model.collection.remove(model); NzbDrone.modalRegion.closeModal();
self.$el.parent().modal('hide');
} }
}); });
} }

View File

@ -33,7 +33,7 @@ define([
}); });
context.notificationCollection.add(context.model, { merge: true }); context.notificationCollection.add(context.model, { merge: true });
context.$el.parent().modal('hide'); NzbDrone.modalRegion.closeModal();
}, },
error: function () { error: function () {

View File

@ -13,7 +13,7 @@ define(['app', 'Quality/QualityProfileModel'], function () {
this.model.save(); this.model.save();
this.trigger('saved'); this.trigger('saved');
this.$el.parent().modal('hide'); NzbDrone.modalRegion.closeModal();
} }
}); });