best/single quote pages are complete

This commit is contained in:
tmont 2011-02-22 04:05:23 +00:00
parent 6ffe713021
commit 01eb39c503
9 changed files with 61 additions and 32 deletions

View File

@ -27,8 +27,7 @@ namespace VideoGameQuotes.Web.Controllers {
} }
var model = new PagedModelWithUser<User> { var model = new PagedModelWithUser<User> {
Start = start, CurrentPage = 1,
End = end,
Records = adminService.GetPagedUsers(start, end), Records = adminService.GetPagedUsers(start, end),
TotalCount = adminService.GetAllUsers().Count(), TotalCount = adminService.GetAllUsers().Count(),
CurrentUser = userProvider.CurrentUser CurrentUser = userProvider.CurrentUser

View File

@ -85,17 +85,23 @@ namespace VideoGameQuotes.Web.Controllers {
}); });
} }
public ActionResult Best(int start = 0, int end = 19) { public ActionResult Best(int page) {
if (start < 0 || end <= 0 || start > end) { if (page < 1) {
return new StatusOverrideResult(View("BadPaging")) { StatusCode = HttpStatusCode.BadRequest }; return new StatusOverrideResult(View("BadPaging")) { StatusCode = HttpStatusCode.BadRequest };
} }
return View(new PagedModelWithUser<Quote> { const int pageSize = 10;
Records = quoteService.GetBestQuotes(start, end), int totalCount;
var model = new PagedModelWithUser<Quote> {
CurrentUser = currentUserProvider.CurrentUser, CurrentUser = currentUserProvider.CurrentUser,
Start = start, CurrentPage = page,
End = end PageSize = pageSize
}); };
model.Records = quoteService.GetBestQuotes(model.Start, model.End, out totalCount);
model.TotalCount = totalCount;
return View(model);
} }
public ActionResult Random() { public ActionResult Random() {

View File

@ -1,14 +1,10 @@
using System; using System.Collections.Specialized;
using System.Collections.Specialized;
using System.Configuration; using System.Configuration;
using System.Web;
using System.Web.Mvc; using System.Web.Mvc;
using System.Web.Routing; using System.Web.Routing;
using Microsoft.Practices.Unity; using Microsoft.Practices.Unity;
using Portoa.Logging; using Portoa.Logging;
using Portoa.Web; using Portoa.Web;
using Portoa.Web.Controllers;
using Portoa.Web.ErrorHandling;
using Portoa.Web.Models; using Portoa.Web.Models;
using Portoa.Web.Security; using Portoa.Web.Security;
using Portoa.Web.Unity; 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("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("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("browse", "browse/{*qualifiers}", new { controller = "Quote", action = "Browse" });
routes.MapRoute("search", "search/{*searchQuery}", new { controller = "Quote", action = "Search" }); 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-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("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("individual-quote", "quote/{id}/{*text}", new { controller = "Quote", action = "Quote" }, new { id = @"\d+" });
routes.MapRoute("create-category", "category/create", new { controller = "Quote", action = "CreateCategory" }); routes.MapRoute("create-category", "category/create", new { controller = "Quote", action = "CreateCategory" });

View File

@ -22,7 +22,7 @@ namespace VideoGameQuotes.Web.Services {
IEnumerable<Quote> GetMostRecentQuotes(int limit); IEnumerable<Quote> GetMostRecentQuotes(int limit);
[CanBeNull] [CanBeNull]
Quote GetRandomQuote(); Quote GetRandomQuote();
IEnumerable<Quote> GetBestQuotes(int start, int end); IEnumerable<Quote> GetBestQuotes(int start, int end, out int totalCount);
Vote SaveVote(Vote vote); Vote SaveVote(Vote vote);
Vote GetVoteOrCreateNew(Quote quote, User voter); Vote GetVoteOrCreateNew(Quote quote, User voter);
IEnumerable<Quote> GetBrowsableQuotes(BrowseModel model); IEnumerable<Quote> GetBrowsableQuotes(BrowseModel model);
@ -126,13 +126,15 @@ namespace VideoGameQuotes.Web.Services {
} }
[UnitOfWork] [UnitOfWork]
public IEnumerable<Quote> GetBestQuotes(int start, int end) { public IEnumerable<Quote> 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(); var records = quoteRepository.Records.ToArray();
totalCount = records.Length;
return records return records
.OrderByDescending(quote => quote.Score) .OrderByDescending(quote => quote.Score)
.ThenByDescending(quote => quote.UpVotes) .ThenByDescending(quote => quote.UpVotes)
.Skip(start) .Skip(start - 1)
.Take(end - start + 1); .Take(end - start + 1);
} }

View File

@ -147,6 +147,7 @@
<Content Include="Views\Home\About.aspx" /> <Content Include="Views\Home\About.aspx" />
<Content Include="Views\Home\Contact.aspx" /> <Content Include="Views\Home\Contact.aspx" />
<Content Include="Views\Home\ContactSuccess.aspx" /> <Content Include="Views\Home\ContactSuccess.aspx" />
<Content Include="Views\Quote\PagingMenu.ascx" />
<Content Include="Views\Shared\BadPaging.aspx" /> <Content Include="Views\Shared\BadPaging.aspx" />
<Content Include="Views\Quote\Best.aspx" /> <Content Include="Views\Quote\Best.aspx" />
<Content Include="Views\Quote\Edit.aspx" /> <Content Include="Views\Quote\Edit.aspx" />

View File

@ -1,19 +1,14 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.PagedModelWithUser<VideoGameQuotes.Api.Quote>>" MasterPageFile="~/Views/Shared/Site.Master" %> <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.PagedModelWithUser<VideoGameQuotes.Api.Quote>>" MasterPageFile="~/Views/Shared/Site.Master" %>
<%@ Import Namespace="Portoa.Web.Models" %>
<%@ Import Namespace="VideoGameQuotes.Web.Models" %> <%@ Import Namespace="VideoGameQuotes.Web.Models" %>
<asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Best: <%= Model.Start %> &ndash; <%= Model.End %></asp:Content> <asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Best: <%= Model.Start %> &ndash; <%= Model.End %></asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent"> <asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<p> <% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "best", Controller = "quote" }); %>
<% 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 }) %>
</p>
<% <%
foreach (var quote in Model.Records) { foreach (var quote in Model.Records) {
Html.RenderPartial("SingleQuote", new QuoteModel { Quote = quote, User = Model.CurrentUser }); Html.RenderPartial("SingleQuote", new QuoteModel { Quote = quote, User = Model.CurrentUser });
} }
%> %>
</asp:Content> </asp:Content>
<asp:Content runat="server" ID="DeferrableScripts" ContentPlaceHolderID="DeferrableScripts"></asp:Content>

View File

@ -0,0 +1,15 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Portoa.Web.Models.PagingMenuModel>" %>
<% if (!Model.HasNext && !Model.HasPrevious) { return; } %>
<div class="paging-menu">
<ul class="menu clearfix">
<% if (Model.HasNext) { %><li><%= Html.ActionLink("\u25B6", Model.Action, Model.Controller, new { page = (Model.CurrentPage + 1) }, new { title = "next page" })%></li><% } %>
<li><strong><%= Model.CurrentPage %></strong></li>
<% if (Model.HasPrevious) { %><li><%= Html.ActionLink("\u25C0", Model.Action, Model.Controller, new { page = (Model.CurrentPage - 1) }, new { title = "previous page" })%></li><% } %>
</ul>
<p>
Showing <strong><%= Model.Start %>&mdash;<%= Model.ActualEnd %></strong> of <strong><%= Model.TotalCount %></strong>.
</p>
</div>

View File

@ -1,5 +1,4 @@
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<VideoGameQuotes.Web.Models.QuoteModel>" %> <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<VideoGameQuotes.Web.Models.QuoteModel>" %>
<%@ Import Namespace="Portoa.Util" %>
<%@ Import Namespace="VideoGameQuotes.Api" %> <%@ Import Namespace="VideoGameQuotes.Api" %>
<div class="quote-container"> <div class="quote-container">

View File

@ -42,9 +42,6 @@ ul.menu {
padding: 0; padding: 0;
list-style: none; list-style: none;
} }
ul.menu li {
float: left;
}
.validation-summary-errors { .validation-summary-errors {
color: #000000; color: #000000;
@ -115,6 +112,24 @@ ul.menu li {
width: 600px; 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 { #browse-default-menu li {
margin-bottom: 2px; margin-bottom: 2px;
padding: 3px; padding: 3px;
@ -148,6 +163,7 @@ ul.menu li {
#main-menu li { #main-menu li {
margin-right: 2px; margin-right: 2px;
float: left;
} }
#main-menu li a { #main-menu li a {
display: block; display: block;