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

Manage edit documentation #8169

Merged
merged 10 commits into from
Dec 16, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 2 additions & 1 deletion src/NuGetGallery/Controllers/PackagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,7 +1708,8 @@ public virtual async Task<ActionResult> Manage(string id, string version = null)
ReportMyPackageReasons,
Url,
await _readMeService.GetReadMeMdAsync(package),
_featureFlagService.IsManageDeprecationEnabled(currentUser, package.PackageRegistration));
_featureFlagService.IsManageDeprecationEnabled(currentUser, package.PackageRegistration),
isReadmeFileUploaded: package.HasReadMe && package.EmbeddedReadmeType != EmbeddedReadmeFileType.Absent);

if (!model.CanEdit && !model.CanManageOwners && !model.CanUnlistOrRelist)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ public ManagePackageViewModel Create(
IReadOnlyList<ReportPackageReason> reasons,
UrlHelper url,
string readMe,
bool isManageDeprecationEnabled)
bool isManageDeprecationEnabled,
bool isReadmeFileUploaded)
zhhyu marked this conversation as resolved.
Show resolved Hide resolved
{
var viewModel = new ManagePackageViewModel();
return Setup(viewModel, package, currentUser, reasons, url, readMe, isManageDeprecationEnabled);
return Setup(viewModel, package, currentUser, reasons, url, readMe, isManageDeprecationEnabled, isReadmeFileUploaded);
}

public ManagePackageViewModel Setup(
Expand All @@ -38,10 +39,11 @@ public ManagePackageViewModel Setup(
IReadOnlyList<ReportPackageReason> reasons,
UrlHelper url,
string readMe,
bool isManageDeprecationEnabled)
bool isManageDeprecationEnabled,
bool isReadmeFileUploaded)
{
_listPackageItemViewModelFactory.Setup(viewModel, package, currentUser);
return SetupInternal(viewModel, package, currentUser, reasons, url, readMe, isManageDeprecationEnabled);
return SetupInternal(viewModel, package, currentUser, reasons, url, readMe, isManageDeprecationEnabled, isReadmeFileUploaded);
}

private ManagePackageViewModel SetupInternal(
Expand All @@ -51,7 +53,8 @@ private ManagePackageViewModel SetupInternal(
IReadOnlyList<ReportPackageReason> reasons,
UrlHelper url,
string readMe,
bool isManageDeprecationEnabled)
bool isManageDeprecationEnabled,
bool isReadmeFileUploaded)
{
viewModel.IsCurrentUserAnAdmin = currentUser != null && currentUser.IsAdministrator;

Expand All @@ -72,6 +75,8 @@ private ManagePackageViewModel SetupInternal(

viewModel.IsManageDeprecationEnabled = isManageDeprecationEnabled;

viewModel.IsReadmeFileUploaded = isReadmeFileUploaded;

var versionSelectPackages = package.PackageRegistration.Packages
.Where(p => p.PackageStatusKey == PackageStatus.Available || p.PackageStatusKey == PackageStatus.Validating)
.OrderByDescending(p => new NuGetVersion(p.Version))
Expand Down Expand Up @@ -118,7 +123,7 @@ private ManagePackageViewModel SetupInternal(

// Update edit model with the readme.md data.
viewModel.ReadMe = new EditPackageVersionReadMeRequest();
if (package.HasReadMe)
if (package.HasReadMe && package.EmbeddedReadmeType == EmbeddedReadmeFileType.Absent)
{
viewModel.ReadMe.ReadMe.SourceType = ReadMeService.TypeWritten;
viewModel.ReadMe.ReadMe.SourceText = readMe;
Expand Down
1 change: 1 addition & 0 deletions src/NuGetGallery/ViewModels/ManagePackageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ManagePackageViewModel : ListPackageItemViewModel
public IReadOnlyDictionary<string, VersionListedState> VersionListedStateDictionary { get; set; }
public IReadOnlyDictionary<string, VersionReadMeState> VersionReadMeStateDictionary { get; set; }
public bool IsManageDeprecationEnabled { get; set; }
public bool IsReadmeFileUploaded { get; set; }
public IReadOnlyDictionary<string, VersionDeprecationState> VersionDeprecationStateDictionary { get; set; }

/// <remarks>
Expand Down
49 changes: 29 additions & 20 deletions src/NuGetGallery/Views/Packages/Manage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@
@<text>@Html.Partial("_ManageListing", Model)</text>,
expanded: false)

@ViewHelpers.Section(
this,
"Documentation",
"Documentation",
@<text>@Html.Partial("_ManageDocumentation", Model)</text>,
expanded: false)
@* @if (!Model.IsReadmeFileUploaded)
{ *@
lyndaidaii marked this conversation as resolved.
Show resolved Hide resolved
@ViewHelpers.Section(
this,
"Documentation",
"Documentation",
@<text>@Html.Partial("_ManageDocumentation", Model)</text>,
expanded: false)
@* }*@
</div>
</div>
</section>
Expand Down Expand Up @@ -92,20 +95,22 @@

$(function () {
// Set up documentation section
var readMeModel = {
"Versions": @Html.ToJson(Model.VersionReadMeStateDictionary),
"Edit": @Html.Raw(Json.Encode(Model.ReadMe))
};

var readMeModelVersion = readMeModel.Versions['@Model.Version'];
if (readMeModelVersion) {
readMeModelVersion.readMe = @Html.Raw(Json.Encode(Model.ReadMe));
var isReadmeFileUploaded = @Html.Raw(Json.Encode(Model.IsReadmeFileUploaded));
if (!isReadmeFileUploaded) {
var readMeModel = {
"Versions": @Html.ToJson(Model.VersionReadMeStateDictionary),
"Edit": @Html.Raw(Json.Encode(Model.ReadMe))
};

var readMeModelVersion = readMeModel.Versions['@Model.Version'];
if (readMeModelVersion) {
readMeModelVersion.readMe = @Html.Raw(Json.Encode(Model.ReadMe));
}

EditReadMeManager.init(
readMeModel,
'@Url.PreviewReadMe()');
}

EditReadMeManager.init(
readMeModel,
'@Url.PreviewReadMe()');

// Set up delete section
var deleteVersionSelect = $('.page-delete-package #input-select-version');
deleteVersionSelect.change(function () {
Expand Down Expand Up @@ -140,5 +145,9 @@
@Scripts.Render("~/Scripts/gallery/page-manage-owners.min.js")
@Scripts.Render("~/Scripts/gallery/page-manage-deprecation.min.js")
@Scripts.Render("~/Scripts/gallery/page-delete-package.min.js")
@Scripts.Render("~/Scripts/gallery/page-edit-readme.min.js")

@if (!Model.IsReadmeFileUploaded)
{
@Scripts.Render("~/Scripts/gallery/page-edit-readme.min.js")
}
}
14 changes: 13 additions & 1 deletion src/NuGetGallery/Views/Packages/_EditForm.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@

<div id="import-readme-container">
</div>
@Html.Partial("_ImportReadMe")
@* @if (Model.VersionSelectList.Selected)
{*@
lyndaidaii marked this conversation as resolved.
Show resolved Hide resolved
@Html.Partial("_ImportReadMe")

@* <span> isReadmeFileUploaded is false, value is @Model.VersionSelectList.SelectedItem.Value</span>
}*@
else
{
@ViewHelpers.AlertInfo(
@<text>
<span>Embedded readme files cannot be edited. To update your readme, please upload a new package version.</span>
</text>)
}

<div id="submit-package-container">
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</div>
</div>

@Html.Partial("_EditForm")
@Html.Partial("_EditForm", Model)
</div>
Copy link
Contributor

@zhhyu zhhyu Dec 17, 2020

Choose a reason for hiding this comment

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

Do we need to pass the model here? I see that we have passed the model:

"Versions": @Html.ToJson(Model.VersionReadMeStateDictionary),


</div>