From a3a658e82079ac8e56193ce4d2047a547e0289c9 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 20 Oct 2013 21:03:33 -0400 Subject: [PATCH] added more info to user library counts --- .../DefaultTheme/DefaultThemeService.cs | 258 +++++++++++++----- MediaBrowser.Api/DefaultTheme/Models.cs | 13 +- MediaBrowser.Api/LibraryService.cs | 56 +++- .../Configuration/ServerConfiguration.cs | 21 -- MediaBrowser.Model/Dto/ItemCounts.cs | 50 ++++ .../ImageFromMediaLocationProvider.cs | 19 +- .../Movies/MovieDbImagesProvider.cs | 4 +- .../Movies/MovieUpdatesPrescanTask.cs | 6 +- .../Movies/TmdbPersonProvider.cs | 2 +- Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 12 files changed, 317 insertions(+), 122 deletions(-) diff --git a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs index 6c7ba96ec..385bef026 100644 --- a/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs +++ b/MediaBrowser.Api/DefaultTheme/DefaultThemeService.cs @@ -51,8 +51,8 @@ namespace MediaBrowser.Api.DefaultTheme public string RomanceGenre { get; set; } } - [Route("/MBT/DefaultTheme/Home", "GET")] - public class GetHomeView : IReturn + [Route("/MBT/DefaultTheme/Favorites", "GET")] + public class GetFavoritesView : IReturn { [ApiMember(Name = "UserId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")] public Guid UserId { get; set; } @@ -78,47 +78,103 @@ namespace MediaBrowser.Api.DefaultTheme _userDataManager = userDataManager; } - public object Get(GetHomeView request) - { - var result = GetHomeView(request); - - return ToOptimizedResult(result); - } - - private HomeView GetHomeView(GetHomeView request) + public object Get(GetFavoritesView request) { var user = _userManager.GetUserById(request.UserId); - var allItems = user.RootFolder.GetRecursiveChildren(user) + var allItems = user.RootFolder.GetRecursiveChildren(user, i => _userDataManager.GetUserData(user.Id, i.GetUserDataKey()).IsFavorite) .ToList(); - var itemsWithBackdrops = allItems.Where(i => i.BackdropImagePaths.Count > 0).ToList(); + var itemsWithImages = allItems.Where(i => !string.IsNullOrEmpty(i.PrimaryImagePath)) + .ToList(); - var view = new HomeView(); + var itemsWithBackdrops = allItems.Where(i => i.BackdropImagePaths.Count > 0) + .ToList(); + + var view = new FavoritesView(); var fields = new List(); - var eligibleSpotlightItems = itemsWithBackdrops - .Where(i => i is Game || i is Movie || i is Series || i is MusicArtist); + view.BackdropItems = FilterItemsForBackdropDisplay(itemsWithBackdrops.OrderBy(i => Guid.NewGuid())) + .Take(10) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); - var dtos = FilterItemsForBackdropDisplay(eligibleSpotlightItems) + var spotlightItems = itemsWithBackdrops.OrderBy(i => Guid.NewGuid()) + .Take(10) + .ToList(); + + view.SpotlightItems = spotlightItems + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); + + view.Albums = itemsWithImages + .OfType() .OrderBy(i => Guid.NewGuid()) - .Take(50) - .Select(i => _dtoService.GetBaseItemDto(i, fields, user)); + .Take(4) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); - view.SpotlightItems = dtos.ToList(); + view.Books = itemsWithImages + .OfType() + .OrderBy(i => Guid.NewGuid()) + .Take(6) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); - return view; + view.Episodes = itemsWithImages + .OfType() + .OrderBy(i => Guid.NewGuid()) + .Take(6) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); + + view.Games = itemsWithImages + .OfType() + .OrderBy(i => Guid.NewGuid()) + .Take(6) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); + + view.Movies = itemsWithImages + .OfType() + .OrderBy(i => Guid.NewGuid()) + .Take(6) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); + + view.Series = itemsWithImages + .OfType() + .OrderBy(i => Guid.NewGuid()) + .Take(6) + .Select(i => _dtoService.GetBaseItemDto(i, fields, user)) + .ToList(); + + view.Songs = itemsWithImages + .OfType