From c5376319fe46dd60098bcfe92b5bef5185455f48 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sun, 19 May 2013 21:19:54 -0700 Subject: [PATCH] Notification settings added to the UI --- NzbDrone.Api/ClientSchema/Field.cs | 1 + NzbDrone.Api/ClientSchema/SchemaBuilder.cs | 2 +- NzbDrone.Api/Commands/CommandModule.cs | 4 -- .../Notifications/NotificationResource.cs | 3 +- .../Annotations/FieldDefinitionAttribute.cs | 8 ++++ .../Notifications/NotificationService.cs | 1 - NzbDrone.Core/Notifications/Xbmc/Xbmc.cs | 11 ++++- .../Notifications/Xbmc/XbmcSettings.cs | 17 ++++--- UI/Form/CheckboxTemplate.html | 2 + UI/Form/PasswordTemplate.html | 12 +++++ UI/Form/TextboxTemplate.html | 8 ++-- UI/Mixins/handlebars.mixin.js | 8 ++++ UI/Settings/Notifications/Collection.js | 7 +++ .../Notifications/CollectionTemplate.html | 5 ++ UI/Settings/Notifications/CollectionView.js | 8 ++++ UI/Settings/Notifications/ItemTemplate.html | 47 +++++++++++++++++++ UI/Settings/Notifications/ItemView.js | 33 +++++++++++++ UI/Settings/Notifications/Model.js | 5 ++ .../Notifications/NotificationsTemplate.html | 3 -- .../Notifications/NotificationsView.js | 11 ----- UI/Settings/SettingsLayout.js | 7 ++- 21 files changed, 168 insertions(+), 35 deletions(-) create mode 100644 UI/Form/PasswordTemplate.html create mode 100644 UI/Settings/Notifications/Collection.js create mode 100644 UI/Settings/Notifications/CollectionTemplate.html create mode 100644 UI/Settings/Notifications/CollectionView.js create mode 100644 UI/Settings/Notifications/ItemTemplate.html create mode 100644 UI/Settings/Notifications/ItemView.js create mode 100644 UI/Settings/Notifications/Model.js delete mode 100644 UI/Settings/Notifications/NotificationsTemplate.html delete mode 100644 UI/Settings/Notifications/NotificationsView.js diff --git a/NzbDrone.Api/ClientSchema/Field.cs b/NzbDrone.Api/ClientSchema/Field.cs index 2fe6388fe..5737cb3a5 100644 --- a/NzbDrone.Api/ClientSchema/Field.cs +++ b/NzbDrone.Api/ClientSchema/Field.cs @@ -7,5 +7,6 @@ public string Label { get; set; } public string HelpText { get; set; } public string Value { get; set; } + public string Type { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Api/ClientSchema/SchemaBuilder.cs b/NzbDrone.Api/ClientSchema/SchemaBuilder.cs index c91b5502b..58f3d11cb 100644 --- a/NzbDrone.Api/ClientSchema/SchemaBuilder.cs +++ b/NzbDrone.Api/ClientSchema/SchemaBuilder.cs @@ -25,7 +25,7 @@ namespace NzbDrone.Api.ClientSchema Label = fieldAttribute.Label, HelpText = fieldAttribute.HelpText, Order = fieldAttribute.Order, - + Type = fieldAttribute.Type.ToString().ToLowerInvariant() }; var value = propertyInfo.GetValue(model, null); diff --git a/NzbDrone.Api/Commands/CommandModule.cs b/NzbDrone.Api/Commands/CommandModule.cs index cddbd414d..2c64ed223 100644 --- a/NzbDrone.Api/Commands/CommandModule.cs +++ b/NzbDrone.Api/Commands/CommandModule.cs @@ -4,8 +4,6 @@ using System.Linq; using NzbDrone.Api.Extensions; using NzbDrone.Common.Composition; using NzbDrone.Common.Messaging; -using NzbDrone.Core.Download; -using NzbDrone.Core.Parser.Model; namespace NzbDrone.Api.Commands { @@ -24,8 +22,6 @@ namespace NzbDrone.Api.Commands private CommandResource RunCommand(CommandResource resource) { - _messageAggregator.PublishEvent(new EpisodeGrabbedEvent(new RemoteEpisode())); - var commandType = _container.GetImplementations(typeof(ICommand)) .Single(c => c.Name.Replace("Command", "") diff --git a/NzbDrone.Api/Notifications/NotificationResource.cs b/NzbDrone.Api/Notifications/NotificationResource.cs index 77deb5426..24cddeff5 100644 --- a/NzbDrone.Api/Notifications/NotificationResource.cs +++ b/NzbDrone.Api/Notifications/NotificationResource.cs @@ -7,8 +7,9 @@ namespace NzbDrone.Api.Notifications { public class NotificationResource : RestResource { - public Boolean Enable { get; set; } public String Name { get; set; } + public Boolean OnGrab { get; set; } + public Boolean OnDownload { get; set; } public List Fields { get; set; } } } \ No newline at end of file diff --git a/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs b/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs index 33a5b8095..3c5728879 100644 --- a/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs +++ b/NzbDrone.Core/Annotations/FieldDefinitionAttribute.cs @@ -13,5 +13,13 @@ namespace NzbDrone.Core.Annotations public int Order { get; private set; } public string Label { get; set; } public string HelpText { get; set; } + public FieldType Type { get; set; } + } + + public enum FieldType + { + Textbox, + Password, + Checkbox } } \ No newline at end of file diff --git a/NzbDrone.Core/Notifications/NotificationService.cs b/NzbDrone.Core/Notifications/NotificationService.cs index d6f52757f..874ff40d5 100644 --- a/NzbDrone.Core/Notifications/NotificationService.cs +++ b/NzbDrone.Core/Notifications/NotificationService.cs @@ -39,7 +39,6 @@ namespace NzbDrone.Core.Notifications public List All() { - var test = _notificationRepository.All();//.Select(ToNotification).ToList(); return _notificationRepository.All().Select(ToNotification).ToList(); } diff --git a/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs b/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs index 514a5dd0e..113396ef1 100644 --- a/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs +++ b/NzbDrone.Core/Notifications/Xbmc/Xbmc.cs @@ -21,14 +21,21 @@ namespace NzbDrone.Core.Notifications.Xbmc { const string header = "NzbDrone [TV] - Grabbed"; - _xbmcProvider.Notify(Settings, header, message); + if (Settings.Notify) + { + _xbmcProvider.Notify(Settings, header, message); + } } public override void OnDownload(string message, Series series) { const string header = "NzbDrone [TV] - Downloaded"; - _xbmcProvider.Notify(Settings, header, message); + if (Settings.Notify) + { + _xbmcProvider.Notify(Settings, header, message); + } + UpdateAndClean(series); } diff --git a/NzbDrone.Core/Notifications/Xbmc/XbmcSettings.cs b/NzbDrone.Core/Notifications/Xbmc/XbmcSettings.cs index f24ff2ae6..110b2cc55 100644 --- a/NzbDrone.Core/Notifications/Xbmc/XbmcSettings.cs +++ b/NzbDrone.Core/Notifications/Xbmc/XbmcSettings.cs @@ -8,25 +8,28 @@ namespace NzbDrone.Core.Notifications.Xbmc { public class XbmcSettings : INotifcationSettings { - [FieldDefinition(0, Label = "Host", HelpText = "XBMC Hostnname or IP")] + [FieldDefinition(0, Label = "Host")] public String Host { get; set; } - [FieldDefinition(1, Label = "Port", HelpText = "Webserver port")] + [FieldDefinition(1, Label = "Port")] public Int32 Port { get; set; } - [FieldDefinition(2, Label = "Username", HelpText = "Webserver Username")] + [FieldDefinition(2, Label = "Username")] public String Username { get; set; } - [FieldDefinition(3, Label = "Password", HelpText = "Webserver Password ")] + [FieldDefinition(3, Label = "Password", Type = FieldType.Password)] public String Password { get; set; } - [FieldDefinition(4, Label = "Update Library", HelpText = "Update Library on Download & Rename?")] + [FieldDefinition(4, Label = "GUI Notification", HelpText = "Show GUI notifications?", Type = FieldType.Checkbox)] + public Boolean Notify { get; set; } + + [FieldDefinition(5, Label = "Update Library", HelpText = "Update Library on Download & Rename?", Type = FieldType.Checkbox)] public Boolean UpdateLibrary { get; set; } - [FieldDefinition(5, Label = "Update Library", HelpText = "Clean Library after update?")] + [FieldDefinition(6, Label = "Clean Library", HelpText = "Clean Library after update?", Type = FieldType.Checkbox)] public Boolean CleanLibrary { get; set; } - [FieldDefinition(6, Label = "Always Update", HelpText = "Update Library even when a video is playing?")] + [FieldDefinition(7, Label = "Always Update", HelpText = "Update Library even when a video is playing?", Type = FieldType.Checkbox)] public Boolean AlwaysUpdate { get; set; } public bool IsValid diff --git a/UI/Form/CheckboxTemplate.html b/UI/Form/CheckboxTemplate.html index 3c155e43f..59858343b 100644 --- a/UI/Form/CheckboxTemplate.html +++ b/UI/Form/CheckboxTemplate.html @@ -12,8 +12,10 @@
+ {{#if helpText}} + {{/if}} \ No newline at end of file diff --git a/UI/Form/PasswordTemplate.html b/UI/Form/PasswordTemplate.html new file mode 100644 index 000000000..077b625fd --- /dev/null +++ b/UI/Form/PasswordTemplate.html @@ -0,0 +1,12 @@ +
+ + +
+ + {{#if helpText}} + + + + {{/if}} +
+
\ No newline at end of file diff --git a/UI/Form/TextboxTemplate.html b/UI/Form/TextboxTemplate.html index c5466fd98..1c72aea70 100644 --- a/UI/Form/TextboxTemplate.html +++ b/UI/Form/TextboxTemplate.html @@ -3,8 +3,10 @@
- - - + {{#if helpText}} + + + + {{/if}}
\ No newline at end of file diff --git a/UI/Mixins/handlebars.mixin.js b/UI/Mixins/handlebars.mixin.js index 838136c52..cb0b7b14c 100644 --- a/UI/Mixins/handlebars.mixin.js +++ b/UI/Mixins/handlebars.mixin.js @@ -12,6 +12,14 @@ Handlebars.registerHelper('formField', function () { return Handlebars.helpers.partial.apply(this, ['Form/TextboxTemplate']); } + if (this.type === 'password') { + return Handlebars.helpers.partial.apply(this, ['Form/PasswordTemplate']); + } + + if (this.type === 'checkbox') { + return Handlebars.helpers.partial.apply(this, ['Form/CheckboxTemplate']); + } + return Handlebars.helpers.partial.apply(this, ['Form/TextboxTemplate']); }); diff --git a/UI/Settings/Notifications/Collection.js b/UI/Settings/Notifications/Collection.js new file mode 100644 index 000000000..57944089e --- /dev/null +++ b/UI/Settings/Notifications/Collection.js @@ -0,0 +1,7 @@ +"use strict"; +define(['app', 'Settings/Notifications/Model'], function () { + NzbDrone.Settings.Notifications.Collection = Backbone.Collection.extend({ + url : NzbDrone.Constants.ApiRoot + '/notification', + model: NzbDrone.Settings.Notifications.Model + }); +}); diff --git a/UI/Settings/Notifications/CollectionTemplate.html b/UI/Settings/Notifications/CollectionTemplate.html new file mode 100644 index 000000000..3b9abe950 --- /dev/null +++ b/UI/Settings/Notifications/CollectionTemplate.html @@ -0,0 +1,5 @@ +
+
+
+
+
\ No newline at end of file diff --git a/UI/Settings/Notifications/CollectionView.js b/UI/Settings/Notifications/CollectionView.js new file mode 100644 index 000000000..24fc4334a --- /dev/null +++ b/UI/Settings/Notifications/CollectionView.js @@ -0,0 +1,8 @@ +'use strict'; +define(['app', 'Settings/Notifications/ItemView'], function () { + NzbDrone.Settings.Notifications.CollectionView = Backbone.Marionette.CompositeView.extend({ + itemView : NzbDrone.Settings.Notifications.ItemView, + itemViewContainer : '#x-notifications', + template : 'Settings/Notifications/CollectionTemplate' + }); +}); diff --git a/UI/Settings/Notifications/ItemTemplate.html b/UI/Settings/Notifications/ItemTemplate.html new file mode 100644 index 000000000..bc8782adb --- /dev/null +++ b/UI/Settings/Notifications/ItemTemplate.html @@ -0,0 +1,47 @@ +
+ {{name}} + +
+ + +
+ + + + + +
+
+ +
+ + +
+ + + + + +
+
+ + {{#each fields}} + {{formField}} + {{/each}} +
diff --git a/UI/Settings/Notifications/ItemView.js b/UI/Settings/Notifications/ItemView.js new file mode 100644 index 000000000..7183c8ff7 --- /dev/null +++ b/UI/Settings/Notifications/ItemView.js @@ -0,0 +1,33 @@ +"use strict"; + +define([ + 'app', + 'Settings/Notifications/Collection' + +], function () { + + NzbDrone.Settings.Notifications.ItemView = Backbone.Marionette.ItemView.extend({ + template : 'Settings/Notifications/ItemTemplate', + initialize: function () { + NzbDrone.vent.on(NzbDrone.Commands.SaveSettings, this.saveSettings, this); + }, + + saveSettings: function () { + + //this.model.save(undefined, this.syncNotification("Naming Settings Saved", "Couldn't Save Naming Settings")); + }, + + + syncNotification: function (success, error) { + return { + success: function () { + window.alert(success); + }, + + error: function () { + window.alert(error); + } + }; + } + }); +}); diff --git a/UI/Settings/Notifications/Model.js b/UI/Settings/Notifications/Model.js new file mode 100644 index 000000000..bee0e1da4 --- /dev/null +++ b/UI/Settings/Notifications/Model.js @@ -0,0 +1,5 @@ +"use strict"; +define(['app'], function () { + NzbDrone.Settings.Notifications.Model = Backbone.DeepModel.extend({ + }); +}); diff --git a/UI/Settings/Notifications/NotificationsTemplate.html b/UI/Settings/Notifications/NotificationsTemplate.html deleted file mode 100644 index 49f9be984..000000000 --- a/UI/Settings/Notifications/NotificationsTemplate.html +++ /dev/null @@ -1,3 +0,0 @@ -
- Notification settings will go here -
\ No newline at end of file diff --git a/UI/Settings/Notifications/NotificationsView.js b/UI/Settings/Notifications/NotificationsView.js deleted file mode 100644 index e1aef27c3..000000000 --- a/UI/Settings/Notifications/NotificationsView.js +++ /dev/null @@ -1,11 +0,0 @@ -'use strict'; - -define([ - 'app', 'Settings/SettingsModel' - -], function () { - - NzbDrone.Settings.Notifications.NotificationsView = Backbone.Marionette.ItemView.extend({ - template: 'Settings/Notifications/NotificationsTemplate' - }); -}); diff --git a/UI/Settings/SettingsLayout.js b/UI/Settings/SettingsLayout.js index 3195f373e..f0c4d5fff 100644 --- a/UI/Settings/SettingsLayout.js +++ b/UI/Settings/SettingsLayout.js @@ -5,7 +5,7 @@ define([ 'Settings/Quality/QualityLayout', 'Settings/Indexers/CollectionView', 'Settings/DownloadClient/DownloadClientView', - 'Settings/Notifications/NotificationsView', + 'Settings/Notifications/CollectionView', 'Settings/System/SystemView', 'Settings/Misc/MiscView' ], @@ -117,6 +117,9 @@ define([ this.indexerSettings = new NzbDrone.Settings.Indexers.Collection(); this.indexerSettings.fetch(); + this.notificationSettings = new NzbDrone.Settings.Notifications.Collection(); + this.notificationSettings.fetch(); + if (options.action) { this.action = options.action.toLowerCase(); } @@ -127,7 +130,7 @@ define([ this.quality.show(new NzbDrone.Settings.Quality.QualityLayout({settings: this.settings})); this.indexers.show(new NzbDrone.Settings.Indexers.CollectionView({collection: this.indexerSettings})); this.downloadClient.show(new NzbDrone.Settings.DownloadClient.DownloadClientView({model: this.settings})); - this.notifications.show(new NzbDrone.Settings.Notifications.NotificationsView({model: this.settings})); + this.notifications.show(new NzbDrone.Settings.Notifications.CollectionView({collection: this.notificationSettings})); this.system.show(new NzbDrone.Settings.System.SystemView({model: this.settings})); this.misc.show(new NzbDrone.Settings.Misc.MiscView({model: this.settings})); },