diff --git a/NzbDrone.Core/Providers/QualityProvider.cs b/NzbDrone.Core/Providers/QualityProvider.cs index e7ced8ee8..8be07272e 100644 --- a/NzbDrone.Core/Providers/QualityProvider.cs +++ b/NzbDrone.Core/Providers/QualityProvider.cs @@ -21,9 +21,9 @@ namespace NzbDrone.Core.Providers _sonicRepo = sonicRepo; } - public virtual void Add(QualityProfile profile) + public virtual int Add(QualityProfile profile) { - _sonicRepo.Add(profile); + return Convert.ToInt32(_sonicRepo.Add(profile)); } public virtual void Update(QualityProfile profile) diff --git a/NzbDrone.Web/Controllers/AddSeriesController.cs b/NzbDrone.Web/Controllers/AddSeriesController.cs index 6e6182309..cee3db2c5 100644 --- a/NzbDrone.Web/Controllers/AddSeriesController.cs +++ b/NzbDrone.Web/Controllers/AddSeriesController.cs @@ -94,7 +94,6 @@ namespace NzbDrone.Web.Controllers "QualityProfileId", "Name", defaultQuality); - ; return PartialView("AddSeriesItem", suggestions); } diff --git a/NzbDrone.Web/Controllers/SeriesController.cs b/NzbDrone.Web/Controllers/SeriesController.cs index 100320133..b659ec7da 100644 --- a/NzbDrone.Web/Controllers/SeriesController.cs +++ b/NzbDrone.Web/Controllers/SeriesController.cs @@ -70,22 +70,15 @@ namespace NzbDrone.Web.Controllers var episodes = _episodeProvider.GetEpisodeBySeason(seasonId).Select(c => new EpisodeModel { EpisodeId = c.EpisodeId, - EpisodeNumber = - c.EpisodeNumber, - SeasonNumber = - c.SeasonNumber, + EpisodeNumber = c.EpisodeNumber, + SeasonNumber = c.SeasonNumber, Title = c.Title, Overview = c.Overview, AirDate = c.AirDate, - Path = - GetEpisodePath( - c.EpisodeFile), - Quality = - c.EpisodeFile == null + Path = GetEpisodePath(c.EpisodeFile), + Quality = c.EpisodeFile == null ? String.Empty - : c.EpisodeFile. - Quality. - ToString() + : c.EpisodeFile.Quality.ToString() }); return View(new GridModel(episodes)); } diff --git a/NzbDrone.Web/Controllers/SettingsController.cs b/NzbDrone.Web/Controllers/SettingsController.cs index 15c4a13a4..7505c71f5 100644 --- a/NzbDrone.Web/Controllers/SettingsController.cs +++ b/NzbDrone.Web/Controllers/SettingsController.cs @@ -210,7 +210,35 @@ namespace NzbDrone.Web.Controllers ViewData["Qualities"] = qualityTypes; - return View("UserProfileSection", new QualityProfile { Name = "New Profile", UserProfile = true }); + var qualityProfile = new QualityProfile + { + Name = "New Profile", + UserProfile = true, + Allowed = new List {QualityTypes.Unknown}, + Cutoff = QualityTypes.Unknown, + }; + + var id = _qualityProvider.Add(qualityProfile); + qualityProfile.QualityProfileId = id; + qualityProfile.Allowed = null; + + ViewData["ProfileId"] = id; + + return View("UserProfileSection", qualityProfile); + } + + public ActionResult 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("UserProfileSection", profile); } public ViewResult AddRootDir() @@ -233,6 +261,21 @@ namespace NzbDrone.Web.Controllers return new QualityModel { DefaultQualityProfileId = defaultQualityQualityProfileId, SelectList = selectList }; } + public JsonResult DeleteQualityProfile(int profileId) + { + try + { + _qualityProvider.Delete(profileId); + } + + catch (Exception) + { + return new JsonResult { Data = "failed" }; + } + + return new JsonResult { Data = "ok" }; + } + [HttpPost] public ActionResult SaveGeneral(SettingsModel data) { @@ -343,12 +386,6 @@ namespace NzbDrone.Web.Controllers if (data.UserProfiles == null) return Content(SETTINGS_SAVED); - foreach (var dbProfile in _qualityProvider.GetAllProfiles().Where(q => q.UserProfile)) - { - if (!data.UserProfiles.Exists(p => p.QualityProfileId == dbProfile.QualityProfileId)) - _qualityProvider.Delete(dbProfile.QualityProfileId); - } - foreach (var profile in data.UserProfiles) { Logger.Debug(String.Format("Updating User Profile: {0}", profile)); @@ -365,14 +402,9 @@ namespace NzbDrone.Web.Controllers return Content("Error Saving Settings, please fix any errors"); //profile.Cutoff = profile.Allowed.Last(); - if (profile.QualityProfileId > 0) - _qualityProvider.Update(profile); - - else - _qualityProvider.Add(profile); - - return Content(SETTINGS_SAVED); + _qualityProvider.Update(profile); } + return Content(SETTINGS_SAVED); } return Content(SETTINGS_FAILED); diff --git a/NzbDrone.Web/NzbDrone.Web.csproj b/NzbDrone.Web/NzbDrone.Web.csproj index 005585fd1..801ac9c28 100644 --- a/NzbDrone.Web/NzbDrone.Web.csproj +++ b/NzbDrone.Web/NzbDrone.Web.csproj @@ -617,7 +617,6 @@ - Designer @@ -635,8 +634,6 @@ - - @@ -654,7 +651,6 @@ - @@ -666,7 +662,9 @@ - + + + diff --git a/NzbDrone.Web/Views/Settings/Quality.cshtml b/NzbDrone.Web/Views/Settings/Quality.cshtml index c65215dc9..4fe3b6a28 100644 --- a/NzbDrone.Web/Views/Settings/Quality.cshtml +++ b/NzbDrone.Web/Views/Settings/Quality.cshtml @@ -49,11 +49,10 @@
- - @foreach (var item in Model.UserProfiles) - { - Html.RenderPartial("UserProfileSection", item); - } + @foreach (var item in Model.UserProfiles) + { + Html.RenderAction("GetQualityProfileView", item); + }
@@ -77,8 +76,27 @@ return false; }); - $("a.deleteRow").live("click", function () { - $(this).parents("div.userProfileSectionEditor:first").remove(); - return false; - }); +// $("a.deleteRow").live("click", function () { +// $(this).parents("div.userProfileSectionEditor:first").remove(); +// return false; + // }); + + var deleteQualityProfileUrl = '@Url.Action("DeleteQualityProfile", "Settings")'; + + function deleteProfile(id) { + //$(this).parents("div.userProfileSectionEditor:first").remove(); + sendToServer(id); + $("#div_" + id).hide(); + } + + function sendToServer(id) { + $.ajax({ + type: "POST", + url: deleteQualityProfileUrl, + data: jQuery.param({ profileId: id }), + error: function (req, status, error) { + alert("Sorry! We could not add " + path + " at this time. " + error); + } + }); + } \ No newline at end of file diff --git a/NzbDrone.Web/Views/Settings/RootDir.cshtml b/NzbDrone.Web/Views/Settings/RootDir.cshtml index b1f2da5ee..5ebe8ed1f 100644 --- a/NzbDrone.Web/Views/Settings/RootDir.cshtml +++ b/NzbDrone.Web/Views/Settings/RootDir.cshtml @@ -1,5 +1,9 @@ @model NzbDrone.Core.Repository.RootDir @using NzbDrone.Web.Helpers; + +@{ + Layout = null; +}