mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Adding pagination to the Contents list admin page.
--HG-- branch : dev
This commit is contained in:
@@ -15,6 +15,7 @@ using Orchard.Data;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Logging;
|
||||
using Orchard.UI.Navigation;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Core.Contents.Controllers {
|
||||
@@ -44,13 +45,10 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
public Localizer T { get; set; }
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
public ActionResult List(ListContentsViewModel model) {
|
||||
public ActionResult List(ListContentsViewModel model, Pager pager) {
|
||||
if (model.ContainerId != null && _contentManager.GetLatest((int)model.ContainerId) == null)
|
||||
return HttpNotFound();
|
||||
|
||||
const int pageSize = 20;
|
||||
var skip = (Math.Max(model.Page ?? 0, 1) - 1) * pageSize;
|
||||
|
||||
var query = _contentManager.Query(VersionOptions.Latest, GetCreatableTypes().Select(ctd => ctd.Name).ToArray());
|
||||
|
||||
if (!string.IsNullOrEmpty(model.TypeName)) {
|
||||
@@ -104,7 +102,7 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
|
||||
//-- instead of this (having the ordering and skip/take after the query)
|
||||
|
||||
contentItems = contentItems.Skip(skip).Take(pageSize).ToList();
|
||||
var pageOfContentItems = contentItems.Skip(pager.GetStartIndex()).Take(pager.PageSize).ToList();
|
||||
|
||||
model.Options.SelectedFilter = model.TypeName;
|
||||
model.Options.FilterOptions = GetCreatableTypes()
|
||||
@@ -113,10 +111,14 @@ namespace Orchard.Core.Contents.Controllers {
|
||||
|
||||
|
||||
var list = Shape.List();
|
||||
list.AddRange(contentItems.Select(ci => _contentManager.BuildDisplay(ci, "SummaryAdmin")));
|
||||
list.AddRange(pageOfContentItems.Select(ci => _contentManager.BuildDisplay(ci, "SummaryAdmin")));
|
||||
|
||||
var hasNextPage = contentItems.Skip(pager.GetStartIndex(pager.Page + 1)).Any();
|
||||
var pagerShape = Shape.Pager(pager).HasNextPage(hasNextPage);
|
||||
|
||||
var viewModel = Shape.ViewModel()
|
||||
.ContentItems(list)
|
||||
.Pager(pagerShape)
|
||||
.Options(model.Options)
|
||||
.TypeDisplayName(model.TypeDisplayName ?? "");
|
||||
|
||||
|
@@ -40,6 +40,6 @@
|
||||
</fieldset>
|
||||
<fieldset class="contentItems bulk-items">
|
||||
@Display(Model.ContentItems)
|
||||
@Display(Model.ContentItems2)
|
||||
</fieldset>
|
||||
@Display(Model.Pager)
|
||||
}
|
Reference in New Issue
Block a user