mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-11-15 18:08:53 -07:00
Fix SortCriteria and refactor SetSorting
This commit is contained in:
parent
53c16c2342
commit
6985a4f255
@ -634,11 +634,10 @@ namespace Emby.Dlna.ContentDirectory
|
||||
IsVirtualItem = false,
|
||||
ExcludeItemTypes = new[] { nameof(Book) },
|
||||
IsPlaceHolder = false,
|
||||
DtoOptions = GetDtoOptions()
|
||||
DtoOptions = GetDtoOptions(),
|
||||
OrderBy = GetOrderBy(sort, folder.IsPreSorted)
|
||||
};
|
||||
|
||||
SetSorting(query, sort, folder.IsPreSorted);
|
||||
|
||||
var queryResult = folder.GetItems(query);
|
||||
|
||||
return ToResult(queryResult);
|
||||
@ -658,11 +657,10 @@ namespace Emby.Dlna.ContentDirectory
|
||||
{
|
||||
StartIndex = startIndex,
|
||||
Limit = limit,
|
||||
IncludeItemTypes = new[] { nameof(LiveTvChannel) }
|
||||
IncludeItemTypes = new[] { nameof(LiveTvChannel) },
|
||||
OrderBy = GetOrderBy(sort, false)
|
||||
};
|
||||
|
||||
SetSorting(query, sort, false);
|
||||
|
||||
var result = _libraryManager.GetItemsResult(query);
|
||||
|
||||
return ToResult(result);
|
||||
@ -683,9 +681,9 @@ namespace Emby.Dlna.ContentDirectory
|
||||
var query = new InternalItemsQuery(user)
|
||||
{
|
||||
StartIndex = startIndex,
|
||||
Limit = limit
|
||||
Limit = limit,
|
||||
OrderBy = GetOrderBy(sort, false)
|
||||
};
|
||||
SetSorting(query, sort, false);
|
||||
|
||||
switch (stubType)
|
||||
{
|
||||
@ -752,9 +750,9 @@ namespace Emby.Dlna.ContentDirectory
|
||||
var query = new InternalItemsQuery(user)
|
||||
{
|
||||
StartIndex = startIndex,
|
||||
Limit = limit
|
||||
Limit = limit,
|
||||
OrderBy = GetOrderBy(sort, false)
|
||||
};
|
||||
SetSorting(query, sort, false);
|
||||
|
||||
switch (stubType)
|
||||
{
|
||||
@ -835,9 +833,9 @@ namespace Emby.Dlna.ContentDirectory
|
||||
var query = new InternalItemsQuery(user)
|
||||
{
|
||||
StartIndex = startIndex,
|
||||
Limit = limit
|
||||
Limit = limit,
|
||||
OrderBy = GetOrderBy(sort, false)
|
||||
};
|
||||
SetSorting(query, sort, false);
|
||||
|
||||
switch (stubType)
|
||||
{
|
||||
@ -1104,11 +1102,10 @@ namespace Emby.Dlna.ContentDirectory
|
||||
IncludeItemTypes = new[] { nameof(MusicAlbum) },
|
||||
Limit = limit,
|
||||
StartIndex = startIndex,
|
||||
DtoOptions = GetDtoOptions()
|
||||
DtoOptions = GetDtoOptions(),
|
||||
OrderBy = GetOrderBy(sort, false)
|
||||
};
|
||||
|
||||
SetSorting(query, sort, false);
|
||||
|
||||
var result = _libraryManager.GetItemsResult(query);
|
||||
|
||||
return ToResult(result);
|
||||
@ -1136,11 +1133,10 @@ namespace Emby.Dlna.ContentDirectory
|
||||
},
|
||||
Limit = limit,
|
||||
StartIndex = startIndex,
|
||||
DtoOptions = GetDtoOptions()
|
||||
DtoOptions = GetDtoOptions(),
|
||||
OrderBy = GetOrderBy(sort, false)
|
||||
};
|
||||
|
||||
SetSorting(query, sort, false);
|
||||
|
||||
var result = _libraryManager.GetItemsResult(query);
|
||||
|
||||
return ToResult(result);
|
||||
@ -1164,11 +1160,10 @@ namespace Emby.Dlna.ContentDirectory
|
||||
IncludeItemTypes = new[] { nameof(MusicAlbum) },
|
||||
Limit = limit,
|
||||
StartIndex = startIndex,
|
||||
DtoOptions = GetDtoOptions()
|
||||
DtoOptions = GetDtoOptions(),
|
||||
OrderBy = GetOrderBy(sort, false)
|
||||
};
|
||||
|
||||
SetSorting(query, sort, false);
|
||||
|
||||
var result = _libraryManager.GetItemsResult(query);
|
||||
|
||||
return ToResult(result);
|
||||
@ -1233,21 +1228,13 @@ namespace Emby.Dlna.ContentDirectory
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the sorting method on a query.
|
||||
/// Gets the sorting method on a query.
|
||||
/// </summary>
|
||||
/// <param name="query">The <see cref="InternalItemsQuery"/>.</param>
|
||||
/// <param name="sort">The <see cref="SortCriteria"/>.</param>
|
||||
/// <param name="isPreSorted">True if pre-sorted.</param>
|
||||
private static void SetSorting(InternalItemsQuery query, SortCriteria sort, bool isPreSorted)
|
||||
private static (string, SortOrder)[] GetOrderBy(SortCriteria sort, bool isPreSorted)
|
||||
{
|
||||
if (isPreSorted)
|
||||
{
|
||||
query.OrderBy = Array.Empty<(string, SortOrder)>();
|
||||
}
|
||||
else
|
||||
{
|
||||
query.OrderBy = new[] { (ItemSortBy.SortName, sort.SortOrder) };
|
||||
}
|
||||
return isPreSorted ? Array.Empty<(string, SortOrder)>() : new[] { (ItemSortBy.SortName, sort.SortOrder) };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -1,15 +1,24 @@
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using Jellyfin.Data.Enums;
|
||||
|
||||
namespace MediaBrowser.Model.Dlna
|
||||
{
|
||||
public class SortCriteria
|
||||
{
|
||||
public SortCriteria(string value)
|
||||
public SortCriteria(string sortOrder)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(sortOrder) && Enum.TryParse<SortOrder>(sortOrder, true, out var sortOrderValue))
|
||||
{
|
||||
SortOrder = sortOrderValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
SortOrder = SortOrder.Ascending;
|
||||
}
|
||||
}
|
||||
|
||||
public SortOrder SortOrder => SortOrder.Ascending;
|
||||
public SortOrder SortOrder { get; }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user