Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"UI" Paging in Profilepage - WIP #2215

Merged
merged 2 commits into from Jun 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/NuGetGallery/Content/Site.css
Expand Up @@ -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;
Expand Down
9 changes: 3 additions & 6 deletions src/NuGetGallery/Controllers/UsersController.cs
Expand Up @@ -253,7 +253,7 @@ public virtual async Task<ActionResult> Confirm(string username, string token)
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)
Expand All @@ -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);
}
Expand Down
51 changes: 38 additions & 13 deletions src/NuGetGallery/UrlExtensions.cs
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
});
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 29 additions & 7 deletions 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; }
}
}
30 changes: 25 additions & 5 deletions src/NuGetGallery/Views/Users/Profiles.cshtml
Expand Up @@ -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>
Expand All @@ -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">
Expand Down Expand Up @@ -59,4 +73,10 @@
</section>
</li>
}
</ul>
</ul>

@if (Model.ShowAllPackages == false)
{
@ViewHelpers.PreviousNextPager(Model.Pager)
}