Skip to content

Commit

Permalink
Merge pull request Ericsson#2028 from csordasmarton/plist-to-html-bug…
Browse files Browse the repository at this point in the history
…-sorting

[plist-to-html] Ordering reports
  • Loading branch information
gyorb authored Apr 2, 2019
2 parents 849ec46 + 67b0608 commit 66ae1ee
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 50 deletions.
18 changes: 10 additions & 8 deletions tools/plist_to_html/plist_to_html/PlistToHtml.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, layout_dir, severity_map=None):
# Mapping layout tags to files.
self._layout_tag_files = {
'STYLE_CSS': os.path.join(css_dir, 'style.css'),
'BUGLIST_CSS': os.path.join(css_dir, 'buglist.css'),
'ICON_CSS': os.path.join(css_dir, 'icon.css'),
'CODEMIRROR_LICENSE': os.path.join(codemirror_dir,
'codemirror.LICENSE'),
Expand All @@ -54,6 +55,7 @@ def __init__(self, layout_dir, severity_map=None):
'CODEMIRROR_JS': os.path.join(codemirror_dir, 'codemirror.min.js'),
'CLIKE_JS': os.path.join(codemirror_dir, 'clike.min.js'),
'BUG_VIEWER': os.path.join(js_dir, 'bugviewer.js'),
'BUG_LIST': os.path.join(js_dir, 'buglist.js'),
'BROWSER_SUPPORT': os.path.join(js_dir, 'browsersupport.js')
}

Expand Down Expand Up @@ -103,12 +105,12 @@ def create_index_html(self, output_dir):
# Create table header.
table_reports = '''
<tr>
<th>&nbsp;</th>
<th>File</th>
<th>Severity</th>
<th>Checker name</th>
<th>Message</th>
<th>Bug path length</th>
<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>
</tr>'''

# Sort reports based on file path levels.
Expand All @@ -131,10 +133,10 @@ def create_index_html(self, output_dir):
table_reports += '''
<tr>
<td>{0}</td>
<td>
<td file="{3}" line="{4}">
<a href="{1}#reportHash={2}">{3} @ Line {4}</a>
</td>
<td class="severity">
<td class="severity" severity="{5}">
<i class="severity-{5}"></i>
</td>
<td>{6}</td>
Expand Down
33 changes: 33 additions & 0 deletions tools/plist_to_html/plist_to_html/static/css/buglist.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#report-list {
width: 100%;
}

#report-list th {
font-size: 1.2em;
color: #fff;
line-height: 1.4;
background-color: #007ea7;
}

#report-list th.active,
#report-list th.sortable:hover {
cursor: pointer;
background-color: #2da6ce;
}

#report-list tr:nth-child(even) {
background-color: #f5f5f5;
}

#report-list tr > td {
padding: 5px;
}

#report-list .bug-path-length {
width: 5%;
text-align: center;
}

#report-list .severity {
text-align: center;
}
46 changes: 4 additions & 42 deletions tools/plist_to_html/plist_to_html/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,26 @@
<meta charset="UTF-8">

<style type="text/css">
table {
width: 100%;
}

th {
font-size: 1.2em;
color: #fff;
line-height: 1.4;
background-color: #007ea7;
}

tr:nth-child(even) {
background-color: #f5f5f5;
}

tr > td {
padding: 5px;
}

.bug-path-length {
width: 5%;
text-align: center;
}

.severity {
text-align: center;
}

<$BUGLIST_CSS$>
<$ICON_CSS$>
</style>

<script>
<$BROWSER_SUPPORT$>

generateRedGreenGradientColor = function (value, max, opacity) {
var red = (255 * value) / max;
var green = (255 * (max - value)) / max;
var blue = 0;
return 'rgba(' + parseInt(red) + ',' + parseInt(green) + ',' + blue
+ ',' + opacity + ')';
}
<$BUG_LIST$>

window.onload = function () {
if (!browserCompatible) {
setNonCompatibleBrowserMessage();
} else {
document.querySelectorAll('.bug-path-length').forEach(
function (widget) {
widget.style.backgroundColor =
generateRedGreenGradientColor(widget.innerHTML, 20, 0.5);
});
BugList.init()
}
}
</script>
</head>
<body>
<div class="container">
<table>
<table id="report-list">
<$TABLE_REPORTS$>
</table>
</div>
Expand Down
150 changes: 150 additions & 0 deletions tools/plist_to_html/plist_to_html/static/js/buglist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// -------------------------------------------------------------------------
// The CodeChecker Infrastructure
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
// -------------------------------------------------------------------------

var BugList = {

init : function () {
this.initTableSort();
this.initBugPathLength();
this.initByUrl();
},

initTableSort : function () {
var that = this;

var table = document.getElementById('report-list');
table.querySelectorAll('th').forEach(function (column) {
if (that.canSort(column.id)) {
column.addEventListener('click', function () {
that.sort(column.id);
});
column.classList.add('sortable');
}
});
},

initBugPathLength : function () {
var that = this;

document.querySelectorAll('.bug-path-length').forEach(
function (widget) {
widget.style.backgroundColor =
that.generateRedGreenGradientColor(widget.innerHTML, 20, 0.5);
});
},

initByUrl : function () {
var state = {};
window.location.hash.substr(1).split('&').forEach(function (s) {
var parts = s.split('=');
state[parts[0]] = parts[1];
});

var column = state['sort'] ? state['sort'] : 'file-path';
var asc = state['asc'] ? !!parseInt(state['asc']) : false;
this.sort(column, asc);
},

generateRedGreenGradientColor : function (value, max, opacity) {
var red = (255 * value) / max;
var green = (255 * (max - value)) / max;
var blue = 0;
return 'rgba(' + parseInt(red) + ',' + parseInt(green) + ',' + blue
+ ',' + opacity + ')';
},

canSort : function (columnId) {
return columnId === 'report-id' ||
columnId === 'file-path' ||
columnId === 'severity' ||
columnId === 'checker-name' ||
columnId === 'message' ||
columnId === 'bug-path-length';
},

compare : function (columnId, a, b, asc) {
switch (columnId) {
case 'report-id':
case 'bug-path-length':
return asc
? parseInt(a.innerHTML) > parseInt(b.innerHTML)
: parseInt(a.innerHTML) < parseInt(b.innerHTML);

case 'file-path':
var fileA = a.getAttribute('file');
var fileB = b.getAttribute('file');
var lineA = parseInt(a.getAttribute('line'));
var lineB = parseInt(b.getAttribute('line'));

if (asc) {
if (fileA > fileB) {
return true;
} else if (fileA === fileB) {
return lineA > lineB ? true : false;
} else {
return false;
}
} else {
if (fileA < fileB) {
return true;
} else if (fileA === fileB) {
return lineA < lineB ? true : false;
} else {
return false;
}
}

case 'severity':
return asc
? a.getAttribute('severity') > b.getAttribute('severity')
: a.getAttribute('severity') < b.getAttribute('severity');

default:
return asc
? a.innerHTML.toLowerCase() > b.innerHTML.toLowerCase()
: a.innerHTML.toLowerCase() < b.innerHTML.toLowerCase();
}
},

sort : function (columnId, asc) {
var rows = null,
switching = true,
i, x, y;

var table = document.getElementById('report-list');
var column = document.getElementById(columnId);
var cellIndex = column.cellIndex;

if (asc === undefined) {
asc = column.getAttribute('sort') === 'desc' ? false : true;
}

while (switching) {
switching = false;
rows = table.rows;

for (i = 1; i < (rows.length - 1); i++) {
x = rows[i].getElementsByTagName('td')[cellIndex];
y = rows[i + 1].getElementsByTagName('td')[cellIndex];

if (this.compare(columnId, x, y, asc)) {
rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
switching = true;
break;
}
}
}

table.querySelectorAll('th').forEach(function (column) {
column.removeAttribute('sort');
column.classList.remove('active');
});

column.classList.add('active');
column.setAttribute('sort', asc ? 'desc' : 'asc');
window.location.hash = '#sort=' + columnId + '&asc=' + (asc ? 1 : 0);
}
};

0 comments on commit 66ae1ee

Please sign in to comment.