mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-24 09:44:47 +03:00
support grouping behind boxsets
This commit is contained in:
@@ -238,6 +238,9 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
|
||||
[ApiMember(Name = "HasOfficialRating", Description = "Optional filter by items that have official ratings", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")]
|
||||
public bool? HasOfficialRating { get; set; }
|
||||
|
||||
[ApiMember(Name = "CollapseBoxSetItems", Description = "Whether or not to hide items behind their boxsets.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
|
||||
public bool CollapseBoxSetItems { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -315,6 +318,11 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
|
||||
items = items.AsEnumerable();
|
||||
|
||||
if (request.CollapseBoxSetItems)
|
||||
{
|
||||
items = CollapseItemsWithinBoxSets(items, user);
|
||||
}
|
||||
|
||||
items = ApplySortOrder(request, items, user, _libraryManager);
|
||||
|
||||
// This must be the last filter
|
||||
@@ -1218,6 +1226,41 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
return false;
|
||||
}
|
||||
|
||||
private IEnumerable<BaseItem> CollapseItemsWithinBoxSets(IEnumerable<BaseItem> items, User user)
|
||||
{
|
||||
var itemsToCollapse = new List<ISupportsBoxSetGrouping>();
|
||||
var boxsets = new List<BaseItem>();
|
||||
|
||||
var list = items.ToList();
|
||||
|
||||
foreach (var item in list.OfType<ISupportsBoxSetGrouping>())
|
||||
{
|
||||
var currentBoxSets = item.BoxSetIdList
|
||||
.Select(i => _libraryManager.GetItemById(i))
|
||||
.Where(i => i != null && i.IsVisible(user))
|
||||
.ToList();
|
||||
|
||||
if (currentBoxSets.Count > 0)
|
||||
{
|
||||
itemsToCollapse.Add(item);
|
||||
boxsets.AddRange(currentBoxSets);
|
||||
}
|
||||
}
|
||||
|
||||
return list.Except(itemsToCollapse.Cast<BaseItem>()).Concat(boxsets).Distinct();
|
||||
}
|
||||
|
||||
private bool AllowBoxSetCollapsing(GetItems request)
|
||||
{
|
||||
// Only allow when using default sort order
|
||||
if (!string.IsNullOrEmpty(request.SortBy) && !string.Equals(request.SortBy, "SortName", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
internal static IEnumerable<BaseItem> FilterForAdjacency(IEnumerable<BaseItem> items, string adjacentToId)
|
||||
{
|
||||
var list = items.ToList();
|
||||
|
||||
Reference in New Issue
Block a user