From d34cae6ac4c77f80f080dbfc505ebb289341912b Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Sun, 31 Oct 2010 23:54:37 -0700 Subject: [PATCH] Making existing paginiation implementations a bit more consistent. For Blog (posts) and Search. --HG-- branch : dev --- src/Orchard.Web/Core/Orchard.Core.csproj | 1 + .../Core/Shapes/Views/Pager.cshtml | 39 ++++++++++++++++++ .../Controllers/BlogAdminController.cs | 6 +++ .../Controllers/BlogController.cs | 25 ++++++----- .../Drivers/BlogPagerPartDriver.cs | 11 ----- .../Orchard.Blogs/Drivers/BlogPartDriver.cs | 27 ++++++------ .../Modules/Orchard.Blogs/Migrations.cs | 4 +- .../Orchard.Blogs/Models/BlogPagerPart.cs | 10 ----- .../Orchard.Blogs/Orchard.Blogs.csproj | 4 -- .../Modules/Orchard.Blogs/Placement.info | 2 - .../Modules/Orchard.Blogs/Routes.cs | 21 +--------- .../Orchard.Blogs/Styles/pagination.css | 19 --------- .../Views/Parts/Blogs.Blog.Pager.cshtml | 18 -------- .../Modules/Orchard.ContentQueries/Module.txt | 2 +- .../Controllers/SearchController.cs | 41 +++++++++---------- .../ViewModels/SearchViewModel.cs | 11 ++--- .../Orchard.Search/Views/Search/Index.cshtml | 25 ++++++----- .../Themes/TheThemeMachine/Styles/Site.css | 15 ++++--- src/Orchard/Orchard.Framework.csproj | 1 + src/Orchard/UI/Navigation/Pager.cs | 22 ++++++++++ 20 files changed, 148 insertions(+), 156 deletions(-) create mode 100644 src/Orchard.Web/Core/Shapes/Views/Pager.cshtml delete mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPagerPartDriver.cs delete mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPagerPart.cs delete mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Styles/pagination.css delete mode 100644 src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.Blog.Pager.cshtml create mode 100644 src/Orchard/UI/Navigation/Pager.cs diff --git a/src/Orchard.Web/Core/Orchard.Core.csproj b/src/Orchard.Web/Core/Orchard.Core.csproj index 5f21661a1..f74e81b86 100644 --- a/src/Orchard.Web/Core/Orchard.Core.csproj +++ b/src/Orchard.Web/Core/Orchard.Core.csproj @@ -370,6 +370,7 @@ + diff --git a/src/Orchard.Web/Core/Shapes/Views/Pager.cshtml b/src/Orchard.Web/Core/Shapes/Views/Pager.cshtml new file mode 100644 index 000000000..cfd69ab51 --- /dev/null +++ b/src/Orchard.Web/Core/Shapes/Views/Pager.cshtml @@ -0,0 +1,39 @@ +@{ + var nextText = HasText(Model.NextText) ? Model.NextText : T("Older").Text; + var previousText = HasText(Model.PreviousText) ? Model.PreviousText : T("Newer").Text; + + var routeData = new RouteValueDictionary(ViewContext.RouteData.Values); + var queryString = ViewContext.HttpContext.Request.QueryString; + if (queryString != null) { + foreach (string key in queryString.Keys) { + if (!routeData.ContainsKey(key)) { + var value = queryString[key]; + routeData[key] = queryString[key]; + } + } + } + + if (routeData.ContainsKey("id") && !HasText(routeData["id"])) { + routeData.Remove("id"); + } + + Model.Classes.Add("pager"); + Model.Classes.Add("group"); + var tag = Tag(Model, "ul"); +} +@if (Model.HasNextPage || Model.Page > 1) { + @tag.StartElement + if(Model.HasNextPage) { + routeData["page"] = Model.Page + 1; +
  • + @Html.ActionLink((string)nextText, (string)routeData["action"], (string)routeData["controller"], routeData, null) +
  • + } + if(Model.Page > 1) { + routeData["page"] = Model.Page - 1; +
  • + @Html.ActionLink((string)previousText, (string)routeData["action"], (string)routeData["controller"], routeData, null) +
  • + } + @tag.EndElement +} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs index b660df687..1a7d64535 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogAdminController.cs @@ -140,6 +140,12 @@ namespace Orchard.Blogs.Controllers { if (blogPart == null) return HttpNotFound(); + //() => { + // var list = shapeHelper.List(); + // list.AddRange(_blogPostService.Get(part, VersionOptions.Latest) + // .Select(bp => _contentManager.BuildDisplay(bp, "SummaryAdmin"))); + // return shapeHelper.Parts_Blogs_BlogPost_List_Admin(ContentPart: part, ContentItems: list); + //}) var model = Services.ContentManager.BuildDisplay(blogPart, "DetailAdmin"); return View(model); diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs index f97bdab92..d540c2ec7 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Controllers/BlogController.cs @@ -3,13 +3,15 @@ using System.Web; using System.Web.Mvc; using System.Web.Routing; using System.Xml.Linq; +using Orchard.Blogs.Extensions; using Orchard.Blogs.Models; using Orchard.Blogs.Routing; using Orchard.Blogs.Services; -using Orchard.ContentManagement; +using Orchard.Core.Feeds; using Orchard.DisplayManagement; using Orchard.Logging; using Orchard.Themes; +using Orchard.UI.Navigation; namespace Orchard.Blogs.Controllers { [Themed] @@ -18,6 +20,7 @@ namespace Orchard.Blogs.Controllers { private readonly IBlogService _blogService; private readonly IBlogPostService _blogPostService; private readonly IBlogSlugConstraint _blogSlugConstraint; + private readonly IFeedManager _feedManager; private readonly RouteCollection _routeCollection; public BlogController( @@ -25,12 +28,14 @@ namespace Orchard.Blogs.Controllers { IBlogService blogService, IBlogPostService blogPostService, IBlogSlugConstraint blogSlugConstraint, + IFeedManager feedManager, RouteCollection routeCollection, IShapeFactory shapeFactory) { _services = services; _blogService = blogService; _blogPostService = blogPostService; _blogSlugConstraint = blogSlugConstraint; + _feedManager = feedManager; _routeCollection = routeCollection; Logger = NullLogger.Instance; Shape = shapeFactory; @@ -51,10 +56,7 @@ namespace Orchard.Blogs.Controllers { return View(viewModel); } - //TODO: (erikpo) Should move the slug parameter and get call and null check up into a model binder - public ActionResult Item(string blogSlug, int page) { - const int pageSize = 10; - + public ActionResult Item(string blogSlug, Pager pager) { var correctedSlug = _blogSlugConstraint.FindSlug(blogSlug); if (correctedSlug == null) return HttpNotFound(); @@ -63,21 +65,18 @@ namespace Orchard.Blogs.Controllers { if (blogPart == null) return HttpNotFound(); - var blogPosts = _blogPostService.Get(blogPart, (page - 1) * pageSize, pageSize) + _feedManager.Register(blogPart); + var blogPosts = _blogPostService.Get(blogPart, pager.GetStartIndex(), pager.PageSize) .Select(b => _services.ContentManager.BuildDisplay(b, "Summary")); - - blogPart.As().Page = page; - blogPart.As().PageSize = pageSize; - blogPart.As().BlogSlug = correctedSlug; - blogPart.As().ThereIsANextPage = _blogPostService.Get(blogPart, (page) * pageSize, pageSize).Any(); - var blog = _services.ContentManager.BuildDisplay(blogPart); var list = Shape.List(); 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"); + return View(blog); } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPagerPartDriver.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPagerPartDriver.cs deleted file mode 100644 index 727ff6b55..000000000 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPagerPartDriver.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Orchard.Blogs.Models; -using Orchard.ContentManagement.Drivers; - -namespace Orchard.Blogs.Drivers { - public class BlogPagerPartDriver : ContentPartDriver { - protected override DriverResult Display(BlogPagerPart part, string displayType, dynamic shapeHelper) { - return ContentShape("Parts_Blogs_Blog_Pager", - () => shapeHelper.Parts_Blogs_Blog_Pager(ContentPart: part, Page: part.Page, PageSize: part.PageSize, BlogSlug: part.BlogSlug, ThereIsANextPage: part.ThereIsANextPage)); - } - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPartDriver.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPartDriver.cs index 8c7bbe885..01452dfd8 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPartDriver.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Drivers/BlogPartDriver.cs @@ -41,24 +41,25 @@ namespace Orchard.Blogs.Drivers { ContentShape("Parts_Blogs_Blog_Description", () => shapeHelper.Parts_Blogs_Blog_Description(ContentPart: part, Description: part.Description)), ContentShape("Parts_Blogs_Blog_BlogPostCount", - () => shapeHelper.Parts_Blogs_Blog_BlogPostCount(ContentPart: part, PostCount: part.PostCount)), + () => shapeHelper.Parts_Blogs_Blog_BlogPostCount(ContentPart: part, PostCount: part.PostCount)) + //, // todo: (heskew) implement a paging solution that doesn't require blog posts to be tied to the blog within the controller - ContentShape("Parts_Blogs_BlogPost_List", - () => { - _feedManager.Register(part); - return null; + //ContentShape("Parts_Blogs_BlogPost_List", + // () => { + // _feedManager.Register(part); // var list = shapeHelper.List(); // list.AddRange(_blogPostService.Get(part) // .Select(bp => _contentManager.BuildDisplay(bp, "Summary"))); // return shapeHelper.Parts_Blogs_BlogPost_List(ContentPart: part, ContentItems: list); - }), - ContentShape("Parts_Blogs_BlogPost_List_Admin", - () => { - var list = shapeHelper.List(); - list.AddRange(_blogPostService.Get(part, VersionOptions.Latest) - .Select(bp => _contentManager.BuildDisplay(bp, "SummaryAdmin"))); - return shapeHelper.Parts_Blogs_BlogPost_List_Admin(ContentPart: part, ContentItems: list); - }) + // }), + //ContentShape("Parts_Blogs_BlogPost_List_Admin", + // () => + // { + // var list = shapeHelper.List(); + // list.AddRange(_blogPostService.Get(part, VersionOptions.Latest) + // .Select(bp => _contentManager.BuildDisplay(bp, "SummaryAdmin"))); + // return shapeHelper.Parts_Blogs_BlogPost_List_Admin(ContentPart: part, ContentItems: list); + // }) ); } diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs index 47605d5ba..90e71d88d 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Migrations.cs @@ -1,5 +1,4 @@ -using System.Data; -using Orchard.ContentManagement.MetaData; +using Orchard.ContentManagement.MetaData; using Orchard.Data.Migration; namespace Orchard.Blogs { @@ -40,7 +39,6 @@ namespace Orchard.Blogs { .WithPart("BlogPart") .WithPart("CommonPart") .WithPart("RoutePart") - .WithPart("BlogPagerPart") ); ContentDefinitionManager.AlterTypeDefinition("BlogPost", diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPagerPart.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPagerPart.cs deleted file mode 100644 index e5e9b4132..000000000 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Models/BlogPagerPart.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Orchard.ContentManagement; - -namespace Orchard.Blogs.Models { - public class BlogPagerPart : ContentPart { - public int Page { get; set; } - public int PageSize { get; set; } - public string BlogSlug { get; set; } - public bool ThereIsANextPage { get; set; } - } -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj index 7983253bb..e1316a27a 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Orchard.Blogs.csproj @@ -68,14 +68,12 @@ - - @@ -120,7 +118,6 @@ - @@ -164,7 +161,6 @@ - diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Placement.info b/src/Orchard.Web/Modules/Orchard.Blogs/Placement.info index 4846f30f5..7d9b458d6 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Placement.info +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Placement.info @@ -4,7 +4,6 @@ Parts_Blogs_Blog_Manage Parts_Blogs_Blog_Description Parts_Blogs_Blog_BlogPostCount - Parts_Blogs_Blog_Pager Parts_Blogs_BlogPost_List -> when in the blog detail display the blog post list is currently hard-coded to Content:5 to enable the current state of blog paging Parts_Blogs_BlogPost_List_Admin --> @@ -23,7 +22,6 @@ ...placing it in in the Content zone as it's currently implemented to light up the RSS feed for the blog... --> diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs b/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs index 452e6783d..eae9111ce 100644 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs +++ b/src/Orchard.Web/Modules/Orchard.Blogs/Routes.cs @@ -261,32 +261,13 @@ 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"}, {"action", "Item"} }, new RouteValueDictionary { - {"blogSlug", _blogSlugConstraint}, - {"page", @"^\d+$"} + {"blogSlug", _blogSlugConstraint} }, new RouteValueDictionary { {"area", "Orchard.Blogs"} diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Styles/pagination.css b/src/Orchard.Web/Modules/Orchard.Blogs/Styles/pagination.css deleted file mode 100644 index 719fb28f4..000000000 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Styles/pagination.css +++ /dev/null @@ -1,19 +0,0 @@ -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; -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.Blog.Pager.cshtml b/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.Blog.Pager.cshtml deleted file mode 100644 index cf0793866..000000000 --- a/src/Orchard.Web/Modules/Orchard.Blogs/Views/Parts/Blogs.Blog.Pager.cshtml +++ /dev/null @@ -1,18 +0,0 @@ -@using Orchard.Blogs.Extensions; -@{ - Style.Include("pagination.css"); -} -@if (Model.ThereIsANextPage || Model.Page > 1) { -
      - @if(Model.ThereIsANextPage) { -
    • - @Html.ActionLink(T("Older Posts").Text, "Item", new { Area = "Orchard.Blogs", blogSlug = Model.BlogSlug, page = Model.Page + 1 }) -
    • - } - @if(Model.Page > 1) { -
    • - @Html.ActionLink(T("Newer Posts").Text, "Item", new { Area = "Orchard.Blogs", blogSlug = Model.BlogSlug, page = Model.Page - 1 }) -
    • - } -
    -} \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.ContentQueries/Module.txt b/src/Orchard.Web/Modules/Orchard.ContentQueries/Module.txt index 9561a77d0..76bb284fa 100644 --- a/src/Orchard.Web/Modules/Orchard.ContentQueries/Module.txt +++ b/src/Orchard.Web/Modules/Orchard.ContentQueries/Module.txt @@ -8,5 +8,5 @@ Features: Orchard.ContentQueries: Name: Queried Content Lists Description: Use simple queries to create orderd lists of content items with optional paging support. - Dependencies: Contents + Dependencies: Contents, Common Category: Content diff --git a/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs b/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs index 04bc91d8c..2383194a6 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs +++ b/src/Orchard.Web/Modules/Orchard.Search/Controllers/SearchController.cs @@ -1,13 +1,15 @@ -using System.Web.Mvc; -using System.Web.Query.Dynamic; +using System.Linq; +using System.Web.Mvc; using JetBrains.Annotations; using Orchard.ContentManagement; +using Orchard.DisplayManagement; using Orchard.Indexing; using Orchard.Localization; using Orchard.Search.Services; using Orchard.Search.ViewModels; using Orchard.Settings; using Orchard.Search.Models; +using Orchard.UI.Navigation; using Orchard.UI.Notify; using System.Collections.Generic; using Orchard.Collections; @@ -22,21 +24,23 @@ namespace Orchard.Search.Controllers { public SearchController( IOrchardServices services, ISearchService searchService, - IContentManager contentManager) { - + IContentManager contentManager, + IShapeFactory shapeFactory) { Services = services; _searchService = searchService; _contentManager = contentManager; T = NullLocalizer.Instance; + Shape = shapeFactory; } private IOrchardServices Services { get; set; } public Localizer T { get; set; } + dynamic Shape { get; set; } protected virtual ISite CurrentSite { get; [UsedImplicitly] private set; } - public ActionResult Index(string q, int page = 1, int pageSize = 10) { + public ActionResult Index(string q, Pager pager) { var searchFields = CurrentSite.As().SearchedFields; IPageOfItems searchHits; @@ -46,38 +50,33 @@ namespace Orchard.Search.Controllers { Services.Notifier.Error(T("'*' or '?' not allowed as first character in WildcardQuery")); } else { - searchHits = _searchService.Query(q, page, pageSize, + searchHits = _searchService.Query(q, pager.Page, pager.PageSize, CurrentSite.As().Record.FilterCulture, searchFields, searchHit => searchHit); } - var searchResultViewModels = new List(); - - foreach(var searchHit in searchHits) { - var contentItem = _contentManager.Get(searchHit.ContentItemId); + var list = Shape.List(); + foreach (var contentItem in searchHits.Select(searchHit => _contentManager.Get(searchHit.ContentItemId))) { // ignore search results which content item has been removed or unpublished if(contentItem == null){ searchHits.TotalItemCount--; continue; } - searchResultViewModels.Add(new SearchResultViewModel { - Content = _contentManager.BuildDisplay(contentItem, "SummaryForSearch"), - SearchHit = searchHit - }); + list.Add(_contentManager.BuildDisplay(contentItem, "Summary")); } - var pageOfItems = new PageOfItems(searchResultViewModels) { - PageNumber = page, - PageSize = searchHits.PageSize, - TotalItemCount = searchHits.TotalItemCount - }; + var hasNextPage = searchHits.TotalPageCount > pager.Page; + var pagerShape = Shape.Pager(pager).HasNextPage(hasNextPage); var searchViewModel = new SearchViewModel { Query = q, - DefaultPageSize = 10, // TODO: sebastien <- yeah, I know :| - PageOfResults = pageOfItems + TotalItemCount = searchHits.TotalItemCount, + StartPosition = (pager.Page - 1) * pager.PageSize + 1, + EndPosition = pager.Page * pager.PageSize > searchHits.TotalItemCount ? searchHits.TotalItemCount : pager.Page * pager.PageSize, + ContentItems = list, + Pager = pagerShape }; //todo: deal with page requests beyond result count diff --git a/src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchViewModel.cs b/src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchViewModel.cs index d1c292757..0ad4e4bfc 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchViewModel.cs +++ b/src/Orchard.Web/Modules/Orchard.Search/ViewModels/SearchViewModel.cs @@ -1,9 +1,10 @@ -using Orchard.Collections; - -namespace Orchard.Search.ViewModels { +namespace Orchard.Search.ViewModels { public class SearchViewModel { public string Query { get; set; } - public int DefaultPageSize { get; set; } - public IPageOfItems PageOfResults { get; set; } + public int TotalItemCount { get; set; } + public int StartPosition { get; set; } + public int EndPosition { get; set; } + public dynamic ContentItems { get; set; } + public dynamic Pager { get; set; } } } \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Search/Views/Search/Index.cshtml b/src/Orchard.Web/Modules/Orchard.Search/Views/Search/Index.cshtml index eea83d5aa..b573cde0e 100644 --- a/src/Orchard.Web/Modules/Orchard.Search/Views/Search/Index.cshtml +++ b/src/Orchard.Web/Modules/Orchard.Search/Views/Search/Index.cshtml @@ -1,23 +1,26 @@ @model Orchard.Search.ViewModels.SearchViewModel -@{ Style.Require("Search"); } +@{ + Style.Require("Search"); + IEnumerable searchResults = Model.ContentItems; + Model.ContentItems.Classes.Add("content-items"); + Model.ContentItems.Classes.Add("search-results"); +}

    @Html.TitleForPage(T("Search").Text)

    - -@using(Html.BeginForm("index", "search", new { area = "Orchard.Search" }, FormMethod.Get, new { @class = "search" })) { +@using(Html.BeginForm("index", "search", new { area = "Orchard.Search" }, FormMethod.Get, new { @class = "search group" })) {
    @Html.TextBox("q", Model.Query)
    } - -@if (!string.IsNullOrWhiteSpace(Model.Query)) { - if (Model.PageOfResults.Count() == 0) { -

    @T.Plural("the one result", "zero results", Model.PageOfResults.Count())

    +@if (HasText(Model.Query)) { + if (searchResults.Count() == 0) { +

    @T.Plural("the one result", "zero results", searchResults.Count())

    } else { -

    @T.Plural("the one result", "{1} - {2} of {0} results", Model.PageOfResults.TotalItemCount, Model.PageOfResults.StartPosition, Model.PageOfResults.EndPosition)

    +

    @T.Plural("the one result", "{1} - {2} of {0} results", Model.TotalItemCount, Model.StartPosition, Model.EndPosition)

    } } -@if (Model.PageOfResults != null && Model.PageOfResults.Count() > 0) { - @Html.UnorderedList(Model.PageOfResults.Where(hit => hit.Content != null), (r, i) => Display(r.Content), "search-results contentItems") - @Html.Pager(Model.PageOfResults, Model.PageOfResults.PageNumber, Model.DefaultPageSize, new {q = Model.Query}) +@if (searchResults != null && searchResults.Count() > 0) { + @Display(searchResults) + @Display(Model.Pager) } \ No newline at end of file diff --git a/src/Orchard.Web/Themes/TheThemeMachine/Styles/Site.css b/src/Orchard.Web/Themes/TheThemeMachine/Styles/Site.css index eb6c6e2a9..820ba98a1 100644 --- a/src/Orchard.Web/Themes/TheThemeMachine/Styles/Site.css +++ b/src/Orchard.Web/Themes/TheThemeMachine/Styles/Site.css @@ -343,11 +343,6 @@ nav ul .blog-post-title {} .meta {} -.blog-pagination { list-style: none; padding: 0; margin: 12px 0 0 0; } -.blog-pagination li { float: left; padding: 0 12px 0 0; margin: 0; } -.blog-pagination a { font-size: 1.077em; display: block; background-color: #dbdbdb; padding: 6px 6px; color: #434343;} -.blog-pagination a:hover { background-color: #434343; color: #fff; } - /* Comments */ #comments { margin: 24px 0 0 0; padding: 0; } .comment-form { margin: 24px 0 0 0; padding: 0; } @@ -491,6 +486,16 @@ nav ul +/* 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: #dbdbdb; padding: 6px 6px; color: #434343;} +.pager a:hover { background-color: #434343; color: #fff; } + + + /* Misc ***************************************************************/ diff --git a/src/Orchard/Orchard.Framework.csproj b/src/Orchard/Orchard.Framework.csproj index ba6bd74ad..f7da9c808 100644 --- a/src/Orchard/Orchard.Framework.csproj +++ b/src/Orchard/Orchard.Framework.csproj @@ -186,6 +186,7 @@ + diff --git a/src/Orchard/UI/Navigation/Pager.cs b/src/Orchard/UI/Navigation/Pager.cs new file mode 100644 index 000000000..27aa646db --- /dev/null +++ b/src/Orchard/UI/Navigation/Pager.cs @@ -0,0 +1,22 @@ +namespace Orchard.UI.Navigation { + public class Pager { + private const int PageDefault = 1; + private const int PageSizeDefault = 10; + private int _pageSize; + private int _size; + + public int Page { + get { return _pageSize > 0 ? _pageSize : PageDefault; } + set { _pageSize = value; } + } + + public int PageSize { + get { return _size > 0 ? _size : PageSizeDefault; } + set { _size = value; } + } + + public int GetStartIndex(int? page = null) { + return ((page ?? Page) - 1)*PageSize; + } + } +} \ No newline at end of file