Pagination fun

Mostly some #5, some tweaks to #4
This commit is contained in:
Thomas Hounsell 2015-05-28 21:18:21 +01:00
parent 2ccf7b5dbe
commit e04ab6fdbd
10 changed files with 155 additions and 48 deletions

View File

@ -0,0 +1,57 @@
@using BuildFeed.Code
@using System.Web.Mvc
@using System.Web.Mvc.Html
@using System.Web.Routing
@helper PaginationBlock(int currentPage, int totalPages, string view, RouteValueDictionary rd)
{
string multiView = view + "Page";
if (totalPages > 1)
{
<div class="text-center">
<ul class="pagination">
@if (currentPage == 2)
{
RouteValueDictionary rvd = new RouteValueDictionary(rd);
rvd.Remove("page");
<li>@MvcIntrinsics.Html.ActionLink(HttpUtility.HtmlDecode("&laquo;"), view, rvd)</li>
}
else if (currentPage > 2)
{
RouteValueDictionary rvd = new RouteValueDictionary(rd);
rvd["page"] = currentPage - 1;
<li>@MvcIntrinsics.Html.ActionLink(HttpUtility.HtmlDecode("&laquo;"), multiView, rvd)</li>
}
else
{
<li class="disabled"><span>&laquo;</span></li>
}
@{
RouteValueDictionary rvdIndex = new RouteValueDictionary(rd);
rvdIndex.Remove("page");
}
<li @((1 == currentPage) ? "class=active" : "")>@MvcIntrinsics.Html.ActionLink("1", view)</li>
@for (int i = 2; i <= totalPages; i++)
{
RouteValueDictionary rvd = new RouteValueDictionary(rd);
rvd["page"] = i;
<li @((i == currentPage) ? "class=active" : "")>@MvcIntrinsics.Html.ActionLink(i.ToString(), multiView, rvd)</li>
}
@if (currentPage < totalPages)
{
RouteValueDictionary rvd = new RouteValueDictionary(rd);
rvd["page"] = currentPage + 1;
<li>@MvcIntrinsics.Html.ActionLink(HttpUtility.HtmlDecode("&raquo;"), multiView, rvd)</li>
}
else
{
<li class="disabled"><span>&raquo;</span></li>
}
</ul>
</div>
}
}

View File

@ -172,6 +172,7 @@
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="Areas\admin\adminAreaRegistration.cs" />
<Compile Include="Areas\admin\Controllers\usersController.cs" />
<Compile Include="Code\MvcIntrinsics.cs" />
<Compile Include="Controllers\apiController.cs" />
<Compile Include="Controllers\frontController.cs" />
<Compile Include="Controllers\rssController.cs" />
@ -212,6 +213,7 @@
<Content Include="Areas\admin\Views\meta\create.cshtml" />
<Content Include="Scripts\Chart.js" />
<Content Include="Scripts\Chart.min.js" />
<Content Include="App_Code\PaginationHelpers.cshtml" />
<None Include="Scripts\jquery-2.1.4.intellisense.js" />
<Content Include="Scripts\jquery-2.1.4.js" />
<Content Include="Scripts\jquery-2.1.4.min.js" />

27
Code/MvcIntrinsics.cs Normal file
View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.WebPages;
namespace BuildFeed.Code
{
public static class MvcIntrinsics
{
public static System.Web.Mvc.HtmlHelper Html
{
get { return ((System.Web.Mvc.WebViewPage)WebPageContext.Current.Page).Html; }
}
public static System.Web.Mvc.AjaxHelper Ajax
{
get { return ((System.Web.Mvc.WebViewPage)WebPageContext.Current.Page).Ajax; }
}
public static System.Web.Mvc.UrlHelper Url
{
get { return ((System.Web.Mvc.WebViewPage)WebPageContext.Current.Page).Url; }
}
}
}

View File

@ -35,7 +35,16 @@ public bool AddWin10Builds(NewBuild apiModel)
}
if (Membership.ValidateUser(apiModel.Username, apiModel.Password))
{
Build.InsertAll(apiModel.NewBuilds);
Build.InsertAll(apiModel.NewBuilds.Select(nb => new Build()
{
MajorVersion = nb.MajorVersion,
MinorVersion = nb.MinorVersion,
Number = nb.Number,
Revision = nb.Revision,
Lab = nb.Lab,
BuildTime = nb.BuildTime,
FlightLevel = nb.FlightLevel
}));
return true;
}
else

View File

@ -11,7 +11,7 @@ namespace BuildFeed.Controllers
{
public class frontController : Controller
{
public const int _pageSize = 84;
public const int _pageSize = 96;
[Route("", Order = 1)]
#if !DEBUG
@ -101,30 +101,56 @@ public ActionResult viewLab(string lab)
return View(builds);
}
[Route("source/{source}/")]
[Route("source/{source}/", Order = 1)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none")]
#endif
public ActionResult viewSource(TypeOfSource source)
{
return viewSourcePage(source, 1);
}
[Route("source/{source}/page-{page:int:min(2)}/", Order = 0)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none")]
#endif
public ActionResult viewSourcePage(TypeOfSource source, int page)
{
ViewBag.MetaItem = MetaItem.SelectById(new MetaItemKey() { Type = MetaType.Source, Value = source.ToString() });
ViewBag.ItemId = DisplayHelpers.GetDisplayTextForEnum(source);
var builds = Build.SelectInBuildOrder().Where(b => b.SourceType == source);
return View(builds);
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(_pageSize));
return View("viewSource", builds.Skip((page - 1) * _pageSize).Take(_pageSize));
}
[Route("year/{year}/")]
[Route("year/{year}/", Order = 1)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none")]
#endif
public ActionResult viewYear(int year)
{
return viewYearPage(year, 1);
}
[Route("year/{year}/page-{page:int:min(2)}/", Order = 0)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none")]
#endif
public ActionResult viewYearPage(int year, int page)
{
ViewBag.MetaItem = MetaItem.SelectById(new MetaItemKey() { Type = MetaType.Year, Value = year.ToString() });
ViewBag.ItemId = year.ToString();
var builds = Build.SelectInBuildOrder().Where(b => b.BuildTime.HasValue && b.BuildTime.Value.Year == year);
return View(builds);
ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count()) / Convert.ToDouble(_pageSize));
return View("viewYear", builds.Skip((page - 1) * _pageSize).Take(_pageSize));
}
[Route("version/{major}.{minor}/")]

View File

@ -10,6 +10,17 @@ public class NewBuild
public string Username { get; set; }
public string Password { get; set; }
public Build[] NewBuilds { get; set; }
public NewBuildObject[] NewBuilds { get; set; }
}
public class NewBuildObject
{
public byte MajorVersion { get; set; }
public byte MinorVersion { get; set; }
public ushort Number { get; set; }
public ushort? Revision { get; set; }
public string Lab { get; set; }
public DateTime? BuildTime { get; set; }
public LevelOfFlight FlightLevel { get; set; }
}
}

View File

@ -27,40 +27,4 @@
</div>
}
</div>
@if (ViewBag.PageCount > 1)
{
<div class="text-center">
<ul class="pagination">
@if (ViewBag.PageNumber == 2)
{
<li>@Html.ActionLink(HttpUtility.HtmlDecode("&laquo;"), "index")</li>
}
else if (ViewBag.PageNumber > 2)
{
<li>@Html.ActionLink(HttpUtility.HtmlDecode("&laquo;"), "indexPage", new { page = ViewBag.PageNumber - 1 })</li>
}
else
{
<li class="disabled"><span>&laquo;</span></li>
}
<li @((1 == ViewBag.PageNumber) ? "class=active" : "")>@Html.ActionLink("1", "index")</li>
@for (int i = 2; i <= ViewBag.PageCount; i++)
{
<li @((i == ViewBag.PageNumber) ? "class=active" : "")>@Html.ActionLink(i.ToString(), "indexPage", new { page = i })</li>
}
@if (ViewBag.PageNumber < ViewBag.PageCount)
{
<li>@Html.ActionLink(HttpUtility.HtmlDecode("&raquo;"), "indexPage", new { page = ViewBag.PageNumber + 1 })</li>
}
else
{
<li class="disabled"><span>&raquo;</span></li>
}
</ul>
</div>
}
@PaginationHelpers.PaginationBlock((int)ViewBag.PageNumber, (int)ViewBag.PageCount, "index", ViewContext.RouteData.Values)

View File

@ -25,7 +25,7 @@
<div class="row">
@foreach (var build in Model)
{
<div class="col-sm-3">
<div class="col-sm-2">
<h3 class="build-group-title">@string.Format("{0}.{1}.{2}.{3}", build.MajorVersion, build.MinorVersion, build.Number, build.Revision)</h3>
<p>
<a href="@Url.Action("viewBuild", new { id = build.Id })" class="btn btn-info btn-xs">Info</a>
@ -41,7 +41,7 @@
<p>
@if (!string.IsNullOrEmpty(build.Lab))
{
<span><i class="fa fa-code-fork fa-fw"></i> @build.Lab</span><br />
<div class="no-wrapping" title="@build.Lab"><i class="fa fa-code-fork fa-fw"></i> @build.Lab</div>
}
@if (build.BuildTime.HasValue)
{
@ -62,6 +62,7 @@
</div>
}
</div>
@PaginationHelpers.PaginationBlock((int)ViewBag.PageNumber, (int)ViewBag.PageCount, "viewSource", ViewContext.RouteData.Values)
@section scripts
{
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5431719a661cbfd0" async="async"></script>

View File

@ -30,7 +30,7 @@
<div class="row">
@foreach (var build in Model)
{
<div class="col-sm-3">
<div class="col-sm-2">
<h3 class="build-group-title">@string.Format("{0}.{1}.{2}.{3}", build.MajorVersion, build.MinorVersion, build.Number, build.Revision)</h3>
<p>
<a href="@Url.Action("viewBuild", new { id = build.Id })" class="btn btn-info btn-xs">Info</a>
@ -46,7 +46,7 @@
<p>
@if (!string.IsNullOrEmpty(build.Lab))
{
<span><i class="fa fa-code-fork fa-fw"></i> @build.Lab</span><br />
<div class="no-wrapping" title="@build.Lab"><i class="fa fa-code-fork fa-fw"></i> @build.Lab</div>
}
@if (build.BuildTime.HasValue)
{
@ -67,6 +67,7 @@
</div>
}
</div>
@PaginationHelpers.PaginationBlock((int)ViewBag.PageNumber, (int)ViewBag.PageCount, "viewYear", ViewContext.RouteData.Values)
@section scripts
{
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-5431719a661cbfd0" async="async"></script>

View File

@ -34,6 +34,15 @@ h1
margin-left: 0.3em;
}
.no-wrapping
{
-ms-text-overflow: ellipsis;
-o-text-overflow: ellipsis;
text-overflow: ellipsis;
overflow: hidden;
white-space: nowrap;
}
.label-build-status
{
padding-bottom: 0;