add movie count sort order
This commit is contained in:
parent
3c2ec758be
commit
9d7b3fdda6
|
@ -3,6 +3,7 @@ using MediaBrowser.Controller.Entities;
|
|||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Querying;
|
||||
using ServiceStack.ServiceHost;
|
||||
using System;
|
||||
|
@ -81,7 +82,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
}
|
||||
else
|
||||
{
|
||||
items = request.Recursive ? folder.RecursiveChildren: folder.Children;
|
||||
items = request.Recursive ? folder.RecursiveChildren : folder.Children;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -163,7 +164,8 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
{
|
||||
items = items.Where(i =>
|
||||
{
|
||||
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
||||
var item = i.GetItem().Result;
|
||||
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
||||
|
||||
return userdata != null && userdata.Likes.HasValue && !userdata.Likes.Value;
|
||||
});
|
||||
|
@ -173,7 +175,8 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
{
|
||||
items = items.Where(i =>
|
||||
{
|
||||
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
||||
var item = i.GetItem().Result;
|
||||
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
||||
|
||||
return userdata != null && userdata.Likes.HasValue && userdata.Likes.Value;
|
||||
});
|
||||
|
@ -183,12 +186,8 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
{
|
||||
items = items.Where(i =>
|
||||
{
|
||||
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
||||
|
||||
if (userdata == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var item = i.GetItem().Result;
|
||||
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
||||
|
||||
var likes = userdata.Likes ?? false;
|
||||
var favorite = userdata.IsFavorite;
|
||||
|
@ -201,7 +200,8 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
{
|
||||
items = items.Where(i =>
|
||||
{
|
||||
var userdata = i.GetUserItemData(UserDataRepository, user.Id).Result;
|
||||
var item = i.GetItem().Result;
|
||||
var userdata = UserDataRepository.GetUserData(user.Id, item.GetUserDataKey());
|
||||
|
||||
return userdata != null && userdata.Likes.HasValue && userdata.IsFavorite;
|
||||
});
|
||||
|
@ -220,7 +220,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
{
|
||||
if (string.Equals(request.SortBy, "SortName", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (request.SortOrder.HasValue && request.SortOrder.Value == Model.Entities.SortOrder.Descending)
|
||||
if (request.SortOrder.HasValue && request.SortOrder.Value == SortOrder.Descending)
|
||||
{
|
||||
items = items.OrderByDescending(i => i.Name);
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
}
|
||||
else if (string.Equals(request.SortBy, "Random", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (request.SortOrder.HasValue && request.SortOrder.Value == Model.Entities.SortOrder.Descending)
|
||||
if (request.SortOrder.HasValue && request.SortOrder.Value == SortOrder.Descending)
|
||||
{
|
||||
items = items.OrderByDescending(i => Guid.NewGuid());
|
||||
}
|
||||
|
@ -361,26 +361,17 @@ namespace MediaBrowser.Api.UserLibrary
|
|||
public class IbnStub<T>
|
||||
where T : BaseItem
|
||||
{
|
||||
private readonly Func<string,Task<T>> _itemFunction;
|
||||
private readonly Func<string, Task<T>> _itemFunction;
|
||||
private Task<T> _itemTask;
|
||||
|
||||
public string Name;
|
||||
|
||||
private UserItemData _userData;
|
||||
|
||||
public Task<T> GetItem()
|
||||
{
|
||||
return _itemTask ?? (_itemTask = _itemFunction(Name));
|
||||
}
|
||||
|
||||
public async Task<UserItemData> GetUserItemData(IUserDataRepository repo, Guid userId)
|
||||
{
|
||||
var item = await GetItem().ConfigureAwait(false);
|
||||
|
||||
return _userData ?? (_userData = repo.GetUserData(userId, item.GetUserDataKey()));
|
||||
}
|
||||
|
||||
public IbnStub(string name, Func<string,Task<T>> item)
|
||||
public IbnStub(string name, Func<string, Task<T>> item)
|
||||
{
|
||||
Name = name;
|
||||
_itemFunction = item;
|
||||
|
|
|
@ -13,4 +13,24 @@ namespace MediaBrowser.Controller.Entities
|
|||
|
||||
Dictionary<Guid, ItemByNameCounts> UserItemCounts { get; set; }
|
||||
}
|
||||
|
||||
public static class IItemByNameExtensions
|
||||
{
|
||||
public static ItemByNameCounts GetItemByNameCounts(this IItemByName item, User user)
|
||||
{
|
||||
if (user == null)
|
||||
{
|
||||
return item.ItemCounts;
|
||||
}
|
||||
|
||||
ItemByNameCounts counts;
|
||||
|
||||
if (item.UserItemCounts.TryGetValue(user.Id, out counts))
|
||||
{
|
||||
return counts;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -74,5 +74,7 @@ namespace MediaBrowser.Model.Querying
|
|||
public const string IsFolder = "IsFolder";
|
||||
public const string IsUnplayed = "IsUnplayed";
|
||||
public const string IsPlayed = "IsPlayed";
|
||||
public const string TrailerCount = "TrailerCount";
|
||||
public const string MovieCount = "MovieCount";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,6 +189,7 @@
|
|||
<Compile Include="Sorting\DatePlayedComparer.cs" />
|
||||
<Compile Include="Sorting\IsFolderComparer.cs" />
|
||||
<Compile Include="Sorting\IsUnplayedComparer.cs" />
|
||||
<Compile Include="Sorting\MovieCountComparer.cs" />
|
||||
<Compile Include="Sorting\NameComparer.cs" />
|
||||
<Compile Include="Sorting\OfficialRatingComparer.cs" />
|
||||
<Compile Include="Sorting\PlayCountComparer.cs" />
|
||||
|
@ -202,6 +203,7 @@
|
|||
<Compile Include="Persistence\SqliteItemRepository.cs" />
|
||||
<Compile Include="Persistence\SqliteUserDataRepository.cs" />
|
||||
<Compile Include="Persistence\SqliteUserRepository.cs" />
|
||||
<Compile Include="Sorting\TrailerCountComparer.cs" />
|
||||
<Compile Include="Udp\UdpMessageReceivedEventArgs.cs" />
|
||||
<Compile Include="Udp\UdpServer.cs" />
|
||||
<Compile Include="WebSocket\AlchemyServer.cs" />
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Sorting;
|
||||
using MediaBrowser.Model.Querying;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Sorting
|
||||
{
|
||||
public class MovieCountComparer : IUserBaseItemComparer
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user.
|
||||
/// </summary>
|
||||
/// <value>The user.</value>
|
||||
public User User { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user manager.
|
||||
/// </summary>
|
||||
/// <value>The user manager.</value>
|
||||
public IUserManager UserManager { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user data repository.
|
||||
/// </summary>
|
||||
/// <value>The user data repository.</value>
|
||||
public IUserDataRepository UserDataRepository { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compares the specified x.
|
||||
/// </summary>
|
||||
/// <param name="x">The x.</param>
|
||||
/// <param name="y">The y.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
public int Compare(BaseItem x, BaseItem y)
|
||||
{
|
||||
return GetValue(x).CompareTo(GetValue(y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date.
|
||||
/// </summary>
|
||||
/// <param name="x">The x.</param>
|
||||
/// <returns>DateTime.</returns>
|
||||
private int GetValue(BaseItem x)
|
||||
{
|
||||
var itemByName = x as IItemByName;
|
||||
|
||||
if (itemByName != null)
|
||||
{
|
||||
var counts = itemByName.GetItemByNameCounts(User);
|
||||
|
||||
if (counts != null)
|
||||
{
|
||||
return counts.MovieCount;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public string Name
|
||||
{
|
||||
get { return ItemSortBy.MovieCount; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Sorting;
|
||||
using MediaBrowser.Model.Querying;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.Sorting
|
||||
{
|
||||
public class TrailerCountComparer : IUserBaseItemComparer
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user.
|
||||
/// </summary>
|
||||
/// <value>The user.</value>
|
||||
public User User { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user manager.
|
||||
/// </summary>
|
||||
/// <value>The user manager.</value>
|
||||
public IUserManager UserManager { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the user data repository.
|
||||
/// </summary>
|
||||
/// <value>The user data repository.</value>
|
||||
public IUserDataRepository UserDataRepository { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compares the specified x.
|
||||
/// </summary>
|
||||
/// <param name="x">The x.</param>
|
||||
/// <param name="y">The y.</param>
|
||||
/// <returns>System.Int32.</returns>
|
||||
public int Compare(BaseItem x, BaseItem y)
|
||||
{
|
||||
return GetValue(x).CompareTo(GetValue(y));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the date.
|
||||
/// </summary>
|
||||
/// <param name="x">The x.</param>
|
||||
/// <returns>DateTime.</returns>
|
||||
private int GetValue(BaseItem x)
|
||||
{
|
||||
var itemByName = x as IItemByName;
|
||||
|
||||
if (itemByName != null)
|
||||
{
|
||||
var counts = itemByName.GetItemByNameCounts(User);
|
||||
|
||||
if (counts != null)
|
||||
{
|
||||
return counts.TrailerCount;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
public string Name
|
||||
{
|
||||
get { return ItemSortBy.TrailerCount; }
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user