Skip to content

Commit

Permalink
#349: Apply query string to referenced CSS and JavaScript files and l…
Browse files Browse the repository at this point in the history
…inks to support SAS tokens (e.g. on blob storage)
  • Loading branch information
danielpalme committed May 26, 2020
1 parent 7d05f5c commit 33a43a0
Show file tree
Hide file tree
Showing 14 changed files with 151 additions and 37 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.201",
"version": "3.1.300",
"rollForward": "latestMajor"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ import { CodeElementViewModel } from "./viewmodels/codelement-viewmodel.class";
})
export class CoverageInfoComponent {
window: Window;
queryString: string = "";

historicCoverageExecutionTimes: string[] = [];
branchCoverageAvailable: boolean = false;
Expand Down Expand Up @@ -193,6 +194,12 @@ export class CoverageInfoComponent {
console.log("Grouping maximum: " + groupingMaximum);
}

const startOfQueryString: number = window.location.href.indexOf("?");

if (startOfQueryString > -1) {
this.queryString = window.location.href.substr(startOfQueryString);
}

this.updateCoverageInfo();

if (restoredFromHistory) {
Expand Down Expand Up @@ -234,7 +241,7 @@ export class CoverageInfoComponent {
codeElements.push(assemblyElement);

for (let j: number = 0; j < assemblies[i].classes.length; j++) {
assemblyElement.insertClass(new ClassViewModel(assemblies[i].classes[j]), null);
assemblyElement.insertClass(new ClassViewModel(assemblies[i].classes[j], this.queryString), null);
numberOfClasses++;
}
}
Expand All @@ -244,7 +251,7 @@ export class CoverageInfoComponent {

for (let i: number = 0; i < assemblies.length; i++) {
for (let j: number = 0; j < assemblies[i].classes.length; j++) {
assemblyElement.insertClass(new ClassViewModel(assemblies[i].classes[j]), null);
assemblyElement.insertClass(new ClassViewModel(assemblies[i].classes[j], this.queryString), null);
numberOfClasses++;
}
}
Expand All @@ -254,7 +261,7 @@ export class CoverageInfoComponent {
codeElements.push(assemblyElement);

for (let j: number = 0; j < assemblies[i].classes.length; j++) {
assemblyElement.insertClass(new ClassViewModel(assemblies[i].classes[j]), this.settings.grouping);
assemblyElement.insertClass(new ClassViewModel(assemblies[i].classes[j], this.queryString), this.settings.grouping);
numberOfClasses++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ export class ClassViewModel extends ElementBase {
currentHistoricCoverage: HistoricCoverage = null;

constructor(
clazz: Class) {
clazz: Class,
queryString: string) {
super();
this.name = clazz.name;
this.reportPath = clazz.rp;
this.reportPath = clazz.rp ? clazz.rp + queryString : clazz.rp;

this.coveredLines = clazz.cl;
this.uncoveredLines = clazz.ucl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ import { RiskHotspotsSettings } from "./data/riskhotspots-settings.class";
<tbody>
<tr *ngFor="let riskHotspot of riskHotspots | slice:0:settings.numberOfRiskHotspots">
<td>{{riskHotspot.assembly}}</td>
<td><a [href]="riskHotspot.reportPath">{{riskHotspot.class}}</a></td>
<td><a [href]="riskHotspot.reportPath + queryString">{{riskHotspot.class}}</a></td>
<td [title]="riskHotspot.methodName">
<a [href]="riskHotspot.reportPath + '#file' + riskHotspot.fileIndex + '_line' + riskHotspot.line">
<a [href]="riskHotspot.reportPath + queryString + '#file' + riskHotspot.fileIndex + '_line' + riskHotspot.line">
{{riskHotspot.methodShortName}}
</a>
</td>
Expand All @@ -83,6 +83,7 @@ import { RiskHotspotsSettings } from "./data/riskhotspots-settings.class";
})
export class RiskHotspotsComponent implements OnInit {
window: Window;
queryString: string = "";

riskHotspotMetrics: RiskHotspotMetric[] = [];
riskHotspots: RiskHotspot[] = [];
Expand Down Expand Up @@ -110,6 +111,13 @@ export class RiskHotspotsComponent implements OnInit {
console.log("Risk hotspots: Restoring from history", this.window.history.state.riskHotspotsSettings);
this.settings = JSON.parse(JSON.stringify(this.window.history.state.riskHotspotsSettings));
}

const startOfQueryString: number = window.location.href.indexOf("?");

if (startOfQueryString > -1) {
this.queryString = window.location.href.substr(startOfQueryString);
}

this.updateRiskHotpots();
}

Expand Down
3 changes: 2 additions & 1 deletion src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ CHANGELOG
4.6.0.0

* New: #210: Strong named all DLLs. Plugins have to be strong named too.
* New: Added Source Link for Nuget package 'ReportGenerator.Core'
* New: #348: Added coverage indicator for methods/properties
* New: #349: Apply query string to referenced CSS and JavaScript files and links to support SAS tokens (e.g. on blob storage)
* New: Added Source Link for Nuget package 'ReportGenerator.Core'

4.5.8.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class HtmlInlineAzurePipelinesDarkReportBuilder : ReportBuilderBase
/// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
{
using (var renderer = new HtmlRenderer(false, true, "custom-azurepipelines.css", "custom-azurepipelines_dark.css"))
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css", "custom-azurepipelines_dark.css"))
{
this.CreateClassReport(renderer, @class, fileAnalyses);
}
Expand All @@ -36,7 +36,7 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
/// <param name="summaryResult">The summary result.</param>
public override void CreateSummaryReport(SummaryResult summaryResult)
{
using (var renderer = new HtmlRenderer(false, true, "custom-azurepipelines.css", "custom-azurepipelines_dark.css"))
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css", "custom-azurepipelines_dark.css"))
{
this.CreateSummaryReport(renderer, summaryResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class HtmlInlineAzurePipelinesReportBuilder : ReportBuilderBase
/// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
{
using (var renderer = new HtmlRenderer(false, true, "custom-azurepipelines.css"))
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css"))
{
this.CreateClassReport(renderer, @class, fileAnalyses);
}
Expand All @@ -36,7 +36,7 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
/// <param name="summaryResult">The summary result.</param>
public override void CreateSummaryReport(SummaryResult summaryResult)
{
using (var renderer = new HtmlRenderer(false, true, "custom-azurepipelines.css"))
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript, "custom-azurepipelines.css"))
{
this.CreateSummaryReport(renderer, summaryResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class HtmlInlineCssAndJavaScriptReportBuilder : ReportBuilderBase
/// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
{
using (var renderer = new HtmlRenderer(false, true))
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript))
{
this.CreateClassReport(renderer, @class, fileAnalyses);
}
Expand All @@ -36,7 +36,7 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
/// <param name="summaryResult">The summary result.</param>
public override void CreateSummaryReport(SummaryResult summaryResult)
{
using (var renderer = new HtmlRenderer(false, true))
using (var renderer = new HtmlRenderer(false, HtmlMode.InlineCssAndJavaScript))
{
this.CreateSummaryReport(renderer, summaryResult);
}
Expand Down
28 changes: 26 additions & 2 deletions src/ReportGenerator.Core/Reporting/Builders/HtmlReportBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,29 @@ namespace Palmmedia.ReportGenerator.Core.Reporting.Builders
/// </summary>
public class HtmlReportBuilder : ReportBuilderBase
{
/// <summary>
/// Defines how CSS and JavaScript are referenced.
/// </summary>
private readonly HtmlMode htmlMode;

/// <summary>
/// Initializes a new instance of the <see cref="HtmlReportBuilder" /> class.
/// </summary>
public HtmlReportBuilder()
: this(true)
{
}

/// <summary>
/// Initializes a new instance of the <see cref="HtmlReportBuilder" /> class.
/// </summary>
/// <param name="externalCssAndJavaScriptWithQueryStringHandling">Defines how CSS and JavaScript are referenced.</param>
public HtmlReportBuilder(bool externalCssAndJavaScriptWithQueryStringHandling)
{
this.htmlMode = externalCssAndJavaScriptWithQueryStringHandling ? HtmlMode.ExternalCssAndJavaScriptWithQueryStringHandling
: HtmlMode.ExternalCssAndJavaScript;
}

/// <summary>
/// Gets the report type.
/// </summary>
Expand All @@ -17,14 +40,15 @@ public class HtmlReportBuilder : ReportBuilderBase
/// </value>
public override string ReportType => "Html";


/// <summary>
/// Creates a class report.
/// </summary>
/// <param name="class">The class.</param>
/// <param name="fileAnalyses">The file analyses that correspond to the class.</param>
public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> fileAnalyses)
{
using (var renderer = new HtmlRenderer(false, false))
using (var renderer = new HtmlRenderer(false, this.htmlMode))
{
this.CreateClassReport(renderer, @class, fileAnalyses);
}
Expand All @@ -36,7 +60,7 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
/// <param name="summaryResult">The summary result.</param>
public override void CreateSummaryReport(SummaryResult summaryResult)
{
using (var renderer = new HtmlRenderer(false, false))
using (var renderer = new HtmlRenderer(false, this.htmlMode))
{
this.CreateSummaryReport(renderer, summaryResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public override void CreateClassReport(Class @class, IEnumerable<FileAnalysis> f
/// <param name="summaryResult">The summary result.</param>
public override void CreateSummaryReport(SummaryResult summaryResult)
{
using (var renderer = new HtmlRenderer(true, true))
using (var renderer = new HtmlRenderer(true, HtmlMode.InlineCssAndJavaScript))
{
this.CreateSummaryReport(renderer, summaryResult);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class MhtmlReportBuilder : IReportBuilder
/// <summary>
/// The <see cref="HtmlReportBuilder"/>.
/// </summary>
private readonly IReportBuilder htmlReportBuilder = new HtmlReportBuilder();
private readonly IReportBuilder htmlReportBuilder = new HtmlReportBuilder(false);

/// <summary>
/// The report context.
Expand Down
23 changes: 23 additions & 0 deletions src/ReportGenerator.Core/Reporting/Builders/Rendering/HtmlMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Palmmedia.ReportGenerator.Core.Reporting.Builders.Rendering
{
/// <summary>
/// Defines how CSS and JavaScript are referenced.
/// </summary>
internal enum HtmlMode
{
/// <summary>
/// CSS and JavaScript is saved into separate files.
/// </summary>
ExternalCssAndJavaScript,

/// <summary>
/// CSS and JavaScript are saved into separate files but query string is appended dynamically to link 'href' and script 'src'.
/// </summary>
ExternalCssAndJavaScriptWithQueryStringHandling,

/// <summary>
/// CSS and JavaScript is included into the HTML instead of separate files.
/// </summary>
InlineCssAndJavaScript
}
}

0 comments on commit 33a43a0

Please sign in to comment.