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.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Linq;
using System.Web.Mvc;
using BuildFeed.Code;
using BuildFeed.Models;
using BuildFeed.Models.ViewModel.Front;
namespace BuildFeed.Controllers
{
@ -15,6 +13,13 @@ public class frontController : Controller
{
public const int PAGE_SIZE = 96;
private Build bModel;
public frontController() : base()
{
bModel = new Build();
}
[Route("", Order = 1)]
#if !DEBUG
[OutputCache(Duration = 600, VaryByParam = "none", VaryByCustom = "userName")]
@ -27,7 +32,6 @@ public class frontController : Controller
#endif
public ActionResult indexPage(int page)
{
Build bModel = new Build();
var buildGroups = bModel.SelectBuildGroups(PAGE_SIZE, (page - 1) * PAGE_SIZE);
ViewBag.PageNumber = page;
@ -35,7 +39,7 @@ public ActionResult indexPage(int page)
Convert.ToDouble(bModel.SelectBuildGroupsCount()) /
Convert.ToDouble(PAGE_SIZE));
if (ViewBag.PageCount != 0 && ViewBag.PageNumber > ViewBag.PageCount)
if (ViewBag.PageNumber > ViewBag.PageCount)
{
return new HttpNotFoundResult();
}
@ -49,7 +53,6 @@ public ActionResult indexPage(int page)
#endif
public ActionResult viewGroup(byte major, byte minor, ushort number, ushort? revision = null)
{
Build bModel = new Build();
var builds = bModel.SelectSingleBuildGroup(new BuildGroup()
{
Major = major,
@ -69,7 +72,7 @@ public ActionResult viewGroup(byte major, byte minor, ushort number, ushort? rev
#endif
public ActionResult viewBuild(Guid id)
{
BuildModel b = new Build().SelectById(id);
BuildModel b = bModel.SelectById(id);
return View(b);
}
@ -80,7 +83,7 @@ public ActionResult viewBuild(Guid id)
#endif
public ActionResult twitterCard(Guid id)
{
BuildModel b = new Build().SelectById(id);
BuildModel b = bModel.SelectById(id);
using (Bitmap bm = new Bitmap(560, 300))
{
@ -128,10 +131,10 @@ public ActionResult viewLabPage(string lab, int page)
});
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.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)
{
@ -160,17 +163,17 @@ public ActionResult viewSourcePage(TypeOfSource source, int page)
});
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.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)
{
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")]
@ -192,17 +195,17 @@ public ActionResult viewYearPage(int year, int page)
});
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.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)
{
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")]
@ -225,17 +228,17 @@ public ActionResult viewVersionPage(int major, int minor, int page)
});
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.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)
{
return new HttpNotFoundResult();
}
return View("viewVersion", builds.Skip((page - 1) * PAGE_SIZE).Take(PAGE_SIZE));
return View("viewVersion", builds);
}
[Route("add/"), Authorize]

View File

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

View File

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