Adding admin content list filter (by type) & sort

--HG--
branch : dev
This commit is contained in:
Nathan Heskew 2010-07-19 10:08:41 -07:00
parent 3c6c58fa84
commit eb14188ccc
3 changed files with 52 additions and 25 deletions

View File

@ -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<CommonRecord, DateTime?>(cr => cr.ModifiedUtc);
break;
case ContentsOrder.Published:
query = query.OrderByDescending<CommonRecord, DateTime?>(cr => cr.PublishedUtc);
break;
case ContentsOrder.Created:
query = query.OrderByDescending<CommonRecord, DateTime?>(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<string, string>(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<int> itemIds, string returnUrl) {

View File

@ -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<KeyValuePair<string, string>> 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 {

View File

@ -15,23 +15,23 @@ using (Html.BeginFormAntiForgeryPost()) { %>
</select>
<button type="submit" name="submit.BulkEdit" value="yes"><%:T("Apply") %></button>
</fieldset>
<%-- <fieldset class="bulk-actions">
<label for="filterResults" class="bulk-filter"><%:T("Filter")%></label>
<select id="filterResults" name="<%:Html.NameOf(m => m.Options.Filter) %>">
<%:Html.SelectOption(Model.Options.Filter, ContentsFilter.All, T("All Content").ToString())%>
<%:Html.SelectOption(Model.Options.Filter, ContentsFilter.Page, T("Page").ToString())%>
<%:Html.SelectOption(Model.Options.Filter, ContentsFilter.BlogPost, T("Blog Post").ToString())%>
<fieldset class="bulk-actions">
<label for="filterResults" class="bulk-filter"><%:T("Show only of type")%></label>
<select id="filterResults" name="<%:Html.NameOf(m => m.Options.SelectedFilter) %>">
<%: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) %><%
} %>
</select>
<label for="orderResults" class="bulk-order"><%:T("Ordered by")%></label>
<select id="orderResults" name="<%:Html.NameOf(m => m.Options.Order) %>">
<%:Html.SelectOption(Model.Options.Order, ContentsOrder.Created, T("Date Created").ToString())%>
<%:Html.SelectOption(Model.Options.Order, ContentsOrder.Modified, T("Date Modified").ToString())%>
<%:Html.SelectOption(Model.Options.Order, ContentsOrder.Published, T("Date Published").ToString())%>
<%:Html.SelectOption(Model.Options.Order, ContentsOrder.Title, T("Title").ToString())%>
<select id="orderResults" name="<%:Html.NameOf(m => m.Options.OrderBy) %>">
<%: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())%>
</select>
<button type="submit" name="submit.Filter"><%:T("Apply") %></button>
<button type="submit" name="submit.Filter" value="yes please"><%:T("Apply") %></button>
</fieldset>
--%> <fieldset class="contentItems bulk-items">
<fieldset class="contentItems bulk-items">
<%:Html.UnorderedList(
Model.Entries,
(entry, i) => Html.DisplayForItem(entry.ViewModel),