Skip to content
This repository has been archived by the owner on Apr 6, 2024. It is now read-only.

Commit

Permalink
(GH-34) Add report using DevExtreme PivotGrid
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalberger committed Jun 27, 2018
1 parent c80ff62 commit 83476b7
Show file tree
Hide file tree
Showing 5 changed files with 158 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public sealed class TheInternalCreateReportMethod
[InlineData(GenericIssueReportTemplate.HtmlDiagnostic)]
[InlineData(GenericIssueReportTemplate.HtmlDataTable)]
[InlineData(GenericIssueReportTemplate.HtmlDxDataGrid)]
[InlineData(GenericIssueReportTemplate.HtmlDxPivotGrid)]
public void Should_Generate_Report_From_Embedded_Template(GenericIssueReportTemplate template)
{
// Given
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<None Include="packages.config" />
<EmbeddedResource Include="Templates\DataTable.cshtml" />
<EmbeddedResource Include="Templates\DxDataGrid.cshtml" />
<EmbeddedResource Include="Templates\DxPivotGrid.cshtml" />
</ItemGroup>
<ItemGroup>
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeQuality.Analyzers.dll" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public enum GenericIssueReportTemplate
/// <summary>
/// Template for a HTML report containing a rich data grid with sorting, filtering, grouping and search capabilities.
/// </summary>
HtmlDxDataGrid
HtmlDxDataGrid,

/// <summary>
/// Template for a HTML report containing a pivot grid showing number of errors, warnings, suggestions and hints,
/// with a detail drill down view and an overview chart.
/// </summary>
HtmlDxPivotGrid
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public static string GetTemplateResourceName(this GenericIssueReportTemplate tem
case GenericIssueReportTemplate.HtmlDxDataGrid:
return "DxDataGrid.cshtml";

case GenericIssueReportTemplate.HtmlDxPivotGrid:
return "DxPivotGrid.cshtml";

default:
throw new ArgumentOutOfRangeException(nameof(template));
}
Expand Down
146 changes: 146 additions & 0 deletions src/Cake.Issues.Reporting.Generic/Templates/DxPivotGrid.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
@model IEnumerable<Cake.Issues.IIssue>

<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>Issues Report</title>

@* DevExtreme dependencies *@
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.1.0.min.js"></script>
@* DevExtreme themes *@
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/18.1.3/css/dx.common.css" />
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/18.1.3/css/dx.light.css" />
@* DevExtreme library *@
<script type="text/javascript" src="https://cdn3.devexpress.com/jslib/18.1.3/js/dx.all.js"></script>
</head>
<body class="dx-viewport">
<h1>Issues Report</h1>

<div class="container">
<div id="pivotgrid-chart"></div>
<div id="pivotgrid"></div>
<div id="pivotgrid-popup"></div>
</div>

<script type="text/javascript">
var issues = [];
@foreach (var issue in Model)
{
@:issues.push({ProviderName: "@issue.ProviderName", ProviderType: "@issue.ProviderType", Priority: "@issue.Priority", PriorityName: "@issue.PriorityName", Project: "@issue.Project", Path: "@if (issue.AffectedFileRelativePath != null) { @issue.AffectedFileRelativePath.GetDirectory() }", File: "@if (issue.AffectedFileRelativePath != null) { @issue.AffectedFileRelativePath.GetFilename() }", Line: "@issue.Line", Rule: "@issue.Rule", RuleUrl: "@issue.RuleUrl", Message: "@issue.Message"});
}
</script>
<script type="text/javascript">
$(function(){
var pivotGridChart = $("#pivotgrid-chart").dxChart({
commonSeriesSettings: {
type: "bar"
},
tooltip: {
enabled: true,
customizeTooltip: function(args) {
return {
html: "Total " + args.seriesName + ": " + args.valueText
};
}
},
size: {
height: 200
},
adaptiveLayout: {
width: 450
}
}).dxChart("instance");
var pivotGrid = $("#pivotgrid").dxPivotGrid({
height: "calc(100% - 200px)",
allowFiltering: true,
fieldPanel: {
showColumnFields: false,
showDataFields: false,
showFilterFields: true,
showRowFields: false,
allowFieldDragging: true,
visible: true
},
onCellClick: function(e) {
if (e.area == "data") {
var pivotGridDataSource = e.component.getDataSource(),
rowPathLength = e.cell.rowPath.length,
rowPathName = e.cell.rowPath[rowPathLength - 1],
popupTitle = (rowPathName ? rowPathName : "Total") + " issues";
drillDownDataSource = pivotGridDataSource.createDrillDownDataSource(e.cell);
pivotgridPopup.option("title", popupTitle);
pivotgridPopup.show();
}
},
dataSource: {
fields: [
{
caption: "Project",
dataField: "Project",
area: "row"
},
{
caption: "Path",
dataField: "Path",
area: "row"
},
{
caption: "File",
dataField: "File",
area: "row"
},
{
caption: "PriorityName",
dataField: "PriorityName",
area: "column"
},
{
caption: "Provider",
dataField: "ProviderName",
area: "filter"
},
{
caption: "Count",
dataField: "Rule",
area: "data"
}
],
store: issues
}
}).dxPivotGrid("instance");
pivotGrid.bindChart(
pivotGridChart, {
inverted: true,
dataFieldsDisplayMode: "splitPanes",
alternateDataFields: false
});
var pivotgridPopup = $("#pivotgrid-popup").dxPopup({
width: 600,
height: 400,
resizeEnabled: true,
contentTemplate: function(contentElement) {
$("<div />")
.addClass("drill-down")
.dxDataGrid({
width: "100%",
height: "100%",
columns: ["Project", "Path", "File", "Line", "Rule", "Message"]
})
.appendTo(contentElement);
},
onShowing: function() {
$(".drill-down")
.dxDataGrid("instance")
.option("dataSource", drillDownDataSource);
}
}).dxPopup("instance");
});
</script>
</body>
</html>

0 comments on commit 83476b7

Please sign in to comment.