The Mongofication continues

All front controller views now more mongofied.
This commit is contained in:
Thomas Hounsell 2015-09-10 09:51:49 +01:00
parent 2919fbea16
commit 8422111ec5
3 changed files with 204 additions and 91 deletions

View File

@ -1,13 +1,11 @@
using System; using BuildFeed.Models;
using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Drawing2D; using System.Drawing.Drawing2D;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Drawing.Text; using System.Drawing.Text;
using System.Linq; using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using BuildFeed.Code;
using BuildFeed.Models;
using BuildFeed.Models.ViewModel.Front;
namespace BuildFeed.Controllers namespace BuildFeed.Controllers
{ {
@ -15,6 +13,13 @@ public class frontController : Controller
{ {
public const int PAGE_SIZE = 96; public const int PAGE_SIZE = 96;
private Build bModel;
public frontController() : base()
{
bModel = new Build();
}
[Route("", Order = 1)] [Route("", Order = 1)]
#if !DEBUG #if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName")] [OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName")]
@ -27,7 +32,6 @@ public class frontController : Controller
#endif #endif
public ActionResult indexPage(int page) public ActionResult indexPage(int page)
{ {
Build bModel = new Build();
var buildGroups = bModel.SelectBuildGroups(PAGE_SIZE, (page - 1) * PAGE_SIZE); var buildGroups = bModel.SelectBuildGroups(PAGE_SIZE, (page - 1) * PAGE_SIZE);
ViewBag.PageNumber = page; ViewBag.PageNumber = page;
@ -35,7 +39,7 @@ public ActionResult indexPage(int page)
Convert.ToDouble(bModel.SelectBuildGroupsCount()) / Convert.ToDouble(bModel.SelectBuildGroupsCount()) /
Convert.ToDouble(PAGE_SIZE)); Convert.ToDouble(PAGE_SIZE));
if (ViewBag.PageCount != 0 && ViewBag.PageNumber > ViewBag.PageCount) if (ViewBag.PageNumber > ViewBag.PageCount)
{ {
return new HttpNotFoundResult(); return new HttpNotFoundResult();
} }
@ -49,7 +53,6 @@ public ActionResult indexPage(int page)
#endif #endif
public ActionResult viewGroup(byte major, byte minor, ushort number, ushort? revision = null) public ActionResult viewGroup(byte major, byte minor, ushort number, ushort? revision = null)
{ {
Build bModel = new Build();
var builds = bModel.SelectSingleBuildGroup(new BuildGroup() var builds = bModel.SelectSingleBuildGroup(new BuildGroup()
{ {
Major = major, Major = major,
@ -69,7 +72,7 @@ public ActionResult viewGroup(byte major, byte minor, ushort number, ushort? rev
#endif #endif
public ActionResult viewBuild(Guid id) public ActionResult viewBuild(Guid id)
{ {
BuildModel b = new Build().SelectById(id); BuildModel b = bModel.SelectById(id);
return View(b); return View(b);
} }
@ -80,7 +83,7 @@ public ActionResult viewBuild(Guid id)
#endif #endif
public ActionResult twitterCard(Guid id) public ActionResult twitterCard(Guid id)
{ {
BuildModel b = new Build().SelectById(id); BuildModel b = bModel.SelectById(id);
using (Bitmap bm = new Bitmap(560, 300)) using (Bitmap bm = new Bitmap(560, 300))
{ {
@ -128,10 +131,10 @@ public ActionResult viewLabPage(string lab, int page)
}); });
ViewBag.ItemId = lab; ViewBag.ItemId = lab;
var builds = new Build().SelectLabInBuildOrder(lab, (page - 1) * PAGE_SIZE, PAGE_SIZE); var builds = bModel.SelectLab(lab, (page - 1) * PAGE_SIZE, PAGE_SIZE);
ViewBag.PageNumber = page; ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Count) / Convert.ToDouble(PAGE_SIZE)); ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(bModel.SelectLabCount(lab)) / Convert.ToDouble(PAGE_SIZE));
if (ViewBag.PageNumber > ViewBag.PageCount) if (ViewBag.PageNumber > ViewBag.PageCount)
{ {
@ -160,17 +163,17 @@ public ActionResult viewSourcePage(TypeOfSource source, int page)
}); });
ViewBag.ItemId = DisplayHelpers.GetDisplayTextForEnum(source); ViewBag.ItemId = DisplayHelpers.GetDisplayTextForEnum(source);
var builds = new Build().SelectInBuildOrder().Where(b => b.SourceType == source).ToArray(); var builds = bModel.SelectSource(source, (page - 1) * PAGE_SIZE, PAGE_SIZE);
ViewBag.PageNumber = page; ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Length) / Convert.ToDouble(PAGE_SIZE)); ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(bModel.SelectSourceCount(source)) / Convert.ToDouble(PAGE_SIZE));
if (ViewBag.PageNumber > ViewBag.PageCount) if (ViewBag.PageNumber > ViewBag.PageCount)
{ {
return new HttpNotFoundResult(); return new HttpNotFoundResult();
} }
return View("viewSource", builds.Skip((page - 1) * PAGE_SIZE).Take(PAGE_SIZE)); return View("viewSource", builds);
} }
[Route("year/{year}/", Order = 1, Name = "Year Root")] [Route("year/{year}/", Order = 1, Name = "Year Root")]
@ -192,17 +195,17 @@ public ActionResult viewYearPage(int year, int page)
}); });
ViewBag.ItemId = year.ToString(); ViewBag.ItemId = year.ToString();
var builds = new Build().SelectInBuildOrder().Where(b => b.BuildTime.HasValue && b.BuildTime.Value.Year == year).ToArray(); var builds = bModel.SelectYear(year, (page - 1) * PAGE_SIZE, PAGE_SIZE);
ViewBag.PageNumber = page; ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Length) / Convert.ToDouble(PAGE_SIZE)); ViewBag.PageCount = Math.Ceiling(bModel.SelectYearCount(year) / Convert.ToDouble(PAGE_SIZE));
if (ViewBag.PageNumber > ViewBag.PageCount) if (ViewBag.PageNumber > ViewBag.PageCount)
{ {
return new HttpNotFoundResult(); return new HttpNotFoundResult();
} }
return View("viewYear", builds.Skip((page - 1) * PAGE_SIZE).Take(PAGE_SIZE)); return View("viewYear", builds);
} }
[Route("version/{major}.{minor}/", Order = 1, Name = "Version Root")] [Route("version/{major}.{minor}/", Order = 1, Name = "Version Root")]
@ -225,17 +228,17 @@ public ActionResult viewVersionPage(int major, int minor, int page)
}); });
ViewBag.ItemId = valueString; ViewBag.ItemId = valueString;
var builds = new Build().SelectInBuildOrder().Where(b => b.MajorVersion == major && b.MinorVersion == minor).ToArray(); var builds = bModel.SelectVersion(major, minor, (page - 1) * PAGE_SIZE, PAGE_SIZE);
ViewBag.PageNumber = page; ViewBag.PageNumber = page;
ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(builds.Length) / Convert.ToDouble(PAGE_SIZE)); ViewBag.PageCount = Math.Ceiling(Convert.ToDouble(bModel.SelectVersionCount(major, minor)) / Convert.ToDouble(PAGE_SIZE));
if (ViewBag.PageNumber > ViewBag.PageCount) if (ViewBag.PageNumber > ViewBag.PageCount)
{ {
return new HttpNotFoundResult(); return new HttpNotFoundResult();
} }
return View("viewVersion", builds.Skip((page - 1) * PAGE_SIZE).Take(PAGE_SIZE)); return View("viewVersion", builds);
} }
[Route("add/"), Authorize] [Route("add/"), Authorize]

View File

@ -222,7 +222,7 @@ public BuildModel SelectByLegacyId(long id)
} }
[DataObjectMethod(DataObjectMethodType.Select, false)] [DataObjectMethod(DataObjectMethodType.Select, false)]
public IEnumerable<BuildModel> SelectInBuildOrder() public List<BuildModel> SelectInBuildOrder()
{ {
var task = _buildCollection.Find(new BsonDocument()) var task = _buildCollection.Find(new BsonDocument())
.SortByDescending(b => b.BuildTime) .SortByDescending(b => b.BuildTime)
@ -236,7 +236,21 @@ public IEnumerable<BuildModel> SelectInBuildOrder()
} }
[DataObjectMethod(DataObjectMethodType.Select, false)] [DataObjectMethod(DataObjectMethodType.Select, false)]
public List<BuildModel> SelectLabInBuildOrder(string lab, int skip, int limit) public List<BuildModel> SelectInVersionOrder()
{
var task = _buildCollection.Find(new BsonDocument())
.SortByDescending(b => b.MajorVersion)
.ThenByDescending(b => b.MinorVersion)
.ThenByDescending(b => b.Number)
.ThenByDescending(b => b.Revision)
.ThenByDescending(b => b.BuildTime)
.ToListAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public List<BuildModel> SelectLab(string lab, int skip, int limit)
{ {
var task = _buildCollection.Find(b => b.Lab != null && (b.Lab.ToLower() == lab.ToLower())) var task = _buildCollection.Find(b => b.Lab != null && (b.Lab.ToLower() == lab.ToLower()))
.SortByDescending(b => b.BuildTime) .SortByDescending(b => b.BuildTime)
@ -252,19 +266,89 @@ public List<BuildModel> SelectLabInBuildOrder(string lab, int skip, int limit)
} }
[DataObjectMethod(DataObjectMethodType.Select, false)] [DataObjectMethod(DataObjectMethodType.Select, false)]
public IEnumerable<BuildModel> SelectInVersionOrder() public long SelectLabCount(string lab)
{ {
var task = _buildCollection.Find(new BsonDocument()) var task = _buildCollection.Find(b => b.Lab != null && (b.Lab.ToLower() == lab.ToLower()))
.SortByDescending(b => b.MajorVersion) .CountAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public List<BuildModel> SelectSource(TypeOfSource source, int skip, int limit)
{
var task = _buildCollection.Find(b => b.SourceType == source)
.SortByDescending(b => b.BuildTime)
.ThenByDescending(b => b.MajorVersion)
.ThenByDescending(b => b.MinorVersion) .ThenByDescending(b => b.MinorVersion)
.ThenByDescending(b => b.Number) .ThenByDescending(b => b.Number)
.ThenByDescending(b => b.Revision) .ThenByDescending(b => b.Revision)
.ThenByDescending(b => b.BuildTime) .Skip(skip)
.Limit(limit)
.ToListAsync(); .ToListAsync();
task.Wait(); task.Wait();
return task.Result; return task.Result;
} }
[DataObjectMethod(DataObjectMethodType.Select, false)]
public long SelectSourceCount(TypeOfSource source)
{
var task = _buildCollection.Find(b => b.SourceType == source)
.CountAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public List<BuildModel> SelectYear(int year, int skip, int limit)
{
var task = _buildCollection.Find(b => b.BuildTime.HasValue && b.BuildTime.Value.Year == year)
.SortByDescending(b => b.BuildTime)
.ThenByDescending(b => b.MajorVersion)
.ThenByDescending(b => b.MinorVersion)
.ThenByDescending(b => b.Number)
.ThenByDescending(b => b.Revision)
.Skip(skip)
.Limit(limit)
.ToListAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public long SelectYearCount(int year)
{
var task = _buildCollection.Find(b => b.BuildTime.HasValue && b.BuildTime.Value.Year == year)
.CountAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public List<BuildModel> SelectVersion(int major, int minor, int skip, int limit)
{
var task = _buildCollection.Find(b => b.MajorVersion == major && b.MinorVersion == minor)
.SortByDescending(b => b.BuildTime)
.ThenByDescending(b => b.MajorVersion)
.ThenByDescending(b => b.MinorVersion)
.ThenByDescending(b => b.Number)
.ThenByDescending(b => b.Revision)
.Skip(skip)
.Limit(limit)
.ToListAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)]
public long SelectVersionCount(int major, int minor)
{
var task = _buildCollection.Find(b => b.MajorVersion == major && b.MinorVersion == minor)
.CountAsync();
task.Wait();
return task.Result;
}
[DataObjectMethod(DataObjectMethodType.Select, false)] [DataObjectMethod(DataObjectMethodType.Select, false)]
public IEnumerable<BuildVersion> SelectBuildVersions() public IEnumerable<BuildVersion> SelectBuildVersions()
{ {
@ -344,31 +428,31 @@ public void DeleteById(Guid id)
public enum TypeOfSource public enum TypeOfSource
{ {
[Display(ResourceType = typeof(Model), Name = "PublicRelease")] [Display(ResourceType = typeof(Model), Name = "PublicRelease")]
PublicRelease, PublicRelease = 0,
[Display(ResourceType = typeof(Model), Name = "InternalLeak")] [Display(ResourceType = typeof(Model), Name = "InternalLeak")]
InternalLeak, InternalLeak = 1,
[Display(ResourceType = typeof(Model), Name = "UpdateGDR")] [Display(ResourceType = typeof(Model), Name = "UpdateGDR")]
UpdateGDR, UpdateGDR = 2,
[Display(ResourceType = typeof(Model), Name = "UpdateLDR")] [Display(ResourceType = typeof(Model), Name = "UpdateLDR")]
UpdateLDR, UpdateLDR = 3,
[Display(ResourceType = typeof(Model), Name = "AppPackage")] [Display(ResourceType = typeof(Model), Name = "AppPackage")]
AppPackage, AppPackage = 4,
[Display(ResourceType = typeof(Model), Name = "BuildTools")] [Display(ResourceType = typeof(Model), Name = "BuildTools")]
BuildTools, BuildTools = 5,
[Display(ResourceType = typeof(Model), Name = "Documentation")] [Display(ResourceType = typeof(Model), Name = "Documentation")]
Documentation, Documentation = 6,
[Display(ResourceType = typeof(Model), Name = "Logging")] [Display(ResourceType = typeof(Model), Name = "Logging")]
Logging, Logging = 7,
[Display(ResourceType = typeof(Model), Name = "PrivateLeak")] [Display(ResourceType = typeof(Model), Name = "PrivateLeak")]
PrivateLeak PrivateLeak = 8
} }
public enum LevelOfFlight public enum LevelOfFlight

View File

@ -1,141 +1,167 @@
body, h1, h2, h3 body, h1, h2, h3
{ {
font-family: 'Hind', sans-serif; font-family: 'Hind', sans-serif;
} }
h1 h1
{ {
font-size: 48px; font-size: 48px;
font-weight: 300; font-weight: 300;
} }
h1 a h1 a
{ {
text-decoration: none; text-decoration: none;
color: #000; color: #000;
} }
#page-content #page-content
{ {
padding-top: 50px; padding-top: 50px;
} }
.build-group .build-group
{ {
margin-bottom: 2em; margin-bottom: 2em;
} }
.build-group-title .build-group-title
{ {
font-size: 24px; font-size: 24px;
font-weight: 300; font-weight: 300;
margin: 0 0 4px 0; margin: 0 0 4px 0;
} }
.build-group-p .build-group-p
{ {
margin-bottom: 4px; margin-bottom: 4px;
} }
.no-wrapping .no-wrapping
{ {
-ms-text-overflow: ellipsis; -ms-text-overflow: ellipsis;
-o-text-overflow: ellipsis; -o-text-overflow: ellipsis;
-moz-text-overflow: ellipsis; -moz-text-overflow: ellipsis;
text-overflow: ellipsis; text-overflow: ellipsis;
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;
} }
.label-build-status .label-build-status
{ {
padding-bottom: 0; padding-bottom: 0;
} }
.field-validation-error .field-validation-error
{ {
color: #ff4136; color: #ff4136;
} }
.form-details label .form-details label
{ {
font-weight: bold; font-weight: bold;
} }
#page-footer #page-footer
{ {
font-size: 12px; font-size: 12px;
margin-top: 3em; margin-top: 3em;
} }
.form-horizontal .control-label .form-horizontal .control-label
{ {
padding-top: 8px; padding-top: 8px;
} }
label, .control-label, .help-block, .checkbox, .radio label, .control-label, .help-block, .checkbox, .radio
{ {
font-size: 14px; font-size: 14px;
} }
.btn-reset .btn-reset
{ {
padding: 9px 0 7px; padding: 9px 0 7px;
} }
.table .btn .table .btn
{ {
padding: 4px 9px; padding: 4px 9px;
} }
.table-admin h4 .table-admin h4
{ {
margin: .1em 0; margin: .1em 0;
} }
.table-admin > tbody > tr > th, .table-admin > tbody > tr > th,
.table-admin > tbody > tr > td .table-admin > tbody > tr > td
{ {
vertical-align: middle; vertical-align: middle;
} }
.trumbowyg-box.trumbowyg, .trumbowyg-editor.trumbowyg .trumbowyg-box.trumbowyg, .trumbowyg-editor.trumbowyg
{ {
margin: 0; margin: 0;
width: 100%; width: 100%;
} }
#search-results #search-results
{ {
margin-top: 1em; margin-top: 1em;
} }
#search-results .list-group-item #search-results .list-group-item
{ {
margin-bottom: 1em; margin-bottom: 1em;
} }
#search-results .list-group-item-heading #search-results .list-group-item-heading
{ {
overflow: hidden; overflow: hidden;
-ms-text-overflow: ellipsis; -ms-text-overflow: ellipsis;
-o-text-overflow: ellipsis; -o-text-overflow: ellipsis;
-moz-text-overflow: ellipsis; -moz-text-overflow: ellipsis;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap; white-space: nowrap;
} }
#search-results .list-group-item-heading h4 #search-results .list-group-item-heading h4
{ {
font-size: 16px; font-size: 16px;
} }
#haackroutedebugger #haackroutedebugger
{ {
color: #000; color: #000;
} }
#haackroutedebugger h1, #haackroutedebugger h2, #haackroutedebugger h3 #haackroutedebugger h1, #haackroutedebugger h2, #haackroutedebugger h3
{ {
text-shadow: none; text-shadow: none;
} }
@media (max-width: 767px)
{
}
@media (min-width: 768px) and (max-width: 991px)
{
.col-sm-2.build-group:nth-child(6n+1),
.col-sm-3.build-group:nth-child(4n+1)
{
clear: left;
}
}
@media (min-width: 992px) and (max-width: 1199px)
{
.col-md-2.build-group:nth-child(6n+1)
{
clear: left;
}
}
@media (min-width: 1200px)
{
}