From eb14188cccb83acec4bed99cea6351dd8f33106f Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Mon, 19 Jul 2010 10:08:41 -0700 Subject: [PATCH] Adding admin content list filter (by type) & sort --HG-- branch : dev --- .../Contents/Controllers/AdminController.cs | 34 +++++++++++++++++++ .../ViewModels/ListContentsViewModel.cs | 17 +++------- .../Core/Contents/Views/Admin/List.ascx | 26 +++++++------- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs b/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs index 10d4bfbff..065886ae7 100644 --- a/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs +++ b/src/Orchard.Web/Core/Contents/Controllers/AdminController.cs @@ -52,6 +52,19 @@ namespace Orchard.Core.Contents.Controllers { var query = _contentManager.Query(VersionOptions.Latest, _contentDefinitionManager.ListTypeDefinitions().Select(ctd => ctd.Name).ToArray()); + // Ordering + switch (model.Options.OrderBy) { + case ContentsOrder.Modified: + query = query.OrderByDescending(cr => cr.ModifiedUtc); + break; + case ContentsOrder.Published: + query = query.OrderByDescending(cr => cr.PublishedUtc); + break; + case ContentsOrder.Created: + query = query.OrderByDescending(cr => cr.CreatedUtc); + break; + } + if (!string.IsNullOrEmpty(model.TypeName)) { var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.TypeName); if (contentTypeDefinition == null) @@ -69,10 +82,31 @@ namespace Orchard.Core.Contents.Controllers { var contentItems = query.Slice(skip, pageSize); model.Entries = contentItems.Select(BuildEntry).ToList(); + model.Options.SelectedFilter = model.TypeName; + model.Options.FilterOptions = _contentDefinitionManager.ListTypeDefinitions() + .Select(ctd => new KeyValuePair(ctd.Name, ctd.DisplayName)) + .ToList().OrderBy(kvp => kvp.Key); return View("List", model); } + [HttpPost, ActionName("List")] + [FormValueRequired("submit.Filter")] + public ActionResult ListFilterPOST(ContentOptions options) { + var routeValues = ControllerContext.RouteData.Values; + if (options != null) { + routeValues["Options.OrderBy"] = options.OrderBy; //todo: don't hard-code the key + if (_contentDefinitionManager.ListTypeDefinitions().Any(ctd => string.Equals(ctd.Name, options.SelectedFilter, StringComparison.OrdinalIgnoreCase))) { + routeValues["id"] = options.SelectedFilter; + } + else { + routeValues.Remove("id"); + } + } + + return RedirectToAction("List", routeValues); + } + [HttpPost, ActionName("List")] [FormValueRequired("submit.BulkEdit")] public ActionResult ListPOST(ContentOptions options, IEnumerable itemIds, string returnUrl) { diff --git a/src/Orchard.Web/Core/Contents/ViewModels/ListContentsViewModel.cs b/src/Orchard.Web/Core/Contents/ViewModels/ListContentsViewModel.cs index 90d108797..dc910aec6 100644 --- a/src/Orchard.Web/Core/Contents/ViewModels/ListContentsViewModel.cs +++ b/src/Orchard.Web/Core/Contents/ViewModels/ListContentsViewModel.cs @@ -33,26 +33,19 @@ namespace Orchard.Core.Contents.ViewModels { public class ContentOptions { public ContentOptions() { - Filter = ContentsFilter.All; - Order = ContentsOrder.Modified; + OrderBy = ContentsOrder.Modified; BulkAction = ContentsBulkAction.None; } - public ContentsFilter Filter { get; set; } - public ContentsOrder Order { get; set; } + public string SelectedFilter { get; set; } + public IEnumerable> FilterOptions { get; set; } + public ContentsOrder OrderBy { get; set; } public ContentsBulkAction BulkAction { get; set; } } - public enum ContentsFilter { - All, - Page, - BlogPost - } - public enum ContentsOrder { Modified, Published, - Created, - Title + Created } public enum ContentsBulkAction { diff --git a/src/Orchard.Web/Core/Contents/Views/Admin/List.ascx b/src/Orchard.Web/Core/Contents/Views/Admin/List.ascx index 9444bdf13..6095e8785 100644 --- a/src/Orchard.Web/Core/Contents/Views/Admin/List.ascx +++ b/src/Orchard.Web/Core/Contents/Views/Admin/List.ascx @@ -15,23 +15,23 @@ using (Html.BeginFormAntiForgeryPost()) { %> -<%--
- - + <%:Html.SelectOption(Model.Options.SelectedFilter, "", T("Any (show all)").ToString()) %> + <% foreach(var filterOption in Model.Options.FilterOptions) { %> + <%:Html.SelectOption(Model.Options.SelectedFilter, filterOption.Key, filterOption.Value) %><% + } %> - + <%:Html.SelectOption(Model.Options.OrderBy, ContentsOrder.Created, T("Date Created").ToString())%> + <%:Html.SelectOption(Model.Options.OrderBy, ContentsOrder.Modified, T("Date Modified").ToString())%> + <%:Html.SelectOption(Model.Options.OrderBy, ContentsOrder.Published, T("Date Published").ToString())%> - +
---%>
+
<%:Html.UnorderedList( Model.Entries, (entry, i) => Html.DisplayForItem(entry.ViewModel),