Permalink
Browse files

"UI" Paging in profiles

  • Loading branch information...
1 parent e50dce0 commit d25db2e06c4ec2b012302ca87acb7289c42cb50c @robertmuehsig robertmuehsig committed Jun 17, 2014
@@ -253,7 +253,7 @@ public virtual ActionResult ResetPassword(bool forgot)
return View(model);
}
- public virtual ActionResult Profiles(string username)
+ public virtual ActionResult Profiles(string username, int page = 1)
{
var user = UserService.FindByUsername(username);
if (user == null)
@@ -269,11 +269,7 @@ public virtual ActionResult Profiles(string username)
Version = null
}).ToList();
- var model = new UserProfileModel(user)
- {
- Packages = packages,
- TotalPackageDownloadCount = packages.Sum(p => p.TotalDownloadCount),
- };
+ var model = new UserProfileModel(user, packages, page - 1, Constants.DefaultPackageListPageSize, Url);
return View(model);
}
@@ -70,6 +70,8 @@ public static string PackageList(this UrlHelper url, int page, string q)
});
}
+
+
public static string CuratedPackageList(this UrlHelper url, int page, string q, string curatedFeedName)
{
return url.Action("ListPackages", "CuratedFeeds", new
@@ -141,7 +143,7 @@ public static string PackageDownload(this UrlHelper url, int feedVersion, string
string routeName = "v" + feedVersion + RouteName.DownloadPackage;
string protocol = url.RequestContext.HttpContext.Request.IsSecureConnection ? "https" : "http";
string result = url.RouteUrl(routeName, new { Id = id, Version = version }, protocol: protocol);
-
+
// Ensure trailing slashes for versionless package URLs, as a fix for package filenames that look like known file extensions
return version == null ? EnsureTrailingSlash(result) : result;
}
@@ -198,14 +200,26 @@ public static string UploadPackage(this UrlHelper url)
return url.RouteUrl(RouteName.UploadPackage);
}
- public static string User(this UrlHelper url, User user, string scheme = null)
+ public static string User(this UrlHelper url, User user, int page = 1, string scheme = null)
{
- string result = url.Action(
- actionName: "Profiles",
- controllerName: "Users",
- routeValues: new { username = user.Username },
- protocol: scheme);
- return EnsureTrailingSlash(result);
+ string result;
+ if (page == 1)
+ {
+ result = url.Action(actionName: "Profiles",
+ controllerName: "Users",
+ routeValues: new { username = user.Username },
+ protocol: scheme);
+ }
+ else
+ {
+ result = url.Action(actionName: "Profiles",
+ controllerName: "Users",
+ routeValues: new { username = user.Username, page = page },
+ protocol: scheme);
+ }
+
+
+ return result;
}
public static string EditPackage(this UrlHelper url, string id, string version)
@@ -221,9 +235,10 @@ public static string EditPackage(this UrlHelper url, string id, string version)
public static string DeletePackage(this UrlHelper url, IPackageVersionModel package)
{
return url.Action(
- actionName: "Delete",
- controllerName: "Packages",
- routeValues: new {
+ actionName: "Delete",
+ controllerName: "Packages",
+ routeValues: new
+ {
id = package.Id,
version = package.Version
});
@@ -252,8 +267,8 @@ public static string ConfirmationUrl(this UrlHelper url, string action, string c
rvd["username"] = username;
rvd["token"] = token;
return url.Action(
- action,
- controller,
+ action,
+ controller,
rvd,
url.RequestContext.HttpContext.Request.Url.Scheme,
url.RequestContext.HttpContext.Request.Url.Host);
@@ -1,22 +1,44 @@
using System.Collections.Generic;
+using System.Linq;
+using System.Web.Mvc;
namespace NuGetGallery
{
public class UserProfileModel
{
- public UserProfileModel() { }
-
- public UserProfileModel(User user)
+ public UserProfileModel(User user, List<PackageViewModel> allPackages, int pageIndex, int pageSize, UrlHelper url)
{
Username = user.Username;
EmailAddress = user.EmailAddress;
UnconfirmedEmailAddress = user.UnconfirmedEmailAddress;
+ AllPackages = allPackages;
+ TotalPackages = allPackages.Count;
+ PackagePage = pageIndex;
+ PackagePageSize = pageSize;
+
+ TotalPackageDownloadCount = AllPackages.Sum(p => p.TotalDownloadCount);
+
+ PackagePageTotalCount = (TotalPackages + PackagePageSize - 1) / PackagePageSize;
+
+ var pager = new PreviousNextPagerViewModel<PackageViewModel>(allPackages, pageIndex, PackagePageTotalCount,
+ page => url.User(user, page));
+
+ Pager = pager;
+ PagedPackages = AllPackages.Skip(PackagePageSize * pageIndex)
+ .Take(PackagePageSize).ToList();
}
- public string Username { get; set; }
- public string EmailAddress { get; set; }
+ public int PackagePageTotalCount { get; private set; }
+ public string Username { get; private set; }
+ public string EmailAddress { get; private set; }
public string UnconfirmedEmailAddress { get; set; }
- public ICollection<PackageViewModel> Packages { get; set; }
- public int TotalPackageDownloadCount { get; set; }
+ public ICollection<PackageViewModel> AllPackages { get; private set; }
+ public ICollection<PackageViewModel> PagedPackages { get; private set; }
+ public int TotalPackageDownloadCount { get; private set; }
+ public int TotalPackages { get; private set; }
+ public int PackagePage { get; private set; }
+ public int PackagePageSize { get; private set; }
+ public IPreviousNextPager Pager { get; private set; }
+
}
}
@@ -12,8 +12,8 @@
}
<div id="stats">
<div class="stat">
- <p class="stat-number">@Model.Packages.Count.ToString("n0")</p>
- <p class="stat-label">@(Model.Packages.Count == 1 ? "Package" : "Packages")</p>
+ <p class="stat-number">@Model.AllPackages.Count.ToString("n0")</p>
+ <p class="stat-label">@(Model.AllPackages.Count == 1 ? "Package" : "Packages")</p>
</div>
<div class="stat">
<p class="stat-number">@Model.TotalPackageDownloadCount.ToString("n0")</p>
@@ -24,9 +24,13 @@
<h1 class="page-heading">@Model.Username's Profile</h1>
-<h2>Packages</h2>
+<h2>Packages
+ @if (Model.PackagePageTotalCount > 1)
+{
+ <small>(Page @(Model.PackagePage + 1) of @Model.PackagePageTotalCount)</small>
+}</h2>
<ul id="searchResults">
- @foreach (var package in Model.Packages)
+ @foreach (var package in Model.PagedPackages)
{
<li>
<section class="package">
@@ -59,4 +63,6 @@
</section>
</li>
}
-</ul>
+</ul>
+
+@ViewHelpers.PreviousNextPager(Model.Pager)

0 comments on commit d25db2e

Please sign in to comment.