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.Controller/Entities/Folder.cs | 73 ++---------------------------- 1 file changed, 3 insertions(+), 70 deletions(-) (limited to 'MediaBrowser.Controller/Entities') diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index c6f4790298..ef34742df4 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -13,7 +13,6 @@ using System.Linq; using System.Runtime.Serialization; using System.Threading; using System.Threading.Tasks; -using SortOrder = MediaBrowser.Controller.Sorting.SortOrder; namespace MediaBrowser.Controller.Entities { @@ -177,63 +176,6 @@ namespace MediaBrowser.Controller.Entities } } - #region Sorting - - /// - /// The _sort by options - /// - private Dictionary> _sortByOptions; - /// - /// Dictionary of sort options - consists of a display value (localized) and an IComparer of BaseItem - /// - /// The sort by options. - [IgnoreDataMember] - public Dictionary> SortByOptions - { - get { return _sortByOptions ?? (_sortByOptions = GetSortByOptions()); } - } - - /// - /// Returns the valid set of sort by options for this folder type. - /// Override or extend to modify. - /// - /// Dictionary{System.StringIComparer{BaseItem}}. - protected virtual Dictionary> GetSortByOptions() - { - return new Dictionary> { - {LocalizedStrings.Instance.GetString("NameDispPref"), new BaseItemComparer(SortOrder.Name, Logger)}, - {LocalizedStrings.Instance.GetString("DateDispPref"), new BaseItemComparer(SortOrder.Date, Logger)}, - {LocalizedStrings.Instance.GetString("RatingDispPref"), new BaseItemComparer(SortOrder.Rating, Logger)}, - {LocalizedStrings.Instance.GetString("RuntimeDispPref"), new BaseItemComparer(SortOrder.Runtime, Logger)}, - {LocalizedStrings.Instance.GetString("YearDispPref"), new BaseItemComparer(SortOrder.Year, Logger)} - }; - - } - - /// - /// Get a sorting comparer by name - /// - /// The name. - /// IComparer{BaseItem}. - private IComparer GetSortingFunction(string name) - { - IComparer sorting; - SortByOptions.TryGetValue(name ?? "", out sorting); - return sorting ?? new BaseItemComparer(SortOrder.Name, Logger); - } - - /// - /// Get the list of sort by choices for this folder (localized). - /// - /// The sort by option strings. - [IgnoreDataMember] - public IEnumerable SortByOptionStrings - { - get { return SortByOptions.Keys; } - } - - #endregion - #region Indexing /// @@ -877,11 +819,9 @@ namespace MediaBrowser.Controller.Entities /// /// The user. /// The index by. - /// The sort by. - /// The sort order. /// IEnumerable{BaseItem}. /// - public virtual IEnumerable GetChildren(User user, string indexBy = null, string sortBy = null, Model.Entities.SortOrder? sortOrder = null) + public virtual IEnumerable GetChildren(User user, string indexBy = null) { if (user == null) { @@ -889,7 +829,7 @@ namespace MediaBrowser.Controller.Entities } //the true root should return our users root folder children - if (IsPhysicalRoot) return user.RootFolder.GetChildren(user, indexBy, sortBy, sortOrder); + if (IsPhysicalRoot) return user.RootFolder.GetChildren(user, indexBy); IEnumerable result = null; @@ -904,14 +844,7 @@ namespace MediaBrowser.Controller.Entities result = ActualChildren.Where(c => c.IsVisible(user)); } - if (string.IsNullOrEmpty(sortBy)) - { - return result; - } - - return sortOrder.HasValue && sortOrder.Value == Model.Entities.SortOrder.Descending - ? result.OrderByDescending(i => i, GetSortingFunction(sortBy)) - : result.OrderBy(i => i, GetSortingFunction(sortBy)); + return result; } /// -- cgit v1.2.3