1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-12-16 11:37:58 +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 object DeserializeSchema(object model, List<Field> fields)
public static T DeserializeSchema<T>(T model, List<Field> fields)
{
var properties = model.GetType().GetSimpleProperties();

View File

@ -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 @@ private IndexerResource Create(IndexerResource indexerResource)
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;
}
}
}

View File

@ -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 @@ private NotificationResource Create(NotificationResource notificationResource)
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);
return notificationResource;
var responseResource = new NotificationResource();
responseResource.InjectFrom(notification);
responseResource.Fields = SchemaBuilder.GenerateSchema(notification.Settings);
return responseResource;
}
private void DeleteNotification(int id)
@ -70,16 +79,13 @@ private Notification GetNotification(NotificationResource notificationResource)
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;
}

View File

@ -54,7 +54,8 @@ protected Action<int> DeleteResource
{
ValidateId(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.Core.Download;
using NzbDrone.Core.MediaFiles.Events;
using Omu.ValueInjecter;
namespace NzbDrone.Core.Notifications
{
@ -82,14 +83,9 @@ public List<Notification> Schema()
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 @@ public Notification Create(Notification notification)
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);

View File

@ -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>

View File

@ -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>

View File

@ -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;

View File

@ -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 () {

View File

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

View File

@ -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();
}
});
}

View File

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

View File

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