#715 - Support creating/editing collections (boxsets) in web client

This commit is contained in:
Luke Pulverenti
2014-03-07 10:53:23 -05:00
parent c85f2957d9
commit e00985d07c
24 changed files with 390 additions and 55 deletions

View File

@@ -5,7 +5,9 @@ using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -30,7 +32,7 @@ namespace MediaBrowser.Server.Implementations.Collections
var folderName = _fileSystem.GetValidFilename(name);
var parentFolder = _libraryManager.GetItemById(options.ParentId) as Folder;
var parentFolder = GetParentFolder(options.ParentId);
if (parentFolder == null)
{
@@ -66,14 +68,94 @@ namespace MediaBrowser.Server.Implementations.Collections
}
}
public Task AddToCollection(Guid collectionId, Guid itemId)
private Folder GetParentFolder(Guid? parentId)
{
throw new NotImplementedException();
if (parentId.HasValue)
{
if (parentId.Value == Guid.Empty)
{
throw new ArgumentNullException("parentId");
}
return _libraryManager.GetItemById(parentId.Value) as Folder;
}
return _libraryManager.RootFolder.Children.OfType<ManualCollectionsFolder>().FirstOrDefault() ??
_libraryManager.RootFolder.GetHiddenChildren().OfType<ManualCollectionsFolder>().FirstOrDefault();
}
public Task RemoveFromCollection(Guid collectionId, Guid itemId)
public async Task AddToCollection(Guid collectionId, IEnumerable<Guid> ids)
{
throw new NotImplementedException();
var collection = _libraryManager.GetItemById(collectionId) as BoxSet;
if (collection == null)
{
throw new ArgumentException("No collection exists with the supplied Id");
}
var list = new List<LinkedChild>();
foreach (var itemId in ids)
{
var item = _libraryManager.GetItemById(itemId);
if (item == null)
{
throw new ArgumentException("No item exists with the supplied Id");
}
if (collection.LinkedChildren.Any(i => i.ItemId.HasValue && i.ItemId == itemId))
{
throw new ArgumentException("Item already exists in collection");
}
list.Add(new LinkedChild
{
ItemName = item.Name,
ItemYear = item.ProductionYear,
ItemType = item.GetType().Name,
Type = LinkedChildType.Manual
});
}
collection.LinkedChildren.AddRange(list);
await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false);
}
public async Task RemoveFromCollection(Guid collectionId, IEnumerable<Guid> itemIds)
{
var collection = _libraryManager.GetItemById(collectionId) as BoxSet;
if (collection == null)
{
throw new ArgumentException("No collection exists with the supplied Id");
}
var list = new List<LinkedChild>();
foreach (var itemId in itemIds)
{
var child = collection.LinkedChildren.FirstOrDefault(i => i.ItemId.HasValue && i.ItemId.Value == itemId);
if (child == null)
{
throw new ArgumentException("No collection title exists with the supplied Id");
}
list.Add(child);
}
foreach (var child in list)
{
collection.LinkedChildren.Remove(child);
}
await collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false);
await collection.RefreshMetadata(CancellationToken.None).ConfigureAwait(false);
}
}
}

View File

@@ -0,0 +1,55 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Controller.Entities;
using System.IO;
using System.Linq;
namespace MediaBrowser.Server.Implementations.Collections
{
public class CollectionsDynamicFolder : IVirtualFolderCreator
{
private readonly IApplicationPaths _appPaths;
public CollectionsDynamicFolder(IApplicationPaths appPaths)
{
_appPaths = appPaths;
}
public BasePluginFolder GetFolder()
{
var path = Path.Combine(_appPaths.DataPath, "collections");
Directory.CreateDirectory(path);
return new ManualCollectionsFolder
{
Path = path
};
}
}
public class ManualCollectionsFolder : BasePluginFolder
{
public ManualCollectionsFolder()
{
Name = "Collections";
}
public override bool IsVisible(User user)
{
if (!GetChildren(user, true).Any())
{
return false;
}
return base.IsVisible(user);
}
public override bool IsHidden
{
get
{
return !ActualChildren.Any() || base.IsHidden;
}
}
}
}

View File

@@ -37,6 +37,12 @@ namespace MediaBrowser.Server.Implementations.Library
var results = await GetSearchHints(inputItems, query).ConfigureAwait(false);
// Include item types
if (query.IncludeItemTypes.Length > 0)
{
results = results.Where(f => query.IncludeItemTypes.Contains(f.Item.GetType().Name, StringComparer.OrdinalIgnoreCase));
}
var searchResultArray = results.ToArray();
results = searchResultArray;

View File

@@ -583,6 +583,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
.ToDictionary(i => i.Name, StringComparer.OrdinalIgnoreCase);
programs = programList.OrderByDescending(i => GetRecommendationScore(i, user.Id, serviceName, genres))
.ThenBy(i => i.HasImage(ImageType.Primary) ? 0 : 1)
.ThenBy(i => i.StartDate);
if (query.Limit.HasValue)

View File

@@ -65,12 +65,9 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite, Version=1.0.90.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86" Condition=" '$(ConfigurationName)' != 'Release Mono' ">
<Reference Include="System.Data.SQLite, Version=1.0.91.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\System.Data.SQLite.x86.1.0.90.0\lib\net45\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Data.SQLite.Linq" Condition=" '$(ConfigurationName)' != 'Release Mono' ">
<HintPath>..\packages\System.Data.SQLite.x86.1.0.90.0\lib\net45\System.Data.SQLite.Linq.dll</HintPath>
<HintPath>..\packages\System.Data.SQLite.Core.1.0.91.3\lib\net45\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="Microsoft.CSharp" />
@@ -110,6 +107,7 @@
</Compile>
<Compile Include="BdInfo\BdInfoExaminer.cs" />
<Compile Include="Collections\CollectionManager.cs" />
<Compile Include="Collections\CollectionsDynamicFolder.cs" />
<Compile Include="Configuration\ServerConfigurationManager.cs" />
<Compile Include="Drawing\ImageHeader.cs" />
<Compile Include="Drawing\PercentPlayedDrawer.cs" />
@@ -378,6 +376,12 @@
<Link>swagger-ui\swagger-ui.min.js</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="x64\SQLite.Interop.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="x86\SQLite.Interop.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<EmbeddedResource Include="Localization\Ratings\be.txt" />
</ItemGroup>
<ItemGroup>

View File

@@ -4,5 +4,5 @@
<package id="MediaBrowser.BdInfo" version="1.0.0.10" targetFramework="net45" />
<package id="Mono.Nat" version="1.2.3" targetFramework="net45" />
<package id="morelinq" version="1.0.16006" targetFramework="net45" />
<package id="System.Data.SQLite.x86" version="1.0.90.0" targetFramework="net45" />
<package id="System.Data.SQLite.Core" version="1.0.91.3" targetFramework="net45" />
</packages>