mirror of
https://github.com/lidarr/Lidarr
synced 2025-01-03 05:25:10 +00:00
Validation changes, moved JS for Client-Side validation to Settings/Index.aspx
Still need to sort out validation for Quality Cutoff (not part of the Model so it seems to cause issues).
This commit is contained in:
parent
baeda11ece
commit
b2524cf697
5 changed files with 29 additions and 27 deletions
|
@ -11,6 +11,7 @@ public class QualityProfile
|
||||||
[SubSonicPrimaryKey(true)]
|
[SubSonicPrimaryKey(true)]
|
||||||
public int ProfileId { get; set; }
|
public int ProfileId { get; set; }
|
||||||
|
|
||||||
|
[Required (ErrorMessage = "A Name is Required")]
|
||||||
[DisplayName("Name")]
|
[DisplayName("Name")]
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public bool UserProfile { get; set; } //Allows us to tell the difference between default and user profiles
|
public bool UserProfile { get; set; } //Allows us to tell the difference between default and user profiles
|
||||||
|
|
|
@ -304,36 +304,38 @@ public ActionResult SaveQuality(QualityModel data)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_configProvider.SetValue("DefaultQualityProfile", data.DefaultProfileId.ToString());
|
if (ModelState.IsValid)
|
||||||
|
|
||||||
foreach (var dbProfile in _qualityProvider.GetAllProfiles().Where(q => q.UserProfile))
|
|
||||||
{
|
{
|
||||||
if (!data.UserProfiles.Exists(p => p.ProfileId == dbProfile.ProfileId))
|
_configProvider.SetValue("DefaultQualityProfile", data.DefaultProfileId.ToString());
|
||||||
_qualityProvider.Delete(dbProfile.ProfileId);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
foreach (var dbProfile in _qualityProvider.GetAllProfiles().Where(q => q.UserProfile))
|
||||||
foreach (var profile in data.UserProfiles)
|
|
||||||
{
|
|
||||||
Logger.Debug(String.Format("Updating User Profile: {0}", profile));
|
|
||||||
|
|
||||||
profile.Allowed = new List<QualityTypes>();
|
|
||||||
foreach (var quality in profile.AllowedString.Split(','))
|
|
||||||
{
|
{
|
||||||
var qType = (QualityTypes)Enum.Parse(typeof(QualityTypes), quality);
|
if (!data.UserProfiles.Exists(p => p.ProfileId == dbProfile.ProfileId))
|
||||||
profile.Allowed.Add(qType);
|
_qualityProvider.Delete(dbProfile.ProfileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//If the Cutoff value selected is not in the allowed list then use the last allowed value, this should be validated on submit
|
foreach (var profile in data.UserProfiles)
|
||||||
if (!profile.Allowed.Contains(profile.Cutoff))
|
{
|
||||||
throw new InvalidOperationException("Invalid Cutoff Value");
|
Logger.Debug(String.Format("Updating User Profile: {0}", profile));
|
||||||
//profile.Cutoff = profile.Allowed.Last();
|
|
||||||
|
|
||||||
if (profile.ProfileId > 0)
|
profile.Allowed = new List<QualityTypes>();
|
||||||
_qualityProvider.Update(profile);
|
foreach (var quality in profile.AllowedString.Split(','))
|
||||||
|
{
|
||||||
|
var qType = (QualityTypes) Enum.Parse(typeof (QualityTypes), quality);
|
||||||
|
profile.Allowed.Add(qType);
|
||||||
|
}
|
||||||
|
|
||||||
else
|
//If the Cutoff value selected is not in the allowed list then use the last allowed value, this should be validated on submit
|
||||||
_qualityProvider.Add(profile);
|
if (!profile.Allowed.Contains(profile.Cutoff))
|
||||||
|
throw new InvalidOperationException("Invalid Cutoff Value");
|
||||||
|
//profile.Cutoff = profile.Allowed.Last();
|
||||||
|
|
||||||
|
if (profile.ProfileId > 0)
|
||||||
|
_qualityProvider.Update(profile);
|
||||||
|
|
||||||
|
else
|
||||||
|
_qualityProvider.Add(profile);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,6 @@ public class QualityModel
|
||||||
{
|
{
|
||||||
public List<QualityProfile> Profiles { get; set; }
|
public List<QualityProfile> Profiles { get; set; }
|
||||||
public List<QualityProfile> UserProfiles { get; set; }
|
public List<QualityProfile> UserProfiles { get; set; }
|
||||||
//public List<QualityTypes> Qualities { get; set; }
|
|
||||||
|
|
||||||
[DisplayName("Default Quality Profile")]
|
[DisplayName("Default Quality Profile")]
|
||||||
public int DefaultProfileId { get; set; }
|
public int DefaultProfileId { get; set; }
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
|
|
||||||
<script src="/Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
|
|
||||||
<% Html.EnableClientValidation(); %>
|
<% Html.EnableClientValidation(); %>
|
||||||
|
|
||||||
<% using (Html.BeginForm("SaveDownloads", "Settings", FormMethod.Post, new { id = "form", name = "form" }))
|
<% using (Html.BeginForm("SaveDownloads", "Settings", FormMethod.Post, new { id = "form", name = "form" }))
|
||||||
|
|
|
@ -26,11 +26,13 @@
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<% Html.EnableClientValidation(); %>
|
||||||
|
|
||||||
<% using (Html.BeginForm("SaveQuality", "Settings", FormMethod.Post, new { id = "form", name = "form" }))
|
<% using (Html.BeginForm("SaveQuality", "Settings", FormMethod.Post, new { id = "form", name = "form" }))
|
||||||
{%>
|
{%>
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Quality</legend>
|
<legend>Quality</legend>
|
||||||
<%: Html.ValidationSummary(true, "Unable to save your settings. Please correct the errors and try again.") %>
|
<%--<%: Html.ValidationSummary(true, "Unable to save your settings. Please correct the errors and try again.") %>--%>
|
||||||
|
|
||||||
<div class="rightSide" style="float: right; width: 65%;">
|
<div class="rightSide" style="float: right; width: 65%;">
|
||||||
<div id="defaultQualityDiv" style="float: left; margin: 30px;">
|
<div id="defaultQualityDiv" style="float: left; margin: 30px;">
|
||||||
|
|
Loading…
Reference in a new issue