mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Adding admin content list filter (by type) & sort
--HG-- branch : dev
This commit is contained in:
@@ -52,6 +52,19 @@ namespace Orchard.Core.Contents.Controllers {
|
|||||||
|
|
||||||
var query = _contentManager.Query(VersionOptions.Latest, _contentDefinitionManager.ListTypeDefinitions().Select(ctd => ctd.Name).ToArray());
|
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)) {
|
if (!string.IsNullOrEmpty(model.TypeName)) {
|
||||||
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.TypeName);
|
var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(model.TypeName);
|
||||||
if (contentTypeDefinition == null)
|
if (contentTypeDefinition == null)
|
||||||
@@ -69,10 +82,31 @@ namespace Orchard.Core.Contents.Controllers {
|
|||||||
var contentItems = query.Slice(skip, pageSize);
|
var contentItems = query.Slice(skip, pageSize);
|
||||||
|
|
||||||
model.Entries = contentItems.Select(BuildEntry).ToList();
|
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);
|
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")]
|
[HttpPost, ActionName("List")]
|
||||||
[FormValueRequired("submit.BulkEdit")]
|
[FormValueRequired("submit.BulkEdit")]
|
||||||
public ActionResult ListPOST(ContentOptions options, IEnumerable<int> itemIds, string returnUrl) {
|
public ActionResult ListPOST(ContentOptions options, IEnumerable<int> itemIds, string returnUrl) {
|
||||||
|
|||||||
@@ -33,26 +33,19 @@ namespace Orchard.Core.Contents.ViewModels {
|
|||||||
|
|
||||||
public class ContentOptions {
|
public class ContentOptions {
|
||||||
public ContentOptions() {
|
public ContentOptions() {
|
||||||
Filter = ContentsFilter.All;
|
OrderBy = ContentsOrder.Modified;
|
||||||
Order = ContentsOrder.Modified;
|
|
||||||
BulkAction = ContentsBulkAction.None;
|
BulkAction = ContentsBulkAction.None;
|
||||||
}
|
}
|
||||||
public ContentsFilter Filter { get; set; }
|
public string SelectedFilter { get; set; }
|
||||||
public ContentsOrder Order { get; set; }
|
public IEnumerable<KeyValuePair<string, string>> FilterOptions { get; set; }
|
||||||
|
public ContentsOrder OrderBy { get; set; }
|
||||||
public ContentsBulkAction BulkAction { get; set; }
|
public ContentsBulkAction BulkAction { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ContentsFilter {
|
|
||||||
All,
|
|
||||||
Page,
|
|
||||||
BlogPost
|
|
||||||
}
|
|
||||||
|
|
||||||
public enum ContentsOrder {
|
public enum ContentsOrder {
|
||||||
Modified,
|
Modified,
|
||||||
Published,
|
Published,
|
||||||
Created,
|
Created
|
||||||
Title
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ContentsBulkAction {
|
public enum ContentsBulkAction {
|
||||||
|
|||||||
@@ -15,23 +15,23 @@ using (Html.BeginFormAntiForgeryPost()) { %>
|
|||||||
</select>
|
</select>
|
||||||
<button type="submit" name="submit.BulkEdit" value="yes"><%:T("Apply") %></button>
|
<button type="submit" name="submit.BulkEdit" value="yes"><%:T("Apply") %></button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<%-- <fieldset class="bulk-actions">
|
<fieldset class="bulk-actions">
|
||||||
<label for="filterResults" class="bulk-filter"><%:T("Filter")%></label>
|
<label for="filterResults" class="bulk-filter"><%:T("Show only of type")%></label>
|
||||||
<select id="filterResults" name="<%:Html.NameOf(m => m.Options.Filter) %>">
|
<select id="filterResults" name="<%:Html.NameOf(m => m.Options.SelectedFilter) %>">
|
||||||
<%:Html.SelectOption(Model.Options.Filter, ContentsFilter.All, T("All Content").ToString())%>
|
<%:Html.SelectOption(Model.Options.SelectedFilter, "", T("Any (show all)").ToString()) %>
|
||||||
<%:Html.SelectOption(Model.Options.Filter, ContentsFilter.Page, T("Page").ToString())%>
|
<% foreach(var filterOption in Model.Options.FilterOptions) { %>
|
||||||
<%:Html.SelectOption(Model.Options.Filter, ContentsFilter.BlogPost, T("Blog Post").ToString())%>
|
<%:Html.SelectOption(Model.Options.SelectedFilter, filterOption.Key, filterOption.Value) %><%
|
||||||
|
} %>
|
||||||
</select>
|
</select>
|
||||||
<label for="orderResults" class="bulk-order"><%:T("Ordered by")%></label>
|
<label for="orderResults" class="bulk-order"><%:T("Ordered by")%></label>
|
||||||
<select id="orderResults" name="<%:Html.NameOf(m => m.Options.Order) %>">
|
<select id="orderResults" name="<%:Html.NameOf(m => m.Options.OrderBy) %>">
|
||||||
<%:Html.SelectOption(Model.Options.Order, ContentsOrder.Created, T("Date Created").ToString())%>
|
<%:Html.SelectOption(Model.Options.OrderBy, ContentsOrder.Created, T("Date Created").ToString())%>
|
||||||
<%:Html.SelectOption(Model.Options.Order, ContentsOrder.Modified, T("Date Modified").ToString())%>
|
<%:Html.SelectOption(Model.Options.OrderBy, ContentsOrder.Modified, T("Date Modified").ToString())%>
|
||||||
<%:Html.SelectOption(Model.Options.Order, ContentsOrder.Published, T("Date Published").ToString())%>
|
<%:Html.SelectOption(Model.Options.OrderBy, ContentsOrder.Published, T("Date Published").ToString())%>
|
||||||
<%:Html.SelectOption(Model.Options.Order, ContentsOrder.Title, T("Title").ToString())%>
|
|
||||||
</select>
|
</select>
|
||||||
<button type="submit" name="submit.Filter"><%:T("Apply") %></button>
|
<button type="submit" name="submit.Filter" value="yes please"><%:T("Apply") %></button>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
--%> <fieldset class="contentItems bulk-items">
|
<fieldset class="contentItems bulk-items">
|
||||||
<%:Html.UnorderedList(
|
<%:Html.UnorderedList(
|
||||||
Model.Entries,
|
Model.Entries,
|
||||||
(entry, i) => Html.DisplayForItem(entry.ViewModel),
|
(entry, i) => Html.DisplayForItem(entry.ViewModel),
|
||||||
|
|||||||
Reference in New Issue
Block a user