From af6e3ddb66c1ed1a93bcda8531805d5c1e4d776b Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 28 May 2013 23:24:45 -0700 Subject: [PATCH] Cleaned up per comments --- .../ClientSchema/SchemaDeserializer.cs | 2 +- NzbDrone.Api/Indexers/IndexerModule.cs | 13 ++++++---- .../Notifications/NotificationModule.cs | 24 ++++++++++++------- NzbDrone.Api/REST/RestModule.cs | 3 ++- .../Notifications/NotificationService.cs | 18 ++++---------- NzbDrone.Core/NzbDrone.Core.csproj | 3 +++ NzbDrone.Core/packages.config | 1 + UI/Calendar/CalendarCollectionView.js | 1 + UI/Series/Edit/EditSeriesView.js | 2 +- UI/Settings/Indexers/EditView.js | 2 +- UI/Settings/Notifications/DeleteView.js | 4 +--- UI/Settings/Notifications/EditView.js | 2 +- .../Quality/Profile/EditQualityProfileView.js | 2 +- 13 files changed, 41 insertions(+), 36 deletions(-) diff --git a/NzbDrone.Api/ClientSchema/SchemaDeserializer.cs b/NzbDrone.Api/ClientSchema/SchemaDeserializer.cs index 22aac90e4..9e807027c 100644 --- a/NzbDrone.Api/ClientSchema/SchemaDeserializer.cs +++ b/NzbDrone.Api/ClientSchema/SchemaDeserializer.cs @@ -7,7 +7,7 @@ namespace NzbDrone.Api.ClientSchema { public static class SchemaDeserializer { - public static object DeserializeSchema(object model, List fields) + public static T DeserializeSchema(T model, List fields) { var properties = model.GetType().GetSimpleProperties(); diff --git a/NzbDrone.Api/Indexers/IndexerModule.cs b/NzbDrone.Api/Indexers/IndexerModule.cs index f24d845f0..a85a1e7fc 100644 --- a/NzbDrone.Api/Indexers/IndexerModule.cs +++ b/NzbDrone.Api/Indexers/IndexerModule.cs @@ -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; } } } \ No newline at end of file diff --git a/NzbDrone.Api/Notifications/NotificationModule.cs b/NzbDrone.Api/Notifications/NotificationModule.cs index 7532bbc4d..8e47057da 100644 --- a/NzbDrone.Api/Notifications/NotificationModule.cs +++ b/NzbDrone.Api/Notifications/NotificationModule.cs @@ -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; } diff --git a/NzbDrone.Api/REST/RestModule.cs b/NzbDrone.Api/REST/RestModule.cs index 60b279b56..4bfaf77c4 100644 --- a/NzbDrone.Api/REST/RestModule.cs +++ b/NzbDrone.Api/REST/RestModule.cs @@ -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(); }; } } diff --git a/NzbDrone.Core/Notifications/NotificationService.cs b/NzbDrone.Core/Notifications/NotificationService.cs index a425b5ad7..c983fb89b 100644 --- a/NzbDrone.Core/Notifications/NotificationService.cs +++ b/NzbDrone.Core/Notifications/NotificationService.cs @@ -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); diff --git a/NzbDrone.Core/NzbDrone.Core.csproj b/NzbDrone.Core/NzbDrone.Core.csproj index 818b18aa7..5f2559af5 100644 --- a/NzbDrone.Core/NzbDrone.Core.csproj +++ b/NzbDrone.Core/NzbDrone.Core.csproj @@ -151,6 +151,9 @@ False ..\packages\NLog.2.0.1.2\lib\net40\NLog.dll + + ..\packages\valueinjecter.2.3.3\lib\net35\Omu.ValueInjecter.dll + False ..\packages\Prowlin.0.9.4456.26422\lib\net40\Prowlin.dll diff --git a/NzbDrone.Core/packages.config b/NzbDrone.Core/packages.config index da37840f9..021bedc53 100644 --- a/NzbDrone.Core/packages.config +++ b/NzbDrone.Core/packages.config @@ -8,4 +8,5 @@ + \ No newline at end of file diff --git a/UI/Calendar/CalendarCollectionView.js b/UI/Calendar/CalendarCollectionView.js index f8a9c30da..85a837bbc 100644 --- a/UI/Calendar/CalendarCollectionView.js +++ b/UI/Calendar/CalendarCollectionView.js @@ -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; diff --git a/UI/Series/Edit/EditSeriesView.js b/UI/Series/Edit/EditSeriesView.js index 640356ec4..c47dd53e1 100644 --- a/UI/Series/Edit/EditSeriesView.js +++ b/UI/Series/Edit/EditSeriesView.js @@ -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 () { diff --git a/UI/Settings/Indexers/EditView.js b/UI/Settings/Indexers/EditView.js index 54bdbe642..f188b37b9 100644 --- a/UI/Settings/Indexers/EditView.js +++ b/UI/Settings/Indexers/EditView.js @@ -29,7 +29,7 @@ define([ }); context.indexerCollection.add(context.model); - context.$el.parent().modal('hide'); + NzbDrone.modalRegion.closeModal(); }, error: function () { diff --git a/UI/Settings/Notifications/DeleteView.js b/UI/Settings/Notifications/DeleteView.js index 65474233e..d9ba35b54 100644 --- a/UI/Settings/Notifications/DeleteView.js +++ b/UI/Settings/Notifications/DeleteView.js @@ -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(); } }); } diff --git a/UI/Settings/Notifications/EditView.js b/UI/Settings/Notifications/EditView.js index 13724b49a..6f731bf9a 100644 --- a/UI/Settings/Notifications/EditView.js +++ b/UI/Settings/Notifications/EditView.js @@ -33,7 +33,7 @@ define([ }); context.notificationCollection.add(context.model, { merge: true }); - context.$el.parent().modal('hide'); + NzbDrone.modalRegion.closeModal(); }, error: function () { diff --git a/UI/Settings/Quality/Profile/EditQualityProfileView.js b/UI/Settings/Quality/Profile/EditQualityProfileView.js index 86af8ac24..34f3f3aa6 100644 --- a/UI/Settings/Quality/Profile/EditQualityProfileView.js +++ b/UI/Settings/Quality/Profile/EditQualityProfileView.js @@ -13,7 +13,7 @@ define(['app', 'Quality/QualityProfileModel'], function () { this.model.save(); this.trigger('saved'); - this.$el.parent().modal('hide'); + NzbDrone.modalRegion.closeModal(); } });