Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #2215 from robertmuehsig/144-paginginprofile

UI paging over packages in Profile page
  • Loading branch information...
commit 8354eee418f107f2c6ef9a870ac7a9f1a2540e16 2 parents 7516257 + f683d29
Jeff Handley authored
View
6 src/NuGetGallery/Content/Site.css
@@ -66,6 +66,12 @@ h6 {
font-size: 1em;
}
+
+small {
+ font-size: 0.5em;
+}
+
+
h1 img, h2 img, h3 img,
h4 img, h5 img, h6 img {
margin: 0;
View
9 src/NuGetGallery/Controllers/UsersController.cs
@@ -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, bool showAllPackages = false)
{
var user = UserService.FindByUsername(username);
if (user == null)
@@ -269,11 +269,8 @@ 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);
+ model.ShowAllPackages = showAllPackages;
return View(model);
}
View
51 src/NuGetGallery/UrlExtensions.cs
@@ -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,36 @@ 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 UserShowAllPackages(this UrlHelper url, string username, string scheme = null)
+ {
+ string result;
+ result = url.Action(actionName: "Profiles",
+ controllerName: "Users",
+ routeValues: new { username = username, showAllPackages = true },
+ protocol: scheme);
+ return result;
}
public static string EditPackage(this UrlHelper url, string id, string version)
@@ -221,9 +245,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 +277,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);
View
36 src/NuGetGallery/ViewModels/UserProfileModel.cs
@@ -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; }
+ public bool ShowAllPackages { get; set; }
}
}
View
30 src/NuGetGallery/Views/Users/Profiles.cshtml
@@ -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,23 @@
<h1 class="page-heading">@Model.Username's Profile</h1>
-<h2>Packages</h2>
+<h2>Packages
+@if (Model.PackagePageTotalCount > 1 && Model.ShowAllPackages == false)
+{
+ <small>(Page @(Model.PackagePage + 1) of @Model.PackagePageTotalCount) <a href="@Url.UserShowAllPackages(Model.Username)">Show all packages</a></small>
+}
+</h2>
<ul id="searchResults">
- @foreach (var package in Model.Packages)
+@{
+ var allOrPagedPackages = Model.PagedPackages;
+
+ if (Model.ShowAllPackages)
+ {
+ allOrPagedPackages = Model.AllPackages;
+ }
+}
+
+ @foreach (var package in allOrPagedPackages)
{
<li>
<section class="package">
@@ -59,4 +73,10 @@
</section>
</li>
}
-</ul>
+</ul>
+
+@if (Model.ShowAllPackages == false)
+{
+ @ViewHelpers.PreviousNextPager(Model.Pager)
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.