update client sync

This commit is contained in:
Luke Pulverenti 2015-09-15 14:09:44 -04:00
parent 6d3fda8693
commit a0fa1b5f8f
9 changed files with 182 additions and 60 deletions

View File

@ -72,6 +72,7 @@ namespace MediaBrowser.Api
_config.Configuration.EnableCustomPathSubFolders = true; _config.Configuration.EnableCustomPathSubFolders = true;
_config.Configuration.DisableXmlSavers = true; _config.Configuration.DisableXmlSavers = true;
_config.Configuration.DisableStartupScan = true; _config.Configuration.DisableStartupScan = true;
_config.Configuration.EnableUserViews = true;
_config.SaveConfiguration(); _config.SaveConfiguration();
} }

View File

@ -39,6 +39,17 @@ namespace MediaBrowser.Api.UserLibrary
public string UserId { get; set; } public string UserId { get; set; }
} }
[Route("/Users/{UserId}/GroupingOptions", "GET")]
public class GetGroupingOptions : IReturn<List<SpecialViewOption>>
{
/// <summary>
/// Gets or sets the user id.
/// </summary>
/// <value>The user id.</value>
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
public string UserId { get; set; }
}
public class UserViewsService : BaseApiService public class UserViewsService : BaseApiService
{ {
private readonly IUserManager _userManager; private readonly IUserManager _userManager;
@ -105,6 +116,29 @@ namespace MediaBrowser.Api.UserLibrary
return ToOptimizedResult(list); return ToOptimizedResult(list);
} }
public async Task<object> Get(GetGroupingOptions request)
{
var user = _userManager.GetUserById(request.UserId);
var views = user.RootFolder
.GetChildren(user, true)
.OfType<Folder>()
.Where(i => !UserView.IsExcludedFromGrouping(i))
.ToList();
var list = views
.Select(i => new SpecialViewOption
{
Name = i.Name,
Id = i.Id.ToString("N")
})
.OrderBy(i => i.Name)
.ToList();
return ToOptimizedResult(list);
}
private bool IsEligibleForSpecialView(ICollectionFolder view) private bool IsEligibleForSpecialView(ICollectionFolder view)
{ {
var types = new[] { CollectionType.Movies, CollectionType.TvShows, CollectionType.Games, CollectionType.Music, CollectionType.Photos }; var types = new[] { CollectionType.Movies, CollectionType.TvShows, CollectionType.Games, CollectionType.Music, CollectionType.Photos };

View File

@ -82,7 +82,27 @@ namespace MediaBrowser.Controller.Entities
{ {
CollectionType.Books, CollectionType.Books,
CollectionType.HomeVideos, CollectionType.HomeVideos,
CollectionType.Photos CollectionType.Photos,
CollectionType.Playlists,
CollectionType.BoxSets
};
var collectionFolder = folder as ICollectionFolder;
if (collectionFolder == null)
{
return false;
}
return standaloneTypes.Contains(collectionFolder.CollectionType ?? string.Empty);
}
public static bool IsUserSpecific(Folder folder)
{
var standaloneTypes = new List<string>
{
CollectionType.Playlists,
CollectionType.BoxSets
}; };
var collectionFolder = folder as ICollectionFolder; var collectionFolder = folder as ICollectionFolder;

View File

@ -1808,6 +1808,13 @@ namespace MediaBrowser.Controller.Entities
private IEnumerable<Folder> GetMediaFolders(User user) private IEnumerable<Folder> GetMediaFolders(User user)
{ {
if (user == null)
{
return _libraryManager.RootFolder
.Children
.OfType<Folder>()
.Where(i => !UserView.IsExcludedFromGrouping(i));
}
return user.RootFolder return user.RootFolder
.GetChildren(user, true, true) .GetChildren(user, true, true)
.OfType<Folder>() .OfType<Folder>()
@ -1816,6 +1823,16 @@ namespace MediaBrowser.Controller.Entities
private IEnumerable<Folder> GetMediaFolders(User user, IEnumerable<string> viewTypes) private IEnumerable<Folder> GetMediaFolders(User user, IEnumerable<string> viewTypes)
{ {
if (user == null)
{
return GetMediaFolders(null)
.Where(i =>
{
var folder = i as ICollectionFolder;
return folder != null && viewTypes.Contains(folder.CollectionType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
});
}
return GetMediaFolders(user) return GetMediaFolders(user)
.Where(i => .Where(i =>
{ {
@ -1839,9 +1856,19 @@ namespace MediaBrowser.Controller.Entities
{ {
if (parent == null || parent is UserView) if (parent == null || parent is UserView)
{ {
if (user == null)
{
return GetMediaFolders(null, viewTypes).SelectMany(i => i.GetRecursiveChildren());
}
return GetMediaFolders(user, viewTypes).SelectMany(i => i.GetRecursiveChildren(user)); return GetMediaFolders(user, viewTypes).SelectMany(i => i.GetRecursiveChildren(user));
} }
if (user == null)
{
return parent.GetRecursiveChildren();
}
return parent.GetRecursiveChildren(user); return parent.GetRecursiveChildren(user);
} }
@ -1849,9 +1876,19 @@ namespace MediaBrowser.Controller.Entities
{ {
if (parent == null || parent is UserView) if (parent == null || parent is UserView)
{ {
if (user == null)
{
return GetMediaFolders(null, viewTypes).SelectMany(i => i.GetRecursiveChildren(filter));
}
return GetMediaFolders(user, viewTypes).SelectMany(i => i.GetRecursiveChildren(user, filter)); return GetMediaFolders(user, viewTypes).SelectMany(i => i.GetRecursiveChildren(user, filter));
} }
if (user == null)
{
return parent.GetRecursiveChildren(filter);
}
return parent.GetRecursiveChildren(user, filter); return parent.GetRecursiveChildren(user, filter);
} }

View File

@ -44,12 +44,6 @@ namespace MediaBrowser.Model.Configuration
/// <value><c>true</c> if [use HTTPS]; otherwise, <c>false</c>.</value> /// <value><c>true</c> if [use HTTPS]; otherwise, <c>false</c>.</value>
public bool EnableHttps { get; set; } public bool EnableHttps { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [enable user specific user views].
/// </summary>
/// <value><c>true</c> if [enable user specific user views]; otherwise, <c>false</c>.</value>
public bool EnableUserSpecificUserViews { get; set; }
/// <summary> /// <summary>
/// Gets or sets the value pointing to the file system where the ssl certiifcate is located.. /// Gets or sets the value pointing to the file system where the ssl certiifcate is located..
/// </summary> /// </summary>
@ -103,6 +97,12 @@ namespace MediaBrowser.Model.Configuration
/// </summary> /// </summary>
/// <value><c>true</c> if [disable startup scan]; otherwise, <c>false</c>.</value> /// <value><c>true</c> if [disable startup scan]; otherwise, <c>false</c>.</value>
public bool DisableStartupScan { get; set; } public bool DisableStartupScan { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [enable user views].
/// </summary>
/// <value><c>true</c> if [enable user views]; otherwise, <c>false</c>.</value>
public bool EnableUserViews { get; set; }
/// <summary> /// <summary>
/// Gets or sets a value indicating whether [enable library metadata sub folder]. /// Gets or sets a value indicating whether [enable library metadata sub folder].

View File

@ -77,11 +77,11 @@ namespace MediaBrowser.Providers.Folders
if (string.Equals(viewType, CollectionType.Books, StringComparison.OrdinalIgnoreCase)) if (string.Equals(viewType, CollectionType.Books, StringComparison.OrdinalIgnoreCase))
{ {
return urlPrefix + "books.png"; //return urlPrefix + "books.png";
} }
if (string.Equals(viewType, CollectionType.Games, StringComparison.OrdinalIgnoreCase)) if (string.Equals(viewType, CollectionType.Games, StringComparison.OrdinalIgnoreCase))
{ {
return urlPrefix + "games.png"; //return urlPrefix + "games.png";
} }
if (string.Equals(viewType, CollectionType.Music, StringComparison.OrdinalIgnoreCase)) if (string.Equals(viewType, CollectionType.Music, StringComparison.OrdinalIgnoreCase))
{ {
@ -109,23 +109,23 @@ namespace MediaBrowser.Providers.Folders
} }
if (string.Equals(viewType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)) if (string.Equals(viewType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase))
{ {
return urlPrefix + "playlists.png"; //return urlPrefix + "playlists.png";
} }
if (string.Equals(viewType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) if (string.Equals(viewType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase))
{ {
return urlPrefix + "homevideos.png"; //return urlPrefix + "homevideos.png";
} }
if (string.Equals(viewType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) if (string.Equals(viewType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase))
{ {
return urlPrefix + "musicvideos.png"; //return urlPrefix + "musicvideos.png";
} }
if (string.Equals(viewType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) if (string.Equals(viewType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
{ {
return urlPrefix + "generic.png"; //return urlPrefix + "generic.png";
} }
if (string.IsNullOrWhiteSpace(viewType)) if (string.IsNullOrWhiteSpace(viewType))
{ {
return urlPrefix + "generic.png"; //return urlPrefix + "generic.png";
} }
return null; return null;

View File

@ -1637,7 +1637,8 @@ namespace MediaBrowser.Server.Implementations.Library
.FirstOrDefault(i => !string.IsNullOrWhiteSpace(i)); .FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));
} }
private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromHours(24); //private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromHours(24);
private readonly TimeSpan _viewRefreshInterval = TimeSpan.FromMinutes(1);
public Task<UserView> GetNamedView(User user, public Task<UserView> GetNamedView(User user,
string name, string name,
@ -1645,12 +1646,7 @@ namespace MediaBrowser.Server.Implementations.Library
string sortName, string sortName,
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
if (ConfigurationManager.Configuration.EnableUserSpecificUserViews) return GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken);
{
return GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken);
}
return GetNamedView(name, viewType, sortName, cancellationToken);
} }
public async Task<UserView> GetNamedView(string name, public async Task<UserView> GetNamedView(string name,
@ -1767,7 +1763,8 @@ namespace MediaBrowser.Server.Implementations.Library
DateCreated = DateTime.UtcNow, DateCreated = DateTime.UtcNow,
Name = name, Name = name,
ViewType = viewType, ViewType = viewType,
ForcedSortName = sortName ForcedSortName = sortName,
UserId = user.Id
}; };
if (!string.IsNullOrWhiteSpace(parentId)) if (!string.IsNullOrWhiteSpace(parentId))
@ -1780,6 +1777,12 @@ namespace MediaBrowser.Server.Implementations.Library
isNew = true; isNew = true;
} }
if (!item.UserId.HasValue)
{
item.UserId = user.Id;
await item.UpdateToRepository(ItemUpdateType.MetadataEdit, cancellationToken).ConfigureAwait(false);
}
if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase)) if (!string.Equals(viewType, item.ViewType, StringComparison.OrdinalIgnoreCase))
{ {
item.ViewType = viewType; item.ViewType = viewType;

View File

@ -65,22 +65,55 @@ namespace MediaBrowser.Server.Implementations.Library
var list = new List<Folder>(); var list = new List<Folder>();
foreach (var folder in standaloneFolders) if (_config.Configuration.EnableUserViews)
{ {
var collectionFolder = folder as ICollectionFolder; foreach (var folder in standaloneFolders)
var folderViewType = collectionFolder == null ? null : collectionFolder.CollectionType; {
var collectionFolder = folder as ICollectionFolder;
var folderViewType = collectionFolder == null ? null : collectionFolder.CollectionType;
if (plainFolderIds.Contains(folder.Id)) if (UserView.IsUserSpecific(folder))
{ {
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, false, string.Empty, user, cancellationToken).ConfigureAwait(false)); list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, user, cancellationToken).ConfigureAwait(false));
}
else if (plainFolderIds.Contains(folder.Id))
{
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, false, string.Empty, cancellationToken).ConfigureAwait(false));
}
else if (!string.IsNullOrWhiteSpace(folderViewType))
{
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, cancellationToken).ConfigureAwait(false));
}
else
{
list.Add(folder);
}
} }
else if (!string.IsNullOrWhiteSpace(folderViewType)) }
else
{
// TODO: Deprecate this whole block
foreach (var folder in standaloneFolders)
{ {
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, user, cancellationToken).ConfigureAwait(false)); var collectionFolder = folder as ICollectionFolder;
} var folderViewType = collectionFolder == null ? null : collectionFolder.CollectionType;
else
{ if (UserView.IsUserSpecific(folder))
list.Add(folder); {
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, user, cancellationToken).ConfigureAwait(false));
}
else if (plainFolderIds.Contains(folder.Id))
{
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, false, string.Empty, user, cancellationToken).ConfigureAwait(false));
}
else if (!string.IsNullOrWhiteSpace(folderViewType))
{
list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, true, string.Empty, user, cancellationToken).ConfigureAwait(false));
}
else
{
list.Add(folder);
}
} }
} }
@ -113,26 +146,7 @@ namespace MediaBrowser.Server.Implementations.Library
if (parents.Count > 0) if (parents.Count > 0)
{ {
var name = _localizationManager.GetLocalizedString("ViewType" + CollectionType.Games); list.Add(await GetUserView(parents, list, CollectionType.Games, string.Empty, user, cancellationToken).ConfigureAwait(false));
list.Add(await _libraryManager.GetNamedView(name, CollectionType.Games, string.Empty, cancellationToken).ConfigureAwait(false));
}
parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase))
.ToList();
if (parents.Count > 0)
{
var name = _localizationManager.GetLocalizedString("ViewType" + CollectionType.BoxSets);
list.Add(await _libraryManager.GetNamedView(name, CollectionType.BoxSets, string.Empty, cancellationToken).ConfigureAwait(false));
}
parents = foldersWithViewTypes.Where(i => string.Equals(i.GetViewType(user), CollectionType.Playlists, StringComparison.OrdinalIgnoreCase))
.ToList();
if (parents.Count > 0)
{
var name = _localizationManager.GetLocalizedString("ViewType" + CollectionType.Playlists);
list.Add(await _libraryManager.GetNamedView(name, CollectionType.Playlists, string.Empty, cancellationToken).ConfigureAwait(false));
} }
if (user.Configuration.DisplayFoldersView) if (user.Configuration.DisplayFoldersView)
@ -200,9 +214,9 @@ namespace MediaBrowser.Server.Implementations.Library
public async Task<UserView> GetUserView(List<ICollectionFolder> parents, List<Folder> currentViews, string viewType, string sortName, User user, CancellationToken cancellationToken) public async Task<UserView> GetUserView(List<ICollectionFolder> parents, List<Folder> currentViews, string viewType, string sortName, User user, CancellationToken cancellationToken)
{ {
var name = _localizationManager.GetLocalizedString("ViewType" + viewType); var name = _localizationManager.GetLocalizedString("ViewType" + viewType);
var enableUserSpecificViews = _config.Configuration.EnableUserSpecificUserViews; var enableUserViews = _config.Configuration.EnableUserViews;
if (parents.Count == 1 && parents.All(i => string.Equals((enableUserSpecificViews ? i.CollectionType : i.GetViewType(user)), viewType, StringComparison.OrdinalIgnoreCase))) if (parents.Count == 1 && parents.All(i => string.Equals((enableUserViews ? i.GetViewType(user) : i.CollectionType), viewType, StringComparison.OrdinalIgnoreCase)))
{ {
if (!string.IsNullOrWhiteSpace(parents[0].Name)) if (!string.IsNullOrWhiteSpace(parents[0].Name))
{ {
@ -218,7 +232,7 @@ namespace MediaBrowser.Server.Implementations.Library
return await GetUserView(parentId, name, viewType, enableRichView, sortName, user, cancellationToken).ConfigureAwait(false); return await GetUserView(parentId, name, viewType, enableRichView, sortName, user, cancellationToken).ConfigureAwait(false);
} }
if (enableUserSpecificViews) if (!enableUserViews)
{ {
var view = await _libraryManager.GetNamedView(user, name, viewType, sortName, cancellationToken).ConfigureAwait(false); var view = await _libraryManager.GetNamedView(user, name, viewType, sortName, cancellationToken).ConfigureAwait(false);
@ -240,6 +254,12 @@ namespace MediaBrowser.Server.Implementations.Library
return _libraryManager.GetNamedView(user, name, parentId.ToString("N"), viewType, sortName, null, cancellationToken); return _libraryManager.GetNamedView(user, name, parentId.ToString("N"), viewType, sortName, null, cancellationToken);
} }
public Task<UserView> GetUserView(Guid parentId, string name, string viewType, bool enableRichView, string sortName, CancellationToken cancellationToken)
{
viewType = enableRichView ? viewType : null;
return _libraryManager.GetNamedView(name, parentId.ToString("N"), viewType, sortName, null, cancellationToken);
}
public List<Tuple<BaseItem, List<BaseItem>>> GetLatestItems(LatestItemsQuery request) public List<Tuple<BaseItem, List<BaseItem>>> GetLatestItems(LatestItemsQuery request)
{ {
var user = _userManager.GetUserById(request.UserId); var user = _userManager.GetUserById(request.UserId);

View File

@ -66,14 +66,14 @@ namespace MediaBrowser.Server.Implementations.UserViews
} }
var isUsingCollectionStrip = IsUsingCollectionStrip(view); var isUsingCollectionStrip = IsUsingCollectionStrip(view);
var recursive = isUsingCollectionStrip && !new[] { CollectionType.Playlists, CollectionType.Channels }.Contains(view.ViewType ?? string.Empty, StringComparer.OrdinalIgnoreCase); var recursive = isUsingCollectionStrip && !new[] { CollectionType.Channels, CollectionType.BoxSets, CollectionType.Playlists }.Contains(view.ViewType ?? string.Empty, StringComparer.OrdinalIgnoreCase);
var result = await view.GetItems(new InternalItemsQuery var result = await view.GetItems(new InternalItemsQuery
{ {
User = (view.UserId.HasValue ? _userManager.GetUserById(view.UserId.Value) : null), User = (view.UserId.HasValue ? _userManager.GetUserById(view.UserId.Value) : null),
CollapseBoxSetItems = false, CollapseBoxSetItems = false,
Recursive = recursive, Recursive = recursive,
ExcludeItemTypes = new[] { "UserView", "CollectionFolder", "Playlist" } ExcludeItemTypes = new[] { "UserView", "CollectionFolder" }
}).ConfigureAwait(false); }).ConfigureAwait(false);
@ -147,7 +147,14 @@ namespace MediaBrowser.Server.Implementations.UserViews
{ {
CollectionType.Movies, CollectionType.Movies,
CollectionType.TvShows, CollectionType.TvShows,
CollectionType.Music CollectionType.Music,
CollectionType.Games,
CollectionType.Books,
CollectionType.MusicVideos,
CollectionType.HomeVideos,
CollectionType.BoxSets,
CollectionType.Playlists,
CollectionType.Photos
}; };
return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty); return collectionStripViewTypes.Contains(view.ViewType ?? string.Empty);