Quality sorting for ManualSearch

This commit is contained in:
Mark McDowall 2013-09-25 20:49:22 -07:00
parent f0e721ee80
commit 0f4bfd7afc
4 changed files with 85 additions and 16 deletions

View File

@ -0,0 +1,69 @@
'use strict';
define(
[
'backgrid',
'Shared/Grid/HeaderCell'
], function (Backgrid, NzbDroneHeaderCell) {
Backgrid.QualityHeaderCell = 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) {
var leftWeight = leftVal.quality.weight;
var rightWeight = rightVal.quality.weight;
if (!leftWeight && !rightWeight) {
return 0;
}
if (!leftWeight) {
return -1;
}
if (!rightWeight) {
return 1;
}
if (leftWeight === rightWeight) {
return 0;
}
if (leftWeight > rightWeight) {
return -1;
}
return 1;
}
});
return Backgrid.QualityHeaderCell;
});

View File

@ -6,9 +6,10 @@ define(
'Cells/FileSizeCell',
'Cells/QualityCell',
'Cells/ApprovalStatusCell',
'Release/DownloadReportCell'
'Release/DownloadReportCell',
'Cells/Header/QualityHeaderCell'
], function (Marionette, Backgrid, FileSizeCell, QualityCell, ApprovalStatusCell, DownloadReportCell) {
], function (Marionette, Backgrid, FileSizeCell, QualityCell, ApprovalStatusCell, DownloadReportCell, QualityHeaderCell) {
return Marionette.Layout.extend({
template: 'Episode/Search/ManualLayoutTemplate',
@ -44,10 +45,11 @@ define(
cell : FileSizeCell
},
{
name : 'quality',
label : 'Quality',
sortable: true,
cell : QualityCell
name : 'quality',
label : 'Quality',
sortable : true,
cell : QualityCell,
headerCell: QualityHeaderCell
},
{

View File

@ -1,15 +1,13 @@
'use strict';
define(
[
'Release/Model',
'backbone.pageable'
], function (ReleaseModel, PagableCollection) {
return PagableCollection.extend({
'backbone',
'Release/Model'
], function (Backbone, ReleaseModel) {
return Backbone.Collection.extend({
url : window.NzbDrone.ApiRoot + '/release',
model: ReleaseModel,
mode: 'client',
state: {
pageSize: 2000
},

View File

@ -23,7 +23,7 @@ define(
var leftVal = left.get(columnName);
var rightVal = right.get(columnName);
return self._comparator(leftVal, rightVal)
return self._comparator(leftVal, rightVal);
});
}
else {
@ -31,7 +31,7 @@ define(
var leftVal = left.get(columnName);
var rightVal = right.get(columnName);
return self._comparator(rightVal, leftVal)
return self._comparator(rightVal, leftVal);
});
}
}
@ -39,7 +39,7 @@ define(
_comparator: function (leftVal, rightVal) {
if (!leftVal && !rightVal) {
return 0
return 0;
}
if (!leftVal) {
@ -47,7 +47,7 @@ define(
}
if (!rightVal) {
return 1
return 1;
}
if (leftVal === rightVal) {