From d65d79a5c9c748ae41422f4e44fbafd812a85f9a Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 12 May 2011 21:46:26 -0700 Subject: [PATCH] Replaced save notifications for settings on page with AJAX Notifications. --- NzbDrone.Core/Providers/Jobs/JobProvider.cs | 2 +- NzbDrone.Web/Content/style.css | 5 ++ .../Controllers/NotificationController.cs | 16 +++++- .../Controllers/SettingsController.cs | 56 ++++++++++++++++++- NzbDrone.Web/Views/Settings/Downloads.cshtml | 2 +- .../Views/Settings/EpisodeSorting.cshtml | 2 +- NzbDrone.Web/Views/Settings/General.cshtml | 2 +- NzbDrone.Web/Views/Settings/Indexers.cshtml | 2 +- .../Views/Settings/Notifications.cshtml | 2 +- NzbDrone.Web/Views/Settings/Quality.cshtml | 2 +- 10 files changed, 81 insertions(+), 10 deletions(-) diff --git a/NzbDrone.Core/Providers/Jobs/JobProvider.cs b/NzbDrone.Core/Providers/Jobs/JobProvider.cs index 092ec74d3..6e8e8aea8 100644 --- a/NzbDrone.Core/Providers/Jobs/JobProvider.cs +++ b/NzbDrone.Core/Providers/Jobs/JobProvider.cs @@ -155,7 +155,7 @@ namespace NzbDrone.Core.Providers.Jobs var timerClass = _jobs.Where(t => t.GetType() == jobType).FirstOrDefault(); if (timerClass == null) { - Logger.Error("Unable to locate implantation for '{0}'. Make sure its properly registered.", jobType.ToString()); + Logger.Error("Unable to locate implementation for '{0}'. Make sure its properly registered.", jobType.ToString()); return; } diff --git a/NzbDrone.Web/Content/style.css b/NzbDrone.Web/Content/style.css index faf9e0c34..57a13989e 100644 --- a/NzbDrone.Web/Content/style.css +++ b/NzbDrone.Web/Content/style.css @@ -278,6 +278,11 @@ button, input[type="button"], input[type="submit"], input[type="reset"] border-bottom-color: #3C3C3C; } +.hiddenResult +{ + display: none; +} + /* Add Series */ .tvDbSearchResults diff --git a/NzbDrone.Web/Controllers/NotificationController.cs b/NzbDrone.Web/Controllers/NotificationController.cs index 6f154de33..3744c8f3d 100644 --- a/NzbDrone.Web/Controllers/NotificationController.cs +++ b/NzbDrone.Web/Controllers/NotificationController.cs @@ -18,9 +18,21 @@ namespace NzbDrone.Web.Controllers public JsonResult Index() { string message = string.Empty; - if (_notifications.GetProgressNotifications.Count != 0) + + var basic = _notifications.BasicNotifications; + + if (basic.Count != 0) + { + message = basic[0].Title; + + if (basic[0].AutoDismiss) + _notifications.Dismiss(basic[0].Id); + } + + else { - message = _notifications.GetProgressNotifications[0].CurrentMessage; + if (_notifications.GetProgressNotifications.Count != 0) + message = _notifications.GetProgressNotifications[0].CurrentMessage; } return Json(message, JsonRequestBehavior.AllowGet); diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 06015b008..ba082c650 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -5,6 +5,7 @@ using System.Web.Mvc; using NLog; using NzbDrone.Core.Helpers; using NzbDrone.Core.Model; +using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Providers; using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Indexer; @@ -25,16 +26,18 @@ namespace NzbDrone.Web.Controllers private readonly QualityProvider _qualityProvider; private readonly RootDirProvider _rootDirProvider; private readonly AutoConfigureProvider _autoConfigureProvider; + private readonly NotificationProvider _notificationProvider; public SettingsController(ConfigProvider configProvider, IndexerProvider indexerProvider, QualityProvider qualityProvider, RootDirProvider rootDirProvider, - AutoConfigureProvider autoConfigureProvider) + AutoConfigureProvider autoConfigureProvider, NotificationProvider notificationProvider) { _configProvider = configProvider; _indexerProvider = indexerProvider; _qualityProvider = qualityProvider; _rootDirProvider = rootDirProvider; _autoConfigureProvider = autoConfigureProvider; + _notificationProvider = notificationProvider; } public ActionResult Index(string viewName) @@ -313,6 +316,10 @@ namespace NzbDrone.Web.Controllers [HttpPost] public ActionResult SaveGeneral(SettingsModel data) { + var basicNotification = new BasicNotification(); + basicNotification.Type = BasicNotificationType.Info; + basicNotification.AutoDismiss = true; + try { foreach (var dir in data.Directories) @@ -324,15 +331,26 @@ namespace NzbDrone.Web.Controllers { Logger.Debug("Failed to save Root Dirs"); Logger.DebugException(ex.Message, ex); + + basicNotification.Title = SETTINGS_FAILED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_FAILED); } + + basicNotification.Title = SETTINGS_SAVED; + _notificationProvider.Register(basicNotification); + return Content(SETTINGS_SAVED); } [HttpPost] public ActionResult SaveIndexers(IndexerSettingsModel data) { + var basicNotification = new BasicNotification(); + basicNotification.Type = BasicNotificationType.Info; + basicNotification.AutoDismiss = true; + if (ModelState.IsValid) { var nzbsOrgSettings = _indexerProvider.GetSettings(typeof(NzbsOrgProvider)); @@ -363,15 +381,23 @@ namespace NzbDrone.Web.Controllers _configProvider.NewzbinUsername = data.NewzbinUsername; _configProvider.NewzbinPassword = data.NewzbinPassword; + basicNotification.Title = SETTINGS_SAVED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_SAVED); } + basicNotification.Title = SETTINGS_FAILED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_FAILED); } [HttpPost] public ActionResult SaveDownloads(DownloadSettingsModel data) { + var basicNotification = new BasicNotification(); + basicNotification.Type = BasicNotificationType.Info; + basicNotification.AutoDismiss = true; + if (ModelState.IsValid) { _configProvider.SyncFrequency = data.SyncFrequency.ToString(); @@ -387,15 +413,23 @@ namespace NzbDrone.Web.Controllers _configProvider.UseBlackhole = data.UseBlackHole; _configProvider.BlackholeDirectory = data.BlackholeDirectory; + basicNotification.Title = SETTINGS_SAVED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_SAVED); } + basicNotification.Title = SETTINGS_FAILED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_FAILED); } [HttpPost] public ActionResult SaveQuality(QualityModel data) { + var basicNotification = new BasicNotification(); + basicNotification.Type = BasicNotificationType.Info; + basicNotification.AutoDismiss = true; + if (ModelState.IsValid) { _configProvider.SetValue("DefaultQualityProfile", data.DefaultQualityProfileId.ToString()); @@ -422,15 +456,23 @@ namespace NzbDrone.Web.Controllers _qualityProvider.Update(profile); } + basicNotification.Title = SETTINGS_SAVED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_SAVED); } + basicNotification.Title = SETTINGS_FAILED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_FAILED); } [HttpPost] public ActionResult SaveNotifications(NotificationSettingsModel data) { + var basicNotification = new BasicNotification(); + basicNotification.Type = BasicNotificationType.Info; + basicNotification.AutoDismiss = true; + if (ModelState.IsValid) { _configProvider.SetValue("XbmcEnabled", data.XbmcEnabled.ToString()); @@ -448,15 +490,23 @@ namespace NzbDrone.Web.Controllers _configProvider.SetValue("XbmcUsername", data.XbmcUsername); _configProvider.SetValue("XbmcPassword", data.XbmcPassword); + basicNotification.Title = SETTINGS_SAVED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_SAVED); } + basicNotification.Title = SETTINGS_FAILED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_FAILED); } [HttpPost] public ActionResult SaveEpisodeSorting(EpisodeSortingModel data) { + var basicNotification = new BasicNotification(); + basicNotification.Type = BasicNotificationType.Info; + basicNotification.AutoDismiss = true; + if (ModelState.IsValid) { _configProvider.SetValue("Sorting_ShowName", data.ShowName.ToString()); @@ -470,9 +520,13 @@ namespace NzbDrone.Web.Controllers _configProvider.SetValue("Sorting_NumberStyle", data.NumberStyle.ToString()); _configProvider.SetValue("Sorting_MultiEpisodeStyle", data.MultiEpisodeStyle.ToString()); + basicNotification.Title = SETTINGS_SAVED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_SAVED); } + basicNotification.Title = SETTINGS_FAILED; + _notificationProvider.Register(basicNotification); return Content(SETTINGS_FAILED); } } diff --git a/NzbDrone.Web/Views/Settings/Downloads.cshtml b/NzbDrone.Web/Views/Settings/Downloads.cshtml index 51aef83d8..7141bfa85 100644 --- a/NzbDrone.Web/Views/Settings/Downloads.cshtml +++ b/NzbDrone.Web/Views/Settings/Downloads.cshtml @@ -216,7 +216,7 @@ } -
+