From 4b9f38128d4b279f5f9570a991a576193645c417 Mon Sep 17 00:00:00 2001 From: Vailorium Date: Wed, 10 Aug 2022 16:51:26 +1200 Subject: [PATCH 1/8] proof-of-concept implementation for show/hide documentation --- .../APIView/APIView/CodeFileRenderer.cs | 5 ++- .../APIView/APIViewWeb/Client/src/review.ts | 20 ++++++++++ .../APIViewWeb/Models/CodeLineModel.cs | 5 ++- .../Pages/Assemblies/Review.cshtml.cs | 39 +++++++++++++++---- .../Pages/Assemblies/_CodeLine.cshtml | 9 +++++ 5 files changed, 67 insertions(+), 11 deletions(-) diff --git a/src/dotnet/APIView/APIView/CodeFileRenderer.cs b/src/dotnet/APIView/APIView/CodeFileRenderer.cs index fa286da99b0..f765d01be15 100644 --- a/src/dotnet/APIView/APIView/CodeFileRenderer.cs +++ b/src/dotnet/APIView/APIView/CodeFileRenderer.cs @@ -39,8 +39,9 @@ private void Render(List list, IEnumerable node, bool s if (enableSkipDiff && isSkipDiffRange && token.Kind != CodeFileTokenKind.SkipDiffRangeEnd) continue; - if (!showDocumentation && isDocumentationRange && token.Kind != CodeFileTokenKind.DocumentRangeEnd) - continue; + // if (!showDocumentation && isDocumentationRange && token.Kind != CodeFileTokenKind.DocumentRangeEnd) + if (isDocumentationRange && token.Kind != CodeFileTokenKind.DocumentRangeEnd) + continue; switch(token.Kind) { diff --git a/src/dotnet/APIView/APIViewWeb/Client/src/review.ts b/src/dotnet/APIView/APIViewWeb/Client/src/review.ts index db73075ac47..f194a3bc376 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/src/review.ts +++ b/src/dotnet/APIView/APIViewWeb/Client/src/review.ts @@ -10,6 +10,8 @@ $(() => { const HIDE_LINE_NUMBERS = "#hide-line-numbers"; const HIDE_LEFT_NAVIGATION = "#hide-left-navigation"; + const TOGGLE_DOCUMENTATION = ".toggle-documentation"; + hideCheckboxIfNoDocs(); /* FUNCTIONS @@ -83,6 +85,24 @@ $(() => { $(SHOW_DIFFONLY_HREF)[0].click(); }); + $(TOGGLE_DOCUMENTATION).on("click", function(e){ + // remove data-documented-by previous actually hide + const documentedBy = $(this).data('documented-by'); + const row = $(this).parent().parent().parent().parent().parent().parent(); + const table = row.parent(); + for(var i = 1; i <= documentedBy; i++) { + $(table.children()[row.index() - i]).toggle(); + } + + if($(this).text() == "-") { + this.innerText = "+"; + } else { + this.innerText = "-"; + } + // console.log($(this).parent().parent().parent().parent().parent().parent()); + // console.log($(this).parent().parent().parent().parent().parent().parent().index()); + }); + $(HIDE_LINE_NUMBERS).on("click", e => { updatePageSettings(function(){ $(".line-number").toggleClass("d-none"); diff --git a/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs b/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs index cb1db3cb471..6f699650118 100644 --- a/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs +++ b/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs @@ -9,13 +9,14 @@ namespace APIViewWeb.Models { public readonly struct CodeLineModel { - public CodeLineModel(DiffLineKind kind, CodeLine codeLine, CommentThreadModel commentThread, CodeDiagnostic[] diagnostics, int lineNumber) + public CodeLineModel(DiffLineKind kind, CodeLine codeLine, CommentThreadModel commentThread, CodeDiagnostic[] diagnostics, int lineNumber, int[] documentedBy) { CodeLine = codeLine; CommentThread = commentThread; Diagnostics = diagnostics; Kind = kind; LineNumber = lineNumber; + DocumentedBy = documentedBy; } public CodeLine CodeLine { get; } @@ -23,5 +24,7 @@ public CodeLineModel(DiffLineKind kind, CodeLine codeLine, CommentThreadModel co public CommentThreadModel CommentThread { get; } public DiffLineKind Kind { get; } public int LineNumber { get; } + + public int[] DocumentedBy { get; } } } diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs index 62a1372c28c..151b570d834 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs @@ -186,20 +186,43 @@ private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, InlineDiffLine diffLine.Kind != DiffLineKind.Removed ? diagnostics.Where(d => d.TargetId == diffLine.Line.ElementId).ToArray() : Array.Empty(), - ++index + ++index, + new int[] { } // temp! )).ToArray(); } private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, CodeLine[] lines, ReviewCommentsModel comments) { + List documentedBy = new List(); return lines.Select( - (line, index) => new CodeLineModel( - DiffLineKind.Unchanged, - line, - comments.TryGetThreadForLine(line.ElementId, out var thread) ? thread : null, - diagnostics.Where(d => d.TargetId == line.ElementId).ToArray(), - ++index - )).ToArray(); + (line, index) => + { + index++; + if (line.DisplayString.Contains("code-comment")) + { + documentedBy.Add(index); + return new CodeLineModel( + DiffLineKind.Unchanged, + line, + comments.TryGetThreadForLine(line.ElementId, out var thread) ? thread : null, + diagnostics.Where(d => d.TargetId == line.ElementId).ToArray(), + index, + new int[] {} + ); + } else + { + CodeLineModel c = new CodeLineModel( + DiffLineKind.Unchanged, + line, + comments.TryGetThreadForLine(line.ElementId, out var thread) ? thread : null, + diagnostics.Where(d => d.TargetId == line.ElementId).ToArray(), + index, + documentedBy.ToArray() + ); + documentedBy = new List(); + return c; + } + }).ToArray(); } private int ComputeActiveConversations(CodeLine[] lines, ReviewCommentsModel comments) diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml index 2c994cc9446..4a915ed55ec 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml @@ -31,6 +31,14 @@ + + @if(Model.DocumentedBy.Length > 0) + { + + } else + { + + } @if(userPreference.HideLineNumbers == true) { @@ -67,6 +75,7 @@ indent += ""; } } + @if (Model.Kind == DiffLineKind.Removed) { @Html.Raw(indent) - @Html.Raw(Model.CodeLine.DisplayString) From 3248e8caf3d51ed03f4b2667d0ffe372c07dd6ec Mon Sep 17 00:00:00 2001 From: Vailorium Date: Mon, 15 Aug 2022 18:07:13 +1200 Subject: [PATCH 2/8] added isComment attribute to codeline, show documentation checkbox now toggles whether comment sections are opened by default --- .../APIView/APIView/CodeFileRenderer.cs | 15 +++++++---- src/dotnet/APIView/APIView/CodeLine.cs | 4 ++- .../APIView/APIViewWeb/Client/css/site.scss | 24 ++++++++++++----- .../APIView/APIViewWeb/Client/src/review.ts | 16 +++++------ .../APIViewWeb/Models/CodeLineModel.cs | 6 ++--- .../APIViewWeb/Models/RenderedCodeFile.cs | 21 ++++----------- .../APIViewWeb/Pages/Assemblies/Review.cshtml | 1 + .../Pages/Assemblies/Review.cshtml.cs | 21 ++++++++------- .../Pages/Assemblies/_CodeLine.cshtml | 27 ++++++++++++++----- .../Repositories/PullRequestManager.cs | 4 +-- .../APIViewWeb/Repositories/ReviewManager.cs | 4 +-- .../APIViewWeb/wwwroot/icons/comment.svg | 3 +++ 12 files changed, 84 insertions(+), 62 deletions(-) create mode 100644 src/dotnet/APIView/APIViewWeb/wwwroot/icons/comment.svg diff --git a/src/dotnet/APIView/APIView/CodeFileRenderer.cs b/src/dotnet/APIView/APIView/CodeFileRenderer.cs index f765d01be15..5899f8d28b5 100644 --- a/src/dotnet/APIView/APIView/CodeFileRenderer.cs +++ b/src/dotnet/APIView/APIView/CodeFileRenderer.cs @@ -14,14 +14,14 @@ public class CodeFileRenderer { public static CodeFileRenderer Instance = new CodeFileRenderer(); - public CodeLine[] Render(CodeFile file, bool showDocumentation = false, bool enableSkipDiff = false) + public CodeLine[] Render(CodeFile file, bool enableSkipDiff = false) { var list = new List(); - Render(list, file.Tokens, showDocumentation, enableSkipDiff); + Render(list, file.Tokens, enableSkipDiff); return list.ToArray(); } - private void Render(List list, IEnumerable node, bool showDocumentation, bool enableSkipDiff) + private void Render(List list, IEnumerable node, bool enableSkipDiff) { var stringBuilder = new StringBuilder(); string currentId = null; @@ -32,6 +32,7 @@ private void Render(List list, IEnumerable node, bool s string lastHeadingEncountered = null; HashSet lineIds = new HashSet(); // Used to ensure there are no duplicate IDs int indentSize = 0; + bool isComment = false; foreach (var token in node) { @@ -39,7 +40,6 @@ private void Render(List list, IEnumerable node, bool s if (enableSkipDiff && isSkipDiffRange && token.Kind != CodeFileTokenKind.SkipDiffRangeEnd) continue; - // if (!showDocumentation && isDocumentationRange && token.Kind != CodeFileTokenKind.DocumentRangeEnd) if (isDocumentationRange && token.Kind != CodeFileTokenKind.DocumentRangeEnd) continue; @@ -69,7 +69,8 @@ private void Render(List list, IEnumerable node, bool s lineClass = lineClass.Trim(); } - list.Add(new CodeLine(stringBuilder.ToString(), currentId, lineClass, indentSize)); + list.Add(new CodeLine(stringBuilder.ToString(), currentId, lineClass, indentSize, isComment)); + isComment = false; currentId = null; stringBuilder.Clear(); break; @@ -124,6 +125,10 @@ private void Render(List list, IEnumerable node, bool s { currentId = token.DefinitionId; } + if(token.Kind == CodeFileTokenKind.Comment) + { + isComment = true; + } RenderToken(token, stringBuilder, isDeprecatedToken); break; } diff --git a/src/dotnet/APIView/APIView/CodeLine.cs b/src/dotnet/APIView/APIView/CodeLine.cs index 9812dd179e7..b4eaec98f60 100644 --- a/src/dotnet/APIView/APIView/CodeLine.cs +++ b/src/dotnet/APIView/APIView/CodeLine.cs @@ -9,13 +9,15 @@ namespace ApiView public string ElementId { get; } public string LineClass { get; } public int IndentSize { get; } + public bool IsDocumentation { get; } - public CodeLine(string html, string id, string lineClass, int indentSize = 0) + public CodeLine(string html, string id, string lineClass, int indentSize = 0, bool isDocumentation = false) { this.DisplayString = html; this.ElementId = id; this.LineClass = lineClass; this.IndentSize = indentSize; + this.IsDocumentation = isDocumentation; } public override string ToString() diff --git a/src/dotnet/APIView/APIViewWeb/Client/css/site.scss b/src/dotnet/APIView/APIViewWeb/Client/css/site.scss index 4e1af355d03..88847a5ab9b 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/css/site.scss +++ b/src/dotnet/APIView/APIViewWeb/Client/css/site.scss @@ -530,13 +530,9 @@ code { display: inline-block; width: 21px; height: 21px; - line-height: 21px; - color: #fff !important; - text-align: center; - text-indent: 0; cursor: pointer; - background-color: #0366d6; - background-image: linear-gradient(#0372ef, #0366d6); + background: #0366d6 url(/icons/comment.svg) no-repeat center center; + background-size: 90%; border-radius: 3px; box-shadow: 0 1px 4px rgba(27, 31, 35, .15); opacity: 0; @@ -553,6 +549,22 @@ code { left: 0px; } +.line-toggle-documentation-button { + display: inline-block; + width: 21px; + height: 21px; + line-height: 21px; + color: #fff !important; + text-align: center; + text-indent: 0; + cursor: pointer; + background-color: #0366d6; + background-image: linear-gradient(#0372ef, #0366d6); + border-radius: 3px; + box-shadow: 0 1px 4px rgba(27, 31, 35, .15); + user-select: none; +} + .line-details-button-cell { width: 22px; height: 22px; diff --git a/src/dotnet/APIView/APIViewWeb/Client/src/review.ts b/src/dotnet/APIView/APIViewWeb/Client/src/review.ts index f194a3bc376..7eb61243e77 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/src/review.ts +++ b/src/dotnet/APIView/APIViewWeb/Client/src/review.ts @@ -9,8 +9,7 @@ $(() => { const SHOW_DIFFONLY_HREF = ".show-diffonly"; const HIDE_LINE_NUMBERS = "#hide-line-numbers"; const HIDE_LEFT_NAVIGATION = "#hide-left-navigation"; - - const TOGGLE_DOCUMENTATION = ".toggle-documentation"; + const TOGGLE_DOCUMENTATION = ".line-toggle-documentation-button"; hideCheckboxIfNoDocs(); @@ -86,21 +85,18 @@ $(() => { }); $(TOGGLE_DOCUMENTATION).on("click", function(e){ - // remove data-documented-by previous actually hide const documentedBy = $(this).data('documented-by'); - const row = $(this).parent().parent().parent().parent().parent().parent(); - const table = row.parent(); - for(var i = 1; i <= documentedBy; i++) { - $(table.children()[row.index() - i]).toggle(); + const codeLines = $(".code-window > tbody > .code-line"); + + for(var i = 0; i < documentedBy.length; i++) { + $(codeLines[documentedBy[i] - 1]).toggle(); } - if($(this).text() == "-") { + if($(this).text() === "-") { this.innerText = "+"; } else { this.innerText = "-"; } - // console.log($(this).parent().parent().parent().parent().parent().parent()); - // console.log($(this).parent().parent().parent().parent().parent().parent().index()); }); $(HIDE_LINE_NUMBERS).on("click", e => { diff --git a/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs b/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs index 6f699650118..dc5d27e5e7f 100644 --- a/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs +++ b/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs @@ -9,14 +9,14 @@ namespace APIViewWeb.Models { public readonly struct CodeLineModel { - public CodeLineModel(DiffLineKind kind, CodeLine codeLine, CommentThreadModel commentThread, CodeDiagnostic[] diagnostics, int lineNumber, int[] documentedBy) + public CodeLineModel(DiffLineKind kind, CodeLine codeLine, CommentThreadModel commentThread, CodeDiagnostic[] diagnostics, int lineNumber, int[] documentedByLines) { CodeLine = codeLine; CommentThread = commentThread; Diagnostics = diagnostics; Kind = kind; LineNumber = lineNumber; - DocumentedBy = documentedBy; + DocumentedByLines = documentedByLines; } public CodeLine CodeLine { get; } @@ -25,6 +25,6 @@ public CodeLineModel(DiffLineKind kind, CodeLine codeLine, CommentThreadModel co public DiffLineKind Kind { get; } public int LineNumber { get; } - public int[] DocumentedBy { get; } + public int[] DocumentedByLines { get; } } } diff --git a/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs b/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs index fde0f8b08f6..398bf35814e 100644 --- a/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs +++ b/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs @@ -19,14 +19,8 @@ public RenderedCodeFile(CodeFile codeFile) public CodeFile CodeFile { get; } - public CodeLine[] Render(bool showDocumentation) + public CodeLine[] Render() { - //Always render when documentation is requested to avoid cach thrashing - if (showDocumentation) - { - return CodeFileHtmlRenderer.Normal.Render(CodeFile, showDocumentation: true); - } - if (_rendered == null) { _rendered = CodeFileHtmlRenderer.Normal.Render(CodeFile); @@ -35,13 +29,8 @@ public CodeLine[] Render(bool showDocumentation) return _rendered; } - public CodeLine[] RenderReadOnly(bool showDocumentation) + public CodeLine[] RenderReadOnly() { - if (showDocumentation) - { - return CodeFileHtmlRenderer.ReadOnly.Render(CodeFile, showDocumentation: true); - } - if (_renderedReadOnly == null) { _renderedReadOnly = CodeFileHtmlRenderer.ReadOnly.Render(CodeFile); @@ -50,11 +39,11 @@ public CodeLine[] RenderReadOnly(bool showDocumentation) return _renderedReadOnly; } - internal CodeLine[] RenderText(bool showDocumentation, bool skipDiff = false) + internal CodeLine[] RenderText(bool skipDiff = false) { - if (showDocumentation || skipDiff) + if (skipDiff) { - return CodeFileRenderer.Instance.Render(CodeFile, showDocumentation: showDocumentation, enableSkipDiff: skipDiff); + return CodeFileRenderer.Instance.Render(CodeFile, enableSkipDiff: skipDiff); } if (_renderedText == null) diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml index c07c6813cb0..622ae87f2be 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml @@ -390,6 +390,7 @@ @{ TempData["UserPreference"] = Model.GetUserPreference(); + TempData["ShowDocumentation"] = Model.ShowDocumentation; } @foreach (var line in Model.Lines) { diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs index 151b570d834..08867d4b830 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs @@ -94,7 +94,7 @@ public async Task OnGetAsync(string id, string revisionId = null) CodeFile = renderedCodeFile.CodeFile; var fileDiagnostics = CodeFile.Diagnostics ?? Array.Empty(); - var fileHtmlLines = renderedCodeFile.Render(ShowDocumentation); + var fileHtmlLines = renderedCodeFile.Render(); if (DiffRevisionId != null) { @@ -102,9 +102,9 @@ public async Task OnGetAsync(string id, string revisionId = null) var previousRevisionFile = await _codeFileRepository.GetCodeFileAsync(DiffRevision); - var previousHtmlLines = previousRevisionFile.RenderReadOnly(ShowDocumentation); - var previousRevisionTextLines = previousRevisionFile.RenderText(ShowDocumentation); - var fileTextLines = renderedCodeFile.RenderText(ShowDocumentation); + var previousHtmlLines = previousRevisionFile.RenderReadOnly(); + var previousRevisionTextLines = previousRevisionFile.RenderText(); + var fileTextLines = renderedCodeFile.RenderText(); var diffLines = InlineDiff.Compute( previousRevisionTextLines, @@ -193,14 +193,14 @@ private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, InlineDiffLine private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, CodeLine[] lines, ReviewCommentsModel comments) { - List documentedBy = new List(); + List documentedByLines = new List(); return lines.Select( (line, index) => { index++; - if (line.DisplayString.Contains("code-comment")) + if (line.IsDocumentation) { - documentedBy.Add(index); + documentedByLines.Add(index); return new CodeLineModel( DiffLineKind.Unchanged, line, @@ -209,7 +209,8 @@ private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, CodeLine[] lin index, new int[] {} ); - } else + } + else { CodeLineModel c = new CodeLineModel( DiffLineKind.Unchanged, @@ -217,9 +218,9 @@ private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, CodeLine[] lin comments.TryGetThreadForLine(line.ElementId, out var thread) ? thread : null, diagnostics.Where(d => d.TargetId == line.ElementId).ToArray(), index, - documentedBy.ToArray() + documentedByLines.ToArray() ); - documentedBy = new List(); + documentedByLines = new List(); return c; } }).ToArray(); diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml index 4a915ed55ec..954680fc6d7 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml @@ -25,20 +25,33 @@ } var userPreference = TempData["UserPreference"] as UserPreferenceModel; + bool? showDocumentation = TempData["ShowDocumentation"] as bool?; + string codeLineDisplay = showDocumentation == false && Model.CodeLine.IsDocumentation ? "hidden-row" : ""; } - +
@Model.LineNumber
- @if(Model.DocumentedBy.Length > 0) + @if(Model.DocumentedByLines.Length > 0) { - - } else - { - + } + @if(userPreference.HideLineNumbers == true) { @@ -50,7 +63,7 @@
+ @if (showDocumentation == true) + { + + - + + } + else + { + + + + + } + @Model.LineNumber @if (!isRemoved && Model.CodeLine.ElementId != null) { - + + } else { diff --git a/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs b/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs index 806d8f2d421..53e2717c1da 100644 --- a/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs +++ b/src/dotnet/APIView/APIViewWeb/Repositories/PullRequestManager.cs @@ -310,8 +310,8 @@ private async Task CreateRevisionIfRequired(CodeFile codeFile, private async Task GetFormattedDiff(RenderedCodeFile renderedCodeFile, ReviewRevisionModel lastRevision, StringBuilder stringBuilder) { RenderedCodeFile autoReview = await _codeFileRepository.GetCodeFileAsync(lastRevision, false); - var autoReviewTextFile = autoReview.RenderText(showDocumentation: false, skipDiff: true); - var prCodeTextFile = renderedCodeFile.RenderText(showDocumentation: false, skipDiff: true); + var autoReviewTextFile = autoReview.RenderText(skipDiff: true); + var prCodeTextFile = renderedCodeFile.RenderText(skipDiff: true); var diffLines = InlineDiff.Compute(autoReviewTextFile, prCodeTextFile, autoReviewTextFile, prCodeTextFile); if (diffLines == null || diffLines.Length == 0 || diffLines.Count(l=>l.Kind != DiffLineKind.Unchanged) > 10) { diff --git a/src/dotnet/APIView/APIViewWeb/Repositories/ReviewManager.cs b/src/dotnet/APIView/APIViewWeb/Repositories/ReviewManager.cs index c2fd98d758d..d065edb63cb 100644 --- a/src/dotnet/APIView/APIViewWeb/Repositories/ReviewManager.cs +++ b/src/dotnet/APIView/APIViewWeb/Repositories/ReviewManager.cs @@ -435,8 +435,8 @@ public async Task IsReviewSame(ReviewRevisionModel revision, RenderedCodeF { //This will compare and check if new code file content is same as revision in parameter var lastRevisionFile = await _codeFileRepository.GetCodeFileAsync(revision, false); - var lastRevisionTextLines = lastRevisionFile.RenderText(showDocumentation: false, skipDiff: true); - var fileTextLines = renderedCodeFile.RenderText(showDocumentation: false, skipDiff: true); + var lastRevisionTextLines = lastRevisionFile.RenderText(skipDiff: true); + var fileTextLines = renderedCodeFile.RenderText(skipDiff: true); return lastRevisionTextLines.SequenceEqual(fileTextLines); } diff --git a/src/dotnet/APIView/APIViewWeb/wwwroot/icons/comment.svg b/src/dotnet/APIView/APIViewWeb/wwwroot/icons/comment.svg new file mode 100644 index 00000000000..84dfe886c96 --- /dev/null +++ b/src/dotnet/APIView/APIViewWeb/wwwroot/icons/comment.svg @@ -0,0 +1,3 @@ + + + From 66bb87a19273e02d5704db762a52fd8821de3e53 Mon Sep 17 00:00:00 2001 From: Vailorium Date: Mon, 15 Aug 2022 19:28:40 +1200 Subject: [PATCH 3/8] adjust name of comment line variable --- src/dotnet/APIView/APIView/CodeFileRenderer.cs | 10 +++++----- src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs | 1 - .../APIViewWeb/Pages/Assemblies/Review.cshtml.cs | 2 +- .../APIViewWeb/Pages/Assemblies/_CodeLine.cshtml | 1 - 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/dotnet/APIView/APIView/CodeFileRenderer.cs b/src/dotnet/APIView/APIView/CodeFileRenderer.cs index 5899f8d28b5..be44c54b486 100644 --- a/src/dotnet/APIView/APIView/CodeFileRenderer.cs +++ b/src/dotnet/APIView/APIView/CodeFileRenderer.cs @@ -32,7 +32,7 @@ private void Render(List list, IEnumerable node, bool e string lastHeadingEncountered = null; HashSet lineIds = new HashSet(); // Used to ensure there are no duplicate IDs int indentSize = 0; - bool isComment = false; + bool isDocumentation = false; foreach (var token in node) { @@ -41,7 +41,7 @@ private void Render(List list, IEnumerable node, bool e continue; if (isDocumentationRange && token.Kind != CodeFileTokenKind.DocumentRangeEnd) - continue; + continue; switch(token.Kind) { @@ -69,8 +69,8 @@ private void Render(List list, IEnumerable node, bool e lineClass = lineClass.Trim(); } - list.Add(new CodeLine(stringBuilder.ToString(), currentId, lineClass, indentSize, isComment)); - isComment = false; + list.Add(new CodeLine(stringBuilder.ToString(), currentId, lineClass, indentSize, isDocumentation)); + isDocumentation = false; currentId = null; stringBuilder.Clear(); break; @@ -127,7 +127,7 @@ private void Render(List list, IEnumerable node, bool e } if(token.Kind == CodeFileTokenKind.Comment) { - isComment = true; + isDocumentation = true; } RenderToken(token, stringBuilder, isDeprecatedToken); break; diff --git a/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs b/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs index dc5d27e5e7f..56971cc1b36 100644 --- a/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs +++ b/src/dotnet/APIView/APIViewWeb/Models/CodeLineModel.cs @@ -24,7 +24,6 @@ public CodeLineModel(DiffLineKind kind, CodeLine codeLine, CommentThreadModel co public CommentThreadModel CommentThread { get; } public DiffLineKind Kind { get; } public int LineNumber { get; } - public int[] DocumentedByLines { get; } } } diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs index 08867d4b830..69e6bf6d941 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs @@ -187,7 +187,7 @@ private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, InlineDiffLine diagnostics.Where(d => d.TargetId == diffLine.Line.ElementId).ToArray() : Array.Empty(), ++index, - new int[] { } // temp! + new int[] { } )).ToArray(); } diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml index 954680fc6d7..0c3c6857960 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml @@ -88,7 +88,6 @@ indent += ""; } } - @if (Model.Kind == DiffLineKind.Removed) { @Html.Raw(indent) - @Html.Raw(Model.CodeLine.DisplayString) From 10d6ec4aeee0b4f1b04b2ec791376c29c9f5ca0d Mon Sep 17 00:00:00 2001 From: Vailorium Date: Wed, 17 Aug 2022 11:23:38 +1200 Subject: [PATCH 4/8] fixed documentation folding, show documentation now toggles without reloading page --- .../APIView/APIView/CodeFileRenderer.cs | 11 +-- .../APIView/APIViewWeb/Client/css/site.scss | 20 ++++-- .../APIView/APIViewWeb/Client/src/review.ts | 68 ++++++++++++++----- .../APIViewWeb/Models/RenderedCodeFile.cs | 6 +- .../APIViewWeb/Pages/Assemblies/Review.cshtml | 4 +- .../Pages/Assemblies/Review.cshtml.cs | 9 +-- .../Pages/Assemblies/_CodeLine.cshtml | 40 ++++++----- .../wwwroot/icons/chevron-right.svg | 3 + .../APIViewWeb/wwwroot/icons/chevron-up.svg | 3 + 9 files changed, 104 insertions(+), 60 deletions(-) create mode 100644 src/dotnet/APIView/APIViewWeb/wwwroot/icons/chevron-right.svg create mode 100644 src/dotnet/APIView/APIViewWeb/wwwroot/icons/chevron-up.svg diff --git a/src/dotnet/APIView/APIView/CodeFileRenderer.cs b/src/dotnet/APIView/APIView/CodeFileRenderer.cs index be44c54b486..7b35563293a 100644 --- a/src/dotnet/APIView/APIView/CodeFileRenderer.cs +++ b/src/dotnet/APIView/APIView/CodeFileRenderer.cs @@ -32,7 +32,6 @@ private void Render(List list, IEnumerable node, bool e string lastHeadingEncountered = null; HashSet lineIds = new HashSet(); // Used to ensure there are no duplicate IDs int indentSize = 0; - bool isDocumentation = false; foreach (var token in node) { @@ -40,9 +39,6 @@ private void Render(List list, IEnumerable node, bool e if (enableSkipDiff && isSkipDiffRange && token.Kind != CodeFileTokenKind.SkipDiffRangeEnd) continue; - if (isDocumentationRange && token.Kind != CodeFileTokenKind.DocumentRangeEnd) - continue; - switch(token.Kind) { case CodeFileTokenKind.Newline: @@ -69,8 +65,7 @@ private void Render(List list, IEnumerable node, bool e lineClass = lineClass.Trim(); } - list.Add(new CodeLine(stringBuilder.ToString(), currentId, lineClass, indentSize, isDocumentation)); - isDocumentation = false; + list.Add(new CodeLine(stringBuilder.ToString(), currentId, lineClass, indentSize, isDocumentationRange)); currentId = null; stringBuilder.Clear(); break; @@ -125,10 +120,6 @@ private void Render(List list, IEnumerable node, bool e { currentId = token.DefinitionId; } - if(token.Kind == CodeFileTokenKind.Comment) - { - isDocumentation = true; - } RenderToken(token, stringBuilder, isDeprecatedToken); break; } diff --git a/src/dotnet/APIView/APIViewWeb/Client/css/site.scss b/src/dotnet/APIView/APIViewWeb/Client/css/site.scss index 88847a5ab9b..f044e556ffe 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/css/site.scss +++ b/src/dotnet/APIView/APIViewWeb/Client/css/site.scss @@ -530,9 +530,13 @@ code { display: inline-block; width: 21px; height: 21px; + line-height: 21px; + color: #fff !important; + text-align: center; + text-indent: 0; cursor: pointer; - background: #0366d6 url(/icons/comment.svg) no-repeat center center; - background-size: 90%; + background-color: #0366d6; + background-image: linear-gradient(#0372ef, #0366d6); border-radius: 3px; box-shadow: 0 1px 4px rgba(27, 31, 35, .15); opacity: 0; @@ -549,6 +553,10 @@ code { left: 0px; } +.line-toggle-documentation-button:hover { + transform: scale(1); +} + .line-toggle-documentation-button { display: inline-block; width: 21px; @@ -558,10 +566,14 @@ code { text-align: center; text-indent: 0; cursor: pointer; - background-color: #0366d6; - background-image: linear-gradient(#0372ef, #0366d6); + background: #0366d6; + background-image: url(/icons/chevron-right.svg); + background-repeat: no-repeat; + background-position: center center; border-radius: 3px; box-shadow: 0 1px 4px rgba(27, 31, 35, .15); + transition: transform .1s ease-in-out; + transform: scale(.8); user-select: none; } diff --git a/src/dotnet/APIView/APIViewWeb/Client/src/review.ts b/src/dotnet/APIView/APIViewWeb/Client/src/review.ts index 7eb61243e77..d15e6125bf0 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/src/review.ts +++ b/src/dotnet/APIView/APIViewWeb/Client/src/review.ts @@ -3,7 +3,7 @@ $(() => { const SEL_DOC_CLASS = ".documentation"; const SHOW_DOC_CHECK_COMPONENT = "#show-documentation-component"; - const SHOW_DOC_CHECKBOX = ".show-doc-checkbox"; + const SHOW_DOC_CHECKBOX = "#show-doc-checkbox"; const SHOW_DOC_HREF = ".show-document"; const SHOW_DIFFONLY_CHECKBOX = ".show-diffonly-checkbox"; const SHOW_DIFFONLY_HREF = ".show-diffonly"; @@ -77,26 +77,40 @@ $(() => { /* TOGGLE PAGE OPTIONS --------------------------------------------------------------------------------------------------------------------------------------------------------*/ $(SHOW_DOC_CHECKBOX).on("click", e => { - $(SHOW_DOC_HREF)[0].click(); + if((e.target as HTMLInputElement).checked) { + // $(".code-line").css("display", "table-row"); + const lines = $(".code-window > tbody > .code-line"); + const buttons = $(TOGGLE_DOCUMENTATION); + for(let i = 0; i < lines.length; i++) { + if (i < 3) { + $(lines[i]).show(); + $(buttons[i]).css("backgroundImage", "url(/icons/chevron-up.svg)"); + } + } + ( + function f(index: number) { + if(index >= lines.length) { + return; + } + $(lines[index]).show(); + $(buttons[index]).css("backgroundImage", "url(/icons/chevron-up.svg)"); + setTimeout(f, 3000, ++index); + } + )(3); + } else { + // + $(".code-window > tbody > .code-line > .code > .code-inner > .code-comment").parent().parent().parent().css("display", "none"); + $(".code-window > tbody > .code-line > .code > .code-inner > .documentation").parent().parent().parent().css("display", "none"); + $(TOGGLE_DOCUMENTATION).css("backgroundImage", "url(/icons/chevron-right.svg)"); + } }); - $(SHOW_DIFFONLY_CHECKBOX).on("click", e => { - $(SHOW_DIFFONLY_HREF)[0].click(); + $(SHOW_DOC_HREF).on("click", e => { + $(SHOW_DOC_CHECKBOX)[0].click(); }); - $(TOGGLE_DOCUMENTATION).on("click", function(e){ - const documentedBy = $(this).data('documented-by'); - const codeLines = $(".code-window > tbody > .code-line"); - - for(var i = 0; i < documentedBy.length; i++) { - $(codeLines[documentedBy[i] - 1]).toggle(); - } - - if($(this).text() === "-") { - this.innerText = "+"; - } else { - this.innerText = "-"; - } + $(SHOW_DIFFONLY_CHECKBOX).on("click", e => { + $(SHOW_DIFFONLY_HREF)[0].click(); }); $(HIDE_LINE_NUMBERS).on("click", e => { @@ -127,6 +141,26 @@ $(() => { }); }); + /* TOGGLE DOCUMENTATION DROPDOWN + --------------------------------------------------------------------------------------------------------------------------------------------------------*/ + $(TOGGLE_DOCUMENTATION).on("click", function(e){ + const documentedBy = $(this).data('documented-by'); + const codeLines = $(".code-window > tbody > .code-line"); + + for(var i = 0; i < documentedBy.length; i++) { + $(codeLines[documentedBy[i] - 1]).toggle(); + } + + if($(this).css('backgroundImage').includes("chevron-right")) { + $(this).css('backgroundImage', 'url(/icons/chevron-up.svg)'); + } else { + $(this).css('backgroundImage', 'url(/icons/chevron-right.svg)'); + } + + // scroll button to center of screen, so that the line is visible after toggling folding + $(this).get(0).scrollIntoView({ block: "center"}); + }); + /* DROPDOWN FILTER FOR REVIEW, REVISIONS AND DIFF (UPDATES REVIEW PAGE ON CHANGE) --------------------------------------------------------------------------------------------------------------------------------------------------------*/ $('#revisions-bootstraps-select, #review-bootstraps-select, #diff-bootstraps-select').each(function(index, value) { diff --git a/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs b/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs index 398bf35814e..02778b5c7d4 100644 --- a/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs +++ b/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs @@ -21,6 +21,7 @@ public RenderedCodeFile(CodeFile codeFile) public CodeLine[] Render() { + return CodeFileHtmlRenderer.Normal.Render(CodeFile); if (_rendered == null) { _rendered = CodeFileHtmlRenderer.Normal.Render(CodeFile); @@ -31,6 +32,7 @@ public CodeLine[] Render() public CodeLine[] RenderReadOnly() { + _renderedReadOnly = CodeFileHtmlRenderer.ReadOnly.Render(CodeFile); if (_renderedReadOnly == null) { _renderedReadOnly = CodeFileHtmlRenderer.ReadOnly.Render(CodeFile); @@ -41,7 +43,7 @@ public CodeLine[] RenderReadOnly() internal CodeLine[] RenderText(bool skipDiff = false) { - if (skipDiff) + if (true || skipDiff) { return CodeFileRenderer.Instance.Render(CodeFile, enableSkipDiff: skipDiff); } @@ -54,4 +56,4 @@ internal CodeLine[] RenderText(bool skipDiff = false) return _renderedText; } } -} \ No newline at end of file +} diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml index 622ae87f2be..1672c8c234e 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml @@ -164,8 +164,8 @@ - - + + diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs index 69e6bf6d941..c944302bd10 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs @@ -194,19 +194,20 @@ private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, InlineDiffLine private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, CodeLine[] lines, ReviewCommentsModel comments) { List documentedByLines = new List(); + int lineNumberExcludingDocumentation = 0; return lines.Select( (line, index) => { - index++; if (line.IsDocumentation) { - documentedByLines.Add(index); + // documentedByLines must include the index of a line, assuming that documentation lines are counted + documentedByLines.Add(++index); return new CodeLineModel( DiffLineKind.Unchanged, line, comments.TryGetThreadForLine(line.ElementId, out var thread) ? thread : null, diagnostics.Where(d => d.TargetId == line.ElementId).ToArray(), - index, + lineNumberExcludingDocumentation, new int[] {} ); } @@ -217,7 +218,7 @@ private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, CodeLine[] lin line, comments.TryGetThreadForLine(line.ElementId, out var thread) ? thread : null, diagnostics.Where(d => d.TargetId == line.ElementId).ToArray(), - index, + ++lineNumberExcludingDocumentation, documentedByLines.ToArray() ); documentedByLines = new List(); diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml index 0c3c6857960..ae5a22cdb79 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml @@ -33,26 +33,7 @@ - - @if(Model.DocumentedByLines.Length > 0) - { - - } - - @if(userPreference.HideLineNumbers == true) + @if(userPreference.HideLineNumbers == true || Model.CodeLine.IsDocumentation) { } @@ -63,13 +44,30 @@ + @{ TempData["UserPreference"] = Model.GetUserPreference(); - TempData["ShowDocumentation"] = Model.ShowDocumentation; } @foreach (var line in Model.Lines) { diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs index c944302bd10..8e4c3421d8d 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs @@ -64,10 +64,6 @@ public ReviewPageModel( [BindProperty(SupportsGet = true)] public string DiffRevisionId { get; set; } - // Flag to decide whether to include documentation - [BindProperty(Name = "doc", SupportsGet = true)] - public bool ShowDocumentation { get; set; } - [BindProperty(Name = "diffOnly", SupportsGet = true)] public bool ShowDiffOnly { get; set; } @@ -275,12 +271,11 @@ public IActionResult OnGetUpdatePageSettings(bool hideLineNumbers = false, bool return new EmptyResult(); } - public Dictionary GetRoutingData(string diffRevisionId = null, bool? showDocumentation = null, bool? showDiffOnly = null, string revisionId = null) + public Dictionary GetRoutingData(string diffRevisionId = null, bool? showDiffOnly = null, string revisionId = null) { var routingData = new Dictionary(); routingData["revisionId"] = revisionId; routingData["diffRevisionId"] = diffRevisionId; - routingData["doc"] = (showDocumentation ?? false).ToString(); routingData["diffOnly"] = (showDiffOnly ?? false).ToString(); return routingData; } diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml index ae5a22cdb79..8f0538cf440 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/_CodeLine.cshtml @@ -25,11 +25,17 @@ } var userPreference = TempData["UserPreference"] as UserPreferenceModel; - bool? showDocumentation = TempData["ShowDocumentation"] as bool?; - string codeLineDisplay = showDocumentation == false && Model.CodeLine.IsDocumentation ? "hidden-row" : ""; + + string documentationRow = String.Empty; + string codeLineDisplay = String.Empty; + if(Model.CodeLine.IsDocumentation) + { + documentationRow = "code-line-documentation"; + codeLineDisplay = "hidden-row"; + } } - +
- @if (showDocumentation == true) - { - - - - - } - else - { - - + - - } - @Model.LineNumber @if (!isRemoved && Model.CodeLine.ElementId != null) { - + + } else { // Added for visual consistency } + @if(Model.DocumentedByLines.Length > 0) + { + if (showDocumentation == true) + { + +   + + } + else + { + +   + + } + } + @if (isHeading) { diff --git a/src/dotnet/APIView/APIViewWeb/wwwroot/icons/chevron-right.svg b/src/dotnet/APIView/APIViewWeb/wwwroot/icons/chevron-right.svg new file mode 100644 index 00000000000..7319afcfbe9 --- /dev/null +++ b/src/dotnet/APIView/APIViewWeb/wwwroot/icons/chevron-right.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/src/dotnet/APIView/APIViewWeb/wwwroot/icons/chevron-up.svg b/src/dotnet/APIView/APIViewWeb/wwwroot/icons/chevron-up.svg new file mode 100644 index 00000000000..74eda9a45bf --- /dev/null +++ b/src/dotnet/APIView/APIViewWeb/wwwroot/icons/chevron-up.svg @@ -0,0 +1,3 @@ + + + \ No newline at end of file From 3386209196ee4c799636ebeffafa5c4261f70201 Mon Sep 17 00:00:00 2001 From: Vailorium Date: Fri, 19 Aug 2022 17:14:09 +1200 Subject: [PATCH 5/8] added more efficient show/hide all documentation --- .../APIView/APIViewWeb/Client/css/site.scss | 14 +++++-- .../APIView/APIViewWeb/Client/src/review.ts | 40 +++++-------------- .../APIViewWeb/Pages/Assemblies/Review.cshtml | 9 +---- .../Pages/Assemblies/Review.cshtml.cs | 7 +--- .../Pages/Assemblies/_CodeLine.cshtml | 27 ++++++------- 5 files changed, 36 insertions(+), 61 deletions(-) diff --git a/src/dotnet/APIView/APIViewWeb/Client/css/site.scss b/src/dotnet/APIView/APIViewWeb/Client/css/site.scss index f044e556ffe..643a773904a 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/css/site.scss +++ b/src/dotnet/APIView/APIViewWeb/Client/css/site.scss @@ -507,6 +507,15 @@ code { height: 16px; z-index: 1; } + +.icon-chevron-right { + background: url(/icons/chevron-right.svg) center center no-repeat; +} + +.icon-chevron-up { + background: url(/icons/chevron-up.svg) center center no-repeat; +} + /*---------------------------------------------------------------------*/ .info-text { @@ -566,10 +575,7 @@ code { text-align: center; text-indent: 0; cursor: pointer; - background: #0366d6; - background-image: url(/icons/chevron-right.svg); - background-repeat: no-repeat; - background-position: center center; + background-color: #0366d6; border-radius: 3px; box-shadow: 0 1px 4px rgba(27, 31, 35, .15); transition: transform .1s ease-in-out; diff --git a/src/dotnet/APIView/APIViewWeb/Client/src/review.ts b/src/dotnet/APIView/APIViewWeb/Client/src/review.ts index d15e6125bf0..c1a076d6a1c 100644 --- a/src/dotnet/APIView/APIViewWeb/Client/src/review.ts +++ b/src/dotnet/APIView/APIViewWeb/Client/src/review.ts @@ -78,30 +78,15 @@ $(() => { --------------------------------------------------------------------------------------------------------------------------------------------------------*/ $(SHOW_DOC_CHECKBOX).on("click", e => { if((e.target as HTMLInputElement).checked) { - // $(".code-line").css("display", "table-row"); - const lines = $(".code-window > tbody > .code-line"); - const buttons = $(TOGGLE_DOCUMENTATION); - for(let i = 0; i < lines.length; i++) { - if (i < 3) { - $(lines[i]).show(); - $(buttons[i]).css("backgroundImage", "url(/icons/chevron-up.svg)"); - } - } - ( - function f(index: number) { - if(index >= lines.length) { - return; - } - $(lines[index]).show(); - $(buttons[index]).css("backgroundImage", "url(/icons/chevron-up.svg)"); - setTimeout(f, 3000, ++index); - } - )(3); + // show all documentation + $(".code-line-documentation").removeClass('hidden-row'); + $(TOGGLE_DOCUMENTATION).removeClass("icon-chevron-right"); + $(TOGGLE_DOCUMENTATION).addClass("icon-chevron-up"); } else { - // - $(".code-window > tbody > .code-line > .code > .code-inner > .code-comment").parent().parent().parent().css("display", "none"); - $(".code-window > tbody > .code-line > .code > .code-inner > .documentation").parent().parent().parent().css("display", "none"); - $(TOGGLE_DOCUMENTATION).css("backgroundImage", "url(/icons/chevron-right.svg)"); + // hide all documentation + $(".code-line-documentation").addClass("hidden-row"); + $(TOGGLE_DOCUMENTATION).removeClass("icon-chevron-up"); + $(TOGGLE_DOCUMENTATION).addClass("icon-chevron-right"); } }); @@ -148,14 +133,11 @@ $(() => { const codeLines = $(".code-window > tbody > .code-line"); for(var i = 0; i < documentedBy.length; i++) { - $(codeLines[documentedBy[i] - 1]).toggle(); + $(codeLines[documentedBy[i] - 1]).toggleClass("hidden-row"); } - if($(this).css('backgroundImage').includes("chevron-right")) { - $(this).css('backgroundImage', 'url(/icons/chevron-up.svg)'); - } else { - $(this).css('backgroundImage', 'url(/icons/chevron-right.svg)'); - } + $(this).toggleClass('icon-chevron-right'); + $(this).toggleClass('icon-chevron-up'); // scroll button to center of screen, so that the line is visible after toggling folding $(this).get(0).scrollIntoView({ block: "center"}); diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml index 1672c8c234e..5fd460dd924 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml @@ -199,7 +199,7 @@ { - + @@ -285,8 +285,7 @@ var optionName = revision.IsApproved ? $"{@revision.DisplayName} {@approvedBadge}" : @revision.DisplayName; var urlValue = @Url.ActionLink("Review", "Assemblies", new { id = @Model.Review.ReviewId, - revisionId = @revision.RevisionId, - doc = @Model.ShowDocumentation + revisionId = @revision.RevisionId }); if (@revision.DisplayName == @Model.Revision.DisplayName) { @@ -309,7 +308,6 @@ id = @Model.Review.ReviewId, revisionId = @Model.Revision.RevisionId, diffRevisionId = @Model.DiffRevisionId, - doc = @Model.ShowDocumentation, diffOnly = @Model.ShowDiffOnly }); @@ -320,7 +318,6 @@ id = @Model.Review.ReviewId, revisionId = @Model.Revision.RevisionId, diffRevisionId = @Model.PreviousRevisions.Last().RevisionId, - doc = @Model.ShowDocumentation, diffOnly = @Model.ShowDiffOnly }); @@ -337,7 +334,6 @@ var urlValue = @Url.ActionLink("Review", "Assemblies", new { id = @Model.Review.ReviewId, diffRevisionId = @revision.RevisionId, - doc = @Model.ShowDocumentation, diffOnly = @Model.ShowDiffOnly, revisionId = @Model.Revision.RevisionId }); @@ -390,7 +386,6 @@
@@ -54,18 +60,9 @@
@if(Model.DocumentedByLines.Length > 0) { - if (showDocumentation == true) - { - -   - - } - else - { - -   - - } + +   + } From aac60511734c19b2c139190085ee6df8bfc6e57d Mon Sep 17 00:00:00 2001 From: Vailorium Date: Fri, 19 Aug 2022 17:30:23 +1200 Subject: [PATCH 6/8] removed unreachable code, removed unused comment icon --- .../APIViewWeb/Models/RenderedCodeFile.cs | 31 ++----------------- .../Pages/Assemblies/Review.cshtml.cs | 2 +- .../APIViewWeb/wwwroot/icons/comment.svg | 3 -- 3 files changed, 4 insertions(+), 32 deletions(-) delete mode 100644 src/dotnet/APIView/APIViewWeb/wwwroot/icons/comment.svg diff --git a/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs b/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs index 02778b5c7d4..c3428e376b8 100644 --- a/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs +++ b/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs @@ -8,10 +8,6 @@ namespace APIViewWeb.Models { public class RenderedCodeFile { - private CodeLine[] _rendered; - private CodeLine[] _renderedReadOnly; - private CodeLine[] _renderedText; - public RenderedCodeFile(CodeFile codeFile) { CodeFile = codeFile; @@ -21,39 +17,18 @@ public RenderedCodeFile(CodeFile codeFile) public CodeLine[] Render() { + //Always render to avoid cach thrashing return CodeFileHtmlRenderer.Normal.Render(CodeFile); - if (_rendered == null) - { - _rendered = CodeFileHtmlRenderer.Normal.Render(CodeFile); - } - - return _rendered; } public CodeLine[] RenderReadOnly() { - _renderedReadOnly = CodeFileHtmlRenderer.ReadOnly.Render(CodeFile); - if (_renderedReadOnly == null) - { - _renderedReadOnly = CodeFileHtmlRenderer.ReadOnly.Render(CodeFile); - } - - return _renderedReadOnly; + return CodeFileHtmlRenderer.ReadOnly.Render(CodeFile); } internal CodeLine[] RenderText(bool skipDiff = false) { - if (true || skipDiff) - { - return CodeFileRenderer.Instance.Render(CodeFile, enableSkipDiff: skipDiff); - } - - if (_renderedText == null) - { - _renderedText = CodeFileRenderer.Instance.Render(CodeFile); - } - - return _renderedText; + return CodeFileRenderer.Instance.Render(CodeFile, enableSkipDiff: skipDiff); } } } diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs index 8e4c3421d8d..c582bf4503a 100644 --- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs +++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml.cs @@ -217,7 +217,7 @@ private CodeLineModel[] CreateLines(CodeDiagnostic[] diagnostics, CodeLine[] lin ++lineNumberExcludingDocumentation, documentedByLines.ToArray() ); - documentedByLines = new List(); + documentedByLines.Clear(); return c; } }).ToArray(); diff --git a/src/dotnet/APIView/APIViewWeb/wwwroot/icons/comment.svg b/src/dotnet/APIView/APIViewWeb/wwwroot/icons/comment.svg deleted file mode 100644 index 84dfe886c96..00000000000 --- a/src/dotnet/APIView/APIViewWeb/wwwroot/icons/comment.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - From fbb93d12fef3ee69fadbfbd563ea5ca40b582880 Mon Sep 17 00:00:00 2001 From: Vailorium Date: Mon, 29 Aug 2022 13:14:26 +1200 Subject: [PATCH 7/8] return rendered arrays cache to renderedcodefile --- .../APIViewWeb/Models/RenderedCodeFile.cs | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs b/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs index c3428e376b8..fb1a5f157ec 100644 --- a/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs +++ b/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs @@ -8,6 +8,10 @@ namespace APIViewWeb.Models { public class RenderedCodeFile { + private CodeLine[] _rendered; + private CodeLine[] _renderedReadOnly; + private CodeLine[] _renderedText; + public RenderedCodeFile(CodeFile codeFile) { CodeFile = codeFile; @@ -17,18 +21,37 @@ public RenderedCodeFile(CodeFile codeFile) public CodeLine[] Render() { - //Always render to avoid cach thrashing - return CodeFileHtmlRenderer.Normal.Render(CodeFile); + if(_rendered == null) + { + _rendered = CodeFileHtmlRenderer.Normal.Render(CodeFile); + } + + return _rendered; } public CodeLine[] RenderReadOnly() { - return CodeFileHtmlRenderer.ReadOnly.Render(CodeFile); + if (_renderedReadOnly == null) + { + _renderedReadOnly = CodeFileHtmlRenderer.ReadOnly.Render(CodeFile); + } + + return _renderedReadOnly; } internal CodeLine[] RenderText(bool skipDiff = false) { - return CodeFileRenderer.Instance.Render(CodeFile, enableSkipDiff: skipDiff); + if(skipDiff) + { + return CodeFileRenderer.Instance.Render(CodeFile, enableSkipDiff: skipDiff); + } + + if (_renderedText == null) + { + _renderedText = CodeFileRenderer.Instance.Render(CodeFile); + } + + return _renderedText; } } } From f7736fcda9db16ee69a27ac6d9b2e8049630445c Mon Sep 17 00:00:00 2001 From: Vailorium Date: Mon, 29 Aug 2022 13:15:46 +1200 Subject: [PATCH 8/8] code style fixes --- src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs b/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs index fb1a5f157ec..49694239e68 100644 --- a/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs +++ b/src/dotnet/APIView/APIViewWeb/Models/RenderedCodeFile.cs @@ -21,7 +21,7 @@ public RenderedCodeFile(CodeFile codeFile) public CodeLine[] Render() { - if(_rendered == null) + if (_rendered == null) { _rendered = CodeFileHtmlRenderer.Normal.Render(CodeFile); } @@ -41,7 +41,7 @@ public CodeLine[] RenderReadOnly() internal CodeLine[] RenderText(bool skipDiff = false) { - if(skipDiff) + if (skipDiff) { return CodeFileRenderer.Instance.Render(CodeFile, enableSkipDiff: skipDiff); }