New: Match only custom formats with score

This commit is contained in:
Bogdan 2024-07-09 18:35:58 +03:00
parent e97e5bfe8f
commit 5b41c710f6
6 changed files with 28 additions and 7 deletions

View File

@ -56,13 +56,13 @@ class QualityProfileFormatItem extends Component {
QualityProfileFormatItem.propTypes = {
formatId: PropTypes.number.isRequired,
name: PropTypes.string.isRequired,
score: PropTypes.number.isRequired,
score: PropTypes.number,
onScoreChange: PropTypes.func
};
QualityProfileFormatItem.defaultProps = {
// To handle the case score is deleted during edit
score: 0
score: null
};
export default QualityProfileFormatItem;

View File

@ -18,9 +18,18 @@ function calcOrder(profileFormatItems) {
return [...profileFormatItems].sort((a, b) => {
if (b.score !== a.score) {
if (a.score === null) {
return 1;
}
if (b.score === null) {
return -1;
}
return b.score - a.score;
}
return a.name > b.name ? 1 : -1;
return a.name.localeCompare(b.name);
}).map((x) => items[x.format]);
}

View File

@ -148,7 +148,16 @@ namespace NzbDrone.Core.CustomFormats
{
var matches = new List<CustomFormat>();
foreach (var customFormat in allCustomFormats)
var profileFormatItems = input.Series?.QualityProfile?.Value?.FormatItems
.Where(f => f.Score.HasValue)
.Select(f => f.Format)
.ToList();
var customFormats = profileFormatItems == null
? allCustomFormats
: allCustomFormats.Intersect(profileFormatItems).ToList();
foreach (var customFormat in customFormats)
{
var specificationMatches = customFormat.Specifications
.GroupBy(t => t.GetType())

View File

@ -6,6 +6,6 @@ namespace NzbDrone.Core.Profiles
public class ProfileFormatItem : IEmbeddedDocument
{
public CustomFormat Format { get; set; }
public int Score { get; set; }
public int? Score { get; set; }
}
}

View File

@ -89,7 +89,7 @@ namespace NzbDrone.Core.Profiles.Qualities
public int CalculateCustomFormatScore(List<CustomFormat> formats)
{
return FormatItems.Where(x => formats.Contains(x.Format)).Sum(x => x.Score);
return FormatItems.Where(x => x.Score.HasValue && formats.Contains(x.Format)).Sum(x => x.Score.Value);
}
}
}

View File

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using NzbDrone.Core.CustomFormats;
using NzbDrone.Core.Profiles;
using NzbDrone.Core.Profiles.Qualities;
@ -35,7 +36,9 @@ namespace Sonarr.Api.V3.Profiles.Quality
{
public int Format { get; set; }
public string Name { get; set; }
public int Score { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public int? Score { get; set; }
}
public static class ProfileResourceMapper