From a52ea4cf084c0e734fa9cd76e332b8e80d9f255b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 2 Aug 2013 16:36:44 -0400 Subject: [PATCH] added metadata editor sidebar --- MediaBrowser.Api/LibraryService.cs | 100 +++++++++++++++++- .../Api/DashboardService.cs | 4 +- .../MediaBrowser.WebDashboard.csproj | 75 +++++++++++++ 3 files changed, 176 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Api/LibraryService.cs b/MediaBrowser.Api/LibraryService.cs index bad3b47962..91ca8a5346 100644 --- a/MediaBrowser.Api/LibraryService.cs +++ b/MediaBrowser.Api/LibraryService.cs @@ -144,6 +144,25 @@ namespace MediaBrowser.Api public Guid? UserId { get; set; } } + [Route("/Items/{Id}/Ancestors", "GET")] + [Api(Description = "Gets all parents of an item")] + public class GetAncestors : IReturn + { + /// + /// Gets or sets the user id. + /// + /// The user id. + [ApiMember(Name = "UserId", Description = "Optional. Filter by user id, and attach user data", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public Guid? UserId { get; set; } + + /// + /// Gets or sets the id. + /// + /// The id. + [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] + public string Id { get; set; } + } + /// /// Class LibraryService /// @@ -174,6 +193,84 @@ namespace MediaBrowser.Api _userDataRepository = userDataRepository; } + /// + /// Gets the specified request. + /// + /// The request. + /// System.Object. + public object Get(GetAncestors request) + { + var result = GetAncestors(request).Result; + + return ToOptimizedResult(result); + } + + /// + /// Gets the ancestors. + /// + /// The request. + /// Task{BaseItemDto[]}. + public async Task GetAncestors(GetAncestors request) + { + var item = DtoBuilder.GetItemByClientId(request.Id, _userManager, _libraryManager); + + var tasks = new List>(); + + var user = request.UserId.HasValue ? _userManager.GetUserById(request.UserId.Value) : null; + + // Get everything + var fields = Enum.GetNames(typeof(ItemFields)) + .Select(i => (ItemFields)Enum.Parse(typeof(ItemFields), i, true)) + .ToList(); + + var dtoBuilder = new DtoBuilder(Logger, _libraryManager, _userDataRepository, _itemRepo); + + BaseItem parent = item.Parent; + + while (parent != null) + { + if (user != null) + { + parent = TranslateParentItem(parent, user); + } + + tasks.Add(dtoBuilder.GetBaseItemDto(parent, fields, user)); + + if (parent is UserRootFolder) + { + break; + } + + parent = parent.Parent; + } + + return await Task.WhenAll(tasks).ConfigureAwait(false); + } + + private BaseItem TranslateParentItem(BaseItem item, User user) + { + if (item.Parent is AggregateFolder) + { + return user.RootFolder.GetChildren(user, true).FirstOrDefault(i => + { + + try + { + return i.LocationType == LocationType.FileSystem && + i.ResolveArgs.PhysicalLocations.Contains(item.Path); + } + catch (Exception ex) + { + Logger.ErrorException("Error getting ResolveArgs for {0}", ex, i.Path); + return false; + } + + }); + } + + return item; + } + /// /// Gets the specified request. /// @@ -231,8 +328,7 @@ namespace MediaBrowser.Api { try { - await - _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None) + await _libraryManager.ValidateMediaLibrary(new Progress(), CancellationToken.None) .ConfigureAwait(false); } catch (Exception ex) diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index 11e842b2c2..32cec1793e 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -418,7 +418,8 @@ namespace MediaBrowser.WebDashboard.Api { "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js", "http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js", - "scripts/all.js" + versionString + "scripts/all.js" + versionString, + "thirdparty/jstree1.0fix2/jquery.jstree.js" }; var tags = files.Select(s => string.Format("", s)).ToArray(); @@ -546,6 +547,7 @@ namespace MediaBrowser.WebDashboard.Api "detailtable.css", "posteritem.css", "tileitem.css", + "metadataeditor.css", "notifications.css", "search.css", "pluginupdates.css", diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index dbe0ba4ee4..be836948bb 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -90,6 +90,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -515,6 +518,78 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + PreserveNewest