From 822de39a9e0002279224908093fd458e599d9aba Mon Sep 17 00:00:00 2001 From: Taloth Saldono Date: Wed, 9 Jul 2014 21:35:05 +0200 Subject: [PATCH] Changed the way additional validation details get sent the UI. --- .../Download/Clients/Sabnzbd/Sabnzbd.cs | 19 +++++++-- src/NzbDrone.Core/NzbDrone.Core.csproj | 1 + .../Validation/NzbDroneValidationFailure.cs | 20 +++++++++ src/UI/Content/form.less | 7 ++++ src/UI/jQuery/jquery.validation.js | 42 ++++++++++++++++--- 5 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 src/NzbDrone.Core/Validation/NzbDroneValidationFailure.cs diff --git a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs index 4b98f55d6..3e5a1e812 100644 --- a/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs +++ b/src/NzbDrone.Core/Download/Clients/Sabnzbd/Sabnzbd.cs @@ -11,6 +11,7 @@ using NzbDrone.Core.Configuration; using NzbDrone.Core.Indexers; using NzbDrone.Core.Parser; using NzbDrone.Core.Parser.Model; +using NzbDrone.Core.Validation; namespace NzbDrone.Core.Download.Clients.Sabnzbd { @@ -312,14 +313,22 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd { if (category.Dir.EndsWith("*")) { - return new ValidationFailure(String.Empty, String.Format("Remove * from Sabnzbd '{2}' category Folder/Path so job folders will be created", Settings.Host, Settings.Port, Settings.TvCategory)); + return new NzbDroneValidationFailure("TvCategory", "Enable Job folders") + { + InfoLink = String.Format("http://{0}:{1}/sabnzbd/config/categories/", Settings.Host, Settings.Port), + DetailedDescription = "NzbDrone prefers each download to have a separate folder. With * appended to the Folder/Path Sabnzbd will not create these job folders. Go to Sabnzbd to fix it." + }; } } else { if (!Settings.TvCategory.IsNullOrWhiteSpace()) { - return new ValidationFailure("TvCategory", String.Format("Category does not exist", Settings.Host, Settings.Port)); + return new NzbDroneValidationFailure("TvCategory", "Category does not exist") + { + InfoLink = String.Format("http://{0}:{1}/sabnzbd/config/categories/", Settings.Host, Settings.Port), + DetailedDescription = "The Category your entered doesn't exist in Sabnzbd. Go to Sabnzbd to create it." + }; } } @@ -329,7 +338,11 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd config.Misc.tv_categories.Contains(Settings.TvCategory) || (Settings.TvCategory.IsNullOrWhiteSpace() && config.Misc.tv_categories.Contains("Default"))) { - return new ValidationFailure(String.Empty, String.Format("Disable TV Sorting for the '{2}' category", Settings.Host, Settings.Port, Settings.TvCategory)); + return new NzbDroneValidationFailure("TvCategory", "Disable TV Sorting") + { + InfoLink = String.Format("http://{0}:{1}/sabnzbd/config/sorting/", Settings.Host, Settings.Port), + DetailedDescription = "You must disable Sabnzbd TV Sorting for the category NzbDrone uses to prevent import issues. Go to Sabnzbd to fix it." + }; } } diff --git a/src/NzbDrone.Core/NzbDrone.Core.csproj b/src/NzbDrone.Core/NzbDrone.Core.csproj index 34d3e69c3..f78805864 100644 --- a/src/NzbDrone.Core/NzbDrone.Core.csproj +++ b/src/NzbDrone.Core/NzbDrone.Core.csproj @@ -725,6 +725,7 @@ + diff --git a/src/NzbDrone.Core/Validation/NzbDroneValidationFailure.cs b/src/NzbDrone.Core/Validation/NzbDroneValidationFailure.cs new file mode 100644 index 000000000..5eaea8862 --- /dev/null +++ b/src/NzbDrone.Core/Validation/NzbDroneValidationFailure.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using FluentValidation.Results; + +namespace NzbDrone.Core.Validation +{ + public class NzbDroneValidationFailure : ValidationFailure + { + public String DetailedDescription { get; set; } + public String InfoLink { get; set; } + + public NzbDroneValidationFailure(String propertyName, String error) + : base(propertyName, error) + { + + } + } +} diff --git a/src/UI/Content/form.less b/src/UI/Content/form.less index 66bf13a81..ee8112e89 100644 --- a/src/UI/Content/form.less +++ b/src/UI/Content/form.less @@ -88,6 +88,13 @@ h3 { } } +.validation-error { + i { + text-decoration: none; + color: #b94a48; + } +} + // Tooltips .help-inline-checkbox, .help-inline { diff --git a/src/UI/jQuery/jquery.validation.js b/src/UI/jQuery/jquery.validation.js index 00f07e24b..fc5abc709 100644 --- a/src/UI/jQuery/jquery.validation.js +++ b/src/UI/jQuery/jquery.validation.js @@ -8,9 +8,16 @@ define( var validationName = error.propertyName.toLowerCase(); + var errorMessage = this.formatErrorMessage(error); + this.find('.validation-errors') .addClass('alert alert-danger') - .append('
' + error.errorMessage + '
'); + .append('
' + errorMessage + '
'); + + if (!validationName || validationName === "") { + this.addFormError(error); + return; + } var input = this.find('[name]').filter(function () { return this.name.toLowerCase() === validationName; @@ -38,11 +45,11 @@ define( var inputGroup = controlGroup.find('.input-group'); if (inputGroup.length === 0) { - controlGroup.append('' + error.errorMessage + ''); + controlGroup.append('' + errorMessage + ''); } else { - inputGroup.parent().append('' + error.errorMessage + ''); + inputGroup.parent().append('' + errorMessage + ''); } } @@ -57,12 +64,15 @@ define( }; $.fn.addFormError = function (error) { + + var errorMessage = this.formatErrorMessage(error); + if (this.find('.modal-body')) { - this.find('.modal-body').prepend('
' + error.errorMessage + '
'); + this.find('.modal-body').prepend('
' + errorMessage + '
'); } - + else { - this.prepend('
' + error.errorMessage + '
'); + this.prepend('
' + errorMessage + '
'); } }; @@ -74,4 +84,24 @@ define( return this.find('.help-inline.error-message').remove(); }; + $.fn.formatErrorMessage = function (error) { + + var errorMessage = error.errorMessage; + var infoLink = ""; + + if (error.infoLink) { + if (error.detailedDescription) { + errorMessage += " "; + } + else { + errorMessage += " "; + } + } + else if (error.detailedDescription) { + errorMessage += " "; + } + + return errorMessage; + } + });