From ae4c4c6ce50c03d0e7bcfe1d2b6eca715dd2f0ff Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 14 May 2013 01:36:36 -0400 Subject: [PATCH] #247 - Web client - Hide views that have no content --- MediaBrowser.Api/LibraryService.cs | 58 ++++++++++++++++++- MediaBrowser.Model/Dto/ItemCounts.cs | 45 ++++++++++++++ MediaBrowser.Model/MediaBrowser.Model.csproj | 1 + MediaBrowser.WebDashboard/ApiClient.js | 19 +++++- .../MediaBrowser.WebDashboard.csproj | 12 ++++ MediaBrowser.WebDashboard/packages.config | 2 +- 6 files changed, 132 insertions(+), 5 deletions(-) create mode 100644 MediaBrowser.Model/Dto/ItemCounts.cs diff --git a/MediaBrowser.Api/LibraryService.cs b/MediaBrowser.Api/LibraryService.cs index d5d90cdb2..b0978a2cd 100644 --- a/MediaBrowser.Api/LibraryService.cs +++ b/MediaBrowser.Api/LibraryService.cs @@ -1,10 +1,16 @@ -using System.Threading; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Audio; +using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Persistence; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Querying; using ServiceStack.ServiceHost; using System; +using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace MediaBrowser.Api @@ -43,7 +49,15 @@ namespace MediaBrowser.Api public class RefreshLibrary : IReturnVoid { } - + + [Route("/Items/Counts", "GET")] + [Api(Description = "Gets counts of various item types")] + public class GetItemCounts : IReturn + { + [ApiMember(Name = "UserId", Description = "Optional. Get counts from a specific user's library.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public Guid? UserId { get; set; } + } + /// /// Class LibraryService /// @@ -55,16 +69,19 @@ namespace MediaBrowser.Api private readonly IItemRepository _itemRepo; private readonly ILibraryManager _libraryManager; + private readonly IUserManager _userManager; /// /// Initializes a new instance of the class. /// /// The item repo. /// The library manager. - public LibraryService(IItemRepository itemRepo, ILibraryManager libraryManager) + /// The user manager. + public LibraryService(IItemRepository itemRepo, ILibraryManager libraryManager, IUserManager userManager) { _itemRepo = itemRepo; _libraryManager = libraryManager; + _userManager = userManager; } /// @@ -79,6 +96,41 @@ namespace MediaBrowser.Api return ToOptimizedResult(result); } + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetItemCounts request) + { + var items = GetItems(request.UserId).ToList(); + + var counts = new ItemCounts + { + AlbumCount = items.OfType().Count(), + EpisodeCount = items.OfType().Count(), + GameCount = items.OfType().Count(), + MovieCount = items.OfType().Count(), + SeriesCount = items.OfType().Count(), + SongCount = items.OfType