From 90eb34b56827c8a5a1853a9891751c2720f08275 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Mon, 1 Nov 2010 00:36:57 -0700 Subject: [PATCH] Adding pagination to the Comments admin index page. --HG-- branch : dev --- .../Controllers/AdminController.cs | 21 ++++++++++++++----- .../ViewModels/CommentsIndexViewModel.cs | 1 + .../Orchard.Comments/Views/Admin/Index.cshtml | 1 + .../Themes/TheAdmin/Styles/site.css | 9 ++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs b/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs index 5b0686f4b..8d172a1f5 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/Controllers/AdminController.cs @@ -5,10 +5,11 @@ using System.Reflection; using System.Web.Mvc; using JetBrains.Annotations; using Orchard.Comments.Models; +using Orchard.DisplayManagement; using Orchard.Localization; using Orchard.Logging; -using Orchard.Services; using Orchard.Settings; +using Orchard.UI.Navigation; using Orchard.UI.Notify; using Orchard.Security; using Orchard.Comments.ViewModels; @@ -19,11 +20,12 @@ namespace Orchard.Comments.Controllers { public class AdminController : Controller { private readonly ICommentService _commentService; - public AdminController(IOrchardServices services, ICommentService commentService) { + public AdminController(IOrchardServices services, ICommentService commentService, IShapeFactory shapeFactory) { _commentService = commentService; Services = services; Logger = NullLogger.Instance; T = NullLocalizer.Instance; + Shape = shapeFactory; } protected virtual IUser CurrentUser { get; [UsedImplicitly] private set; } @@ -32,8 +34,9 @@ namespace Orchard.Comments.Controllers { public IOrchardServices Services { get; set; } public ILogger Logger { 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 if (options == null) options = new CommentIndexOptions(); @@ -57,8 +60,16 @@ namespace Orchard.Comments.Controllers { default: throw new ArgumentOutOfRangeException(); } - var entries = comments.Select(comment => CreateCommentEntry(comment.Record)).ToList(); - var model = new CommentsIndexViewModel {Comments = entries, Options = options}; + 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 model = new CommentsIndexViewModel { + Comments = entries, + Options = options, + Pager = pagerShape + }; return View(model); } catch (Exception exception) { diff --git a/src/Orchard.Web/Modules/Orchard.Comments/ViewModels/CommentsIndexViewModel.cs b/src/Orchard.Web/Modules/Orchard.Comments/ViewModels/CommentsIndexViewModel.cs index e364e2cd7..a4ec034cc 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/ViewModels/CommentsIndexViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.Comments/ViewModels/CommentsIndexViewModel.cs @@ -5,6 +5,7 @@ namespace Orchard.Comments.ViewModels { public class CommentsIndexViewModel { public IList Comments { get; set; } public CommentIndexOptions Options { get; set; } + public dynamic Pager { get; set; } } public class CommentEntry { diff --git a/src/Orchard.Web/Modules/Orchard.Comments/Views/Admin/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Comments/Views/Admin/Index.cshtml index d028b4fac..74dfb26f1 100644 --- a/src/Orchard.Web/Modules/Orchard.Comments/Views/Admin/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Comments/Views/Admin/Index.cshtml @@ -80,5 +80,6 @@ commentIndex = commentIndex + 1; } + @Display(Model.Pager) } \ No newline at end of file diff --git a/src/Orchard.Web/Themes/TheAdmin/Styles/site.css b/src/Orchard.Web/Themes/TheAdmin/Styles/site.css index eb9b37bbc..b7d7da8f0 100644 --- a/src/Orchard.Web/Themes/TheAdmin/Styles/site.css +++ b/src/Orchard.Web/Themes/TheAdmin/Styles/site.css @@ -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 ----------------------------------------------------------*/ /* Routable */