From 3d3390187e03bbee985b094e367dc47d6337b778 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 10 Feb 2014 17:09:31 -0800 Subject: [PATCH] New: Optionally disable notifications for upgraded episode files --- .../Notifications/NotificationResource.cs | 1 + .../038_add_on_upgrade_to_notifications.cs | 16 +++++++++ .../Notifications/NotificationDefinition.cs | 1 + .../Notifications/NotificationFactory.cs | 6 ++++ .../Notifications/NotificationService.cs | 5 +++ src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + src/UI/Settings/Notifications/AddItemView.js | 9 ++--- .../Notifications/NotificationEditView.js | 24 ++++++++++++- .../NotificationEditViewTemplate.html | 34 +++++++++++++++---- src/UI/Settings/SettingsLayout.js | 2 +- 10 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/038_add_on_upgrade_to_notifications.cs diff --git a/src/NzbDrone.Api/Notifications/NotificationResource.cs b/src/NzbDrone.Api/Notifications/NotificationResource.cs index 54ffe720a..51c7fb7df 100644 --- a/src/NzbDrone.Api/Notifications/NotificationResource.cs +++ b/src/NzbDrone.Api/Notifications/NotificationResource.cs @@ -7,6 +7,7 @@ namespace NzbDrone.Api.Notifications public String Link { get; set; } public Boolean OnGrab { get; set; } public Boolean OnDownload { get; set; } + public Boolean OnUpgrade { get; set; } public String TestCommand { get; set; } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Datastore/Migration/038_add_on_upgrade_to_notifications.cs b/src/NzbDrone.Core/Datastore/Migration/038_add_on_upgrade_to_notifications.cs new file mode 100644 index 000000000..f5cae2ba0 --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/038_add_on_upgrade_to_notifications.cs @@ -0,0 +1,16 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(38)] + public class add_on_upgrade_to_notifications : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Alter.Table("Notifications").AddColumn("OnUpgrade").AsBoolean().Nullable(); + + Execute.Sql("UPDATE Notifications SET OnUpgrade = OnDownload"); + } + } +} diff --git a/src/NzbDrone.Core/Notifications/NotificationDefinition.cs b/src/NzbDrone.Core/Notifications/NotificationDefinition.cs index a48d2b28d..b1143db3f 100644 --- a/src/NzbDrone.Core/Notifications/NotificationDefinition.cs +++ b/src/NzbDrone.Core/Notifications/NotificationDefinition.cs @@ -7,5 +7,6 @@ namespace NzbDrone.Core.Notifications { public Boolean OnGrab { get; set; } public Boolean OnDownload { get; set; } + public Boolean OnUpgrade { get; set; } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Notifications/NotificationFactory.cs b/src/NzbDrone.Core/Notifications/NotificationFactory.cs index 54037acef..4a4fc9bc2 100644 --- a/src/NzbDrone.Core/Notifications/NotificationFactory.cs +++ b/src/NzbDrone.Core/Notifications/NotificationFactory.cs @@ -10,6 +10,7 @@ namespace NzbDrone.Core.Notifications { List OnGrabEnabled(); List OnDownloadEnabled(); + List OnUpgradeEnabled(); } public class NotificationFactory : ProviderFactory, INotificationFactory @@ -28,5 +29,10 @@ namespace NzbDrone.Core.Notifications { return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnDownload).ToList(); } + + public List OnUpgradeEnabled() + { + return GetAvailableProviders().Where(n => ((NotificationDefinition)n.Definition).OnUpgrade).ToList(); + } } } \ No newline at end of file diff --git a/src/NzbDrone.Core/Notifications/NotificationService.cs b/src/NzbDrone.Core/Notifications/NotificationService.cs index 768c3fda3..e52dd1fac 100644 --- a/src/NzbDrone.Core/Notifications/NotificationService.cs +++ b/src/NzbDrone.Core/Notifications/NotificationService.cs @@ -80,6 +80,11 @@ namespace NzbDrone.Core.Notifications { try { + if (downloadMessage.OldFiles.Any() && !((NotificationDefinition) notification.Definition).OnUpgrade) + { + continue; + } + notification.OnDownload(downloadMessage); } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 4c85322c3..c09e55f48 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -194,6 +194,7 @@ + diff --git a/src/UI/Settings/Notifications/AddItemView.js b/src/UI/Settings/Notifications/AddItemView.js index c1264354b..2c031b3e0 100644 --- a/src/UI/Settings/Notifications/AddItemView.js +++ b/src/UI/Settings/Notifications/AddItemView.js @@ -24,10 +24,11 @@ define([ } this.model.set({ - id: undefined, - name: this.model.get('implementationName'), - onGrab: true, - onDownload: true + id : undefined, + name : this.model.get('implementationName'), + onGrab : true, + onDownload : true, + onUpgrade : true }); var editView = new EditView({ model: this.model, notificationCollection: this.notificationCollection }); diff --git a/src/UI/Settings/Notifications/NotificationEditView.js b/src/UI/Settings/Notifications/NotificationEditView.js index 92a6f8af1..03de47197 100644 --- a/src/UI/Settings/Notifications/NotificationEditView.js +++ b/src/UI/Settings/Notifications/NotificationEditView.js @@ -16,18 +16,28 @@ define( var model = Marionette.ItemView.extend({ template: 'Settings/Notifications/NotificationEditViewTemplate', + ui: { + onDownloadToggle: '.x-on-download', + onUpgradeSection: '.x-on-upgrade' + }, + events: { 'click .x-save' : '_saveNotification', 'click .x-save-and-add': '_saveAndAddNotification', 'click .x-delete' : '_deleteNotification', 'click .x-back' : '_back', - 'click .x-test' : '_test' + 'click .x-test' : '_test', + 'change .x-on-download': '_onDownloadChanged' }, initialize: function (options) { this.notificationCollection = options.notificationCollection; }, + onRender: function () { + this._onDownloadChanged(); + }, + _saveNotification: function () { var self = this; var promise = this.model.saveSettings(); @@ -71,6 +81,18 @@ define( }); CommandController.Execute(testCommand, properties); + }, + + _onDownloadChanged: function () { + var checked = this.ui.onDownloadToggle.prop('checked'); + + if (checked) { + this.ui.onUpgradeSection.show(); + } + + else { + this.ui.onUpgradeSection.hide(); + } } }); diff --git a/src/UI/Settings/Notifications/NotificationEditViewTemplate.html b/src/UI/Settings/Notifications/NotificationEditViewTemplate.html index c785fe9c1..e6abfa829 100644 --- a/src/UI/Settings/Notifications/NotificationEditViewTemplate.html +++ b/src/UI/Settings/Notifications/NotificationEditViewTemplate.html @@ -30,9 +30,9 @@
- - - + + +
@@ -41,7 +41,7 @@
+ +
+ + +
+
diff --git a/src/UI/Settings/SettingsLayout.js b/src/UI/Settings/SettingsLayout.js index db90a0a7d..2770feee5 100644 --- a/src/UI/Settings/SettingsLayout.js +++ b/src/UI/Settings/SettingsLayout.js @@ -66,7 +66,7 @@ define( 'click .x-notifications-tab' : '_showNotifications', 'click .x-general-tab' : '_showGeneral', 'click .x-save-settings' : '_save', - 'change .x-advanced-settings' : '_toggleAdvancedSettings' + 'change .x-advanced-settings' : '_toggleAdvancedSettings' }, initialize: function (options) {