From 31d079f1baea895b5cb0f1a737140ab94dc9a4fe Mon Sep 17 00:00:00 2001 From: LukePulverenti Date: Sat, 9 Mar 2013 23:22:36 -0500 Subject: unified the two sorting api's --- MediaBrowser.ServerApplication/ApplicationHost.cs | 3 +- .../LibraryExplorer.xaml.cs | 62 +++++++++++++++++---- .../MediaBrowser.ServerApplication.csproj | 5 +- ...MediaBrowser.ServerApplication_TemporaryKey.pfx | Bin 1676 -> 0 bytes 4 files changed, 58 insertions(+), 12 deletions(-) delete mode 100644 MediaBrowser.ServerApplication/MediaBrowser.ServerApplication_TemporaryKey.pfx (limited to 'MediaBrowser.ServerApplication') diff --git a/MediaBrowser.ServerApplication/ApplicationHost.cs b/MediaBrowser.ServerApplication/ApplicationHost.cs index c822aae847..e156c465be 100644 --- a/MediaBrowser.ServerApplication/ApplicationHost.cs +++ b/MediaBrowser.ServerApplication/ApplicationHost.cs @@ -18,6 +18,7 @@ using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Plugins; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Resolvers; +using MediaBrowser.Controller.Sorting; using MediaBrowser.Controller.Updates; using MediaBrowser.Controller.Weather; using MediaBrowser.IsoMounter; @@ -242,7 +243,7 @@ namespace MediaBrowser.ServerApplication ServerManager.AddWebSocketListeners(GetExports(false)); ServerManager.Start(); - LibraryManager.AddParts(GetExports(), GetExports(), GetExports(), GetExports()); + LibraryManager.AddParts(GetExports(), GetExports(), GetExports(), GetExports(), GetExports()); ProviderManager.AddMetadataProviders(GetExports().OrderBy(e => e.Priority).ToArray()); } diff --git a/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs b/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs index d567a9fd8e..26e0978a34 100644 --- a/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs +++ b/MediaBrowser.ServerApplication/LibraryExplorer.xaml.cs @@ -4,6 +4,7 @@ using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; +using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; @@ -78,7 +79,8 @@ namespace MediaBrowser.ServerApplication Cursor = Cursors.Wait; await Task.Run(() => { - IEnumerable children = CurrentUser.Name == "Physical" ? _libraryManager.RootFolder.Children.OrderBy(i => i.SortName) : _libraryManager.RootFolder.GetChildren(CurrentUser, sortBy: LocalizedStrings.Instance.GetString("NameDispPref")); + IEnumerable children = CurrentUser.Name == "Physical" ? _libraryManager.RootFolder.Children : _libraryManager.RootFolder.GetChildren(CurrentUser); + children = OrderByName(children, CurrentUser); foreach (Folder folder in children) { @@ -86,9 +88,12 @@ namespace MediaBrowser.ServerApplication var currentFolder = folder; Task.Factory.StartNew(() => { - var prefs = ddlProfile.SelectedItem != null ? currentFolder.GetDisplayPrefs(ddlProfile.SelectedItem as User, false) ?? new DisplayPreferences {SortBy = LocalizedStrings.Instance.GetString("NameDispPref")} : new DisplayPreferences {SortBy = LocalizedStrings.Instance.GetString("NameDispPref")}; + var prefs = ddlProfile.SelectedItem != null ? currentFolder.GetDisplayPrefs(ddlProfile.SelectedItem as User, false) ?? new DisplayPreferences {SortBy = ItemSortBy.SortName} : new DisplayPreferences {SortBy = ItemSortBy.SortName}; var node = new TreeViewItem { Tag = currentFolder }; - AddChildren(node, currentFolder.GetChildren(CurrentUser, prefs.IndexBy, prefs.SortBy ?? LocalizedStrings.Instance.GetString("NameDispPref")), CurrentUser); + + var subChildren = currentFolder.GetChildren(CurrentUser, prefs.IndexBy); + subChildren = OrderByName(subChildren, CurrentUser); + AddChildren(node, subChildren, CurrentUser); node.Header = currentFolder.Name + " (" + node.Items.Count + ")"; tvwLibrary.Items.Add(node); @@ -100,6 +105,28 @@ namespace MediaBrowser.ServerApplication } + /// + /// Orders the name of the by. + /// + /// The items. + /// The user. + /// IEnumerable{BaseItem}. + private IEnumerable OrderByName(IEnumerable items, User user) + { + return OrderBy(items, user, ItemSortBy.SortName); + } + + /// + /// Orders the name of the by. + /// + /// The items. + /// The user. + /// IEnumerable{BaseItem}. + private IEnumerable OrderBy(IEnumerable items, User user, string order) + { + return _libraryManager.Sort(items, user, new[] { order }, SortOrder.Ascending); + } + /// /// Adds the children. /// @@ -115,7 +142,7 @@ namespace MediaBrowser.ServerApplication if (subFolder != null) { var prefs = subFolder.GetDisplayPrefs(user, false) ?? new DisplayPreferences {SortBy = LocalizedStrings.Instance.GetString("NameDispPref")}; - AddChildren(node, subFolder.GetChildren(user, sortBy: prefs.SortBy), user); + AddChildren(node, OrderBy(subFolder.GetChildren(user), user, prefs.SortBy), user); node.Header = item.Name + " (" + node.Items.Count + ")"; } else @@ -152,14 +179,29 @@ namespace MediaBrowser.ServerApplication { lblIndexBy.Visibility = ddlIndexBy.Visibility = ddlSortBy.Visibility = lblSortBy.Visibility = Visibility.Visible; ddlIndexBy.ItemsSource = folder.IndexByOptionStrings; - ddlSortBy.ItemsSource = folder.SortByOptionStrings; + + ddlSortBy.ItemsSource = new [] + { + ItemSortBy.SortName, + ItemSortBy.Album, + ItemSortBy.AlbumArtist, + ItemSortBy.Artist, + ItemSortBy.CommunityRating, + ItemSortBy.DateCreated, + ItemSortBy.DatePlayed, + ItemSortBy.PremiereDate, + ItemSortBy.ProductionYear, + ItemSortBy.Random, + ItemSortBy.Runtime + }; + var prefs = folder.GetDisplayPrefs(ddlProfile.SelectedItem as User, false); ddlIndexBy.SelectedItem = prefs != null ? prefs.IndexBy ?? LocalizedStrings.Instance.GetString("NoneDispPref") : LocalizedStrings.Instance.GetString("NoneDispPref"); ddlSortBy.SelectedItem = prefs != null - ? prefs.SortBy ?? LocalizedStrings.Instance.GetString("NameDispPref") - : LocalizedStrings.Instance.GetString("NameDispPref"); + ? prefs.SortBy ?? ItemSortBy.SortName + : ItemSortBy.SortName; } else { @@ -311,7 +353,7 @@ namespace MediaBrowser.ServerApplication var folder = treeItem != null ? treeItem.Tag as Folder : null; - var prefs = folder != null ? folder.GetDisplayPrefs(CurrentUser, true) : new DisplayPreferences {SortBy = LocalizedStrings.Instance.GetString("NameDispPref")}; + var prefs = folder != null ? folder.GetDisplayPrefs(CurrentUser, true) : new DisplayPreferences {SortBy = ItemSortBy.SortName}; if (folder != null && prefs.IndexBy != ddlIndexBy.SelectedItem as string) { //grab UI context so we can update within the below task @@ -326,7 +368,7 @@ namespace MediaBrowser.ServerApplication //re-build the current item's children as an index prefs.IndexBy = ddlIndexBy.SelectedItem as string; treeItem.Items.Clear(); - AddChildren(treeItem,folder.GetChildren(CurrentUser, prefs.IndexBy, prefs.SortBy), CurrentUser); + AddChildren(treeItem, OrderBy(folder.GetChildren(CurrentUser, prefs.IndexBy), CurrentUser, prefs.SortBy), CurrentUser); treeItem.Header = folder.Name + "(" + treeItem.Items.Count + ")"; Cursor = Cursors.Arrow; @@ -367,7 +409,7 @@ namespace MediaBrowser.ServerApplication //re-sort prefs.SortBy = ddlSortBy.SelectedItem as string; treeItem.Items.Clear(); - AddChildren(treeItem,folder.GetChildren(CurrentUser,prefs.IndexBy, prefs.SortBy ?? LocalizedStrings.Instance.GetString("NameDispPref")), CurrentUser); + AddChildren(treeItem, OrderBy(folder.GetChildren(CurrentUser, prefs.IndexBy), CurrentUser, prefs.SortBy ?? ItemSortBy.SortName), CurrentUser); treeItem.Header = folder.Name + "(" + treeItem.Items.Count + ")"; Cursor = Cursors.Arrow; diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj index ec3137d837..88ef979509 100644 --- a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj +++ b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication.csproj @@ -76,7 +76,7 @@ - true + false false @@ -112,6 +112,9 @@ MinimumRecommendedRules.ruleset true + + LocalIntranet + ..\packages\Hardcodet.Wpf.TaskbarNotification.1.0.4.0\lib\net40\Hardcodet.Wpf.TaskbarNotification.dll diff --git a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication_TemporaryKey.pfx b/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication_TemporaryKey.pfx deleted file mode 100644 index 64676b0546..0000000000 Binary files a/MediaBrowser.ServerApplication/MediaBrowser.ServerApplication_TemporaryKey.pfx and /dev/null differ -- cgit v1.2.3