Skip to content

Commit 0671bbd

Browse files
committed
Support for report charts
1 parent 153fe89 commit 0671bbd

File tree

7 files changed

+233
-95
lines changed

7 files changed

+233
-95
lines changed
Lines changed: 61 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
@using TS.NET.Sequencer
1+
@using RazorLight
2+
@inherits TemplatePage<Sequence>
3+
@using TS.NET.Sequencer
24
@using static TS.NET.Sequencer.ReportHelpers
35
@using static TS.NET.Sequencer.TimeSpanUtility
46
@{
5-
bool d3Charts = false;
7+
bool includeD3 = false;
68
}
79
<!DOCTYPE html>
810
<html lang="en">
@@ -25,8 +27,8 @@
2527
</div>
2628
<div class="flex flex-col gap-1">
2729
<div>@Model.Name</div>
28-
<div>@Model.StartTimestamp.ToString("yyyy-MM-dd HH:mm:ssZ") (@Model.TzId)</div>
29-
<div>@TimeSpanUtility.HumanDuration(Model.Duration)</div>
30+
<div>@Model.StartTimestamp.ToString("yyyy-MM-dd HH:mm:ssK") (@Model.TzId)</div>
31+
<div>@HumanDuration(Model.Duration)</div>
3032
<div>TS0019</div>
3133
</div>
3234
</div>
@@ -52,7 +54,7 @@
5254
<tr class="@(hasMetadata ? "" : "border-b border-gray-300")">
5355
<td class="p-1 pl-2 text-left whitespace-nowrap">@step.Index</td>
5456
<td class="p-1 pl-2 text-left">@step.Name</td>
55-
<td class="p-1 text-left">@TimeSpanUtility.HumanDuration(step.Result?.Duration)</td>
57+
<td class="p-1 text-left">@HumanDuration(step.Result?.Duration)</td>
5658
<td class="p-1 text-left">@(step.Result?.Summary ?? "-")</td>
5759
<td class="p-1 pr-2 text-left @StatusTextColour(step.Result?.Status)">@(step.Result?.Status.ToString() ?? "-")</td>
5860
</tr>
@@ -65,70 +67,67 @@
6567
<td class="p-2 bg-gray-100"></td>
6668
<td colspan="4" class="p-2">
6769
<div class="text-xs">
68-
@if (step.Result.Metadata != null)
70+
@foreach (var meta in step.Result!.Metadata!)
6971
{
70-
@foreach (var meta in step.Result.Metadata)
72+
@if (!meta.ShowInReport)
7173
{
72-
@if (!meta.ShowInReport)
73-
{
74-
continue;
75-
}
76-
@switch (meta)
77-
{
78-
case ResultMetadataException exception:
79-
{
80-
<div class="@(firstMetadataItem ? "pb-2" : "py-2") text-xs underline">Exception:</div>
81-
<pre class="bg-red-100 text-xs p-2 whitespace-pre-wrap overflow-auto max-w-full break-words">@exception.Exception</pre>
82-
}
83-
break;
84-
case ResultMetadataTable table:
85-
{
86-
<div class="@(firstMetadataItem ? "pb-2" : "py-2") text-xs underline">@table.Name</div>
87-
<table class="text-xs border border-gray-400">
88-
@if (table.Headers != null && table.Headers.Length > 0)
89-
{
90-
<thead>
74+
continue;
75+
}
76+
@switch (meta)
77+
{
78+
case ResultMetadataException exception:
79+
{
80+
<div class="@(firstMetadataItem ? "pb-2" : "py-2") text-xs underline">Exception:</div>
81+
<pre class="bg-red-100 text-xs p-2 whitespace-pre-wrap overflow-auto max-w-full break-words">@exception.Exception</pre>
82+
}
83+
break;
84+
case ResultMetadataTable table:
85+
{
86+
<div class="@(firstMetadataItem ? "pb-2" : "py-2") text-xs underline">@table.Name</div>
87+
<table class="text-xs border border-gray-400">
88+
@if (table.Headers != null && table.Headers.Length > 0)
89+
{
90+
<thead>
91+
<tr>
92+
@foreach (var h in table.Headers)
93+
{
94+
<th class="px-2 py-1 border-b border-gray-400 text-left font-normal">@h</th>
95+
}
96+
</tr>
97+
</thead>
98+
}
99+
@if (table.Rows != null && table.Rows.Length > 0)
100+
{
101+
<tbody>
102+
@foreach (var row in table.Rows)
103+
{
91104
<tr>
92-
@foreach (var h in table.Headers)
105+
@if (row != null)
93106
{
94-
<th class="px-2 py-1 border-b border-gray-400 text-left font-normal">@h</th>
95-
}
96-
</tr>
97-
</thead>
98-
}
99-
@if (table.Rows != null && table.Rows.Length > 0)
100-
{
101-
<tbody>
102-
@foreach (var row in table.Rows)
103-
{
104-
<tr>
105-
@if (row != null)
107+
@foreach (var cell in row)
106108
{
107-
@foreach (var cell in row)
108-
{
109-
<td class="px-2 py-1 border-b border-gray-300">@cell</td>
110-
}
109+
<td class="px-2 py-1 border-b border-gray-300">@cell</td>
111110
}
112-
</tr>
113-
}
114-
</tbody>
115-
}
116-
</table>
117-
}
118-
break;
119-
case ResultMetadataXYChart chart:
120-
{
121-
<div>Chart here</div>
122-
}
123-
break;
124-
default:
125-
<em class="text-gray-500">Metadata type not implemented in report generator.</em>
126-
break;
127-
}
128-
firstMetadataItem = false;
111+
}
112+
</tr>
113+
}
114+
</tbody>
115+
}
116+
</table>
117+
}
118+
break;
119+
case ResultMetadataXYChart chart:
120+
{
121+
<div>Chart here</div>
122+
includeD3 = true;
123+
}
124+
break;
125+
default:
126+
<em class="text-gray-500">Metadata type not implemented in report generator.</em>
127+
break;
129128
}
129+
firstMetadataItem = false;
130130
}
131-
132131
</div>
133132
</td>
134133
</tr>
@@ -139,5 +138,6 @@
139138
</table>
140139
</div>
141140
@Raw(GetStyles(Model))
141+
@Raw(GetLibraryD3(includeD3))
142142
</body>
143143
</html>

source/TS.NET.Sequencer/HTML/ReportHelpers.cs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,33 +22,42 @@ public static string GetStyles(Sequence sequence)
2222
var sb = new StringBuilder();
2323
sb.AppendLine("<style>");
2424

25-
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TS.NET.Sequencer.report.css"))
25+
using var stream1 = Assembly.GetExecutingAssembly().GetManifestResourceStream("TS.NET.Sequencer.HTML.report.css");
26+
if (stream1 != null)
2627
{
27-
if (stream != null)
28-
{
29-
using (var reader = new StreamReader(stream))
30-
{
31-
var content = reader.ReadToEnd();
32-
content = content.Replace("[@top-center content]", sequence.Name);
33-
content = content.Replace("[@top-right content]", "Device: TS0019");
34-
content = content.Replace("[@bottom-left content]", sequence.StartTimestamp.ToString("yyyy-MM-dd HH:mm:ss"));
35-
sb.Append(content);
36-
}
37-
}
28+
using var reader = new StreamReader(stream1);
29+
var content = reader.ReadToEnd();
30+
content = content.Replace("[@top-center content]", sequence.Name);
31+
content = content.Replace("[@top-right content]", "Device: TS0019");
32+
content = content.Replace("[@bottom-left content]", sequence.StartTimestamp.ToString("yyyy-MM-dd HH:mm:ss"));
33+
sb.Append(content);
3834
}
3935

40-
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TS.NET.Sequencer.report-tailwind.css"))
36+
using var stream2 = Assembly.GetExecutingAssembly().GetManifestResourceStream("TS.NET.Sequencer.HTML.report-tailwind.css");
37+
if (stream2 != null)
38+
{
39+
using var reader = new StreamReader(stream2);
40+
sb.Append(reader.ReadToEnd());
41+
}
42+
43+
sb.AppendLine("</style>");
44+
return sb.ToString();
45+
}
46+
47+
public static string GetLibraryD3(bool include)
48+
{
49+
var sb = new StringBuilder();
50+
if (include)
4151
{
52+
using var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("TS.NET.Sequencer.HTML.d3.v7.min.js");
4253
if (stream != null)
4354
{
44-
using (var reader = new StreamReader(stream))
45-
{
46-
sb.Append(reader.ReadToEnd());
47-
}
55+
using var reader = new StreamReader(stream);
56+
sb.AppendLine("<script>");
57+
sb.Append(reader.ReadToEnd());
58+
sb.AppendLine("</script>");
4859
}
4960
}
50-
51-
sb.AppendLine("</style>");
5261
return sb.ToString();
5362
}
5463
}

0 commit comments

Comments
 (0)