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

Persist Show Documentation in UserPreference #7820

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
22 changes: 0 additions & 22 deletions src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ $(() => {
const TOGGLE_DOCUMENTATION = ".line-toggle-documentation-button";
const SEL_HIDDEN_CLASS = ".hidden-api-toggleable";
const SHOW_HIDDEN_CHECKBOX = "#show-hidden-api-checkbox";
const SHOW_HIDDEN_HREF = ".show-hidden-api";

rvM.hideCheckboxesIfNotApplicable();

Expand Down Expand Up @@ -73,34 +72,13 @@ $(() => {
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
$(SHOW_DOC_CHECKBOX).on("click", e => {
$(SHOW_DOC_HREF)[0].click();
/*if((e.target as HTMLInputElement).checked) {
// show all documentation
$(".code-line-documentation").removeClass('hidden-row');
$(TOGGLE_DOCUMENTATION).children('i').removeClass("fa-square-plus");
$(TOGGLE_DOCUMENTATION).children('i').addClass("fa-square-minus");
$(TOGGLE_DOCUMENTATION).children('svg').removeClass("invisible");
} else {
// hide all documentation
$(".code-line-documentation").addClass("hidden-row");
$(TOGGLE_DOCUMENTATION).children('i').removeClass("fa-square-minus");
$(TOGGLE_DOCUMENTATION).children('i').addClass("fa-square-plus");
$(TOGGLE_DOCUMENTATION).children('svg').addClass("invisible");
}*/
});

$(SHOW_DOC_HREF).on("click", e => {
$(SHOW_DOC_CHECKBOX)[0].click();
});

$(SHOW_HIDDEN_CHECKBOX).on("click", e => {
hp.updatePageSettings(function() {
$(SEL_HIDDEN_CLASS).toggleClass("d-none");
});
});

$(SHOW_HIDDEN_HREF).on("click", e => {
$(SHOW_HIDDEN_CHECKBOX)[0].click();
});

$(SHOW_DIFFONLY_CHECKBOX).on("click", e => {
$(SHOW_DIFFONLY_HREF)[0].click();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Channel;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.DataContracts;

namespace APIViewWeb.Filters
{
Expand Down
8 changes: 8 additions & 0 deletions src/dotnet/APIView/APIViewWeb/Models/UserPreferenceModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class UserPreferenceModel
internal bool? _hideLineNumbers;
internal bool? _hideLeftNavigation;
internal bool? _showHiddenApis;
internal bool? _showDocumentation;
internal bool? _hideReviewPageOptions;
internal bool? _hideIndexPageOptions;
internal bool? _hideSamplesPageOptions;
Expand Down Expand Up @@ -81,6 +82,13 @@ public bool? ShowHiddenApis {
set => _showHiddenApis = value;
}

[Name("ShowDocumentation")]
public bool? ShowDocumentation
{
get => _showDocumentation ?? false;
set => _showDocumentation = value;
}

[Name("HideReviewPageOptions")]
public bool? HideReviewPageOptions
{
Expand Down
27 changes: 13 additions & 14 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
@{
Layout = "Shared/_Layout";
ViewData["Title"] = Model.ReviewContent.Review.PackageName;
var userPreference = PageModelHelpers.GetUserPreference(Model._preferenceCache, User);
TempData["UserPreference"] = userPreference;
TempData["UserPreference"] = Model.UserPreference;
TempData["LanguageCssSafeName"] = PageModelHelpers.GetLanguageCssSafeName(Model.ReviewContent.Review.Language);
TempData["Comments"] = Model.Comments;
ViewBag.HasSections = Model.ReviewContent.PageHasLoadableSections;
Expand All @@ -17,7 +16,7 @@
var leftOffCanvasClass = " show-left-offcanvas";
var mainContainerLeftClass = " move-main-content-container-left";
var mainContainerRightClass = " move-main-content-container-right";
if (userPreference.HideReviewPageOptions.HasValue && userPreference.HideReviewPageOptions == true)
if (Model.UserPreference.HideReviewPageOptions.HasValue && Model.UserPreference.HideReviewPageOptions == true)
{
rightOffCanvasClass = String.Empty;
mainContainerRightClass = String.Empty;
Expand Down Expand Up @@ -368,7 +367,7 @@
<ul class="list-group collapse mb-3@(pageSettingsCollapseState)" id="pageSettingsCollapse">
<li class="list-group-item">
<div class="form-check form-switch">
@if (userPreference.ShowComments == true)
@if (Model.UserPreference.ShowComments == true)
{
<input class="form-check-input" type="checkbox" role="switch" id="show-comments-checkbox" checked>
}
Expand All @@ -381,7 +380,7 @@
</li>
<li class="list-group-item">
<div class="form-check form-switch">
@if (userPreference.ShowSystemComments == true)
@if (Model.UserPreference.ShowSystemComments == true)
{
<input class="form-check-input" type="checkbox" role="switch" id="show-system-comments-checkbox" checked>
}
Expand All @@ -394,22 +393,22 @@
</li>
<li class="list-group-item" id="show-documentation-component">
<div class="form-check form-switch">
@if (Model.ShowDocumentation)
@if (Model.ShowDocumentation ?? false)
{
<input class="form-check-input show-documentation-checkbox" checked type="checkbox" role="switch" asp-for="@Model.ShowDocumentation" id="showDocumentationSwitch">
<input class="form-check-input show-documentation-checkbox" checked type="checkbox" role="switch" id="showDocumentationSwitch">
}
else
{
<input class="form-check-input show-documentation-checkbox" type="checkbox" role="switch" asp-for="@Model.ShowDocumentation" id="showDocumentationSwitch">
<input class="form-check-input show-documentation-checkbox" type="checkbox" role="switch" id="showDocumentationSwitch">
}
<a class="show-documentation-switch" [email protected](diffRevisionId: Model.DiffRevisionId, showDocumentation: !Model.ShowDocumentation, showDiffOnly: Model.ShowDiffOnly, revisionId: Model.ReviewContent.ActiveAPIRevision.Id)>
<a class="show-documentation-switch" [email protected](diffRevisionId: Model.DiffRevisionId, showDocumentation: !(Model.ShowDocumentation ?? false), showDiffOnly: Model.ShowDiffOnly, revisionId: Model.ReviewContent.ActiveAPIRevision.Id)>
<label class="form-check-label" for="showDocumentationSwitch">Show Documentation</label>
</a>
</div>
</li>
<li class="list-group-item" id="show-hidden-api-component">
<div class="form-check form-switch">
@if (userPreference.ShowHiddenApis == true)
@if (Model.UserPreference.ShowHiddenApis == true)
{
<input class="form-check-input" type="checkbox" role="switch" id="show-hidden-api-checkbox" checked>
}
Expand All @@ -422,7 +421,7 @@
</li>
<li class="list-group-item">
<div class="form-check form-switch">
@if (userPreference.HideLineNumbers == true)
@if (Model.UserPreference.HideLineNumbers == true)
{
<input class="form-check-input" type="checkbox" role="switch" id="hide-line-numbers">
}
Expand All @@ -435,7 +434,7 @@
</li>
<li class="list-group-item">
<div class="form-check form-switch">
@if (userPreference.HideLeftNavigation == true)
@if (Model.UserPreference.HideLeftNavigation == true)
{
<input class="form-check-input" type="checkbox" role="switch" id="hide-left-navigation">
}
Expand Down Expand Up @@ -470,7 +469,7 @@

<div class="container-fluid mx-0 px-0 sub-header-content">
<div class="row px-3 py-2 border-bottom" id="review-info-bar">
<partial name="Shared/_ReviewBadge" model="(Model.ReviewContent.Review, Model.ReviewContent.ActiveAPIRevision, Model.ReviewContent.DiffAPIRevision, userPreference)" />
<partial name="Shared/_ReviewBadge" model="(Model.ReviewContent.Review, Model.ReviewContent.ActiveAPIRevision, Model.ReviewContent.DiffAPIRevision, Model.UserPreference)" />
</div>
</div>

Expand All @@ -479,7 +478,7 @@
@{
var reviewLeftDisplay = String.Empty;
var reviewRightSize = "10";
if (userPreference.HideLeftNavigation == true)
if (Model.UserPreference.HideLeftNavigation == true)
{
reviewLeftDisplay = "d-none";
reviewRightSize = "12";
Expand Down
86 changes: 16 additions & 70 deletions src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ public ReviewPageModel(
public string DiffRevisionId { get; set; }
// Flag to decide whether to include documentation
[BindProperty(Name = "doc", SupportsGet = true)]
public bool ShowDocumentation { get; set; }
public bool? ShowDocumentation { get; set; }
[BindProperty(Name = "diffOnly", SupportsGet = true)]
public bool ShowDiffOnly { get; set; }
[BindProperty(Name = "notificationMessage", SupportsGet = true)]
public string NotificationMessage { get; set; }
public UserPreferenceModel UserPreference { get; set; }

/// <summary>
/// Handler for loading page
Expand All @@ -87,7 +88,7 @@ public async Task<IActionResult> OnGetAsync(string id, string revisionId = null)
reviewManager: _reviewManager, preferenceCache: _preferenceCache, userProfileRepository: _userProfileRepository,
reviewRevisionsManager: _apiRevisionsManager, commentManager: _commentsManager, codeFileRepository: _codeFileRepository,
signalRHubContext: _signalRHubContext, user: User, reviewId: id, revisionId: revisionId, diffRevisionId: DiffRevisionId,
showDocumentation: ShowDocumentation, showDiffOnly: ShowDiffOnly, diffContextSize: REVIEW_DIFF_CONTEXT_SIZE,
showDocumentation: (ShowDocumentation ?? false), showDiffOnly: ShowDiffOnly, diffContextSize: REVIEW_DIFF_CONTEXT_SIZE,
diffContextSeperator: DIFF_CONTEXT_SEPERATOR);

if (ReviewContent.Directive == ReviewContentModelDirective.TryGetlegacyReview)
Expand Down Expand Up @@ -167,78 +168,11 @@ public async Task<PartialViewResult> OnGetCodeLineSectionAsync(
sectionKeyA: sectionKeyA, sectionKeyB: sectionKeyB
);

var userPrefernce = await _preferenceCache.GetUserPreferences(User) ?? new UserPreferenceModel();

TempData["CodeLineSection"] = codeLines;
TempData["UserPreference"] = userPrefernce;
TempData["UserPreference"] = UserPreference;
return Partial("_CodeLinePartial", sectionKey);
}

/// <summary>
/// Get Revisions Partial
/// </summary>
/// <param name="reviewId"></param>
/// <param name="apiRevisionType"></param>
/// <param name="showDoc"></param>
/// <param name="showDiffOnly"></param>
/// <returns></returns>
public async Task<PartialViewResult> OnGetAPIRevisionsPartialAsync(string reviewId, APIRevisionType apiRevisionType, bool showDoc = false, bool showDiffOnly = false)
{
var revisions = await _apiRevisionsManager.GetAPIRevisionsAsync(reviewId);
revisions = revisions.Where(r => r.APIRevisionType == apiRevisionType).OrderByDescending(c => c.CreatedOn).ToList();
(IEnumerable<APIRevisionListItemModel> revisions, APIRevisionListItemModel activeRevision, APIRevisionListItemModel diffRevision, bool forDiff, bool showDocumentation, bool showDiffOnly) revisionSelectModel = (
revisions: revisions,
activeRevision: default(APIRevisionListItemModel),
diffRevision: default(APIRevisionListItemModel),
forDiff: false,
showDocumentation: showDoc,
showDiffOnly: showDiffOnly
);
return Partial("_RevisionSelectPickerPartial", revisionSelectModel);
}

/// <summary>
/// Get Diff Revisions Partial
/// </summary>
/// <param name="reviewId"></param>
/// <param name="apiRevisionId"></param>
/// <param name="apiRevisionType"></param>
/// <param name="showDoc"></param>
/// <param name="showDiffOnly"></param>
/// <returns></returns>
public async Task<PartialViewResult> OnGetAPIDiffRevisionsPartialAsync(string reviewId, string apiRevisionId, APIRevisionType apiRevisionType, bool showDoc = false, bool showDiffOnly = false)
{
var apiRevisions = await _apiRevisionsManager.GetAPIRevisionsAsync(reviewId);
if (apiRevisions.IsNullOrEmpty())
{
var notifcation = new NotificationModel() { Message = $"This review has no valid apiRevisons", Level = NotificatonLevel.Warning };
await _signalRHubContext.Clients.Group(User.GetGitHubLogin()).SendAsync("RecieveNotification", notifcation);
}

APIRevisionListItemModel activeRevision = default(APIRevisionListItemModel);

if (!Guid.TryParse(apiRevisionId, out _))
{
activeRevision = await _apiRevisionsManager.GetLatestAPIRevisionsAsync(reviewId, apiRevisions);
}
else
{
activeRevision = apiRevisions.FirstOrDefault(r => r.Id == apiRevisionId);
}

var revisionsForDiff = apiRevisions.Where(r => r.APIRevisionType == apiRevisionType && r.Id != activeRevision.Id).OrderByDescending(c => c.CreatedOn).ToList();

(IEnumerable<APIRevisionListItemModel> revisions, APIRevisionListItemModel activeRevision, APIRevisionListItemModel diffRevision, bool forDiff, bool showDocumentation, bool showDiffOnly) revisionSelectModel = (
revisions: revisionsForDiff,
activeRevision: activeRevision,
diffRevision: default(APIRevisionListItemModel),
forDiff: true,
showDocumentation: showDoc,
showDiffOnly: showDiffOnly
);
return Partial("_RevisionSelectPickerPartial", revisionSelectModel);
}

/// <summary>
/// Toggle Review State
/// </summary>
Expand Down Expand Up @@ -374,9 +308,21 @@ public async Task<IEnumerable<PullRequestModel>> GetPRsOfAssoicatedReviews()
/// <returns></returns>
private async Task GetReviewPageModelPropertiesAsync(string id, string revisionId = null, string diffRevisionId = null, bool diffOnly = false)
{
UserPreference = await _preferenceCache.GetUserPreferences(User) ?? new UserPreferenceModel();
Comments = await _commentsManager.GetReviewCommentsAsync(id);
DiffRevisionId = (DiffRevisionId == null) ? diffRevisionId : DiffRevisionId;
ShowDiffOnly = (ShowDiffOnly == false) ? diffOnly : ShowDiffOnly;

if (ShowDocumentation.HasValue)
{
UserPreference.ShowDocumentation = ShowDocumentation.Value;
_preferenceCache.UpdateUserPreference(UserPreference, User);
}
else
{
ShowDocumentation = UserPreference.ShowDocumentation;
}

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@
using System;
using System.Collections.Generic;
using AutoMapper;
using Microsoft.Extensions.Configuration;
using Microsoft.Azure.Cosmos;
using System.Threading.Tasks;
using System.Text.Json;
using System.Collections;
using Microsoft.Azure.Cosmos.Serialization.HybridRow;
using System.Linq;
using Octokit;
using System.Threading;
using Microsoft.Extensions.Primitives;
using System.Security.Claims;
Expand Down