diff --git a/NzbDrone.Core/Repository/Quality/QualityProfile.cs b/NzbDrone.Core/Repository/Quality/QualityProfile.cs index cb7571630..f11f8e640 100644 --- a/NzbDrone.Core/Repository/Quality/QualityProfile.cs +++ b/NzbDrone.Core/Repository/Quality/QualityProfile.cs @@ -12,23 +12,13 @@ namespace NzbDrone.Core.Repository.Quality public class QualityProfile { public virtual int QualityProfileId { get; set; } - - [Required(ErrorMessage = "A Name is Required")] - [DisplayName("Name")] - [DisplayFormat(ConvertEmptyStringToNull = false)] public string Name { get; set; } [Ignore] - [DisplayName("Allowed Qualities")] public List Allowed { get; set; } [Ignore] - [DisplayName("Allowed Qualities String")] - [DisplayFormat(ConvertEmptyStringToNull = false)] public string AllowedString { get; set; } - - [DisplayName("Cut-off")] - [Required(ErrorMessage = "Valid Cut-off is Required")] public QualityTypes Cutoff { get; set; } [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 956abc48c..4d1390378 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -120,29 +120,14 @@ namespace NzbDrone.Web.Controllers public ActionResult Quality() { - var qualityTypes = new List(); - - foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes))) - { - qualityTypes.Add(qual); - } - - ViewData["Qualities"] = qualityTypes; - var profiles = _qualityProvider.All().ToList(); - foreach (var qualityProfile in profiles) - { - qualityProfile.AllowedString = string.Join(",", qualityProfile.Allowed); - } - var defaultQualityQualityProfileId = Convert.ToInt32(_configProvider.DefaultQualityProfile); var qualityProfileSelectList = new SelectList(profiles, "QualityProfileId", "Name"); var qualityTypesFromDb = _qualityTypeProvider.All(); var model = new QualityModel { - Profiles = profiles, DefaultQualityProfileId = defaultQualityQualityProfileId, QualityProfileSelectList = qualityProfileSelectList, SdtvMaxSize = qualityTypesFromDb.Single(q => q.QualityTypeId == 1).MaxSize, @@ -153,6 +138,8 @@ namespace NzbDrone.Web.Controllers Bluray1080pMaxSize = qualityTypesFromDb.Single(q => q.QualityTypeId == 7).MaxSize }; + ViewData["Profiles"] = profiles; + return View(model); } @@ -197,9 +184,9 @@ namespace NzbDrone.Web.Controllers return View(model); } - public ActionResult EpisodeSorting() + public ActionResult Naming() { - var model = new EpisodeSortingModel(); + var model = new EpisodeNamingModel(); model.SeriesName = _configProvider.SortingIncludeSeriesName; model.EpisodeName = _configProvider.SortingIncludeEpisodeTitle; @@ -239,17 +226,8 @@ namespace NzbDrone.Web.Controllers return View(model); } - public ViewResult AddProfile() + public PartialViewResult AddProfile() { - var qualityTypes = new List(); - - foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes))) - { - qualityTypes.Add(qual); - } - - ViewData["Qualities"] = qualityTypes; - var qualityProfile = new QualityProfile { Name = "New Profile", @@ -257,28 +235,25 @@ namespace NzbDrone.Web.Controllers Cutoff = QualityTypes.Unknown }; - var id = _qualityProvider.Add(qualityProfile); - qualityProfile.QualityProfileId = id; - qualityProfile.AllowedString = "Unknown"; - - ViewData["ProfileId"] = id; + qualityProfile.QualityProfileId = _qualityProvider.Add(qualityProfile); - return View("QualityProfileItem", qualityProfile); + return GetQualityProfileView(qualityProfile); } - public ActionResult GetQualityProfileView(QualityProfile profile) + public PartialViewResult GetQualityProfileView(QualityProfile profile) { - var qualityTypes = new List(); - - foreach (QualityTypes qual in Enum.GetValues(typeof(QualityTypes))) - { - qualityTypes.Add(qual); - } - - ViewData["Qualities"] = qualityTypes; - ViewData["ProfileId"] = profile.QualityProfileId; - - return PartialView("QualityProfileItem", profile); + var model = new QualityProfileModel(); + model.QualityProfileId = profile.QualityProfileId; + model.Name = profile.Name; + model.Allowed = profile.Allowed; + model.Sdtv = profile.Allowed.Contains(QualityTypes.SDTV); + model.Dvd = profile.Allowed.Contains(QualityTypes.DVD); + model.Hdtv = profile.Allowed.Contains(QualityTypes.HDTV); + model.Webdl = profile.Allowed.Contains(QualityTypes.WEBDL); + model.Bluray720p = profile.Allowed.Contains(QualityTypes.Bluray720p); + model.Bluray1080p = profile.Allowed.Contains(QualityTypes.Bluray1080p); + + return PartialView("QualityProfileItem", model); } public JsonResult DeleteQualityProfile(int profileId) @@ -451,25 +426,38 @@ namespace NzbDrone.Web.Controllers if (data.Profiles == null) return GetSuccessResult(); - foreach (var profile in data.Profiles) + foreach (var profileModel in data.Profiles) { - Logger.Debug(String.Format("Updating Profile: {0}", profile)); + Logger.Debug(String.Format("Updating Profile: {0}", profileModel)); + var profile = new QualityProfile(); + profile.QualityProfileId = profileModel.QualityProfileId; + profile.Name = profileModel.Name; + profile.Cutoff = profileModel.Cutoff; + profile.Allowed = new List(); - //Remove the extra comma from the end - profile.AllowedString = profile.AllowedString.Trim(','); + if (profileModel.Sdtv) + profile.Allowed.Add(QualityTypes.SDTV); + + if (profileModel.Dvd) + profile.Allowed.Add(QualityTypes.DVD); + + if (profileModel.Hdtv) + profile.Allowed.Add(QualityTypes.HDTV); + + if (profileModel.Webdl) + profile.Allowed.Add(QualityTypes.WEBDL); + + if (profileModel.Bluray720p) + profile.Allowed.Add(QualityTypes.Bluray720p); - foreach (var quality in profile.AllowedString.Split(',')) - { - var qType = (QualityTypes)Enum.Parse(typeof(QualityTypes), quality); - profile.Allowed.Add(qType); - } + if (profileModel.Bluray1080p) + profile.Allowed.Add(QualityTypes.Bluray1080p); - //If the Cutoff value selected is not in the allowed list then use the last allowed value, this should be validated on submit + //If the Cutoff value selected is not in the allowed list then return an error if (!profile.Allowed.Contains(profile.Cutoff)) return GetInvalidModelResult(); - //profile.Cutoff = profile.Allowed.Last(); _qualityProvider.Update(profile); } @@ -559,7 +547,7 @@ namespace NzbDrone.Web.Controllers } [HttpPost] - public JsonResult SaveEpisodeSorting(EpisodeSortingModel data) + public JsonResult SaveNaming(EpisodeNamingModel data) { if (ModelState.IsValid) { diff --git a/NzbDrone.Web/Models/EpisodeSortingModel.cs b/NzbDrone.Web/Models/EpisodeNamingModel.cs similarity index 98% rename from NzbDrone.Web/Models/EpisodeSortingModel.cs rename to NzbDrone.Web/Models/EpisodeNamingModel.cs index 0f21794c2..1c9f40bbe 100644 --- a/NzbDrone.Web/Models/EpisodeSortingModel.cs +++ b/NzbDrone.Web/Models/EpisodeNamingModel.cs @@ -4,7 +4,7 @@ using System.Web.Mvc; namespace NzbDrone.Web.Models { - public class EpisodeSortingModel + public class EpisodeNamingModel { [DisplayName("Series Name")] [Description("Should filenames contain the series name when renamed?")] diff --git a/NzbDrone.Web/Models/CodeFile1.cs b/NzbDrone.Web/Models/FooterModel.cs similarity index 100% rename from NzbDrone.Web/Models/CodeFile1.cs rename to NzbDrone.Web/Models/FooterModel.cs diff --git a/NzbDrone.Web/Models/QualityModel.cs b/NzbDrone.Web/Models/QualityModel.cs index 27796406b..a0ee8041d 100644 --- a/NzbDrone.Web/Models/QualityModel.cs +++ b/NzbDrone.Web/Models/QualityModel.cs @@ -7,7 +7,7 @@ namespace NzbDrone.Web.Models { public class QualityModel { - public List Profiles { get; set; } + public List Profiles { get; set; } [DisplayName("Default Quality Profile")] [Description("The default quality to use when adding series to NzbDrone")] diff --git a/NzbDrone.Web/Models/QualityProfileModel.cs b/NzbDrone.Web/Models/QualityProfileModel.cs new file mode 100644 index 000000000..0d7db88b2 --- /dev/null +++ b/NzbDrone.Web/Models/QualityProfileModel.cs @@ -0,0 +1,45 @@ +using System.Collections.Generic; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Web.Mvc; +using NzbDrone.Core.Repository.Quality; +using PetaPoco; + +namespace NzbDrone.Web.Models +{ + public class QualityProfileModel + { + public int QualityProfileId { get; set; } + + [Required(ErrorMessage = "A Name is Required")] + [DisplayName("Name")] + [DisplayFormat(ConvertEmptyStringToNull = false)] + public string Name { get; set; } + + [DisplayName("Cut-off")] + [Required(ErrorMessage = "Valid Cut-off is Required")] + public QualityTypes Cutoff { get; set; } + + [DisplayName("Allowed Qualities")] + public List Allowed { get; set; } + + //Quality Booleans + [DisplayName("SDTV")] + public bool Sdtv { get; set; } + + [DisplayName("DVD")] + public bool Dvd { get; set; } + + [DisplayName("HDTV")] + public bool Hdtv { get; set; } + + [DisplayName("WEBDL")] + public bool Webdl { get; set; } + + [DisplayName("Bluray720p")] + public bool Bluray720p { get; set; } + + [DisplayName("Bluray1080p")] + public bool Bluray1080p { get; set; } + } +} \ No newline at end of file diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 466fdcddb..ac4cc469b 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -221,7 +221,8 @@ - + + @@ -231,7 +232,7 @@ - + @@ -408,7 +409,7 @@ - + diff --git a/NzbDrone.Web/Views/Settings/EpisodeSorting.cshtml b/NzbDrone.Web/Views/Settings/Naming.cshtml similarity index 88% rename from NzbDrone.Web/Views/Settings/EpisodeSorting.cshtml rename to NzbDrone.Web/Views/Settings/Naming.cshtml index bcb95299a..b9ac80acd 100644 --- a/NzbDrone.Web/Views/Settings/EpisodeSorting.cshtml +++ b/NzbDrone.Web/Views/Settings/Naming.cshtml @@ -1,5 +1,5 @@ @using NzbDrone.Web.Helpers -@model NzbDrone.Web.Models.EpisodeSortingModel +@model NzbDrone.Web.Models.EpisodeNamingModel @section HeaderContent{ @@ -7,10 +7,15 @@ } @@ -24,8 +29,9 @@ @section MainContent{
- @using (Html.BeginForm("SaveEpisodeSorting", "Settings", FormMethod.Post, new { id = "form", name = "form", @class = "settingsForm" })) + @using (Html.BeginForm("SaveNaming", "Settings", FormMethod.Post, new { id = "form", name = "form", @class = "settingsForm" })) { +
@Html.ValidationSummary(true, "Unable to save your settings. Please correct the errors and try again.") @Html.DropDownListFor(m => m.MultiEpisodeStyle, Model.MultiEpisodeStyles, new { @class = "inputClass selectClass" }) - +
-
-
+
Single Episode Example:
+
Multi-Episode Example:
@@ -129,9 +135,9 @@ if ($('#ReplaceSpaces').attr('checked')) result = result.replace(/\s/g, '.'); - result = 'Single Episode Example: ' + result; + //result = 'Single Episode Example: ' + result; - $('#singleEpisodeExample').html(result); + $('#singleEpisodeExample').children('.result').text(result); } function createMultiEpisodeExample() { @@ -194,9 +200,9 @@ if ($('#ReplaceSpaces').attr('checked')) result = result.replace(/\s/g, '.'); - result = 'Multi-Episode Example: ' + result; + //result = 'Multi-Episode Example: ' + result; - $('#multiEpisodeExample').html(result); + $('#multiEpisodeExample').children('.result').text(result); } } diff --git a/NzbDrone.Web/Views/Settings/Quality.cshtml b/NzbDrone.Web/Views/Settings/Quality.cshtml index 5d69c5322..55409cdd9 100644 --- a/NzbDrone.Web/Views/Settings/Quality.cshtml +++ b/NzbDrone.Web/Views/Settings/Quality.cshtml @@ -1,4 +1,5 @@ -@using NzbDrone.Web.Helpers; +@using NzbDrone.Core.Repository.Quality +@using NzbDrone.Web.Helpers; @model NzbDrone.Web.Models.QualityModel @section HeaderContent{ @@ -73,7 +74,7 @@ Settings > Quality Add New Profile
- @foreach (var item in Model.Profiles) + @foreach (var item in (List)ViewData["Profiles"]) { Html.RenderAction("GetQualityProfileView", item); } @@ -91,6 +92,12 @@ Settings > Quality type="text/javascript"> \ No newline at end of file diff --git a/NzbDrone.Web/Views/Settings/SubMenu.cshtml b/NzbDrone.Web/Views/Settings/SubMenu.cshtml index 48ffe01ac..f55d5bb49 100644 --- a/NzbDrone.Web/Views/Settings/SubMenu.cshtml +++ b/NzbDrone.Web/Views/Settings/SubMenu.cshtml @@ -1,6 +1,6 @@