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

Alternate install command for global tools packages on the packages page #5684

Merged
merged 7 commits into from
Apr 11, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/NuGetGallery/ViewModels/PackageManagerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,22 @@ public class PackageManagerViewModel
/// A string that represents the command used to install a specific package.
/// </summary>
public string InstallPackageCommand { get; set; }

/// <summary>
/// The alert message that contains clarifications about the command/scenario
/// </summary>
public string AlertMessage { get; set; }

/// <summary>
/// The level with which the above message will be displayed.
/// </summary>
public AlertLevel AlertLevel { get; set; }
}

public enum AlertLevel
{
None,
Info,
Warning
}
}
2 changes: 2 additions & 0 deletions src/NuGetGallery/ViewModels/PackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public PackageViewModel(Package package)
LatestStableVersionSemVer2 = package.IsLatestStableSemVer2;
LastUpdated = package.Published;
Listed = package.Listed;
IsDotnetToolPackageType = package.PackageTypes.Any(e => e.Name.Equals("DotnetTool", StringComparison.OrdinalIgnoreCase));
_packageStatus = package.PackageStatusKey;
DownloadCount = package.DownloadCount;
Prerelease = package.IsPrerelease;
Expand Down Expand Up @@ -71,6 +72,7 @@ public PackageViewModel(Package package)
public bool Prerelease { get; set; }
public int DownloadCount { get; set; }
public bool Listed { get; set; }
public bool IsDotnetToolPackageType { get; set; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why set?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No particular reason.

I was following the conventions, because all of the above fields had setters as well, despite only being initialized in the constructor.

I can remove it though

public bool FailedValidation => _packageStatus == PackageStatus.FailedValidation;
public bool Available => _packageStatus == PackageStatus.Available;
public bool Validating => _packageStatus == PackageStatus.Validating;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,12 @@ public class ThirdPartyPackageManagerViewModel : PackageManagerViewModel
/// for support.
/// </summary>
public string ContactUrl { get; set; }

public ThirdPartyPackageManagerViewModel(string contactUrl)
{
ContactUrl = contactUrl;
AlertLevel = AlertLevel.Warning;
AlertMessage = string.Format("The NuGet Team does not provide support for this client. Please contact its <a href=\"{0}\">maintainers</a> for support.", contactUrl);
}
}
}
88 changes: 59 additions & 29 deletions src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,54 @@

var absolutePackageUrl = Url.Absolute(Url.Package(Model.Id));

var packageManagers = new PackageManagerViewModel[]
PackageManagerViewModel[] packageManagers;

if (Model.IsDotnetToolPackageType)
{
new PackageManagerViewModel()
packageManagers = new PackageManagerViewModel[]
{
Id = "package-manager",
Name = "Package Manager",
CommandPrefix = "PM> ",
InstallPackageCommand = string.Format("Install-Package {0} -Version {1}", Model.Id, Model.Version)
},

new PackageManagerViewModel()
new PackageManagerViewModel()
{
Id = "dotnet-cli",
Name = ".NET CLI",
CommandPrefix = "> ",
InstallPackageCommand = string.Format("dotnet tool install --global {0} --version {1}", Model.Id, Model.Version),
AlertLevel = AlertLevel.Info,
AlertMessage = string.Format("This package contains a <a href=\"{0}\">.NET Core Global Tool</a> you can call from the shell/command line.", "https://aka.ms/global-tools"),
}
};
}
else
{
packageManagers = new PackageManagerViewModel[]
{
Id = "dotnet-cli",
Name = ".NET CLI",
CommandPrefix = "> ",
InstallPackageCommand = string.Format("dotnet add package {0} --version {1}", Model.Id, Model.Version)
},
new PackageManagerViewModel()
{
Id = "package-manager",
Name = "Package Manager",
CommandPrefix = "PM> ",
InstallPackageCommand = string.Format("Install-Package {0} -Version {1}", Model.Id, Model.Version)
},

new ThirdPartyPackageManagerViewModel()
{
Id = "paket-cli",
Name = "Paket CLI",
CommandPrefix = "> ",
InstallPackageCommand = string.Format("paket add {0} --version {1}", Model.Id, Model.Version),
ContactUrl = "https://fsprojects.github.io/Paket/contact.html"
},
};
new PackageManagerViewModel()
{
Id = "dotnet-cli",
Name = ".NET CLI",
CommandPrefix = "> ",
InstallPackageCommand = string.Format("dotnet add package {0} --version {1}", Model.Id, Model.Version)
},

new ThirdPartyPackageManagerViewModel("https://fsprojects.github.io/Paket/contact.html")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why even keep ThirdPartyPackageManagerViewModel around at this point? The only property it adds is ContactUrl, but that property isn't used anymore (the contact url is just part of the message).

Copy link
Member Author

@nkolev92 nkolev92 Apr 2, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@khellang

The third party manager message is consistent, having it in the model will remove the need for duplication of that string.
It's a fraction cleaner to have it this way :)

{
Id = "paket-cli",
Name = "Paket CLI",
CommandPrefix = "> ",
InstallPackageCommand = string.Format("paket add {0} --version {1}", Model.Id, Model.Version),
}
};
}
}

@section SocialMeta {
@if (!String.IsNullOrWhiteSpace(ViewBag.FacebookAppID))
{
Expand Down Expand Up @@ -96,13 +116,23 @@
</button>
</div>
</div>
@if (thirdPartyPackageManager != null)

@switch (packageManager.AlertLevel)
{
@ViewHelpers.AlertWarning(
@<text>
The NuGet Team does not provide support for this client.
Please contact its <a href="@thirdPartyPackageManager.ContactUrl">maintainers</a> for support.
</text>)
case AlertLevel.Info:
@ViewHelpers.AlertInfo(
@<text>
@Html.Raw(packageManager.AlertMessage)
</text>);
break;
case AlertLevel.Warning:
@ViewHelpers.AlertWarning(
@<text>
@Html.Raw(packageManager.AlertMessage)
</text>);
break;
default:
break;
}
</div>
}
Expand Down