Cleaned up per comments

pull/3113/head
Mark McDowall 12 years ago
parent 4d101cc6dc
commit af6e3ddb66

@ -7,7 +7,7 @@ namespace NzbDrone.Api.ClientSchema
{
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();

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

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

@ -54,7 +54,8 @@ namespace NzbDrone.Api.REST
{
ValidateId(options.Id);
DeleteResource((int)options.Id);
return new Response { StatusCode = HttpStatusCode.OK };
return new object().AsResponse();
};
}
}

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

@ -151,6 +151,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NLog.2.0.1.2\lib\net40\NLog.dll</HintPath>
</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">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Prowlin.0.9.4456.26422\lib\net40\Prowlin.dll</HintPath>

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

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

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

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

@ -11,12 +11,10 @@ define(['app', 'Settings/Notifications/Model'], function () {
removeNotification: function () {
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({
wait : true,
success: function (model) {
model.collection.remove(model);
self.$el.parent().modal('hide');
NzbDrone.modalRegion.closeModal();
}
});
}

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

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

Loading…
Cancel
Save