updated the asc/desc sort to only display one button at a time

This commit is contained in:
Ryan Plessner 2015-02-16 20:55:29 -05:00
parent 0a0ac410df
commit 4a68d56bec
3 changed files with 35 additions and 30 deletions

View File

@ -32,26 +32,35 @@ window.onload = function() {
}
};
var createTableSorter = function(className, compare) {
return function() {
sortTable(className, compare);
};
var oppositeArrowDirection = function(dir) {
if (dir === 'up') {
return 'down';
} else {
return 'up';
}
};
var createSorter = function(className, sortAscending, sortDescending) {
var ascending = document.querySelector('th.' + className + ' .sorter div.sort-icon-up');
var descending = document.querySelector('th.' + className + ' .sorter div.sort-icon-down');
ascending.addEventListener('click', createTableSorter(className, sortAscending));
descending.addEventListener('click', createTableSorter(className, sortDescending));
var createSorter = function(className, arrowDirection, compare, negativeCompare) {
var sortClass = 'th.' + className + ' div.sort-icon-' + arrowDirection;
var element = document.querySelector(sortClass);
var clickHandler = function() {
var oppArrowDirection = oppositeArrowDirection(arrowDirection);
sortTable(className, compare);
element.removeEventListener('click', clickHandler);
element.className = 'sort-icon-' + oppArrowDirection;
createSorter(className, oppArrowDirection, negativeCompare, compare);
};
element.addEventListener('click', clickHandler);
};
var stringCompareAsc = function(a, b) { return a.localeCompare(b); };
var stringCompareDesc = function(a, b) { return b.localeCompare(a); };
var floatCompareAsc = function(a, b) { return parseFloat(a) - parseFloat(b); };
var floatCompareDesc = function(a, b) { return parseFloat(b) - parseFloat(a); };
createSorter('file-name', stringCompareAsc, stringCompareDesc);
createSorter('coverage-percentage', floatCompareAsc, floatCompareDesc);
createSorter('covered-expressions', floatCompareAsc, floatCompareDesc);
createSorter('total-expressions', floatCompareAsc, floatCompareDesc);
createSorter('file-name', 'up', stringCompareDesc, stringCompareAsc);
createSorter('coverage-percentage', 'up', floatCompareAsc, floatCompareDesc);
createSorter('covered-expressions', 'up', floatCompareAsc, floatCompareDesc);
createSorter('total-expressions', 'up', floatCompareAsc, floatCompareDesc);
sortTable('file-name', stringCompareAsc);
};

View File

@ -63,30 +63,28 @@ div.file-lines {
/* Sorting Triangles */
div.sorter {
display: inline-block;
margin-left: 0.5em;
margin-bottom: 0.1em;
}
.sort-icon-up {
cursor: pointer;
margin-bottom: 0.1em;
display: inline-block;
margin-left: 0.5em;
margin-bottom: 0.2em;
width: 0px;
height: 0px;
border-left: 0.25em solid transparent;
border-right: 0.25em solid transparent;
border-bottom: 0.25em solid black;
border-left: 0.3em solid transparent;
border-right: 0.3em solid transparent;
border-bottom: 0.3em solid black;
}
.sort-icon-down {
cursor: pointer;
margin-top: 0.1em;
display: inline-block;
margin-left: 0.5em;
margin-bottom: 0.2em;
width: 0px;
height: 0px;
border-left: 0.25em solid transparent;
border-right: 0.25em solid transparent;
border-top: 0.25em solid black;
border-left: 0.3em solid transparent;
border-right: 0.3em solid transparent;
border-top: 0.3em solid black;
}

View File

@ -266,9 +266,7 @@
(tr:file-report path expr-info)))))
(define (file-sorter class-name)
`(div ([class "sorter"])
(div ([class "sort-icon-up"]))
(div ([class "sort-icon-down"]))))
`(div ([class "sort-icon-up"])))
;; PathString ExpressionInfo -> Xexpr
;; create a div that holds a link to the file report and expression