Adding/Deleting QualityProfiles will now save/delete the profile from the database to make the process less hacky.

RootDir and UserProfileSection do not inherit the master layout automatically.
This commit is contained in:
Mark McDowall 2011-04-21 17:30:19 -07:00
parent a977443676
commit ec8c83760b
8 changed files with 109 additions and 52 deletions

View File

@ -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)

View File

@ -94,7 +94,6 @@ namespace NzbDrone.Web.Controllers
"QualityProfileId",
"Name",
defaultQuality);
;
return PartialView("AddSeriesItem", suggestions);
}

View File

@ -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));
}

View File

@ -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> {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<QualityTypes>();
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);

View File

@ -617,7 +617,6 @@
<Content Include="Views\AddSeries\AddExisting.cshtml" />
<Content Include="Views\AddSeries\AddNew.cshtml" />
<None Include="Views\AddSeries\AddSeriesItem.cshtml" />
<Content Include="Views\Series\SeriesSearchResults2.ascx" />
<Content Include="Web.config">
<SubType>Designer</SubType>
</Content>
@ -635,8 +634,6 @@
<Content Include="Scripts\MicrosoftMvcAjax.debug.js" />
<Content Include="Scripts\MicrosoftMvcValidation.js" />
<Content Include="Scripts\MicrosoftMvcValidation.debug.js" />
<Content Include="Views\Shared\Error.aspx" />
<Content Include="Views\Shared\Site.Master" />
<Content Include="Scripts\jquery-ui.js" />
<Content Include="Scripts\jquery-ui.min.js" />
<Content Include="Scripts\jquery.validate.min.js" />
@ -654,7 +651,6 @@
<Content Include="Views\Settings\Quality.cshtml" />
<Content Include="Views\Settings\RootDir.cshtml" />
<Content Include="Views\Settings\SubMenu.cshtml" />
<Content Include="Views\Settings\UserProfileSection.cshtml" />
<Content Include="Views\Shared\SiteLayout.cshtml" />
<Content Include="Views\Shared\Footer.cshtml" />
<Content Include="Views\Settings\Index.cshtml" />
@ -666,7 +662,9 @@
<Content Include="Views\Series\Edit.cshtml" />
<Content Include="Views\Series\Index.cshtml" />
<Content Include="Views\Series\SubMenu.cshtml" />
<Content Include="Views\Series\SeriesSearchResult.cshtml" />
<Content Include="Views\Series\SeriesSearchResults.cshtml" />
<Content Include="Views\Shared\Error.cshtml" />
<Content Include="Views\Settings\UserProfileSection.cshtml" />
</ItemGroup>
<ItemGroup>
<Folder Include="App_Data\" />

View File

@ -49,11 +49,10 @@
</div>
<div id="user-profiles">
@foreach (var item in Model.UserProfiles)
{
Html.RenderPartial("UserProfileSection", item);
}
@foreach (var item in Model.UserProfiles)
{
Html.RenderAction("GetQualityProfileView", item);
}
</div>
</div>
@ -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);
}
});
}
</script>

View File

@ -1,5 +1,9 @@
@model NzbDrone.Core.Repository.RootDir
@using NzbDrone.Web.Helpers;
@{
Layout = null;
}
<style type="text/css">
.root_dir_text

View File

@ -2,10 +2,15 @@
@using NzbDrone.Core.Repository.Quality
@using NzbDrone.Web.Helpers
@{
Layout = null;
}
@using (Html.BeginCollectionItem("UserProfiles"))
{
var idClean = ViewData.TemplateInfo.HtmlFieldPrefix.Replace('[', '_').Replace(']', '_');
var ugly = ViewData.TemplateInfo.HtmlFieldPrefix;
string sortable1 = String.Format("{0}_sortable1", idClean);
string sortable2 = String.Format("{0}_sortable2", idClean);
@ -13,6 +18,7 @@
string connectedSortable = String.Format("connected{0}", idClean);
string title = String.Format("{0}_Title", idClean);
string nameBox = String.Format("{0}_Name", idClean);
string cutoff = String.Format("{0}.Cutoff", ugly);
<style type="text/css">
.sortable1, .sortable2 { list-style-type: none; margin-right: 10px; background: #eee; padding-left: 5px; padding-right: 5px; padding-top: 0px; padding-bottom: 6px; width: 117px; margin-bottom: 3px; }
@ -35,25 +41,32 @@
create: function (event, ui) {
var order = $('#@sortable1').sortable("toArray");
$("#@allowedStringName>").val(order);
$("#@allowedStringName").val(order);
},
update: function (event, ui) {
var order = $('#@sortable1').sortable("toArray");
$("#@allowedStringName").val(order);
}
//If this is the first QualityType added to the Profile select it as the cutoff value (in-case the user forgets)
var $list = $('#@sortable1 li');
if ($list.length == 1) {
var $radios = $('input[name="@cutoff"]');
$radios.filter('[value=' + order + ']').attr('checked', true);
}
}
}).disableSelection();
});
</script>
<div class="userProfileSectionEditor">
<div class="userProfileSectionEditor" id="div_@(ViewData["ProfileId"])">
<fieldset style="width:285px; margin:5px; margin-top: 0px; border-color:#CCCCCD">
<div id="tester"></div>
<div id="qualityHeader" style="padding-bottom: 5px; margin: 0px;">
<h2 style="display:inline; padding-right: 4px; margin-left: 4px;" id="@title"><@Html.DisplayTextFor(m => m.Name)</h2>
<a href="#" class="deleteRow"><img src="../../Content/Images/X.png" alt="Delete" /></a>
<h2 style="display:inline; padding-right: 4px; margin-left: 4px;" id="@title">@{Html.DisplayTextFor(m => m.Name);}</h2>
<a href="#" id="@Model.QualityProfileId" class="deleteRow" onclick="deleteProfile('@ViewData["ProfileId"]')"><img src="../../Content/Images/X.png" alt="Delete" /></a>
</div>
<div class="config-group" style="width: 250px; margin-bottom: 5px; margin-left: 5px;">
@ -88,10 +101,10 @@
@for (int i = 0; i < qualitiesList.Count(); i++)
{
//Skip Unknown and any item that is in the allowed list
if (qualitiesList[i].ToString() == "Unknown")
{
continue;
}
//if (qualitiesList[i].ToString() == "Unknown")
//{
// continue;
//}
if (Model.Allowed != null)
{