From a0fa1b5f8f2a67c0a3f8cafce20540cb5349f89d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 15 Sep 2015 14:09:44 -0400 Subject: [PATCH] update client sync --- MediaBrowser.Api/StartupWizardService.cs | 1 + .../UserLibrary/UserViewsService.cs | 34 +++++++ MediaBrowser.Controller/Entities/UserView.cs | 22 ++++- .../Entities/UserViewBuilder.cs | 37 ++++++++ .../Configuration/ServerConfiguration.cs | 12 +-- .../Folders/DefaultImageProvider.cs | 14 +-- .../Library/LibraryManager.cs | 19 ++-- .../Library/UserViewManager.cs | 90 +++++++++++-------- .../UserViews/DynamicImageProvider.cs | 13 ++- 9 files changed, 182 insertions(+), 60 deletions(-) diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index 735384717..962334cdc 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -72,6 +72,7 @@ namespace MediaBrowser.Api _config.Configuration.EnableCustomPathSubFolders = true; _config.Configuration.DisableXmlSavers = true; _config.Configuration.DisableStartupScan = true; + _config.Configuration.EnableUserViews = true; _config.SaveConfiguration(); } diff --git a/MediaBrowser.Api/UserLibrary/UserViewsService.cs b/MediaBrowser.Api/UserLibrary/UserViewsService.cs index a49ab8556..9d7c38d6f 100644 --- a/MediaBrowser.Api/UserLibrary/UserViewsService.cs +++ b/MediaBrowser.Api/UserLibrary/UserViewsService.cs @@ -39,6 +39,17 @@ namespace MediaBrowser.Api.UserLibrary public string UserId { get; set; } } + [Route("/Users/{UserId}/GroupingOptions", "GET")] + public class GetGroupingOptions : IReturn> + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string UserId { get; set; } + } + public class UserViewsService : BaseApiService { private readonly IUserManager _userManager; @@ -105,6 +116,29 @@ namespace MediaBrowser.Api.UserLibrary return ToOptimizedResult(list); } + public async Task Get(GetGroupingOptions request) + { + var user = _userManager.GetUserById(request.UserId); + + var views = user.RootFolder + .GetChildren(user, true) + .OfType() + .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) { var types = new[] { CollectionType.Movies, CollectionType.TvShows, CollectionType.Games, CollectionType.Music, CollectionType.Photos }; diff --git a/MediaBrowser.Controller/Entities/UserView.cs b/MediaBrowser.Controller/Entities/UserView.cs index 488e54cc3..f4577435f 100644 --- a/MediaBrowser.Controller/Entities/UserView.cs +++ b/MediaBrowser.Controller/Entities/UserView.cs @@ -82,7 +82,27 @@ namespace MediaBrowser.Controller.Entities { CollectionType.Books, 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 + { + CollectionType.Playlists, + CollectionType.BoxSets }; var collectionFolder = folder as ICollectionFolder; diff --git a/MediaBrowser.Controller/Entities/UserViewBuilder.cs b/MediaBrowser.Controller/Entities/UserViewBuilder.cs index cee5dadd2..c3605fa6d 100644 --- a/MediaBrowser.Controller/Entities/UserViewBuilder.cs +++ b/MediaBrowser.Controller/Entities/UserViewBuilder.cs @@ -1808,6 +1808,13 @@ namespace MediaBrowser.Controller.Entities private IEnumerable GetMediaFolders(User user) { + if (user == null) + { + return _libraryManager.RootFolder + .Children + .OfType() + .Where(i => !UserView.IsExcludedFromGrouping(i)); + } return user.RootFolder .GetChildren(user, true, true) .OfType() @@ -1816,6 +1823,16 @@ namespace MediaBrowser.Controller.Entities private IEnumerable GetMediaFolders(User user, IEnumerable 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) .Where(i => { @@ -1839,9 +1856,19 @@ namespace MediaBrowser.Controller.Entities { 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)); } + if (user == null) + { + return parent.GetRecursiveChildren(); + } + return parent.GetRecursiveChildren(user); } @@ -1849,9 +1876,19 @@ namespace MediaBrowser.Controller.Entities { 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)); } + if (user == null) + { + return parent.GetRecursiveChildren(filter); + } + return parent.GetRecursiveChildren(user, filter); } diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index 0bf73eba1..1fcad8c95 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -44,12 +44,6 @@ namespace MediaBrowser.Model.Configuration /// true if [use HTTPS]; otherwise, false. public bool EnableHttps { get; set; } - /// - /// Gets or sets a value indicating whether [enable user specific user views]. - /// - /// true if [enable user specific user views]; otherwise, false. - public bool EnableUserSpecificUserViews { get; set; } - /// /// Gets or sets the value pointing to the file system where the ssl certiifcate is located.. /// @@ -103,6 +97,12 @@ namespace MediaBrowser.Model.Configuration /// /// true if [disable startup scan]; otherwise, false. public bool DisableStartupScan { get; set; } + + /// + /// Gets or sets a value indicating whether [enable user views]. + /// + /// true if [enable user views]; otherwise, false. + public bool EnableUserViews { get; set; } /// /// Gets or sets a value indicating whether [enable library metadata sub folder]. diff --git a/MediaBrowser.Providers/Folders/DefaultImageProvider.cs b/MediaBrowser.Providers/Folders/DefaultImageProvider.cs index 13e486ae9..114346191 100644 --- a/MediaBrowser.Providers/Folders/DefaultImageProvider.cs +++ b/MediaBrowser.Providers/Folders/DefaultImageProvider.cs @@ -77,11 +77,11 @@ namespace MediaBrowser.Providers.Folders if (string.Equals(viewType, CollectionType.Books, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "books.png"; + //return urlPrefix + "books.png"; } if (string.Equals(viewType, CollectionType.Games, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "games.png"; + //return urlPrefix + "games.png"; } if (string.Equals(viewType, CollectionType.Music, StringComparison.OrdinalIgnoreCase)) { @@ -109,23 +109,23 @@ namespace MediaBrowser.Providers.Folders } if (string.Equals(viewType, CollectionType.Playlists, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "playlists.png"; + //return urlPrefix + "playlists.png"; } if (string.Equals(viewType, CollectionType.HomeVideos, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "homevideos.png"; + //return urlPrefix + "homevideos.png"; } if (string.Equals(viewType, CollectionType.MusicVideos, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "musicvideos.png"; + //return urlPrefix + "musicvideos.png"; } if (string.Equals(viewType, CollectionType.BoxSets, StringComparison.OrdinalIgnoreCase)) { - return urlPrefix + "generic.png"; + //return urlPrefix + "generic.png"; } if (string.IsNullOrWhiteSpace(viewType)) { - return urlPrefix + "generic.png"; + //return urlPrefix + "generic.png"; } return null; diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 8d843e1ca..8ef363b64 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -1637,7 +1637,8 @@ namespace MediaBrowser.Server.Implementations.Library .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 GetNamedView(User user, string name, @@ -1645,12 +1646,7 @@ namespace MediaBrowser.Server.Implementations.Library string sortName, CancellationToken cancellationToken) { - if (ConfigurationManager.Configuration.EnableUserSpecificUserViews) - { - return GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken); - } - - return GetNamedView(name, viewType, sortName, cancellationToken); + return GetNamedViewInternal(user, name, null, viewType, sortName, null, cancellationToken); } public async Task GetNamedView(string name, @@ -1767,7 +1763,8 @@ namespace MediaBrowser.Server.Implementations.Library DateCreated = DateTime.UtcNow, Name = name, ViewType = viewType, - ForcedSortName = sortName + ForcedSortName = sortName, + UserId = user.Id }; if (!string.IsNullOrWhiteSpace(parentId)) @@ -1780,6 +1777,12 @@ namespace MediaBrowser.Server.Implementations.Library 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)) { item.ViewType = viewType; diff --git a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs index 15648058e..fe9e09318 100644 --- a/MediaBrowser.Server.Implementations/Library/UserViewManager.cs +++ b/MediaBrowser.Server.Implementations/Library/UserViewManager.cs @@ -65,22 +65,55 @@ namespace MediaBrowser.Server.Implementations.Library var list = new List(); - foreach (var folder in standaloneFolders) + if (_config.Configuration.EnableUserViews) { - var collectionFolder = folder as ICollectionFolder; - var folderViewType = collectionFolder == null ? null : collectionFolder.CollectionType; + foreach (var folder in standaloneFolders) + { + var collectionFolder = folder as ICollectionFolder; + var folderViewType = collectionFolder == null ? null : collectionFolder.CollectionType; - if (plainFolderIds.Contains(folder.Id)) - { - list.Add(await GetUserView(folder.Id, folder.Name, folderViewType, false, string.Empty, user, cancellationToken).ConfigureAwait(false)); + if (UserView.IsUserSpecific(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, 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)); - } - else - { - list.Add(folder); + var collectionFolder = folder as ICollectionFolder; + var folderViewType = collectionFolder == null ? null : collectionFolder.CollectionType; + + if (UserView.IsUserSpecific(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) { - var name = _localizationManager.GetLocalizedString("ViewType" + CollectionType.Games); - 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)); + list.Add(await GetUserView(parents, list, CollectionType.Games, string.Empty, user, cancellationToken).ConfigureAwait(false)); } if (user.Configuration.DisplayFoldersView) @@ -200,9 +214,9 @@ namespace MediaBrowser.Server.Implementations.Library public async Task GetUserView(List parents, List currentViews, string viewType, string sortName, User user, CancellationToken cancellationToken) { 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)) { @@ -218,7 +232,7 @@ namespace MediaBrowser.Server.Implementations.Library 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); @@ -240,6 +254,12 @@ namespace MediaBrowser.Server.Implementations.Library return _libraryManager.GetNamedView(user, name, parentId.ToString("N"), viewType, sortName, null, cancellationToken); } + public Task 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>> GetLatestItems(LatestItemsQuery request) { var user = _userManager.GetUserById(request.UserId); diff --git a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs index 8321ab952..2f5702983 100644 --- a/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs +++ b/MediaBrowser.Server.Implementations/UserViews/DynamicImageProvider.cs @@ -66,14 +66,14 @@ namespace MediaBrowser.Server.Implementations.UserViews } 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 { User = (view.UserId.HasValue ? _userManager.GetUserById(view.UserId.Value) : null), CollapseBoxSetItems = false, Recursive = recursive, - ExcludeItemTypes = new[] { "UserView", "CollectionFolder", "Playlist" } + ExcludeItemTypes = new[] { "UserView", "CollectionFolder" } }).ConfigureAwait(false); @@ -147,7 +147,14 @@ namespace MediaBrowser.Server.Implementations.UserViews { CollectionType.Movies, 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);