Quality sorting for ManualSearch

pull/4/head
Mark McDowall 11 years ago
parent f0e721ee80
commit 0f4bfd7afc

@ -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;
});

@ -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',
@ -46,8 +47,9 @@ define(
{
name : 'quality',
label : 'Quality',
sortable: true,
cell : QualityCell
sortable : true,
cell : QualityCell,
headerCell: QualityHeaderCell
},
{

@ -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
},

@ -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) {

Loading…
Cancel
Save