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> {
Start = start,
End = end,
CurrentPage = 1,
Records = adminService.GetPagedUsers(start, end),
TotalCount = adminService.GetAllUsers().Count(),
CurrentUser = userProvider.CurrentUser

View File

@ -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<Quote> {
Records = quoteService.GetBestQuotes(start, end),
const int pageSize = 10;
int totalCount;
var model = new PagedModelWithUser<Quote> {
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() {

View File

@ -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" });

View File

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

View File

@ -147,6 +147,7 @@
<Content Include="Views\Home\About.aspx" />
<Content Include="Views\Home\Contact.aspx" />
<Content Include="Views\Home\ContactSuccess.aspx" />
<Content Include="Views\Quote\PagingMenu.ascx" />
<Content Include="Views\Shared\BadPaging.aspx" />
<Content Include="Views\Quote\Best.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" %>
<%@ Import Namespace="Portoa.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="Main" ContentPlaceHolderID="MainContent">
<p>
<% 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>
<% 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 });
}
%>
</asp:Content>
<asp:Content runat="server" ID="DeferrableScripts" ContentPlaceHolderID="DeferrableScripts"></asp:Content>
</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>" %>
<%@ Import Namespace="Portoa.Util" %>
<%@ Import Namespace="VideoGameQuotes.Api" %>
<div class="quote-container">

View File

@ -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;