Skip to content

Commit

Permalink
template switchable + recursive groups
Browse files Browse the repository at this point in the history
  • Loading branch information
fentas committed Sep 21, 2022
1 parent 6b0a96e commit c10fc88
Show file tree
Hide file tree
Showing 5 changed files with 1,703 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/bundle.js

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions src/bootstrap.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,12 @@
</div>
<div class="tab-pane" id="checks-and-groups" role="tabpanel" aria-labelledby="checks-and-group-tab">
<div class="row">
<% for(group of data.root_group.groups) { %>

<% function render_group(group) { %>
<div class="col-12 mb-3">
<h4 class="mb-3">Group - <%= group.name %></h4>
<% let i = group.path.match(/::/g).length %>
<h<%= i+3 %> class="mb-3"><%= i === 1 ? 'Group - ' : '' %><%= group.name %></h<%= i+3 %>>
<% if(group.checks.length) { %>
<div class="table-responsive">
<table class="table table-striped">
<thead>
Expand All @@ -335,8 +338,11 @@
</tbody>
</table>
</div>
<% } %>
<% group.groups.map(render_group) %>
</div>
<% } %>
<% data.root_group.groups.map(render_group) %>
<div class="col-12 mb-3">
<h4 class="mb-3">Other Checks</h4>
<div class="table-responsive">
Expand Down
25 changes: 18 additions & 7 deletions src/html-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

// Have to import ejs this way, nothing else works
import ejs from '../node_modules/ejs/ejs.min.js'
import template from './template.ejs'
const templates = {
'standard': require('./template.ejs'),
'bootstrap': require('./bootstrap.ejs'),
}

const version = '2.3.0'
const version = '2.4.0'

//
// Main function should be imported and wrapped with the function handleSummary
Expand Down Expand Up @@ -55,13 +58,17 @@ export function htmlReport(data, opts = {}) {
checkPasses += passes
}

for (let group of data.root_group.groups) {
if (group.checks) {
let { passes, fails } = countChecks(group.checks)
checkFailures += fails
checkPasses += passes
const group_checks = (groups) => {
for (let group of groups) {
if (group.checks) {
let { passes, fails } = countChecks(group.checks)
checkFailures += fails
checkPasses += passes
}
group_checks(group.groups)
}
}
// group_checks(data.root_group.groups)

const standardMetrics = [
'grpc_req_duration',
Expand Down Expand Up @@ -93,6 +100,10 @@ export function htmlReport(data, opts = {}) {
]

// Render the template
const template = opts.template in templates
? templates[opts.template]
: templates['standard']

const html = ejs.render(template, {
data,
title: opts.title,
Expand Down
7 changes: 5 additions & 2 deletions src/template.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,9 @@
<label for="tabthree"><i class="fas fa-tasks"></i> Checks & Groups</label>
<div class="tab">

<% for(group of data.root_group.groups) { %>
<% function render_group(group) { %>
<h2>&bull; Group - <%= group.name %></h2>
<% if(group.checks.length) { %>
<table class="pure-table pure-table-horizontal" style="width: 100%">
<thead>
<tr>
Expand All @@ -422,8 +423,10 @@
</tr>
<% } %>
</table>
<br>
<% } %>
<% for(sub_group of group.groups) render_group(sub_group) %>
<% } %>
<% for(group of data.root_group.groups) render_group(group) %>

<h2>&bull; Other Checks</h2>
<table class="pure-table pure-table-horizontal" style="width: 100%">
Expand Down

0 comments on commit c10fc88

Please sign in to comment.