Updating pagination to use the total item count instead of a has next page bool for better flexibility.

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-11-02 00:25:25 -07:00
parent f4721065b9
commit 10a7abd278
10 changed files with 45 additions and 40 deletions

View File

@@ -88,8 +88,7 @@ namespace Orchard.Core.Contents.Controllers {
var list = Shape.List();
list.AddRange(pageOfContentItems.Select(ci => _contentManager.BuildDisplay(ci, "SummaryAdmin")));
var hasNextPage = query.Slice(pager.GetStartIndex(pager.Page + 1), 1).Any();
var pagerShape = Shape.Pager(pager).HasNextPage(hasNextPage);
var pagerShape = Shape.Pager(pager).TotalItemCount(query.Count());
var viewModel = Shape.ViewModel()
.ContentItems(list)

View File

@@ -17,13 +17,15 @@
routeData.Remove("id");
}
var hasNextPage = (Model.Page * Model.PageSize) < Model.TotalItemCount;
Model.Classes.Add("pager");
Model.Classes.Add("group");
var tag = Tag(Model, "ul");
}
@if (Model.HasNextPage || Model.Page > 1) {
@if (hasNextPage || Model.Page > 1) {
@tag.StartElement
if(Model.HasNextPage) {
if(hasNextPage) {
routeData["page"] = Model.Page + 1;
<li class="older">
@Html.ActionLink((string)nextText, (string)routeData["action"], (string)routeData["controller"], routeData, null)

View File

@@ -74,8 +74,8 @@ namespace Orchard.Blogs.Controllers {
list.AddRange(blogPosts);
blog.Content.Add(Shape.Parts_Blogs_BlogPost_List(ContentItems: list), "5");
var hasNextPage = _blogPostService.Get(blogPart, pager.GetStartIndex(pager.Page + 1), 1).Any();
blog.Content.Add(Shape.Pager(pager).HasNextPage(hasNextPage), "Content:after");
var totalItemCount = _blogPostService.PostCount(blogPart);
blog.Content.Add(Shape.Pager(pager).TotalItemCount(totalItemCount), "Content:after");
return View(blog);
}

View File

@@ -49,11 +49,18 @@ namespace Orchard.Blogs.Services {
return GetBlogQuery(blogPart, versionOptions).List().Select(ci => ci.As<BlogPostPart>());
}
public int PostCount(BlogPart blogPart, VersionOptions versionOptions) {
return GetBlogQuery(blogPart, versionOptions).Count();
}
public IEnumerable<BlogPostPart> Get(BlogPart blogPart, int skip, int count) {
return GetBlogQuery(blogPart, VersionOptions.Published).Slice(skip, count).ToList().Select(ci => ci.As<BlogPostPart>());
}
public int PostCount(BlogPart blogPart) {
return PostCount(blogPart, VersionOptions.Published);
}
public IEnumerable<BlogPostPart> Get(BlogPart blogPart, ArchiveData archiveData) {
var query = GetBlogQuery(blogPart, VersionOptions.Published);

View File

@@ -13,6 +13,8 @@ namespace Orchard.Blogs.Services {
IEnumerable<BlogPostPart> Get(BlogPart blogPart, VersionOptions versionOptions);
IEnumerable<BlogPostPart> Get(BlogPart blogPart, ArchiveData archiveData);
IEnumerable<BlogPostPart> Get(BlogPart blogPart, int skip, int count);
int PostCount(BlogPart blogPart);
int PostCount(BlogPart blogPart, VersionOptions versionOptions);
IEnumerable<KeyValuePair<ArchiveData, int>> GetArchives(BlogPart blogPart);
void Delete(BlogPostPart blogPostPart);
void Publish(BlogPostPart blogPostPart);

View File

@@ -5,6 +5,8 @@ using System.Reflection;
using System.Web.Mvc;
using JetBrains.Annotations;
using Orchard.Comments.Models;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Records;
using Orchard.DisplayManagement;
using Orchard.Localization;
using Orchard.Logging;
@@ -42,7 +44,7 @@ namespace Orchard.Comments.Controllers {
options = new CommentIndexOptions();
// Filtering
IEnumerable<CommentPart> comments;
IContentQuery<CommentPart, CommentPartRecord> comments;
try {
switch (options.Filter) {
case CommentIndexFilter.All:
@@ -60,13 +62,13 @@ namespace Orchard.Comments.Controllers {
default:
throw new ArgumentOutOfRangeException();
}
var entries = comments.Skip(pager.GetStartIndex()).Take(pager.PageSize).Select(comment => CreateCommentEntry(comment.Record)).ToList();
var hasNextPage = comments.Skip(pager.GetStartIndex(pager.Page + 1)).Any();
var pagerShape = Shape.Pager(pager).HasNextPage(hasNextPage);
var entries = comments.Slice(pager.GetStartIndex(), pager.PageSize).ToList().Select(comment => CreateCommentEntry(comment.Record));
var pagerShape = Shape.Pager(pager).TotalItemCount(comments.Count());
var model = new CommentsIndexViewModel {
Comments = entries,
Comments = entries.ToList(),
Options = options,
Pager = pagerShape
};
@@ -140,7 +142,7 @@ namespace Orchard.Comments.Controllers {
options = new CommentDetailsOptions();
// Filtering
IEnumerable<CommentPart> comments;
IContentQuery<CommentPart, CommentPartRecord> comments;
try {
switch (options.Filter) {
case CommentDetailsFilter.All:
@@ -158,7 +160,7 @@ namespace Orchard.Comments.Controllers {
default:
throw new ArgumentOutOfRangeException();
}
var entries = comments.Select(comment => CreateCommentEntry(comment.Record)).ToList();
var entries = comments.List().Select(comment => CreateCommentEntry(comment.Record)).ToList();
var model = new CommentsDetailsViewModel {
Comments = entries,
Options = options,

View File

@@ -35,7 +35,8 @@ namespace Orchard.Comments.Handlers {
OnRemoved<CommentsPart>(
(context, c) => {
foreach (var comment in commentService.GetCommentsForCommentedContent(context.ContentItem.Id)) {
var comments = commentService.GetCommentsForCommentedContent(context.ContentItem.Id).List();
foreach (var comment in comments) {
contentManager.Remove(comment.ContentItem);
}
});

View File

@@ -1,7 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using JetBrains.Annotations;
using Orchard.Comments.Drivers;
using Orchard.Comments.Models;
using Orchard.ContentManagement.Aspects;
using Orchard.Data;
@@ -32,32 +30,28 @@ namespace Orchard.Comments.Services {
public ILogger Logger { get; set; }
protected virtual IUser CurrentUser { get; [UsedImplicitly] private set; }
public IEnumerable<CommentPart> GetComments() {
public IContentQuery<CommentPart, CommentPartRecord> GetComments() {
return _contentManager
.Query<CommentPart, CommentPartRecord>()
.List();
.Query<CommentPart, CommentPartRecord>();
}
public IEnumerable<CommentPart> GetComments(CommentStatus status) {
public IContentQuery<CommentPart, CommentPartRecord> GetComments(CommentStatus status) {
return _contentManager
.Query<CommentPart, CommentPartRecord>()
.Where(c => c.Status == status)
.List();
.Query<CommentPart, CommentPartRecord>()
.Where(c => c.Status == status);
}
public IEnumerable<CommentPart> GetCommentsForCommentedContent(int id) {
public IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id) {
return _contentManager
.Query<CommentPart, CommentPartRecord>()
.Where(c => c.CommentedOn == id || c.CommentedOnContainer == id)
.List();
.Query<CommentPart, CommentPartRecord>()
.Where(c => c.CommentedOn == id || c.CommentedOnContainer == id);
}
public IEnumerable<CommentPart> GetCommentsForCommentedContent(int id, CommentStatus status) {
public IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id, CommentStatus status) {
return _contentManager
.Query<CommentPart, CommentPartRecord>()
.Where(c => c.CommentedOn == id || c.CommentedOnContainer == id)
.Where(ctx => ctx.Status == status)
.List();
.Query<CommentPart, CommentPartRecord>()
.Where(c => c.CommentedOn == id || c.CommentedOnContainer == id)
.Where(ctx => ctx.Status == status);
}
public CommentPart GetComment(int id) {

View File

@@ -1,13 +1,12 @@
using System.Collections.Generic;
using Orchard.Comments.Models;
using Orchard.ContentManagement;
namespace Orchard.Comments.Services {
public interface ICommentService : IDependency {
IEnumerable<CommentPart> GetComments();
IEnumerable<CommentPart> GetComments(CommentStatus status);
IEnumerable<CommentPart> GetCommentsForCommentedContent(int id);
IEnumerable<CommentPart> GetCommentsForCommentedContent(int id, CommentStatus status);
IContentQuery<CommentPart, CommentPartRecord> GetComments();
IContentQuery<CommentPart, CommentPartRecord> GetComments(CommentStatus status);
IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id);
IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id, CommentStatus status);
CommentPart GetComment(int id);
ContentItemMetadata GetDisplayForCommentedContent(int id);
CommentPart CreateComment(CreateCommentContext commentRecord, bool moderateComments);

View File

@@ -66,8 +66,7 @@ namespace Orchard.Search.Controllers {
list.Add(_contentManager.BuildDisplay(contentItem, "Summary"));
}
var hasNextPage = searchHits.TotalPageCount > pager.Page;
var pagerShape = Shape.Pager(pager).HasNextPage(hasNextPage);
var pagerShape = Shape.Pager(pager).TotalItemCount(searchHits.TotalItemCount);
var searchViewModel = new SearchViewModel {
Query = q,