mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Adding Blog pagination
- Yeah !!!! --HG-- branch : dev
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
@@ -6,6 +7,7 @@ using System.Xml.Linq;
|
||||
using Orchard.Blogs.Models;
|
||||
using Orchard.Blogs.Routing;
|
||||
using Orchard.Blogs.Services;
|
||||
using Orchard.Blogs.ViewModels;
|
||||
using Orchard.DisplayManagement;
|
||||
using Orchard.Logging;
|
||||
using Orchard.Mvc.Results;
|
||||
@@ -16,12 +18,14 @@ namespace Orchard.Blogs.Controllers {
|
||||
public class BlogController : Controller {
|
||||
private readonly IOrchardServices _services;
|
||||
private readonly IBlogService _blogService;
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
private readonly IBlogSlugConstraint _blogSlugConstraint;
|
||||
private readonly RouteCollection _routeCollection;
|
||||
|
||||
public BlogController(IOrchardServices services, IBlogService blogService, IBlogSlugConstraint blogSlugConstraint, RouteCollection routeCollection, IShapeHelperFactory shapeHelperFactory) {
|
||||
public BlogController(IOrchardServices services, IBlogService blogService, IBlogPostService blogPostService, IBlogSlugConstraint blogSlugConstraint, RouteCollection routeCollection, IShapeHelperFactory shapeHelperFactory) {
|
||||
_services = services;
|
||||
_blogService = blogService;
|
||||
_blogPostService = blogPostService;
|
||||
_blogSlugConstraint = blogSlugConstraint;
|
||||
_routeCollection = routeCollection;
|
||||
Logger = NullLogger.Instance;
|
||||
@@ -44,18 +48,31 @@ namespace Orchard.Blogs.Controllers {
|
||||
}
|
||||
|
||||
//TODO: (erikpo) Should move the slug parameter and get call and null check up into a model binder
|
||||
public ActionResult Item(string blogSlug) {
|
||||
public ActionResult Item(string blogSlug, int page) {
|
||||
const int pageSize = 10;
|
||||
|
||||
var correctedSlug = _blogSlugConstraint.FindSlug(blogSlug);
|
||||
if (correctedSlug == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
var blog = _blogService.Get(correctedSlug);
|
||||
BlogPart blog = _blogService.Get(correctedSlug);
|
||||
if (blog == null)
|
||||
return new NotFoundResult();
|
||||
|
||||
//todo: (heskew) "Blog" should be an alternative instead of a display type
|
||||
var model = _services.ContentManager.BuildDisplay(blog, "Blog");
|
||||
var blogPosts = _blogPostService.Get(blog, (page - 1)*pageSize, pageSize).Select(b => _services.ContentManager.BuildDisplay(b, "Summary.BlogPost"));
|
||||
|
||||
var list = Shape.List();
|
||||
list.AddRange(blogPosts);
|
||||
|
||||
var model = new DisplayBlogViewModel {
|
||||
BlogPostList = list,
|
||||
BlogPart = blog,
|
||||
Page = page,
|
||||
PageSize = pageSize
|
||||
};
|
||||
|
||||
return View(model);
|
||||
|
||||
}
|
||||
|
||||
public ActionResult LiveWriterManifest(string blogSlug) {
|
||||
|
@@ -107,6 +107,7 @@
|
||||
<Compile Include="Services\IBlogService.cs" />
|
||||
<Compile Include="Services\XmlRpcHandler.cs" />
|
||||
<Compile Include="ViewModels\BlogPostArchiveViewModel.cs" />
|
||||
<Compile Include="ViewModels\DisplayBlogViewModel.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Content\Admin\images\draft.gif" />
|
||||
@@ -118,6 +119,7 @@
|
||||
<Content Include="Scripts\archives.js" />
|
||||
<Content Include="Styles\admin.css" />
|
||||
<Content Include="Styles\archives.css" />
|
||||
<Content Include="Styles\pagination.css" />
|
||||
<Content Include="Views\BlogAdmin\Create.cshtml" />
|
||||
<Content Include="Views\BlogAdmin\Edit.cshtml" />
|
||||
<Content Include="Views\BlogAdmin\Item.cshtml" />
|
||||
@@ -131,7 +133,6 @@
|
||||
<Content Include="Views\Parts\Blogs.Blog.Manage.cshtml" />
|
||||
<Content Include="Views\Parts\Blogs.Blog.Description.cshtml" />
|
||||
<Content Include="Views\Parts\Common.Metadata.Admin.Blog.cshtml" />
|
||||
<Content Include="Views\Parts\Blogs.BlogPost.List.cshtml" />
|
||||
<Content Include="Views\EditorTemplates\Parts\Blogs.Blog.Fields.cshtml" />
|
||||
<Content Include="Views\Parts\Blogs.BlogPost.List.Admin.cshtml">
|
||||
<SubType>Code</SubType>
|
||||
@@ -190,6 +191,7 @@
|
||||
<None Include="Views\DisplayTemplates\Parts\Blogs.BlogArchives.cshtml" />
|
||||
<None Include="Views\EditorTemplates\Parts\Blogs.RecentBlogPosts.cshtml" />
|
||||
<None Include="Views\EditorTemplates\Parts\Blogs.BlogArchives.cshtml" />
|
||||
<None Include="Views\Parts\Blogs.BlogPost.List.cshtml" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
|
||||
|
@@ -259,6 +259,24 @@ namespace Orchard.Blogs {
|
||||
Priority = 11,
|
||||
Route = new Route(
|
||||
"{blogSlug}",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"},
|
||||
{"controller", "Blog"},
|
||||
{"action", "Item"},
|
||||
{"page", 1}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"blogSlug", _blogSlugConstraint}
|
||||
},
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"}
|
||||
},
|
||||
new MvcRouteHandler())
|
||||
},
|
||||
new RouteDescriptor {
|
||||
Priority = 11,
|
||||
Route = new Route(
|
||||
"{blogSlug}/Page/{*page}",
|
||||
new RouteValueDictionary {
|
||||
{"area", "Orchard.Blogs"},
|
||||
{"controller", "Blog"},
|
||||
|
@@ -49,6 +49,11 @@ namespace Orchard.Blogs.Services {
|
||||
return GetBlogQuery(blogPart, versionOptions).List().Select(ci => ci.As<BlogPostPart>());
|
||||
}
|
||||
|
||||
|
||||
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 IEnumerable<BlogPostPart> Get(BlogPart blogPart, ArchiveData archiveData) {
|
||||
var query = GetBlogQuery(blogPart, VersionOptions.Published);
|
||||
|
||||
|
@@ -12,6 +12,7 @@ namespace Orchard.Blogs.Services {
|
||||
IEnumerable<BlogPostPart> Get(BlogPart blogPart);
|
||||
IEnumerable<BlogPostPart> Get(BlogPart blogPart, VersionOptions versionOptions);
|
||||
IEnumerable<BlogPostPart> Get(BlogPart blogPart, ArchiveData archiveData);
|
||||
IEnumerable<BlogPostPart> Get(BlogPart blogPart, int skip, int count);
|
||||
IEnumerable<KeyValuePair<ArchiveData, int>> GetArchives(BlogPart blogPart);
|
||||
void Delete(BlogPostPart blogPostPart);
|
||||
void Publish(BlogPostPart blogPostPart);
|
||||
|
19
src/Orchard.Web/Modules/Orchard.Blogs/Styles/pagination.css
Normal file
19
src/Orchard.Web/Modules/Orchard.Blogs/Styles/pagination.css
Normal file
@@ -0,0 +1,19 @@
|
||||
ul.pagination
|
||||
{
|
||||
list-style-type:none;
|
||||
}
|
||||
|
||||
ul.pagination li a
|
||||
{
|
||||
font-size:13px;
|
||||
}
|
||||
|
||||
ul.pagination li.newer
|
||||
{
|
||||
float:left;
|
||||
}
|
||||
|
||||
ul.pagination li.older
|
||||
{
|
||||
float:right;
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
using Orchard.Blogs.Models;
|
||||
|
||||
namespace Orchard.Blogs.ViewModels {
|
||||
public class DisplayBlogViewModel {
|
||||
public BlogPart BlogPart { get; set; }
|
||||
public dynamic BlogPostList { get; set; }
|
||||
public int Page { get; set; }
|
||||
public int PageSize { get; set; }
|
||||
}
|
||||
}
|
@@ -1 +1,28 @@
|
||||
@Display(Model)
|
||||
@model Orchard.Blogs.ViewModels.DisplayBlogViewModel
|
||||
@using Orchard.Blogs.Extensions;
|
||||
|
||||
@{
|
||||
Style.Include("pagination.css");
|
||||
}
|
||||
|
||||
@if (Model.BlogPostList.Items.Count > 0) {
|
||||
@Display(Model.BlogPostList)
|
||||
|
||||
<ul class="pagination">
|
||||
@if(Model.BlogPostList.Items.Count == Model.PageSize) {
|
||||
<li class="older">
|
||||
@Html.ActionLink(T("Older Posts").Text, "Item", new { Area = "Orchard.Blogs", blogSlug = Model.BlogPart.Slug, page = Model.Page + 1 })
|
||||
</li>
|
||||
}
|
||||
|
||||
@if(Model.Page > 1) {
|
||||
<li class="newer">
|
||||
@Html.ActionLink(T("Newer Posts").Text, "Item", new { Area = "Orchard.Blogs", blogSlug = Model.BlogPart.Slug, page = Model.Page - 1 })
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
}
|
||||
else {
|
||||
<p>@T("There are no posts for this blog.")</p>
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user