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 8a19305b6..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); } @@ -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); } 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 19e049898..ac4cc469b 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -221,6 +221,7 @@ + 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/Test.cshtml b/NzbDrone.Web/Views/Settings/Test.cshtml index 9cfd89666..12100aa1e 100644 --- a/NzbDrone.Web/Views/Settings/Test.cshtml +++ b/NzbDrone.Web/Views/Settings/Test.cshtml @@ -1,30 +1,12 @@ -@{ Layout = null; } - - - - -
-
- Local Series Search - -
-
-
- Search
-
-
-
+ + + + + \ No newline at end of file