diff --git a/Src/VideoGameQuotes.Web/Controllers/AdminController.cs b/Src/VideoGameQuotes.Web/Controllers/AdminController.cs index c294401..3b892fd 100644 --- a/Src/VideoGameQuotes.Web/Controllers/AdminController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/AdminController.cs @@ -27,8 +27,7 @@ namespace VideoGameQuotes.Web.Controllers { } var model = new PagedModelWithUser { - Start = start, - End = end, + CurrentPage = 1, Records = adminService.GetPagedUsers(start, end), TotalCount = adminService.GetAllUsers().Count(), CurrentUser = userProvider.CurrentUser diff --git a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs index 39754a6..051a749 100644 --- a/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs +++ b/Src/VideoGameQuotes.Web/Controllers/QuoteController.cs @@ -85,17 +85,23 @@ namespace VideoGameQuotes.Web.Controllers { }); } - public ActionResult Best(int start = 0, int end = 19) { - if (start < 0 || end <= 0 || start > end) { + public ActionResult Best(int page) { + if (page < 1) { return new StatusOverrideResult(View("BadPaging")) { StatusCode = HttpStatusCode.BadRequest }; } - return View(new PagedModelWithUser { - Records = quoteService.GetBestQuotes(start, end), + const int pageSize = 10; + int totalCount; + var model = new PagedModelWithUser { CurrentUser = currentUserProvider.CurrentUser, - Start = start, - End = end - }); + CurrentPage = page, + PageSize = pageSize + }; + + model.Records = quoteService.GetBestQuotes(model.Start, model.End, out totalCount); + model.TotalCount = totalCount; + + return View(model); } public ActionResult Random() { diff --git a/Src/VideoGameQuotes.Web/Global.asax.cs b/Src/VideoGameQuotes.Web/Global.asax.cs index d66b094..7e29b00 100644 --- a/Src/VideoGameQuotes.Web/Global.asax.cs +++ b/Src/VideoGameQuotes.Web/Global.asax.cs @@ -1,14 +1,10 @@ -using System; -using System.Collections.Specialized; +using System.Collections.Specialized; using System.Configuration; -using System.Web; using System.Web.Mvc; using System.Web.Routing; using Microsoft.Practices.Unity; using Portoa.Logging; using Portoa.Web; -using Portoa.Web.Controllers; -using Portoa.Web.ErrorHandling; using Portoa.Web.Models; using Portoa.Web.Security; using Portoa.Web.Unity; @@ -80,11 +76,11 @@ namespace VideoGameQuotes.Web { routes.MapRoute("api", "api/{action}/{id}/{*criteria}", new { controller = "Api" }, new { action = "game|system|category|publisher|quote", id = @"\d+|all" }); routes.MapRoute("home", "{action}", new { controller = "Home", action = "Index" }, new { action = "about|contact|login|logout" }); - routes.MapRoute("best", "best/{start}-{end}/", new { controller = "Quote", action = "Best" }, new { start = @"\d+", end = @"\d+" }); + routes.MapRoute("best", "best/{page}", new { controller = "Quote", action = "Best", page = 1 }, new { page = @"\d+" }); routes.MapRoute("browse", "browse/{*qualifiers}", new { controller = "Quote", action = "Browse" }); routes.MapRoute("search", "search/{*searchQuery}", new { controller = "Quote", action = "Search" }); routes.MapRoute("quote-task", "{action}/{id}", new { controller = "Quote" }, new { action = "edit|flags", id = @"\d+" }); - routes.MapRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|recent|random|best|vote|report" }); + routes.MapRoute("quote", "{action}", new { controller = "Quote" }, new { action = "submit|recent|random|vote|report" }); routes.MapRoute("dismiss-flag", "dismiss-flag", new { controller = "Quote", action = "DismissFlag" }); routes.MapRoute("individual-quote", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }, new { id = @"\d+" }); routes.MapRoute("create-category", "category/create", new { controller = "Quote", action = "CreateCategory" }); diff --git a/Src/VideoGameQuotes.Web/Services/QuoteService.cs b/Src/VideoGameQuotes.Web/Services/QuoteService.cs index 1422814..ffaca49 100644 --- a/Src/VideoGameQuotes.Web/Services/QuoteService.cs +++ b/Src/VideoGameQuotes.Web/Services/QuoteService.cs @@ -22,7 +22,7 @@ namespace VideoGameQuotes.Web.Services { IEnumerable GetMostRecentQuotes(int limit); [CanBeNull] Quote GetRandomQuote(); - IEnumerable GetBestQuotes(int start, int end); + IEnumerable GetBestQuotes(int start, int end, out int totalCount); Vote SaveVote(Vote vote); Vote GetVoteOrCreateNew(Quote quote, User voter); IEnumerable GetBrowsableQuotes(BrowseModel model); @@ -126,13 +126,15 @@ namespace VideoGameQuotes.Web.Services { } [UnitOfWork] - public IEnumerable GetBestQuotes(int start, int end) { + public IEnumerable GetBestQuotes(int start, int end, out int totalCount) { + //TODO this does a select * on all quotes, which is kind of bad var records = quoteRepository.Records.ToArray(); + totalCount = records.Length; return records .OrderByDescending(quote => quote.Score) .ThenByDescending(quote => quote.UpVotes) - .Skip(start) + .Skip(start - 1) .Take(end - start + 1); } diff --git a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj index 43ab00f..5a1d27b 100644 --- a/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj +++ b/Src/VideoGameQuotes.Web/VideoGameQuotes.Web.csproj @@ -147,6 +147,7 @@ + diff --git a/Src/VideoGameQuotes.Web/Views/Quote/Best.aspx b/Src/VideoGameQuotes.Web/Views/Quote/Best.aspx index 4343a19..809b42c 100644 --- a/Src/VideoGameQuotes.Web/Views/Quote/Best.aspx +++ b/Src/VideoGameQuotes.Web/Views/Quote/Best.aspx @@ -1,19 +1,14 @@ <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage>" MasterPageFile="~/Views/Shared/Site.Master" %> +<%@ Import Namespace="Portoa.Web.Models" %> <%@ Import Namespace="VideoGameQuotes.Web.Models" %> Best: <%= Model.Start %> – <%= Model.End %> -

- <% if (Model.HasPrevious) { %> - <%= Html.ActionLink("previous", "best", new { start = Model.PreviousStart, end = Model.PreviousEnd }) %> - <% } %> - <%= Html.ActionLink("next", "best", new { start = Model.NextStart, end = Model.NextEnd }) %> -

- + <% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "best", Controller = "quote" }); %> + <% foreach (var quote in Model.Records) { Html.RenderPartial("SingleQuote", new QuoteModel { Quote = quote, User = Model.CurrentUser }); } %> -
- + \ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Views/Quote/PagingMenu.ascx b/Src/VideoGameQuotes.Web/Views/Quote/PagingMenu.ascx new file mode 100644 index 0000000..14ed87b --- /dev/null +++ b/Src/VideoGameQuotes.Web/Views/Quote/PagingMenu.ascx @@ -0,0 +1,15 @@ +<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> + +<% if (!Model.HasNext && !Model.HasPrevious) { return; } %> + +
+ + +

+ Showing <%= Model.Start %>—<%= Model.ActualEnd %> of <%= Model.TotalCount %>. +

+
\ No newline at end of file diff --git a/Src/VideoGameQuotes.Web/Views/Shared/SingleQuote.ascx b/Src/VideoGameQuotes.Web/Views/Shared/SingleQuote.ascx index ba9f760..efd1f1f 100644 --- a/Src/VideoGameQuotes.Web/Views/Shared/SingleQuote.ascx +++ b/Src/VideoGameQuotes.Web/Views/Shared/SingleQuote.ascx @@ -1,5 +1,4 @@ <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> -<%@ Import Namespace="Portoa.Util" %> <%@ Import Namespace="VideoGameQuotes.Api" %>
diff --git a/Src/VideoGameQuotes.Web/media/css/global.css b/Src/VideoGameQuotes.Web/media/css/global.css index d52e0a3..410a7be 100644 --- a/Src/VideoGameQuotes.Web/media/css/global.css +++ b/Src/VideoGameQuotes.Web/media/css/global.css @@ -42,9 +42,6 @@ ul.menu { padding: 0; list-style: none; } -ul.menu li { - float: left; -} .validation-summary-errors { color: #000000; @@ -115,6 +112,24 @@ ul.menu li { width: 600px; } +.paging-menu p { + text-align: right; + font-size: 80%; +} +.paging-menu li { + margin-left: 5px; + float: right !important; +} +.paging-menu a { + display: block; + color: #000000 !important; + border: none !important; +} +.paging-menu a:hover { + color: #46C46E !important; + border: none !important; +} + #browse-default-menu li { margin-bottom: 2px; padding: 3px; @@ -148,6 +163,7 @@ ul.menu li { #main-menu li { margin-right: 2px; + float: left; } #main-menu li a { display: block;