Added DateHeaderCell to prevent drunk sorting on null dates

This commit is contained in:
Mark McDowall 2013-07-31 19:12:39 -07:00
parent 4e7468e6fe
commit bdab0d585f
2 changed files with 72 additions and 3 deletions

View File

@ -10,6 +10,7 @@ define(
'Cells/SeriesTitleCell', 'Cells/SeriesTitleCell',
'Cells/TemplatedCell', 'Cells/TemplatedCell',
'Cells/QualityProfileCell', 'Cells/QualityProfileCell',
'Shared/Grid/DateHeaderCell',
'Series/Index/Table/SeriesStatusCell', 'Series/Index/Table/SeriesStatusCell',
'Series/Index/Table/Row', 'Series/Index/Table/Row',
'Series/Index/FooterView', 'Series/Index/FooterView',
@ -25,6 +26,7 @@ define(
SeriesTitleCell, SeriesTitleCell,
TemplatedCell, TemplatedCell,
QualityProfileCell, QualityProfileCell,
DateHeaderCell,
SeriesStatusCell, SeriesStatusCell,
SeriesIndexRow, SeriesIndexRow,
FooterView, FooterView,
@ -69,9 +71,10 @@ define(
cell : 'string' cell : 'string'
}, },
{ {
name : 'nextAiring', name : 'nextAiring',
label: 'Next Airing', label : 'Next Airing',
cell : RelativeDateCell cell : RelativeDateCell,
headerCell: DateHeaderCell
}, },
{ {
name : 'this', name : 'this',

View File

@ -0,0 +1,66 @@
'use strict';
define(
[
'backgrid',
'Shared/Grid/HeaderCell'
], function (Backgrid, NzbDroneHeaderCell) {
Backgrid.DateHeaderCell = NzbDroneHeaderCell.extend({
events: {
'click': 'onClick'
},
onClick: function (e) {
e.preventDefault();
var self = this;
var columnName = this.column.get('name');
if (this.column.get('sortable')) {
if (this.direction() === 'ascending') {
this.sort(columnName, 'descending', function (left, right) {
var leftVal = left.get(columnName);
var rightVal = right.get(columnName);
return self._comparator(leftVal, rightVal)
});
}
else {
this.sort(columnName, 'ascending', function (left, right) {
var leftVal = left.get(columnName);
var rightVal = right.get(columnName);
return self._comparator(rightVal, leftVal)
});
}
}
},
_comparator: function (leftVal, rightVal) {
if (!leftVal && !rightVal) {
return 0
}
if (!leftVal) {
return -1;
}
if (!rightVal) {
return 1
}
if (leftVal === rightVal) {
return 0;
}
if (leftVal > rightVal) {
return -1;
}
return 1;
}
});
return Backgrid.DateHeaderCell;
});