Skip to content

Commit 4508849

Browse files
Persist Show Documentation in UserPreference
1 parent 2038a7b commit 4508849

6 files changed

Lines changed: 38 additions & 115 deletions

File tree

src/dotnet/APIView/APIViewWeb/Client/src/pages/review.ts

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ $(() => {
1111
const TOGGLE_DOCUMENTATION = ".line-toggle-documentation-button";
1212
const SEL_HIDDEN_CLASS = ".hidden-api-toggleable";
1313
const SHOW_HIDDEN_CHECKBOX = "#show-hidden-api-checkbox";
14-
const SHOW_HIDDEN_HREF = ".show-hidden-api";
1514

1615
rvM.hideCheckboxesIfNotApplicable();
1716

@@ -73,34 +72,13 @@ $(() => {
7372
--------------------------------------------------------------------------------------------------------------------------------------------------------*/
7473
$(SHOW_DOC_CHECKBOX).on("click", e => {
7574
$(SHOW_DOC_HREF)[0].click();
76-
/*if((e.target as HTMLInputElement).checked) {
77-
// show all documentation
78-
$(".code-line-documentation").removeClass('hidden-row');
79-
$(TOGGLE_DOCUMENTATION).children('i').removeClass("fa-square-plus");
80-
$(TOGGLE_DOCUMENTATION).children('i').addClass("fa-square-minus");
81-
$(TOGGLE_DOCUMENTATION).children('svg').removeClass("invisible");
82-
} else {
83-
// hide all documentation
84-
$(".code-line-documentation").addClass("hidden-row");
85-
$(TOGGLE_DOCUMENTATION).children('i').removeClass("fa-square-minus");
86-
$(TOGGLE_DOCUMENTATION).children('i').addClass("fa-square-plus");
87-
$(TOGGLE_DOCUMENTATION).children('svg').addClass("invisible");
88-
}*/
89-
});
90-
91-
$(SHOW_DOC_HREF).on("click", e => {
92-
$(SHOW_DOC_CHECKBOX)[0].click();
9375
});
9476

9577
$(SHOW_HIDDEN_CHECKBOX).on("click", e => {
9678
hp.updatePageSettings(function() {
9779
$(SEL_HIDDEN_CLASS).toggleClass("d-none");
9880
});
9981
});
100-
101-
$(SHOW_HIDDEN_HREF).on("click", e => {
102-
$(SHOW_HIDDEN_CHECKBOX)[0].click();
103-
});
10482

10583
$(SHOW_DIFFONLY_CHECKBOX).on("click", e => {
10684
$(SHOW_DIFFONLY_HREF)[0].click();

src/dotnet/APIView/APIViewWeb/Filters/TelemetryIpAddressFilter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
using Microsoft.ApplicationInsights.Channel;
1+
using Microsoft.ApplicationInsights.Channel;
22
using Microsoft.ApplicationInsights.Extensibility;
3-
using Microsoft.ApplicationInsights.DataContracts;
43

54
namespace APIViewWeb.Filters
65
{

src/dotnet/APIView/APIViewWeb/Models/UserPreferenceModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class UserPreferenceModel
1616
internal bool? _hideLineNumbers;
1717
internal bool? _hideLeftNavigation;
1818
internal bool? _showHiddenApis;
19+
internal bool? _showDocumentation;
1920
internal bool? _hideReviewPageOptions;
2021
internal bool? _hideIndexPageOptions;
2122
internal bool? _hideSamplesPageOptions;
@@ -81,6 +82,13 @@ public bool? ShowHiddenApis {
8182
set => _showHiddenApis = value;
8283
}
8384

85+
[Name("ShowDocumentation")]
86+
public bool? ShowDocumentation
87+
{
88+
get => _showDocumentation ?? false;
89+
set => _showDocumentation = value;
90+
}
91+
8492
[Name("HideReviewPageOptions")]
8593
public bool? HideReviewPageOptions
8694
{

src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
@{
77
Layout = "Shared/_Layout";
88
ViewData["Title"] = Model.ReviewContent.Review.PackageName;
9-
var userPreference = PageModelHelpers.GetUserPreference(Model._preferenceCache, User);
10-
TempData["UserPreference"] = userPreference;
9+
TempData["UserPreference"] = Model.UserPreference;
1110
TempData["LanguageCssSafeName"] = PageModelHelpers.GetLanguageCssSafeName(Model.ReviewContent.Review.Language);
1211
TempData["Comments"] = Model.Comments;
1312
ViewBag.HasSections = Model.ReviewContent.PageHasLoadableSections;
@@ -17,7 +16,7 @@
1716
var leftOffCanvasClass = " show-left-offcanvas";
1817
var mainContainerLeftClass = " move-main-content-container-left";
1918
var mainContainerRightClass = " move-main-content-container-right";
20-
if (userPreference.HideReviewPageOptions.HasValue && userPreference.HideReviewPageOptions == true)
19+
if (Model.UserPreference.HideReviewPageOptions.HasValue && Model.UserPreference.HideReviewPageOptions == true)
2120
{
2221
rightOffCanvasClass = String.Empty;
2322
mainContainerRightClass = String.Empty;
@@ -368,7 +367,7 @@
368367
<ul class="list-group collapse mb-3@(pageSettingsCollapseState)" id="pageSettingsCollapse">
369368
<li class="list-group-item">
370369
<div class="form-check form-switch">
371-
@if (userPreference.ShowComments == true)
370+
@if (Model.UserPreference.ShowComments == true)
372371
{
373372
<input class="form-check-input" type="checkbox" role="switch" id="show-comments-checkbox" checked>
374373
}
@@ -381,7 +380,7 @@
381380
</li>
382381
<li class="list-group-item">
383382
<div class="form-check form-switch">
384-
@if (userPreference.ShowSystemComments == true)
383+
@if (Model.UserPreference.ShowSystemComments == true)
385384
{
386385
<input class="form-check-input" type="checkbox" role="switch" id="show-system-comments-checkbox" checked>
387386
}
@@ -394,22 +393,22 @@
394393
</li>
395394
<li class="list-group-item" id="show-documentation-component">
396395
<div class="form-check form-switch">
397-
@if (Model.ShowDocumentation)
396+
@if (Model.ShowDocumentation ?? false)
398397
{
399-
<input class="form-check-input show-documentation-checkbox" checked type="checkbox" role="switch" asp-for="@Model.ShowDocumentation" id="showDocumentationSwitch">
398+
<input class="form-check-input show-documentation-checkbox" checked type="checkbox" role="switch" id="showDocumentationSwitch">
400399
}
401400
else
402401
{
403-
<input class="form-check-input show-documentation-checkbox" type="checkbox" role="switch" asp-for="@Model.ShowDocumentation" id="showDocumentationSwitch">
402+
<input class="form-check-input show-documentation-checkbox" type="checkbox" role="switch" id="showDocumentationSwitch">
404403
}
405-
<a class="show-documentation-switch" asp-all-route-data=@Model.GetRoutingData(diffRevisionId: Model.DiffRevisionId, showDocumentation: !Model.ShowDocumentation, showDiffOnly: Model.ShowDiffOnly, revisionId: Model.ReviewContent.ActiveAPIRevision.Id)>
404+
<a class="show-documentation-switch" asp-all-route-data=@Model.GetRoutingData(diffRevisionId: Model.DiffRevisionId, showDocumentation: !(Model.ShowDocumentation ?? false), showDiffOnly: Model.ShowDiffOnly, revisionId: Model.ReviewContent.ActiveAPIRevision.Id)>
406405
<label class="form-check-label" for="showDocumentationSwitch">Show Documentation</label>
407406
</a>
408407
</div>
409408
</li>
410409
<li class="list-group-item" id="show-hidden-api-component">
411410
<div class="form-check form-switch">
412-
@if (userPreference.ShowHiddenApis == true)
411+
@if (Model.UserPreference.ShowHiddenApis == true)
413412
{
414413
<input class="form-check-input" type="checkbox" role="switch" id="show-hidden-api-checkbox" checked>
415414
}
@@ -422,7 +421,7 @@
422421
</li>
423422
<li class="list-group-item">
424423
<div class="form-check form-switch">
425-
@if (userPreference.HideLineNumbers == true)
424+
@if (Model.UserPreference.HideLineNumbers == true)
426425
{
427426
<input class="form-check-input" type="checkbox" role="switch" id="hide-line-numbers">
428427
}
@@ -435,7 +434,7 @@
435434
</li>
436435
<li class="list-group-item">
437436
<div class="form-check form-switch">
438-
@if (userPreference.HideLeftNavigation == true)
437+
@if (Model.UserPreference.HideLeftNavigation == true)
439438
{
440439
<input class="form-check-input" type="checkbox" role="switch" id="hide-left-navigation">
441440
}
@@ -470,7 +469,7 @@
470469

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

@@ -479,7 +478,7 @@
479478
@{
480479
var reviewLeftDisplay = String.Empty;
481480
var reviewRightSize = "10";
482-
if (userPreference.HideLeftNavigation == true)
481+
if (Model.UserPreference.HideLeftNavigation == true)
483482
{
484483
reviewLeftDisplay = "d-none";
485484
reviewRightSize = "12";

src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs

Lines changed: 16 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ public ReviewPageModel(
6565
public string DiffRevisionId { get; set; }
6666
// Flag to decide whether to include documentation
6767
[BindProperty(Name = "doc", SupportsGet = true)]
68-
public bool ShowDocumentation { get; set; }
68+
public bool? ShowDocumentation { get; set; }
6969
[BindProperty(Name = "diffOnly", SupportsGet = true)]
7070
public bool ShowDiffOnly { get; set; }
7171
[BindProperty(Name = "notificationMessage", SupportsGet = true)]
7272
public string NotificationMessage { get; set; }
73+
public UserPreferenceModel UserPreference { get; set; }
7374

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

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

170-
var userPrefernce = await _preferenceCache.GetUserPreferences(User) ?? new UserPreferenceModel();
171-
172171
TempData["CodeLineSection"] = codeLines;
173-
TempData["UserPreference"] = userPrefernce;
172+
TempData["UserPreference"] = UserPreference;
174173
return Partial("_CodeLinePartial", sectionKey);
175174
}
176175

177-
/// <summary>
178-
/// Get Revisions Partial
179-
/// </summary>
180-
/// <param name="reviewId"></param>
181-
/// <param name="apiRevisionType"></param>
182-
/// <param name="showDoc"></param>
183-
/// <param name="showDiffOnly"></param>
184-
/// <returns></returns>
185-
public async Task<PartialViewResult> OnGetAPIRevisionsPartialAsync(string reviewId, APIRevisionType apiRevisionType, bool showDoc = false, bool showDiffOnly = false)
186-
{
187-
var revisions = await _apiRevisionsManager.GetAPIRevisionsAsync(reviewId);
188-
revisions = revisions.Where(r => r.APIRevisionType == apiRevisionType).OrderByDescending(c => c.CreatedOn).ToList();
189-
(IEnumerable<APIRevisionListItemModel> revisions, APIRevisionListItemModel activeRevision, APIRevisionListItemModel diffRevision, bool forDiff, bool showDocumentation, bool showDiffOnly) revisionSelectModel = (
190-
revisions: revisions,
191-
activeRevision: default(APIRevisionListItemModel),
192-
diffRevision: default(APIRevisionListItemModel),
193-
forDiff: false,
194-
showDocumentation: showDoc,
195-
showDiffOnly: showDiffOnly
196-
);
197-
return Partial("_RevisionSelectPickerPartial", revisionSelectModel);
198-
}
199-
200-
/// <summary>
201-
/// Get Diff Revisions Partial
202-
/// </summary>
203-
/// <param name="reviewId"></param>
204-
/// <param name="apiRevisionId"></param>
205-
/// <param name="apiRevisionType"></param>
206-
/// <param name="showDoc"></param>
207-
/// <param name="showDiffOnly"></param>
208-
/// <returns></returns>
209-
public async Task<PartialViewResult> OnGetAPIDiffRevisionsPartialAsync(string reviewId, string apiRevisionId, APIRevisionType apiRevisionType, bool showDoc = false, bool showDiffOnly = false)
210-
{
211-
var apiRevisions = await _apiRevisionsManager.GetAPIRevisionsAsync(reviewId);
212-
if (apiRevisions.IsNullOrEmpty())
213-
{
214-
var notifcation = new NotificationModel() { Message = $"This review has no valid apiRevisons", Level = NotificatonLevel.Warning };
215-
await _signalRHubContext.Clients.Group(User.GetGitHubLogin()).SendAsync("RecieveNotification", notifcation);
216-
}
217-
218-
APIRevisionListItemModel activeRevision = default(APIRevisionListItemModel);
219-
220-
if (!Guid.TryParse(apiRevisionId, out _))
221-
{
222-
activeRevision = await _apiRevisionsManager.GetLatestAPIRevisionsAsync(reviewId, apiRevisions);
223-
}
224-
else
225-
{
226-
activeRevision = apiRevisions.FirstOrDefault(r => r.Id == apiRevisionId);
227-
}
228-
229-
var revisionsForDiff = apiRevisions.Where(r => r.APIRevisionType == apiRevisionType && r.Id != activeRevision.Id).OrderByDescending(c => c.CreatedOn).ToList();
230-
231-
(IEnumerable<APIRevisionListItemModel> revisions, APIRevisionListItemModel activeRevision, APIRevisionListItemModel diffRevision, bool forDiff, bool showDocumentation, bool showDiffOnly) revisionSelectModel = (
232-
revisions: revisionsForDiff,
233-
activeRevision: activeRevision,
234-
diffRevision: default(APIRevisionListItemModel),
235-
forDiff: true,
236-
showDocumentation: showDoc,
237-
showDiffOnly: showDiffOnly
238-
);
239-
return Partial("_RevisionSelectPickerPartial", revisionSelectModel);
240-
}
241-
242176
/// <summary>
243177
/// Toggle Review State
244178
/// </summary>
@@ -374,9 +308,21 @@ public async Task<IEnumerable<PullRequestModel>> GetPRsOfAssoicatedReviews()
374308
/// <returns></returns>
375309
private async Task GetReviewPageModelPropertiesAsync(string id, string revisionId = null, string diffRevisionId = null, bool diffOnly = false)
376310
{
311+
UserPreference = await _preferenceCache.GetUserPreferences(User) ?? new UserPreferenceModel();
377312
Comments = await _commentsManager.GetReviewCommentsAsync(id);
378313
DiffRevisionId = (DiffRevisionId == null) ? diffRevisionId : DiffRevisionId;
379314
ShowDiffOnly = (ShowDiffOnly == false) ? diffOnly : ShowDiffOnly;
315+
316+
if (ShowDocumentation.HasValue)
317+
{
318+
UserPreference.ShowDocumentation = ShowDocumentation.Value;
319+
_preferenceCache.UpdateUserPreference(UserPreference, User);
320+
}
321+
else
322+
{
323+
ShowDocumentation = UserPreference.ShowDocumentation;
324+
}
325+
380326
}
381327
}
382328
}

src/dotnet/APIView/APIViewWeb/Repositories/UserPreferenceCache.cs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using AutoMapper;
7-
using Microsoft.Extensions.Configuration;
8-
using Microsoft.Azure.Cosmos;
97
using System.Threading.Tasks;
10-
using System.Text.Json;
11-
using System.Collections;
12-
using Microsoft.Azure.Cosmos.Serialization.HybridRow;
13-
using System.Linq;
14-
using Octokit;
158
using System.Threading;
169
using Microsoft.Extensions.Primitives;
1710
using System.Security.Claims;

0 commit comments

Comments
 (0)