mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 03:58:13 +08:00
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:
@@ -88,8 +88,7 @@ namespace Orchard.Core.Contents.Controllers {
|
|||||||
var list = Shape.List();
|
var list = Shape.List();
|
||||||
list.AddRange(pageOfContentItems.Select(ci => _contentManager.BuildDisplay(ci, "SummaryAdmin")));
|
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).TotalItemCount(query.Count());
|
||||||
var pagerShape = Shape.Pager(pager).HasNextPage(hasNextPage);
|
|
||||||
|
|
||||||
var viewModel = Shape.ViewModel()
|
var viewModel = Shape.ViewModel()
|
||||||
.ContentItems(list)
|
.ContentItems(list)
|
||||||
|
|||||||
@@ -17,13 +17,15 @@
|
|||||||
routeData.Remove("id");
|
routeData.Remove("id");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var hasNextPage = (Model.Page * Model.PageSize) < Model.TotalItemCount;
|
||||||
|
|
||||||
Model.Classes.Add("pager");
|
Model.Classes.Add("pager");
|
||||||
Model.Classes.Add("group");
|
Model.Classes.Add("group");
|
||||||
var tag = Tag(Model, "ul");
|
var tag = Tag(Model, "ul");
|
||||||
}
|
}
|
||||||
@if (Model.HasNextPage || Model.Page > 1) {
|
@if (hasNextPage || Model.Page > 1) {
|
||||||
@tag.StartElement
|
@tag.StartElement
|
||||||
if(Model.HasNextPage) {
|
if(hasNextPage) {
|
||||||
routeData["page"] = Model.Page + 1;
|
routeData["page"] = Model.Page + 1;
|
||||||
<li class="older">
|
<li class="older">
|
||||||
@Html.ActionLink((string)nextText, (string)routeData["action"], (string)routeData["controller"], routeData, null)
|
@Html.ActionLink((string)nextText, (string)routeData["action"], (string)routeData["controller"], routeData, null)
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ namespace Orchard.Blogs.Controllers {
|
|||||||
list.AddRange(blogPosts);
|
list.AddRange(blogPosts);
|
||||||
blog.Content.Add(Shape.Parts_Blogs_BlogPost_List(ContentItems: list), "5");
|
blog.Content.Add(Shape.Parts_Blogs_BlogPost_List(ContentItems: list), "5");
|
||||||
|
|
||||||
var hasNextPage = _blogPostService.Get(blogPart, pager.GetStartIndex(pager.Page + 1), 1).Any();
|
var totalItemCount = _blogPostService.PostCount(blogPart);
|
||||||
blog.Content.Add(Shape.Pager(pager).HasNextPage(hasNextPage), "Content:after");
|
blog.Content.Add(Shape.Pager(pager).TotalItemCount(totalItemCount), "Content:after");
|
||||||
|
|
||||||
return View(blog);
|
return View(blog);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,11 +49,18 @@ namespace Orchard.Blogs.Services {
|
|||||||
return GetBlogQuery(blogPart, versionOptions).List().Select(ci => ci.As<BlogPostPart>());
|
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) {
|
public IEnumerable<BlogPostPart> Get(BlogPart blogPart, int skip, int count) {
|
||||||
return GetBlogQuery(blogPart, VersionOptions.Published).Slice(skip, count).ToList().Select(ci => ci.As<BlogPostPart>());
|
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) {
|
public IEnumerable<BlogPostPart> Get(BlogPart blogPart, ArchiveData archiveData) {
|
||||||
var query = GetBlogQuery(blogPart, VersionOptions.Published);
|
var query = GetBlogQuery(blogPart, VersionOptions.Published);
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace Orchard.Blogs.Services {
|
|||||||
IEnumerable<BlogPostPart> Get(BlogPart blogPart, VersionOptions versionOptions);
|
IEnumerable<BlogPostPart> Get(BlogPart blogPart, VersionOptions versionOptions);
|
||||||
IEnumerable<BlogPostPart> Get(BlogPart blogPart, ArchiveData archiveData);
|
IEnumerable<BlogPostPart> Get(BlogPart blogPart, ArchiveData archiveData);
|
||||||
IEnumerable<BlogPostPart> Get(BlogPart blogPart, int skip, int count);
|
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);
|
IEnumerable<KeyValuePair<ArchiveData, int>> GetArchives(BlogPart blogPart);
|
||||||
void Delete(BlogPostPart blogPostPart);
|
void Delete(BlogPostPart blogPostPart);
|
||||||
void Publish(BlogPostPart blogPostPart);
|
void Publish(BlogPostPart blogPostPart);
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ using System.Reflection;
|
|||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Orchard.Comments.Models;
|
using Orchard.Comments.Models;
|
||||||
|
using Orchard.ContentManagement;
|
||||||
|
using Orchard.ContentManagement.Records;
|
||||||
using Orchard.DisplayManagement;
|
using Orchard.DisplayManagement;
|
||||||
using Orchard.Localization;
|
using Orchard.Localization;
|
||||||
using Orchard.Logging;
|
using Orchard.Logging;
|
||||||
@@ -42,7 +44,7 @@ namespace Orchard.Comments.Controllers {
|
|||||||
options = new CommentIndexOptions();
|
options = new CommentIndexOptions();
|
||||||
|
|
||||||
// Filtering
|
// Filtering
|
||||||
IEnumerable<CommentPart> comments;
|
IContentQuery<CommentPart, CommentPartRecord> comments;
|
||||||
try {
|
try {
|
||||||
switch (options.Filter) {
|
switch (options.Filter) {
|
||||||
case CommentIndexFilter.All:
|
case CommentIndexFilter.All:
|
||||||
@@ -60,13 +62,13 @@ namespace Orchard.Comments.Controllers {
|
|||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
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 entries = comments.Slice(pager.GetStartIndex(), pager.PageSize).ToList().Select(comment => CreateCommentEntry(comment.Record));
|
||||||
var pagerShape = Shape.Pager(pager).HasNextPage(hasNextPage);
|
|
||||||
|
var pagerShape = Shape.Pager(pager).TotalItemCount(comments.Count());
|
||||||
|
|
||||||
var model = new CommentsIndexViewModel {
|
var model = new CommentsIndexViewModel {
|
||||||
Comments = entries,
|
Comments = entries.ToList(),
|
||||||
Options = options,
|
Options = options,
|
||||||
Pager = pagerShape
|
Pager = pagerShape
|
||||||
};
|
};
|
||||||
@@ -140,7 +142,7 @@ namespace Orchard.Comments.Controllers {
|
|||||||
options = new CommentDetailsOptions();
|
options = new CommentDetailsOptions();
|
||||||
|
|
||||||
// Filtering
|
// Filtering
|
||||||
IEnumerable<CommentPart> comments;
|
IContentQuery<CommentPart, CommentPartRecord> comments;
|
||||||
try {
|
try {
|
||||||
switch (options.Filter) {
|
switch (options.Filter) {
|
||||||
case CommentDetailsFilter.All:
|
case CommentDetailsFilter.All:
|
||||||
@@ -158,7 +160,7 @@ namespace Orchard.Comments.Controllers {
|
|||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
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 {
|
var model = new CommentsDetailsViewModel {
|
||||||
Comments = entries,
|
Comments = entries,
|
||||||
Options = options,
|
Options = options,
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ namespace Orchard.Comments.Handlers {
|
|||||||
|
|
||||||
OnRemoved<CommentsPart>(
|
OnRemoved<CommentsPart>(
|
||||||
(context, c) => {
|
(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);
|
contentManager.Remove(comment.ContentItem);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System.Linq;
|
||||||
using System.Linq;
|
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Orchard.Comments.Drivers;
|
|
||||||
using Orchard.Comments.Models;
|
using Orchard.Comments.Models;
|
||||||
using Orchard.ContentManagement.Aspects;
|
using Orchard.ContentManagement.Aspects;
|
||||||
using Orchard.Data;
|
using Orchard.Data;
|
||||||
@@ -32,32 +30,28 @@ namespace Orchard.Comments.Services {
|
|||||||
public ILogger Logger { get; set; }
|
public ILogger Logger { get; set; }
|
||||||
protected virtual IUser CurrentUser { get; [UsedImplicitly] private set; }
|
protected virtual IUser CurrentUser { get; [UsedImplicitly] private set; }
|
||||||
|
|
||||||
public IEnumerable<CommentPart> GetComments() {
|
public IContentQuery<CommentPart, CommentPartRecord> GetComments() {
|
||||||
return _contentManager
|
return _contentManager
|
||||||
.Query<CommentPart, CommentPartRecord>()
|
.Query<CommentPart, CommentPartRecord>();
|
||||||
.List();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<CommentPart> GetComments(CommentStatus status) {
|
public IContentQuery<CommentPart, CommentPartRecord> GetComments(CommentStatus status) {
|
||||||
return _contentManager
|
return _contentManager
|
||||||
.Query<CommentPart, CommentPartRecord>()
|
.Query<CommentPart, CommentPartRecord>()
|
||||||
.Where(c => c.Status == status)
|
.Where(c => c.Status == status);
|
||||||
.List();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<CommentPart> GetCommentsForCommentedContent(int id) {
|
public IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id) {
|
||||||
return _contentManager
|
return _contentManager
|
||||||
.Query<CommentPart, CommentPartRecord>()
|
.Query<CommentPart, CommentPartRecord>()
|
||||||
.Where(c => c.CommentedOn == id || c.CommentedOnContainer == id)
|
.Where(c => c.CommentedOn == id || c.CommentedOnContainer == id);
|
||||||
.List();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<CommentPart> GetCommentsForCommentedContent(int id, CommentStatus status) {
|
public IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id, CommentStatus status) {
|
||||||
return _contentManager
|
return _contentManager
|
||||||
.Query<CommentPart, CommentPartRecord>()
|
.Query<CommentPart, CommentPartRecord>()
|
||||||
.Where(c => c.CommentedOn == id || c.CommentedOnContainer == id)
|
.Where(c => c.CommentedOn == id || c.CommentedOnContainer == id)
|
||||||
.Where(ctx => ctx.Status == status)
|
.Where(ctx => ctx.Status == status);
|
||||||
.List();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommentPart GetComment(int id) {
|
public CommentPart GetComment(int id) {
|
||||||
|
|||||||
@@ -1,13 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
|
||||||
using Orchard.Comments.Models;
|
using Orchard.Comments.Models;
|
||||||
using Orchard.ContentManagement;
|
using Orchard.ContentManagement;
|
||||||
|
|
||||||
namespace Orchard.Comments.Services {
|
namespace Orchard.Comments.Services {
|
||||||
public interface ICommentService : IDependency {
|
public interface ICommentService : IDependency {
|
||||||
IEnumerable<CommentPart> GetComments();
|
IContentQuery<CommentPart, CommentPartRecord> GetComments();
|
||||||
IEnumerable<CommentPart> GetComments(CommentStatus status);
|
IContentQuery<CommentPart, CommentPartRecord> GetComments(CommentStatus status);
|
||||||
IEnumerable<CommentPart> GetCommentsForCommentedContent(int id);
|
IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id);
|
||||||
IEnumerable<CommentPart> GetCommentsForCommentedContent(int id, CommentStatus status);
|
IContentQuery<CommentPart, CommentPartRecord> GetCommentsForCommentedContent(int id, CommentStatus status);
|
||||||
CommentPart GetComment(int id);
|
CommentPart GetComment(int id);
|
||||||
ContentItemMetadata GetDisplayForCommentedContent(int id);
|
ContentItemMetadata GetDisplayForCommentedContent(int id);
|
||||||
CommentPart CreateComment(CreateCommentContext commentRecord, bool moderateComments);
|
CommentPart CreateComment(CreateCommentContext commentRecord, bool moderateComments);
|
||||||
|
|||||||
@@ -66,8 +66,7 @@ namespace Orchard.Search.Controllers {
|
|||||||
list.Add(_contentManager.BuildDisplay(contentItem, "Summary"));
|
list.Add(_contentManager.BuildDisplay(contentItem, "Summary"));
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasNextPage = searchHits.TotalPageCount > pager.Page;
|
var pagerShape = Shape.Pager(pager).TotalItemCount(searchHits.TotalItemCount);
|
||||||
var pagerShape = Shape.Pager(pager).HasNextPage(hasNextPage);
|
|
||||||
|
|
||||||
var searchViewModel = new SearchViewModel {
|
var searchViewModel = new SearchViewModel {
|
||||||
Query = q,
|
Query = q,
|
||||||
|
|||||||
Reference in New Issue
Block a user