* fixed quote links menu

* made recent quotes paged
This commit is contained in:
tmont 2011-02-24 22:45:29 +00:00
parent 38f148be2f
commit 296b7c56b8
9 changed files with 55 additions and 25 deletions

View File

@ -74,11 +74,23 @@ namespace VideoGameQuotes.Web.Controllers {
} }
} }
public ActionResult Recent() { public ActionResult Recent(int page) {
return View(new QuoteCollectionModel { if (page < 1) {
Quotes = quoteService.GetMostRecentQuotes(10), return new StatusOverrideResult(View("BadPaging")) { StatusCode = HttpStatusCode.BadRequest };
User = currentUserProvider.CurrentUser }
});
const int pageSize = 10;
int totalCount;
var model = new PagedModelWithUser<Quote> {
CurrentUser = currentUserProvider.CurrentUser,
CurrentPage = page,
PageSize = pageSize
};
model.Records = quoteService.GetMostRecentQuotes(model.Start, model.End, out totalCount);
model.TotalCount = totalCount;
return View(model);
} }
public ActionResult Best(int page) { public ActionResult Best(int page) {

View File

@ -82,7 +82,7 @@ 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/{page}", new { controller = "Quote", action = "Best", page = 1 }, new { page = @"\d+" }); routes.MapRoute("paged", "{action}/{page}", new { controller = "Quote", page = 1 }, new { action = "best|recent", 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+" });

View File

@ -19,7 +19,7 @@ namespace VideoGameQuotes.Web.Services {
GamingSystem GetSystem(int systemId); GamingSystem GetSystem(int systemId);
Category GetCategory(int categoryId); Category GetCategory(int categoryId);
Category SaveCategory(Category category); Category SaveCategory(Category category);
IEnumerable<Quote> GetMostRecentQuotes(int limit); IEnumerable<Quote> GetMostRecentQuotes(int start, int end, out int totalCount);
[CanBeNull] [CanBeNull]
Quote GetRandomQuote(); Quote GetRandomQuote();
IEnumerable<Quote> GetBestQuotes(int start, int end, out int totalCount); IEnumerable<Quote> GetBestQuotes(int start, int end, out int totalCount);
@ -109,11 +109,13 @@ namespace VideoGameQuotes.Web.Services {
} }
[UnitOfWork] [UnitOfWork]
public IEnumerable<Quote> GetMostRecentQuotes(int limit) { public IEnumerable<Quote> GetMostRecentQuotes(int start, int end, out int totalCount) {
totalCount = quoteRepository.Records.Count();
return quoteRepository return quoteRepository
.Records .Records
.OrderByDescending(quote => quote.Created) .OrderByDescending(quote => quote.Created)
.Take(limit); .Skip(start - 1)
.Take(end - start + 1);
} }
[UnitOfWork] [UnitOfWork]
@ -132,15 +134,13 @@ namespace VideoGameQuotes.Web.Services {
[UnitOfWork] [UnitOfWork]
public IEnumerable<Quote> GetBestQuotes(int start, int end, out int totalCount) { public IEnumerable<Quote> GetBestQuotes(int start, int end, out int totalCount) {
var records = quoteRepository.Records totalCount = quoteRepository.Records.Count();
return quoteRepository.Records
.OrderByDescending(quote => quote.Score) .OrderByDescending(quote => quote.Score)
.ThenByDescending(quote => quote.UpVotes) .ThenByDescending(quote => quote.UpVotes)
.Skip(start - 1) .Skip(start - 1)
.Take(end - start + 1); .Take(end - start + 1);
totalCount = quoteRepository.Records.Count();
return records;
} }
[UnitOfWork] [UnitOfWork]

View File

@ -1,7 +1,7 @@
<%@ 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="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">
<% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "best", Controller = "quote" }); %> <% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "best", Controller = "quote" }); %>

View File

@ -1,10 +1,13 @@
<%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<VideoGameQuotes.Web.Models.QuoteCollectionModel>" MasterPageFile="~/Views/Shared/Site.Master" %> <%@ Page Title="" Language="C#" Inherits="System.Web.Mvc.ViewPage<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">Recently Submitted Quotes</asp:Content> <asp:Content runat="server" ID="Title" ContentPlaceHolderID="TitleContent">Recent: <%= Model.Start %>&ndash;<%= Model.End %></asp:Content>
<asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent"> <asp:Content runat="server" ID="Main" ContentPlaceHolderID="MainContent">
<% <% Html.RenderPartial("PagingMenu", new PagingMenuModel(Model) { Action = "recent", Controller = "quote" }); %>
foreach (var quote in Model.Quotes) {
Html.RenderPartial("SingleQuote", new QuoteModel { Quote = quote, User = Model.User }); <%
foreach (var quote in Model.Records) {
Html.RenderPartial("SingleQuote", new QuoteModel { Quote = quote, User = Model.CurrentUser });
} }
%> %>
</asp:Content> </asp:Content>

View File

@ -32,11 +32,11 @@
</p> </p>
<p class="quote-links"> <p class="quote-links">
<a class="quote-report-link" href="#" title="report this quote as inaccurate, fake, spam, duplicate, etc.">report</a> | <a class="quote-flag-link" href="#" title="flag this quote as inaccurate, fake, spam, duplicate, etc."></a>
<%= Html.ActionLink("permalink", "quote", "quote", new { id = Model.Quote.Id, text = Model.Quote.GetUrlFriendlyText() }, new { title = "permanent link to this quote" })%> <a class="quote-permalink" href="<%= Url.Action("quote", "quote", new { id = Model.Quote.Id, text = Model.Quote.GetUrlFriendlyText() }) %>" title="permanent link to this quote"></a>
<% if (Model.User != null && Model.User.Group >= UserGroup.Admin) { %> <% if (Model.User != null && Model.User.Group >= UserGroup.Admin) { %>
| <%= Html.ActionLink("edit", "edit", "quote", new { id = Model.Quote.Id }, null) %> <a class="edit-link" href="<%= Url.Action("edit", "quote", new { id = Model.Quote.Id }) %>" title="edit this quote"></a>
(<%= Model.Quote.Flags.Count() %> flags) <small>(<%= Model.Quote.Flags.Count() %>)</small>
<% } %> <% } %>
</p> </p>
</div> </div>

View File

@ -37,6 +37,9 @@ legend {
margin-left: 20px; margin-left: 20px;
padding: 5px; padding: 5px;
} }
small {
font-size: 80%;
}
ul.menu { ul.menu {
margin: 0; margin: 0;

View File

@ -81,8 +81,20 @@
} }
.quote-links { .quote-links {
float: right; float: right;
text-align: right;
width: 100px;
} }
.report-dialog { .report-dialog {
width: 400px; width: 400px;
}
.quote-flag-link, .quote-permalink {
padding-left: 16px;
background-repeat: no-repeat;
}
.quote-flag-link {
background-image: url(/media/images/flag_red.png);
}
.quote-permalink {
background-image: url(/media/images/link.png);
} }

View File

@ -204,7 +204,7 @@
}; };
var setupReportLink = function() { var setupReportLink = function() {
$(".quote-report-link").click(function() { $(".quote-flag-link").click(function() {
if ($(".report-dialog").length > 0) { if ($(".report-dialog").length > 0) {
return false; return false;
} }