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

Commit c80ff62

Browse files
authored
Merge pull request #32 from cake-contrib/feature/gh-31
(GH-31) Add report using DevExtreme DataGrid
2 parents 4ecf644 + fc73c4a commit c80ff62

File tree

5 files changed

+151
-1
lines changed

5 files changed

+151
-1
lines changed

src/Cake.Issues.Reporting.Generic.Tests/GenericIssueReportGeneratorTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public sealed class TheInternalCreateReportMethod
4242
[Theory]
4343
[InlineData(GenericIssueReportTemplate.HtmlDiagnostic)]
4444
[InlineData(GenericIssueReportTemplate.HtmlDataTable)]
45+
[InlineData(GenericIssueReportTemplate.HtmlDxDataGrid)]
4546
public void Should_Generate_Report_From_Embedded_Template(GenericIssueReportTemplate template)
4647
{
4748
// Given

src/Cake.Issues.Reporting.Generic/Cake.Issues.Reporting.Generic.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
<None Include="FodyWeavers.xml" />
8787
<None Include="packages.config" />
8888
<EmbeddedResource Include="Templates\DataTable.cshtml" />
89+
<EmbeddedResource Include="Templates\DxDataGrid.cshtml" />
8990
</ItemGroup>
9091
<ItemGroup>
9192
<Analyzer Include="..\packages\Microsoft.CodeQuality.Analyzers.2.6.0\analyzers\dotnet\cs\Microsoft.CodeQuality.Analyzers.dll" />

src/Cake.Issues.Reporting.Generic/GenericIssueReportTemplate.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ public enum GenericIssueReportTemplate
1313
/// <summary>
1414
/// Template for a HTML report containing a rich data table view with sorting and search functionality.
1515
/// </summary>
16-
HtmlDataTable
16+
HtmlDataTable,
17+
18+
/// <summary>
19+
/// Template for a HTML report containing a rich data grid with sorting, filtering, grouping and search capabilities.
20+
/// </summary>
21+
HtmlDxDataGrid
1722
}
1823
}

src/Cake.Issues.Reporting.Generic/GenericIssueReportTemplateExtensions.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public static string GetTemplateResourceName(this GenericIssueReportTemplate tem
2222
case GenericIssueReportTemplate.HtmlDataTable:
2323
return "DataTable.cshtml";
2424

25+
case GenericIssueReportTemplate.HtmlDxDataGrid:
26+
return "DxDataGrid.cshtml";
27+
2528
default:
2629
throw new ArgumentOutOfRangeException(nameof(template));
2730
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
@model IEnumerable<Cake.Issues.IIssue>
2+
@using Newtonsoft.Json
3+
@using Cake.Issues.Reporting.Generic
4+
5+
<!DOCTYPE html>
6+
7+
@{
8+
var issues =
9+
from issue in Model
10+
select
11+
new
12+
{
13+
issue.ProviderName,
14+
issue.ProviderType,
15+
issue.Priority,
16+
issue.PriorityName,
17+
issue.Project,
18+
Path = issue.FilePath(),
19+
File = issue.FileName(),
20+
issue.Line,
21+
issue.Rule,
22+
issue.RuleUrl,
23+
issue.Message
24+
};
25+
}
26+
27+
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
28+
<head>
29+
<meta charset="utf-8" />
30+
<title>Issues Report</title>
31+
32+
@* DevExtreme dependencies *@
33+
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.1.0.min.js"></script>
34+
@* DevExtreme themes *@
35+
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/18.1.3/css/dx.common.css" />
36+
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/18.1.3/css/dx.light.css" />
37+
@* DevExtreme library *@
38+
<script type="text/javascript" src="https://cdn3.devexpress.com/jslib/18.1.3/js/dx.all.js"></script>
39+
</head>
40+
<body class="dx-viewport">
41+
<h1>Issues Report</h1>
42+
43+
<div class="container">
44+
<div id="gridContainer"></div>
45+
</div>
46+
47+
<script type="text/javascript">
48+
var issues = @Raw(JsonConvert.SerializeObject(issues));
49+
</script>
50+
51+
<script type="text/javascript">
52+
$(function(){
53+
$("#gridContainer").dxDataGrid({
54+
dataSource: issues,
55+
loadPanel: {
56+
enabled: true
57+
},
58+
searchPanel: {
59+
visible: true
60+
},
61+
groupPanel: {
62+
visible: true
63+
},
64+
headerFilter: {
65+
visible: true
66+
},
67+
rowAlternationEnabled: true,
68+
allowColumnResizing: true,
69+
columns: [
70+
{
71+
dataField: "ProviderName",
72+
groupIndex: 0
73+
},
74+
{
75+
caption: "Severity",
76+
dataField: "PriorityName",
77+
calculateSortValue: "Priority",
78+
width: "90px",
79+
sortIndex: 0,
80+
sortOrder: "desc"
81+
},
82+
{
83+
dataField: "Project",
84+
sortIndex: 1,
85+
sortOrder: "asc"
86+
},
87+
{
88+
dataField: "Path",
89+
sortIndex: 2,
90+
sortOrder: "asc"
91+
},
92+
{
93+
dataField: "File",
94+
sortIndex: 3,
95+
sortOrder: "asc"
96+
},
97+
{
98+
dataField: "Line",
99+
allowFiltering: false,
100+
allowGrouping: false,
101+
width: "70px",
102+
sortIndex: 4,
103+
sortOrder: "asc"
104+
},
105+
{
106+
dataField: "Rule",
107+
cellTemplate: function (container, options) {
108+
if (options.data["RuleUrl"]) {
109+
$('<a>', {
110+
text: options.value,
111+
href: options.data["RuleUrl"],
112+
target: "_blank"
113+
}).appendTo(container);
114+
}
115+
else {
116+
container.text(options.value);
117+
}
118+
}
119+
},
120+
{
121+
dataField: "Message"
122+
}
123+
],
124+
summary: {
125+
groupItems: [{
126+
column: "ProviderType",
127+
summaryType: "count",
128+
displayFormat: "{0} issues",
129+
}],
130+
totalItems: [{
131+
column: "Severity",
132+
summaryType: "count",
133+
displayFormat: "{0} issues"
134+
}]
135+
}
136+
});
137+
});
138+
</script>
139+
</body>
140+
</html>

0 commit comments

Comments
 (0)