Skip to content

Commit

Permalink
[cmd] Restructure static HTML generation
Browse files Browse the repository at this point in the history
"CodeChecker parse <report_dir> -e html -o html" command generates a
static HTML page showing all reports in the report directory. If the
report dir is too big, then the generated HTML is too big and the
browser freezes while loading it.

In this commit the logic of the statis HTML page has been restructured
in a way, that the reports are not HTML table elements automatically,
but first they are stored in a JS object. Only those reports are
inserted to the DOM tree that are currently visible based on the sorting
and paging.
  • Loading branch information
bruntib committed Feb 19, 2024
1 parent 230a065 commit 4172433
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 180 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,82 +302,22 @@ def create_index_html(self, output_dir: str):
for report in reports:
html_report_links.append({'link': html_file, 'report': report})

html_report_links.sort(
key=lambda data: self.files[data['report']['fileId']]['filePath'])

with io.StringIO() as table_reports:
# Create table header.
table_reports.write('''
<tr>
<th id="report-id">&nbsp;</th>
<th id="file-path">File</th>
<th id="severity">Severity</th>
<th id="checker-name">Checker name</th>
<th id="message">Message</th>
<th id="bug-path-length">Bug path length</th>
<th id="review-status">Review status</th>
</tr>''')

# Create table lines.
for i, data in enumerate(html_report_links):
html_file = os.path.basename(data['link'])
report = data['report']

severity = report['severity'].lower() \
if 'severity' in report \
and report['severity'] is not None \
else ''

review_status = report['reviewStatus'] \
if 'reviewStatus' in report and \
report['reviewStatus'] is not None \
else ''

events = report['events']
if events:
line = events[-1]['line']
message = events[-1]['message']
bug_path_length = len(events)
else:
line = report['line']
message = report['message']
bug_path_length = 1

rs = review_status.lower().replace(' ', '-')
file_path = self.files[report['fileId']]['filePath']

checker = report['checker']
doc_url = checker.get('url')
if doc_url:
checker_name_col_content = f'<a href="{doc_url}" '\
f'target="_blank">{checker["name"]}</a>'
else:
checker_name_col_content = checker["name"]

table_reports.write(f'''
<tr>
<td>{i + 1}</td>
<td file="{file_path}" line="{line}">
<a href="{html_file}#reportHash={report['reportHash']}">
{file_path} @ Line&nbsp;{line}
</a>
</td>
<td class="severity" severity="{severity}">
<i class="severity-{severity}"
title="{severity}"></i>
</td>
<td>{checker_name_col_content}</td>
<td>{message}</td>
<td class="bug-path-length">{bug_path_length}</td>
<td class="review-status review-status-{rs}">
{review_status}
</td>
</tr>''')

substitute_data = self._tag_contents
substitute_data.update({'table_reports': table_reports.getvalue()})

content = self._index.substitute(substitute_data)
table_reports = map(lambda data: {
'link': data['link'],
'file-path': data['report']['fileId'],
'report-hash': data['report']['reportHash'],
'checker-name': data['report']['checker']['name'],
'checker-url': data['report']['checker']['url'],
'line': data['report']['line'],
'message': data['report']['message'],
'review-status': data['report']['reviewStatus'],
'severity': data['report']['severity'],
'bug-path-length': len(data['report']['events'])
}, html_report_links)

self._tag_contents['table_reports'] = json.dumps(list(table_reports))

content = self._index.substitute(self._tag_contents)
output_path = os.path.join(output_dir, 'index.html')
with open(output_path, 'w+', encoding='utf-8',
errors='replace') as html_output:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#report-list {
#report-list-table {
width: 100%;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,45 @@
${browser_support}
${bug_list}

var reports = ${table_reports};

window.onload = function () {
if (!browserCompatible) {
setNonCompatibleBrowserMessage();
} else {
BugList.init()
BugList.initByUrl();
}
}
</script>
</head>
<body>
<div class="container">
<a href="statistics.html" class="button">Go To Statistics</a>
<table id="report-list">
${table_reports}
<table id="report-list-table">
<thead>
<tr>
<th id="report-id">&nbsp;</th>
<th id="file-path">File</th>
<th id="severity">Severity</th>
<th id="checker-name">Checker name</th>
<th id="message">Message</th>
<th id="bug-path-length">Bug path length</th>
<th id="review-status">Review status</th>
</tr>
</thead>
<tbody id="report-list">
</tbody>
</table>

<select id="page-size" onchange="BugList.init()">
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
</select>

<button onclick="BugList.prevPage()">&lt;</button>
<select id="page-number" onchange="BugList.selectPage(this.value)"></select>
<button onclick="BugList.nextPage()">&gt;</button>
</div>
</body>
</html>
Loading

0 comments on commit 4172433

Please sign in to comment.