Skip to content

Commit

Permalink
Merge pull request #205 from tonyhallett/report-grouping
Browse files Browse the repository at this point in the history
Report grouping
  • Loading branch information
tonyhallett authored Nov 16, 2021
2 parents c1b41ea + f18af6c commit 5cbaf45
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ ThresholdForNPathComplexity When [npath complexity](https://en.wikipedia.
ThresholdForCrapScore When [crap score](https://testing.googleblog.com/2011/02/this-code-is-crap.html) exceeds this value for a method then the method will be present in the risk hotspots tab. OpenCover only.
StickyCoverageTable Set to true for coverage table to have a sticky thead.
NamespacedClasses Set to false to show classes in report in short form. Affects grouping.
RunSettingsOnly Specify false for global and project options to be used for coverlet data collector configuration elements when not specified in runsettings
CoverletCollectorDirectoryPath Specify path to directory containing coverlet collector files if you need functionality that the FCC version does not provide.
Expand Down
79 changes: 69 additions & 10 deletions SharedProject/Core/ReportGenerator/ReportGeneratorUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,38 @@ function Plugin(el, options)
";
}

private string GetGroupingCss(bool namespacedClasses)
{
if (namespacedClasses)
{
return "";
}
return HideGroupingCss();

}

private string HideGroupingCss()
{
return @"
coverage-info div.customizebox div:nth-child(2) { visibility:hidden;font-size:1px;height:1px;padding:0;border:0;margin:0 }
coverage-info div.customizebox div:nth-child(2) * { visibility:hidden;font-size:1px;height:1px;padding:0;border:0;margin:0 }
";
}

private string HackGroupingToAllowAll()
{
return @"
var customizeBox = document.getElementsByClassName('customizebox')[0];
var groupingInput = customizeBox.querySelector('input');
groupingInput.max = 1;
";

}

public string ProcessUnifiedHtml(string htmlForProcessing, string reportOutputFolder)
{
var appOptions = appOptionsProvider.Get();
var namespacedClasses = appOptions.NamespacedClasses;
reportColours = reportColoursProvider.GetColours();
return assemblyUtil.RunInAssemblyResolvingContext(() =>
{
Expand Down Expand Up @@ -792,10 +822,12 @@ public string ProcessUnifiedHtml(string htmlForProcessing, string reportOutputFo
}
else
{
// simplify name
var lastIndexOfDotInName = className.LastIndexOf('.');
if (lastIndexOfDotInName != -1) @class["name"] = className.Substring(lastIndexOfDotInName).Trim('.');
if (!namespacedClasses)
{
// simplify name
var lastIndexOfDotInName = className.LastIndexOf('.');
if (lastIndexOfDotInName != -1) @class["name"] = className.Substring(lastIndexOfDotInName).Trim('.');
}
//mark with # and add the assembly name
var rp = @class["rp"].ToString();
var htmlIndex = rp.IndexOf(".html");
Expand Down Expand Up @@ -825,9 +857,12 @@ public string ProcessUnifiedHtml(string htmlForProcessing, string reportOutputFo
{
var assembly = riskHotspot["assembly"].ToString();
var qualifiedClassName = riskHotspot["class"].ToString();
// simplify name
var lastIndexOfDotInName = qualifiedClassName.LastIndexOf('.');
if (lastIndexOfDotInName != -1) riskHotspot["class"] = qualifiedClassName.Substring(lastIndexOfDotInName).Trim('.');
if (!namespacedClasses)
{
// simplify name
var lastIndexOfDotInName = qualifiedClassName.LastIndexOf('.');
if (lastIndexOfDotInName != -1) riskHotspot["class"] = qualifiedClassName.Substring(lastIndexOfDotInName).Trim('.');
}
var newReportPath = $"#{assembly}{assemblyClassDelimiter}{qualifiedClassName}.html";
riskHotspot["reportPath"] = newReportPath;
}
Expand All @@ -847,19 +882,35 @@ public string ProcessUnifiedHtml(string htmlForProcessing, string reportOutputFo
table,tr,th,td {{ font-size: small; }}
body {{ -webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none }}
table.overview th, table.overview td {{ font-size: small; white-space: nowrap; word-break: normal; padding-left:10px;padding-right:10px; }}
coverage-info div.customizebox div:nth-child(2) {{ visibility:hidden;font-size:1px;height:1px;padding:0;border:0;margin:0 }}
coverage-info div.customizebox div:nth-child(2) * {{ visibility:hidden;font-size:1px;height:1px;padding:0;border:0;margin:0 }}
{GetGroupingCss(namespacedClasses)}
table,tr,th,td {{ border: 1px solid; font-size: small; }}
input[type=text] {{ color:{ToJsColour(reportColours.TextBoxTextColour)}; background-color:{ToJsColour(reportColours.TextBoxColour)};border-color:{ToJsColour(reportColours.TextBoxBorderColour)} }}
select {{ color:{ToJsColour(reportColours.ComboBoxTextColour)}; background-color:{ToJsColour(reportColours.ComboBoxColour)};border-color:{ToJsColour(reportColours.ComboBoxBorderColour)} }}
body, html {{ scrollbar-arrow-color:{ToJsColour(reportColours.ScrollBarArrowColour)};scrollbar-track-color:{ToJsColour(reportColours.ScrollBarTrackColour)};scrollbar-face-color:{scrollbarThumbColour};scrollbar-shadow-color:{scrollbarThumbColour};scrollbar-highlight-color:{scrollbarThumbColour};scrollbar-3dlight-color:{scrollbarThumbColour};scrollbar-darkshadow-color:{scrollbarThumbColour} }}
input[type=range]::-ms-thumb {{
background: {scrollbarThumbColour};
border: {scrollbarThumbColour}
}}
input[type=range]::-ms-track {{
color: transparent;
border-color: transparent;
background: transparent;
}}
input[type=range]::-ms-fill-lower {{
background: {ToJsColour(reportColours.ScrollBarTrackColour)};
}}
input[type=range]::-ms-fill-upper {{
background: {ToJsColour(reportColours.ScrollBarTrackColour)};
}}
</style>
</head>
");
htmlSb.Replace("</body>", $@"
<script type=""text/javascript"">
{GetStickyTableHead()}
{HackGroupingToAllowAll()}
function getRuleBySelector(cssRules,selector){{
for(var i=0;i<cssRules.length;i++){{
if(cssRules[i].selectorText == selector){{
Expand All @@ -881,12 +932,20 @@ function getStyleSheetById(id){{
}}
function {ThemeChangedJSFunctionName}(theme){{
var fccMediaStylesheet = getStyleSheetById('fccMediaStyle');
var highContrastRule = fccMediaStylesheet.cssRules[1]
var highContrastRule = fccMediaStylesheet.cssRules[0]
var highContrastRules = highContrastRule.cssRules
getStyleBySelector(highContrastRules,'table.coverage > td.gray').setProperty('background-color',theme.{nameof(JsThemeStyling.GrayCoverage)});
var fccStyleSheet1Rules = getStyleSheetById('fccStyle1').cssRules;
var rangeInputFillLower = getStyleBySelector(fccStyleSheet1Rules, 'input[type=range]::-ms-fill-lower');
rangeInputFillLower.setProperty('background',theme.{nameof(JsThemeStyling.ScrollBarTrack)});
var rangeInputFillUpper = getStyleBySelector(fccStyleSheet1Rules, 'input[type=range]::-ms-fill-upper');
rangeInputFillUpper.setProperty('background',theme.{nameof(JsThemeStyling.ScrollBarTrack)});
var rangeInputThumb = getStyleBySelector(fccStyleSheet1Rules, 'input[type=range]::-ms-thumb');
rangeInputThumb.setProperty('background',theme.{nameof(JsThemeStyling.ScrollBarThumb)});
rangeInputThumb.setProperty('border',theme.{nameof(JsThemeStyling.ScrollBarThumb)});
var scrollBarStyle = getStyleBySelector(fccStyleSheet1Rules,'body, html');
scrollBarStyle.setProperty('scrollbar-arrow-color',theme.{nameof(JsThemeStyling.ScrollBarArrow)});
scrollBarStyle.setProperty('scrollbar-track-color',theme.{nameof(JsThemeStyling.ScrollBarTrack)});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public ThemeResourceKey Provide(string reportPart)
{
throw new Exception($"Cannot find report part {reportPart}");
}
return null;
}
}

Expand Down
4 changes: 4 additions & 0 deletions SharedProject/Options/AppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ You can also ignore additional attributes by adding to this list (short name or
[Description("Set to true for coverage table to have a sticky thead.")]
public bool StickyCoverageTable { get; set; }

[Category(reportCategory)]
[Description("Set to false to show classes in report in short form.")]
public bool NamespacedClasses { get; set; } = true;

[SuppressMessage("Usage", "VSTHRD010:Invoke single-threaded types on Main thread")]
public override void SaveSettingsToStorage()
{
Expand Down
1 change: 1 addition & 0 deletions SharedProject/Options/IAppOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ public interface IAppOptions
int ThresholdForCrapScore { get; }
bool CoverageColoursFromFontsAndColours { get; }
bool StickyCoverageTable { get; }
bool NamespacedClasses { get; }
}
}

0 comments on commit 5cbaf45

Please sign in to comment.