Skip to content

Commit

Permalink
Show full version on package details page (#3887)
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierdecoster committed May 15, 2017
1 parent 837b9d3 commit 8354e23
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/NuGetGallery.Core/Auditing/PackageAuditRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public PackageAuditRecord(Package package, AuditedPackageAction action)

public override string GetPath()
{
return $"{Id}/{NuGetVersionNormalizer.Normalize(Version)}"
return $"{Id}/{NuGetVersionFormatter.Normalize(Version)}"
.ToLowerInvariant();
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/NuGetGallery.Core/NuGetVersionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace NuGetGallery
{
public static class NuGetVersionNormalizer
public static class NuGetVersionFormatter
{
public static string Normalize(string version)
{
Expand All @@ -19,6 +19,19 @@ public static string Normalize(string version)

return parsed.ToNormalizedString();
}

public static string ToFullStringOrFallback(string version, string fallback = "")
{
NuGetVersion nugetVersion;
if (NuGetVersion.TryParse(version, out nugetVersion))
{
return nugetVersion.ToFullString();
}
else
{
return fallback;
}
}
}

public static class NuGetVersionExtensions
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Controllers/ApiController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public virtual async Task<ActionResult> GetPackage(string id, string version)
}

// Normalize the version
version = NuGetVersionNormalizer.Normalize(version);
version = NuGetVersionFormatter.Normalize(version);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Controllers/PackagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public virtual async Task<ActionResult> UploadPackage(HttpPostedFileBase uploadF

public virtual async Task<ActionResult> DisplayPackage(string id, string version)
{
string normalized = NuGetVersionNormalizer.Normalize(version);
string normalized = NuGetVersionFormatter.Normalize(version);
if (!string.Equals(version, normalized))
{
// Permanent redirect to the normalized one (to avoid multiple URLs for the same content)
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Infrastructure/PackageIndexEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public Document ToDocument()
document.Add(new Field("Version", Package.Version.ToStringSafe(), Field.Store.YES, Field.Index.NO));

string normalizedVersion = String.IsNullOrEmpty(Package.NormalizedVersion) ?
NuGetVersionNormalizer.Normalize(Package.Version) :
NuGetVersionFormatter.Normalize(Package.Version) :
Package.NormalizedVersion;
document.Add(new Field("NormalizedVersion", normalizedVersion.ToStringSafe(), Field.Store.YES, Field.Index.NO));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected override Expression VisitBinary(BinaryExpression node)
// We have a "Package.Version == <constant>" expression!

// Transform the constant version into a normalized version
string newVersion = NuGetVersionNormalizer.Normalize((string)constSide.Value);
string newVersion = NuGetVersionFormatter.Normalize((string)constSide.Value);

// Create a new expression that checks the new constant against NormalizedVersion instead
return Expression.MakeBinary(
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/OData/SearchService/SearchHijacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private static Tuple<Target, string> ExtractComparison(BinaryExpression binExpr)
}
else if (memberSide.Member == VersionMember)
{
return Tuple.Create(Target.Version, NuGetVersionNormalizer.Normalize((string)constSide.Value));
return Tuple.Create(Target.Version, NuGetVersionFormatter.Normalize((string)constSide.Value));
}
else if (memberSide.Member == IdMember)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override void Annotate(HttpRequestMessage request, ODataEntry entry, obje
}

// Patch links to use normalized versions
var normalizedVersion = NuGetVersionNormalizer.Normalize(feedPackage.Version);
var normalizedVersion = NuGetVersionFormatter.Normalize(feedPackage.Version);
NormalizeNavigationLinks(entry, request, feedPackage, normalizedVersion);

// Set Atom entry metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void InterceptPackageMaterialized(Package package)
}

var packageNormalizedVersion = String.IsNullOrEmpty(package.NormalizedVersion)
? NuGetVersionNormalizer.Normalize(package.Version)
? NuGetVersionFormatter.Normalize(package.Version)
: package.NormalizedVersion;

int downloadCount;
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Services/PackageFileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private static string BuildFileName(Package package)
return BuildFileName(
package.PackageRegistration.Id,
String.IsNullOrEmpty(package.NormalizedVersion) ?
NuGetVersionNormalizer.Normalize(package.Version) :
NuGetVersionFormatter.Normalize(package.Version) :
package.NormalizedVersion);
}

Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Services/PackageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public virtual Package FindPackageByIdAndVersionStrict(string id, string version
throw new ArgumentException(nameof(version));
}

var normalizedVersion = NuGetVersionNormalizer.Normalize(version);
var normalizedVersion = NuGetVersionFormatter.Normalize(version);

// These string comparisons are case-(in)sensitive depending on SQLServer collation.
// Case-insensitive collation is recommended, e.g. SQL_Latin1_General_CP1_CI_AS.
Expand Down
10 changes: 9 additions & 1 deletion src/NuGetGallery/ViewModels/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
using System;
using System.Linq;
using System.Collections.Generic;
using NuGet.Versioning;

namespace NuGetGallery
{
public class PackageViewModel : IPackageVersionModel
{
private readonly Package _package;
private string _pendingTitle;
private string _fullVersion;

public PackageViewModel(Package package)
{
_package = package;

_fullVersion = NuGetVersionFormatter.ToFullStringOrFallback(package.Version, fallback: package.Version);

Version = String.IsNullOrEmpty(package.NormalizedVersion) ?
NuGetVersionNormalizer.Normalize(package.Version) :
NuGetVersionFormatter.Normalize(package.Version) :
package.NormalizedVersion;

Description = package.Description;
ReleaseNotes = package.ReleaseNotes;
IconUrl = package.IconUrl;
Expand All @@ -40,6 +46,7 @@ public PackageViewModel(Package package)
LicenseNames = licenseNames.Split(',').Select(l => l.Trim());
}
}

public string Description { get; set; }
public string ReleaseNotes { get; set; }
public string IconUrl { get; set; }
Expand Down Expand Up @@ -69,6 +76,7 @@ public string Id
}

public string Version { get; set; }
public string FullVersion => _fullVersion;

public string Title
{
Expand Down
6 changes: 3 additions & 3 deletions src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@

<div class="package-page-heading">
<h1 title="@Model.Title">@Model.Title.Abbreviate(40)</h1>
<h2>@Model.Version</h2>
<h2>@Model.FullVersion</h2>
</div>
@foreach (var line in Model.Description.ToStringSafe().Split('\n'))
{
Expand Down Expand Up @@ -354,7 +354,7 @@
<td class="version" title="@cellTitle">
@if (!packageVersion.IsCurrent(Model))
{
<a title="@packageVersion.Title @packageVersion.Version" href="@Url.Package(packageVersion) ">
<a title="@packageVersion.Title @packageVersion.FullVersion" href="@Url.Package(packageVersion) ">
@packageVersion.Title.Abbreviate(20)
@packageVersion.Version
@if (packageVersion.LatestStableVersion)
Expand All @@ -365,7 +365,7 @@
}
else
{
<a href="@Url.Package(packageVersion)" title="@packageVersion.Title @packageVersion.Version (this version)">
<a href="@Url.Package(packageVersion)" title="@packageVersion.Title @packageVersion.FullVersion (this version)">
@packageVersion.Title.Abbreviate(20) @packageVersion.Version (this version)
</a>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ static string BuildFileName(
return string.Format(
Constants.PackageFileSavePathTemplate,
id.ToLowerInvariant(),
NuGetVersionNormalizer.Normalize(version).ToLowerInvariant(), // No matter what ends up getting passed in, the version should be normalized
NuGetVersionFormatter.Normalize(version).ToLowerInvariant(), // No matter what ends up getting passed in, the version should be normalized
Constants.NuGetPackageFileExtension);
}

Expand Down

0 comments on commit 8354e23

Please sign in to comment.