diff --git a/NzbDrone.Web/Content/jquery.gritter.css b/NzbDrone.Web/Content/jquery.gritter.css index 73f96ef7f..2e9bfa6df 100644 --- a/NzbDrone.Web/Content/jquery.gritter.css +++ b/NzbDrone.Web/Content/jquery.gritter.css @@ -97,6 +97,8 @@ font-size: 20px; padding: 0; display: block; + line-height: 1; + padding-bottom: 10px; text-shadow: 1px 1px #000; /* Not supported by IE :( */ } .gritter-image diff --git a/NzbDrone.Web/Controllers/AddSeriesController.cs b/NzbDrone.Web/Controllers/AddSeriesController.cs index c177ef436..8a38d5f49 100644 --- a/NzbDrone.Web/Controllers/AddSeriesController.cs +++ b/NzbDrone.Web/Controllers/AddSeriesController.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; using System.Web.Mvc; -using NLog; using NzbDrone.Common; using NzbDrone.Core.Jobs; using NzbDrone.Core.Providers; @@ -16,7 +15,6 @@ namespace NzbDrone.Web.Controllers { public class AddSeriesController : Controller { - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); private readonly ConfigProvider _configProvider; private readonly QualityProvider _qualityProvider; private readonly RootDirProvider _rootFolderProvider; @@ -42,10 +40,10 @@ namespace NzbDrone.Web.Controllers } [HttpPost] - public JsonResult ScanNewSeries() + public EmptyResult ScanNewSeries() { _jobProvider.QueueJob(typeof(ImportNewSeriesJob)); - return new JsonResult(); + return new EmptyResult(); } public ActionResult AddNew() @@ -117,22 +115,16 @@ namespace NzbDrone.Web.Controllers } [HttpPost] + [JsonErrorFilter] public JsonResult AddExistingSeries(string path, string seriesName, int seriesId, int qualityProfileId) { if (seriesId == 0 || String.IsNullOrWhiteSpace(seriesName)) - return Json(new NotificationResult() { Title = "Failed", Text = "Invalid Series Information, Series not added.", NotificationType = NotificationType.Error }); + return JsonNotificationResult.Error("Add Existing series failed.", "Invalid Series information"); - try - { - _seriesProvider.AddSeries(path, seriesId, qualityProfileId); - ScanNewSeries(); - return Json(new NotificationResult() { Title = seriesName, Text = "Was added successfully" }); - } + _seriesProvider.AddSeries(path, seriesId, qualityProfileId); + ScanNewSeries(); - catch (Exception ex) - { - return Json(new NotificationResult() { Title = "Failed", Text = ex.Message, NotificationType = NotificationType.Error }); - } + return JsonNotificationResult.Info(seriesName, "Was added successfully"); } [HttpPost] @@ -148,19 +140,6 @@ namespace NzbDrone.Web.Controllers return AddExistingSeries(path, seriesName, seriesId, qualityProfileId); } - public JsonResult AddSeries(string path, int seriesId, int qualityProfileId) - { - //Get TVDB Series Name - //Create new folder for series - //Add the new series to the Database - - _seriesProvider.AddSeries( - path.Replace('|', Path.DirectorySeparatorChar).Replace('^', Path.VolumeSeparatorChar).Replace('`', '\''), seriesId, - qualityProfileId); - ScanNewSeries(); - return new JsonResult { Data = "ok" }; - } - [ChildActionOnly] public ActionResult QuickAdd() { @@ -178,19 +157,15 @@ namespace NzbDrone.Web.Controllers [HttpPost] - [JsonErrorFilter("Can't add root folder")] + [JsonErrorFilter] public JsonResult SaveRootDir(string path) { if (String.IsNullOrWhiteSpace(path)) - NotificationResult.Error("Can't add root folder", "Path can not be empty"); - - //Don't let a user add a rootDir that is the same as their SABnzbd TV Directory - if (path.Equals(_configProvider.SabDropDirectory, StringComparison.InvariantCultureIgnoreCase)) - NotificationResult.Error("Can't add root folder", "Path can not be same as sab folder."); + JsonNotificationResult.Error("Can't add root folder", "Path can not be empty"); _rootFolderProvider.Add(new RootDir { Path = path }); - return NotificationResult.Info("Root Folder saved", "Root foler saved successfully."); + return JsonNotificationResult.Info("Root Folder saved", "Root foler saved successfully."); } [HttpGet] @@ -217,20 +192,14 @@ namespace NzbDrone.Web.Controllers return PartialView("RootDir"); } + [JsonErrorFilter] public JsonResult DeleteRootDir(string path) { - try - { - var id = _rootFolderProvider.GetAll().Where(c => c.Path == path).First().Id; - _rootFolderProvider.Remove(id); - } - catch (Exception) - { - return new JsonResult { Data = "failed" }; - } + var id = _rootFolderProvider.GetAll().Where(c => c.Path == path).First().Id; + _rootFolderProvider.Remove(id); - return new JsonResult { Data = "ok" }; + return null; } } } \ No newline at end of file diff --git a/NzbDrone.Web/Controllers/CommandController.cs b/NzbDrone.Web/Controllers/CommandController.cs index 5abff28c8..aedf1a036 100644 --- a/NzbDrone.Web/Controllers/CommandController.cs +++ b/NzbDrone.Web/Controllers/CommandController.cs @@ -1,12 +1,7 @@ -using System; -using System.Collections.Generic; -using System.Web; -using System.Web.Mvc; -using NLog; +using System.Web.Mvc; using NzbDrone.Core.Jobs; -using NzbDrone.Core.Model; -using NzbDrone.Core.Model.Twitter; using NzbDrone.Core.Providers; +using NzbDrone.Web.Filters; using NzbDrone.Web.Models; namespace NzbDrone.Web.Controllers @@ -18,8 +13,6 @@ namespace NzbDrone.Web.Controllers private readonly SmtpProvider _smtpProvider; private readonly TwitterProvider _twitterProvider; - private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); - public CommandController(JobProvider jobProvider, SabProvider sabProvider, SmtpProvider smtpProvider, TwitterProvider twitterProvider) { @@ -32,54 +25,41 @@ namespace NzbDrone.Web.Controllers public JsonResult RssSync() { _jobProvider.QueueJob(typeof(RssSyncJob)); - return new JsonResult { Data = "ok", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; + return JsonNotificationResult.Info("Queued"); } public JsonResult BacklogSearch() { _jobProvider.QueueJob(typeof(BacklogSearchJob)); - return new JsonResult { Data = "ok", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; + return JsonNotificationResult.Info("Queued"); } public JsonResult ScanDisk(int seriesId) { - //Syncs the episodes on disk for the specified series _jobProvider.QueueJob(typeof(DiskScanJob), seriesId); - - return new JsonResult { Data = "ok", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; + return JsonNotificationResult.Info("Queued"); } public JsonResult UpdateInfo(int seriesId) { - //Syncs the episodes on disk for the specified series _jobProvider.QueueJob(typeof(UpdateInfoJob), seriesId); - - return new JsonResult { Data = "ok", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; + return JsonNotificationResult.Info("Queued"); } [HttpPost] + [JsonErrorFilter] public JsonResult GetSabnzbdCategories(string host, int port, string apiKey, string username, string password) { - try - { - return new JsonResult {Data = _sabProvider.GetCategories(host, port, apiKey, username, password)}; - } - - catch (Exception ex) - { - Logger.Warn("Unable to get Categories from SABnzbd"); - Logger.DebugException(ex.Message, ex); - return Json(new NotificationResult { Title = "Failed", Text = "Unable to get SABnzbd Categories", NotificationType = NotificationType.Error }); - } + return new JsonResult { Data = _sabProvider.GetCategories(host, port, apiKey, username, password) }; } [HttpPost] public JsonResult SendTestEmail(string server, int port, bool ssl, string username, string password, string fromAddress, string toAddresses) { if (_smtpProvider.SendTestEmail(server, port, ssl, username, password, fromAddress, toAddresses)) - return Json(new NotificationResult { Title = "Successfully sent test email." }); + JsonNotificationResult.Info("Successfull", "Test email sent."); - return Json(new NotificationResult { Title = "Failed", Text = "Unable to send Email, please check your settings", NotificationType = NotificationType.Error }); + return JsonNotificationResult.Opps("Couldn't send Email, please check your settings"); } public JsonResult GetTwitterAuthorization() @@ -87,7 +67,7 @@ namespace NzbDrone.Web.Controllers var result = _twitterProvider.GetAuthorization(); if (result == null) - return Json(new NotificationResult { Title = "Failed", Text = "Unable to get Twitter Authorization", NotificationType = NotificationType.Error }, JsonRequestBehavior.AllowGet); + JsonNotificationResult.Opps("Couldn't get Twitter Authorization"); return new JsonResult { Data = result, JsonRequestBehavior = JsonRequestBehavior.AllowGet }; } @@ -97,9 +77,10 @@ namespace NzbDrone.Web.Controllers var result = _twitterProvider.GetAndSaveAccessToken(token, verifier); if (!result) - return Json(new NotificationResult { Title = "Failed", Text = "Unable to verify Twitter Authorization", NotificationType = NotificationType.Error }, JsonRequestBehavior.AllowGet); + JsonNotificationResult.Opps("Couldn't verify Twitter Authorization"); + + return JsonNotificationResult.Info("Good News!", "Successfully verified Twitter Authorization."); - return Json(new NotificationResult { Title = "Successfully verified Twitter Authorization." }, JsonRequestBehavior.AllowGet); } } } diff --git a/NzbDrone.Web/Controllers/DirectoryController.cs b/NzbDrone.Web/Controllers/DirectoryController.cs index b4c711171..a7ae263f1 100644 --- a/NzbDrone.Web/Controllers/DirectoryController.cs +++ b/NzbDrone.Web/Controllers/DirectoryController.cs @@ -15,7 +15,7 @@ namespace NzbDrone.Web.Controllers } [HttpPost] - public ActionResult _autoCompletePath(string text, int? filterMode) + public JsonResult _autoCompletePath(string text, int? filterMode) { var data = GetDirectories(text); diff --git a/NzbDrone.Web/Controllers/EpisodeController.cs b/NzbDrone.Web/Controllers/EpisodeController.cs index 06038f350..8b27a5e6a 100644 --- a/NzbDrone.Web/Controllers/EpisodeController.cs +++ b/NzbDrone.Web/Controllers/EpisodeController.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Web.Mvc; +using System.Web.Mvc; using NzbDrone.Core.Jobs; -using NzbDrone.Core.Providers; -using NzbDrone.Core.Providers.Core; using NzbDrone.Web.Models; namespace NzbDrone.Web.Controllers @@ -15,7 +10,6 @@ namespace NzbDrone.Web.Controllers public EpisodeController(JobProvider jobProvider) { - _jobProvider = jobProvider; } @@ -23,44 +17,38 @@ namespace NzbDrone.Web.Controllers public JsonResult Search(int episodeId) { _jobProvider.QueueJob(typeof(EpisodeSearchJob), episodeId); - return new JsonResult { Data = "ok" }; + return JsonNotificationResult.Info("Queued"); } [HttpPost] public JsonResult SearchSeason(int seriesId, int seasonNumber) { _jobProvider.QueueJob(typeof(SeasonSearchJob), seriesId, seasonNumber); - return new JsonResult { Data = "ok" }; + return JsonNotificationResult.Info("Queued"); } public JsonResult BacklogSeries(int seriesId) { - //Syncs the episodes on disk for the specified series _jobProvider.QueueJob(typeof(SeriesSearchJob), seriesId); - - return new JsonResult { Data = "ok", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; + return JsonNotificationResult.Info("Queued"); } public JsonResult Rename(int episodeFileId) { _jobProvider.QueueJob(typeof(RenameEpisodeJob), episodeFileId); - - return new JsonResult { Data = "ok" }; + return JsonNotificationResult.Info("Queued"); } public JsonResult RenameSeason(int seriesId, int seasonNumber) { _jobProvider.QueueJob(typeof(RenameSeasonJob), seriesId, seasonNumber); - - return new JsonResult { Data = "ok" }; + return JsonNotificationResult.Info("Queued"); } public JsonResult RenameEpisodes(int seriesId) { - //Syncs the episodes on disk for the specified series _jobProvider.QueueJob(typeof(RenameSeriesJob), seriesId); - - return new JsonResult { Data = "ok", JsonRequestBehavior = JsonRequestBehavior.AllowGet }; + return JsonNotificationResult.Info("Queued"); } } } \ No newline at end of file diff --git a/NzbDrone.Web/Controllers/HealthController.cs b/NzbDrone.Web/Controllers/HealthController.cs index 6988a2ede..d9f6eaeec 100644 --- a/NzbDrone.Web/Controllers/HealthController.cs +++ b/NzbDrone.Web/Controllers/HealthController.cs @@ -1,15 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Web; -using System.Web.Mvc; +using System.Web.Mvc; namespace NzbDrone.Web.Controllers { public class HealthController : Controller { - // - // GET: /Health/ - [HttpGet] public JsonResult Index() { diff --git a/NzbDrone.Web/Controllers/HistoryController.cs b/NzbDrone.Web/Controllers/HistoryController.cs index 1c430a1ca..f742f4804 100644 --- a/NzbDrone.Web/Controllers/HistoryController.cs +++ b/NzbDrone.Web/Controllers/HistoryController.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Web.Mvc; using NzbDrone.Core.Jobs; -using NzbDrone.Core.Model; using NzbDrone.Core.Providers; using NzbDrone.Web.Models; using Telerik.Web.Mvc; @@ -21,9 +18,6 @@ namespace NzbDrone.Web.Controllers _jobProvider = jobProvider; } - // - // GET: /History/ - public ActionResult Index() { return View(); @@ -32,13 +26,13 @@ namespace NzbDrone.Web.Controllers public JsonResult Trim() { _historyProvider.Trim(); - return Json(new NotificationResult() { Title = "Trimmed History items"}); + return JsonNotificationResult.Info("Trimmed History"); } public JsonResult Purge() { _historyProvider.Purge(); - return Json(new NotificationResult() { Title = "History Cleared" }); + return JsonNotificationResult.Info("History Cleared"); } [HttpPost] @@ -47,7 +41,7 @@ namespace NzbDrone.Web.Controllers //Delete the existing item from history _historyProvider.Delete(historyId); - return Json(new NotificationResult() { Title = "History Item Deleted" }); + return JsonNotificationResult.Info("History Item Deleted"); } [HttpPost] @@ -59,7 +53,7 @@ namespace NzbDrone.Web.Controllers //Queue a job to download the replacement episode _jobProvider.QueueJob(typeof(EpisodeSearchJob), episodeId); - return Json(new NotificationResult() { Title = "Episode Redownload Started" }); + return JsonNotificationResult.Info("Episode Redownload Started"); } [GridAction] diff --git a/NzbDrone.Web/Controllers/LogController.cs b/NzbDrone.Web/Controllers/LogController.cs index 1bbf476ba..d248a51c8 100644 --- a/NzbDrone.Web/Controllers/LogController.cs +++ b/NzbDrone.Web/Controllers/LogController.cs @@ -23,7 +23,7 @@ namespace NzbDrone.Web.Controllers { _logProvider.DeleteAll(); - return Json(new NotificationResult() { Title = "Logs Cleared" }); + return JsonNotificationResult.Info("Logs Cleared"); } [GridAction] diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index dfa2a3d6f..42f53b241 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -112,19 +112,17 @@ namespace NzbDrone.Web.Controllers } [HttpPost] - public JsonResult SaveSeasonIgnore(int seriesId, int seasonNumber, bool ignored) + public EmptyResult SaveSeasonIgnore(int seriesId, int seasonNumber, bool ignored) { _episodeProvider.SetSeasonIgnore(seriesId, seasonNumber, ignored); - - return new JsonResult { Data = "ok" }; + return new EmptyResult(); } [HttpPost] - public JsonResult SaveEpisodeIgnore(int episodeId, bool ignored) + public EmptyResult SaveEpisodeIgnore(int episodeId, bool ignored) { _episodeProvider.SetEpisodeIgnore(episodeId, ignored); - - return new JsonResult { Data = "ok" }; + return new EmptyResult(); } public ActionResult Details(int seriesId) diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 9492194ca..1c84065d6 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -1,20 +1,18 @@ using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Web.Mvc; using NLog; using NzbDrone.Common; using NzbDrone.Common.Model; 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.ExternalNotification; using NzbDrone.Core.Providers.Indexer; using NzbDrone.Core.Repository; using NzbDrone.Core.Repository.Quality; +using NzbDrone.Web.Filters; using NzbDrone.Web.Models; namespace NzbDrone.Web.Controllers @@ -58,7 +56,7 @@ namespace NzbDrone.Web.Controllers results.Add(new TvDbSearchResultModel { Id = 1, Title = "30 Rock", FirstAired = DateTime.Today.ToShortDateString() }); results.Add(new TvDbSearchResultModel { Id = 2, Title = "The Office", FirstAired = DateTime.Today.AddDays(-1).ToShortDateString() }); - return Json(results, JsonRequestBehavior.AllowGet ); + return Json(results, JsonRequestBehavior.AllowGet); } public ActionResult Index() @@ -260,22 +258,15 @@ namespace NzbDrone.Web.Controllers return PartialView("QualityProfileItem", model); } + [JsonErrorFilter] public JsonResult DeleteQualityProfile(int profileId) { - try - { - if (_seriesProvider.GetAllSeries().Where(s => s.QualityProfileId == profileId).Count() != 0) - return new JsonResult { Data = "Unable to delete Profile, it is still in use." }; + if (_seriesProvider.GetAllSeries().Where(s => s.QualityProfileId == profileId).Count() != 0) + return JsonNotificationResult.Opps("Profile is still in use."); - _qualityProvider.Delete(profileId); - } - - catch (Exception) - { - return new JsonResult { Data = "failed" }; - } + _qualityProvider.Delete(profileId); - return new JsonResult { Data = "ok" }; + return new JsonResult(); } public PartialViewResult AddNewznabProvider() @@ -301,19 +292,11 @@ namespace NzbDrone.Web.Controllers return PartialView("NewznabProvider", provider); } - public JsonResult DeleteNewznabProvider(int providerId) + [JsonErrorFilter] + public EmptyResult DeleteNewznabProvider(int providerId) { - try - { - _newznabProvider.Delete(providerId); - } - - catch (Exception) - { - return new JsonResult { Data = "failed" }; - } - - return new JsonResult { Data = "ok" }; + _newznabProvider.Delete(providerId); + return new EmptyResult(); } public QualityModel GetUpdatedProfileList() @@ -324,7 +307,7 @@ namespace NzbDrone.Web.Controllers var selectList = new SelectList(profiles, "QualityProfileId", "Name"); return new QualityModel { DefaultQualityProfileId = defaultQualityQualityProfileId, QualityProfileSelectList = selectList }; - } + } public JsonResult AutoConfigureSab() { @@ -334,19 +317,13 @@ namespace NzbDrone.Web.Controllers if (info != null) return Json(info, JsonRequestBehavior.AllowGet); - - return Json(new NotificationResult - { - Title = "Auto-Configure Failed", - Text = "Please enter your SAB Settings Manually", - NotificationType = NotificationType.Error - }, JsonRequestBehavior.AllowGet); } catch (Exception) { - return new JsonResult { Data = "failed" }; } + + return JsonNotificationResult.Error("Auto-Configure Failed", "Please enter your SAB Settings Manually"); } [HttpPost] @@ -400,11 +377,6 @@ namespace NzbDrone.Web.Controllers { if (ModelState.IsValid) { - //Check to see if the TV Directory matches any RootDirs (Ignoring Case), if it does, return an error to the user - //This prevents a user from finding a way to delete their entire TV Library - var rootDirs = _rootDirProvider.GetAll(); - if (rootDirs.Any(r => r.Path.Equals(data.SabDropDirectory, StringComparison.InvariantCultureIgnoreCase))) - Json(new NotificationResult { Title = "Failed", Text = "Invalid TV Directory", NotificationType = NotificationType.Error }); _configProvider.SabHost = data.SabHost; _configProvider.SabPort = data.SabPort; @@ -419,8 +391,7 @@ namespace NzbDrone.Web.Controllers return GetSuccessResult(); } - return - Json(new NotificationResult() { Title = "Failed", Text = "Invalid request data.", NotificationType = NotificationType.Error }); + return JsonNotificationResult.Opps("Invalid Data"); } [HttpPost] @@ -442,7 +413,7 @@ namespace NzbDrone.Web.Controllers profile.QualityProfileId = profileModel.QualityProfileId; profile.Name = profileModel.Name; profile.Cutoff = profileModel.Cutoff; - + profile.Allowed = new List(); if (profileModel.Sdtv) @@ -506,7 +477,7 @@ namespace NzbDrone.Web.Controllers _configProvider.XbmcPassword = data.XbmcPassword; //SMTP - var smtpSettings = _externalNotificationProvider.GetSettings(typeof (Smtp)); + var smtpSettings = _externalNotificationProvider.GetSettings(typeof(Smtp)); smtpSettings.Enable = data.SmtpEnabled; _externalNotificationProvider.SaveSettings(smtpSettings); @@ -605,18 +576,18 @@ namespace NzbDrone.Web.Controllers private JsonResult GetSuccessResult() { - return Json(new NotificationResult() { Title = "Settings Saved" }); + return JsonNotificationResult.Info("Settings Saved"); } private JsonResult GetInvalidModelResult() { - return Json(new NotificationResult() { Title = "Unable to save setting", Text = "Invalid post data", NotificationType = NotificationType.Error }); + return JsonNotificationResult.Opps("Invalid post data"); } private SelectList GetProwlPrioritySelectList() { var list = new List(); - list.Add(new ProwlPrioritySelectListModel{ Name = "Very Low", Value = -2 }); + list.Add(new ProwlPrioritySelectListModel { Name = "Very Low", Value = -2 }); list.Add(new ProwlPrioritySelectListModel { Name = "Moderate", Value = -1 }); list.Add(new ProwlPrioritySelectListModel { Name = "Normal", Value = 0 }); list.Add(new ProwlPrioritySelectListModel { Name = "High", Value = 1 }); diff --git a/NzbDrone.Web/Controllers/StreamController.cs b/NzbDrone.Web/Controllers/StreamController.cs deleted file mode 100644 index 854c4b298..000000000 --- a/NzbDrone.Web/Controllers/StreamController.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Web; -using System.Web.Mvc; - -namespace NzbDrone.Web.Controllers -{ - public class StreamController : Controller - { - // - // GET: /Stream/ - - public ActionResult Index() - { - return File(@"Z:\Clone High\Season 1\S01E02 - Episode Two- Election Blu-Galoo.avi", "video/divx"); - //return File(@"Z:\30 Rock\Season 5\S05E04 - Live Show (East Coast Taping) - HD TV.mkv", "video/divx"); - } - } -} diff --git a/NzbDrone.Web/Controllers/SystemController.cs b/NzbDrone.Web/Controllers/SystemController.cs index c3b2969c5..f5d0c43df 100644 --- a/NzbDrone.Web/Controllers/SystemController.cs +++ b/NzbDrone.Web/Controllers/SystemController.cs @@ -30,11 +30,12 @@ namespace NzbDrone.Web.Controllers public ActionResult Jobs() { - ViewData["Queue"] = _jobProvider.Queue.Select(c => new JobQueueItemModel { - Name = c.JobType.Name, - TargetId = c.TargetId, - SecondaryTargetId = c.SecondaryTargetId - }); + ViewData["Queue"] = _jobProvider.Queue.Select(c => new JobQueueItemModel + { + Name = c.JobType.Name, + TargetId = c.TargetId, + SecondaryTargetId = c.SecondaryTargetId + }); var jobs = _jobProvider.All(); @@ -139,9 +140,9 @@ namespace NzbDrone.Web.Controllers public JsonResult RunJob(string typeName) { if (!_jobProvider.QueueJob(typeName)) - return Json(new NotificationResult { Title = "Failed to Start Job", Text = "Invalid job name", NotificationType = NotificationType.Error }); + return JsonNotificationResult.Opps("Invalid Job Name"); - return Json(new NotificationResult { Title = "Job Queued" }); + return JsonNotificationResult.Info("Job Queued"); } } } diff --git a/NzbDrone.Web/Controllers/UpdateController.cs b/NzbDrone.Web/Controllers/UpdateController.cs index b1c5bc2a1..0aa08c881 100644 --- a/NzbDrone.Web/Controllers/UpdateController.cs +++ b/NzbDrone.Web/Controllers/UpdateController.cs @@ -39,7 +39,7 @@ namespace NzbDrone.Web.Controllers { _jobProvider.QueueJob(typeof(AppUpdateJob), 0, 0); - return Json(new NotificationResult { Title = "Update will begin shortly", NotificationType = NotificationType.Info, Text = "NzbDrone will restart automatically." }); + return JsonNotificationResult.Info("Update will begin shortly", "NzbDrone will restart automatically."); } public ActionResult ViewLog( string filepath) diff --git a/NzbDrone.Web/Filters/JsonErrorFilter.cs b/NzbDrone.Web/Filters/JsonErrorFilter.cs index 289858ec7..16376ad10 100644 --- a/NzbDrone.Web/Filters/JsonErrorFilter.cs +++ b/NzbDrone.Web/Filters/JsonErrorFilter.cs @@ -6,16 +6,9 @@ namespace NzbDrone.Web.Filters { public class JsonErrorFilter : FilterAttribute, IExceptionFilter { - private readonly string _errorTitle; - - public JsonErrorFilter(string errorTitle) - { - _errorTitle = errorTitle; - } - public void OnException(ExceptionContext filterContext) { - filterContext.Result = NotificationResult.Error(_errorTitle, filterContext.Exception.Message); + filterContext.Result = JsonNotificationResult.Opps(filterContext.Exception.Message); filterContext.ExceptionHandled = true; } diff --git a/NzbDrone.Web/Models/NotificationResult.cs b/NzbDrone.Web/Models/JsonNotificationResult.cs similarity index 61% rename from NzbDrone.Web/Models/NotificationResult.cs rename to NzbDrone.Web/Models/JsonNotificationResult.cs index 223b64f0a..548e88846 100644 --- a/NzbDrone.Web/Models/NotificationResult.cs +++ b/NzbDrone.Web/Models/JsonNotificationResult.cs @@ -2,9 +2,9 @@ using System.Web.Mvc; namespace NzbDrone.Web.Models { - public class NotificationResult + public class JsonNotificationResult { - public NotificationResult() + private JsonNotificationResult() { Text = string.Empty; } @@ -16,7 +16,12 @@ namespace NzbDrone.Web.Models public static JsonResult Info(string title, string text) { - return GetJsonResult(NotificationType.Error, title, text); + return GetJsonResult(NotificationType.Info, title, text); + } + + public static JsonResult Info(string title) + { + return GetJsonResult(NotificationType.Info, title, string.Empty); } public static JsonResult Error(string title, string text) @@ -24,11 +29,17 @@ namespace NzbDrone.Web.Models return GetJsonResult(NotificationType.Error, title, text); } + public static JsonResult Opps(string text) + { + return GetJsonResult(NotificationType.Error, "Opps!", text); + } + + public static JsonResult GetJsonResult(NotificationType notificationType, string title, string text) { return new JsonResult { - Data = new NotificationResult { NotificationType = notificationType, Title = title, Text = text }, + Data = new JsonNotificationResult { NotificationType = notificationType, Title = title, Text = text }, ContentType = null, ContentEncoding = null, JsonRequestBehavior = JsonRequestBehavior.AllowGet diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 965adf7cb..253dd378e 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -213,7 +213,6 @@ - @@ -232,7 +231,7 @@ - +