Skip to content

Commit

Permalink
htmlreport: Add checkboxes to toggle error visibility by id
Browse files Browse the repository at this point in the history
  • Loading branch information
JIghtuse committed Mar 11, 2016
1 parent e4f81ba commit cbb4b1b
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions htmlreport/cppcheck-htmlreport
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,17 @@ HTML_HEAD = """
clickable.onclick = toggle;
}
}
function set_class_display(c, st) {
var elements = document.querySelectorAll('.' + c),
len = elements.length;
for (i = 0; i < len; i++) {
elements[i].style.display = st;
}
}
function toggle_class_visibility(id) {
var box = document.getElementById(id);
set_class_display(id, box.checked ? '' : 'none');
}
</script>
</head>
<body onload="init_expandables()">
Expand Down Expand Up @@ -547,12 +558,18 @@ if __name__ == '__main__':
except IndexError:
cnt_min = 0

stat_fmt = " <tr><td><input type='checkbox' onclick='toggle_class_visibility(this.id)' id='{}' name='{}' checked></td><td>{}</td><td>{}</td></tr>"
for occurrences in reversed(range(cnt_min, cnt_max + 1)):
for _id in [k for k, v in sorted(counter.items()) if v == occurrences]:
stat_html.append(" " + str(dict(counter.most_common())[_id]) + " " + str(_id) + "<br/>\n")
stat_html.append(stat_fmt.format(_id, _id, dict(counter.most_common())[_id], _id))

output_file.write(HTML_HEAD.replace('id="menu" dir="rtl"', 'id="menu_index"', 1).replace("Defects:", "Defect summary;", 1) % (options.title, '', options.title, '', ''))
output_file.write(' <p>\n' + ' ' + str(stats_count) + ' total<br/><br/>\n' + ''.join(stat_html) + '<br/><br/><a href="stats.html">Statistics</a></p>')
output_file.write(' <table>')
output_file.write(' <tr><th>Show</th><th>#</th><th>Defect ID</th></tr>')
output_file.write(''.join(stat_html))
output_file.write(' <tr><td></td><td>' + str(stats_count) + '</td><td>total</td></tr>')
output_file.write(' </table>')
output_file.write(' <a href="stats.html">Statistics</a></p>')
output_file.write(HTML_HEAD_END.replace("content", "content_index", 1))
output_file.write(' <table>\n')

Expand Down Expand Up @@ -591,17 +608,17 @@ if __name__ == '__main__':
error_class = 'class="error"'
if error['id'] == 'missingInclude':
output_file.write(
'\n <tr><td></td><td>%s</td><td></td><td>%s</td><td>%s</td></tr>' %
(error['id'], error['severity'], error['msg']))
'\n <tr class="%s"><td></td><td>%s</td><td></td><td>%s</td><td>%s</td></tr>' %
(error['id'], error['id'], error['severity'], error['msg']))
elif (error['id'] == 'unmatchedSuppression') and filename.endswith('*'):
output_file.write(
'\n <tr><td></td><td>%s</td><td></td><td>%s</td><td %s>%s</td></tr>' %
(error['id'], error['severity'], error_class,
'\n <tr class="%s"><td></td><td>%s</td><td></td><td>%s</td><td %s>%s</td></tr>' %
(error['id'], error['id'], error['severity'], error_class,
error['msg']))
else:
output_file.write(
'\n <tr><td><a href="%s#line-%d">%d</a></td><td>%s</td><td>%s</td><td>%s</td><td %s>%s</td></tr>' %
(data['htmlfile'], error['line'], error['line'],
'\n <tr class="%s"><td><a href="%s#line-%d">%d</a></td><td>%s</td><td>%s</td><td>%s</td><td %s>%s</td></tr>' %
(error['id'], data['htmlfile'], error['line'], error['line'],
error['id'], cwe_url, error['severity'], error_class,
error['msg']))

Expand Down

0 comments on commit cbb4b1b

Please sign in to comment.