more support for episodes directly in a series folder

This commit is contained in:
Luke Pulverenti
2013-12-03 23:18:50 -05:00
parent 61a78e2be9
commit 40959a816f
12 changed files with 231 additions and 32 deletions

View File

@@ -310,6 +310,12 @@ namespace MediaBrowser.Api.UserLibrary
items = ApplySortOrder(request, items, user, _libraryManager);
// This must be the last filter
if (!string.IsNullOrEmpty(request.AdjacentTo))
{
items = FilterForAdjacency(items, request.AdjacentTo);
}
var itemsArray = items.ToList();
var pagedItems = ApplyPaging(request, itemsArray);
@@ -666,30 +672,6 @@ namespace MediaBrowser.Api.UserLibrary
});
}
if (!string.IsNullOrEmpty(request.AdjacentTo))
{
var item = _dtoService.GetItemByDtoId(request.AdjacentTo);
var allSiblings = item.Parent.GetChildren(user, true).OrderBy(i => i.SortName).ToList();
var index = allSiblings.IndexOf(item);
var previousId = Guid.Empty;
var nextId = Guid.Empty;
if (index > 0)
{
previousId = allSiblings[index - 1].Id;
}
if (index < allSiblings.Count - 1)
{
nextId = allSiblings[index + 1].Id;
}
items = items.Where(i => i.Id == previousId || i.Id == nextId);
}
// Min index number
if (request.MinIndexNumber.HasValue)
{
@@ -1144,6 +1126,31 @@ namespace MediaBrowser.Api.UserLibrary
return false;
}
internal static IEnumerable<BaseItem> FilterForAdjacency(IEnumerable<BaseItem> items, string adjacentToId)
{
var list = items.ToList();
var adjacentToIdGuid = new Guid(adjacentToId);
var adjacentToItem = list.FirstOrDefault(i => i.Id == adjacentToIdGuid);
var index = list.IndexOf(adjacentToItem);
var previousId = Guid.Empty;
var nextId = Guid.Empty;
if (index > 0)
{
previousId = list[index - 1].Id;
}
if (index < list.Count - 1)
{
nextId = list[index + 1].Id;
}
return list.Where(i => i.Id == previousId || i.Id == nextId);
}
/// <summary>
/// Determines whether the specified item has image.
/// </summary>