forked from Ericsson/codechecker
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Ericsson#2028 from csordasmarton/plist-to-html-bug…
…-sorting [plist-to-html] Ordering reports
- Loading branch information
Showing
4 changed files
with
197 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}; |