Adding pagination to the Comments admin index page.

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-11-01 00:36:57 -07:00
parent 6111dbb786
commit 90eb34b568
4 changed files with 27 additions and 5 deletions

View File

@@ -5,10 +5,11 @@ 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.DisplayManagement;
using Orchard.Localization; using Orchard.Localization;
using Orchard.Logging; using Orchard.Logging;
using Orchard.Services;
using Orchard.Settings; using Orchard.Settings;
using Orchard.UI.Navigation;
using Orchard.UI.Notify; using Orchard.UI.Notify;
using Orchard.Security; using Orchard.Security;
using Orchard.Comments.ViewModels; using Orchard.Comments.ViewModels;
@@ -19,11 +20,12 @@ namespace Orchard.Comments.Controllers {
public class AdminController : Controller { public class AdminController : Controller {
private readonly ICommentService _commentService; private readonly ICommentService _commentService;
public AdminController(IOrchardServices services, ICommentService commentService) { public AdminController(IOrchardServices services, ICommentService commentService, IShapeFactory shapeFactory) {
_commentService = commentService; _commentService = commentService;
Services = services; Services = services;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
T = NullLocalizer.Instance; T = NullLocalizer.Instance;
Shape = shapeFactory;
} }
protected virtual IUser CurrentUser { get; [UsedImplicitly] private set; } protected virtual IUser CurrentUser { get; [UsedImplicitly] private set; }
@@ -32,8 +34,9 @@ namespace Orchard.Comments.Controllers {
public IOrchardServices Services { get; set; } public IOrchardServices Services { get; set; }
public ILogger Logger { get; set; } public ILogger Logger { get; set; }
public Localizer T { get; set; } public Localizer T { get; set; }
dynamic Shape { get; set; }
public ActionResult Index(CommentIndexOptions options) { public ActionResult Index(CommentIndexOptions options, Pager pager) {
// Default options // Default options
if (options == null) if (options == null)
options = new CommentIndexOptions(); options = new CommentIndexOptions();
@@ -57,8 +60,16 @@ namespace Orchard.Comments.Controllers {
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
var entries = comments.Select(comment => CreateCommentEntry(comment.Record)).ToList(); var entries = comments.Skip(pager.GetStartIndex()).Take(pager.PageSize).Select(comment => CreateCommentEntry(comment.Record)).ToList();
var model = new CommentsIndexViewModel {Comments = entries, Options = options};
var hasNextPage = comments.Skip(pager.GetStartIndex(pager.Page + 1)).Any();
var pagerShape = Shape.Pager(pager).HasNextPage(hasNextPage);
var model = new CommentsIndexViewModel {
Comments = entries,
Options = options,
Pager = pagerShape
};
return View(model); return View(model);
} }
catch (Exception exception) { catch (Exception exception) {

View File

@@ -5,6 +5,7 @@ namespace Orchard.Comments.ViewModels {
public class CommentsIndexViewModel { public class CommentsIndexViewModel {
public IList<CommentEntry> Comments { get; set; } public IList<CommentEntry> Comments { get; set; }
public CommentIndexOptions Options { get; set; } public CommentIndexOptions Options { get; set; }
public dynamic Pager { get; set; }
} }
public class CommentEntry { public class CommentEntry {

View File

@@ -80,5 +80,6 @@
commentIndex = commentIndex + 1; commentIndex = commentIndex + 1;
} }
</table> </table>
@Display(Model.Pager)
</fieldset> </fieldset>
} }

View File

@@ -798,6 +798,15 @@ table .button {
} }
/* Pager
***************************************************************/
.pager { list-style: none; padding: 0; margin: 12px 0 0 0; }
.pager li { float: left; padding: 0 12px 0 0; margin: 0; }
.pager a { font-size: 1.077em; display: block; background-color: whiteSmoke; padding: 6px 6px; color: #333;}
.pager a:hover { background-color: #eaeaea; color: #333; }
/* Core Modules /* Core Modules
----------------------------------------------------------*/ ----------------------------------------------------------*/
/* Routable */ /* Routable */