Quality sorting for ManualSearch
This commit is contained in:
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/FileSizeCell',
|
||||||
'Cells/QualityCell',
|
'Cells/QualityCell',
|
||||||
'Cells/ApprovalStatusCell',
|
'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({
|
return Marionette.Layout.extend({
|
||||||
template: 'Episode/Search/ManualLayoutTemplate',
|
template: 'Episode/Search/ManualLayoutTemplate',
|
||||||
|
@ -44,10 +45,11 @@ define(
|
||||||
cell : FileSizeCell
|
cell : FileSizeCell
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name : 'quality',
|
name : 'quality',
|
||||||
label : 'Quality',
|
label : 'Quality',
|
||||||
sortable: true,
|
sortable : true,
|
||||||
cell : QualityCell
|
cell : QualityCell,
|
||||||
|
headerCell: QualityHeaderCell
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
define(
|
define(
|
||||||
[
|
[
|
||||||
'Release/Model',
|
'backbone',
|
||||||
'backbone.pageable'
|
'Release/Model'
|
||||||
], function (ReleaseModel, PagableCollection) {
|
], function (Backbone, ReleaseModel) {
|
||||||
return PagableCollection.extend({
|
return Backbone.Collection.extend({
|
||||||
url : window.NzbDrone.ApiRoot + '/release',
|
url : window.NzbDrone.ApiRoot + '/release',
|
||||||
model: ReleaseModel,
|
model: ReleaseModel,
|
||||||
|
|
||||||
mode: 'client',
|
|
||||||
|
|
||||||
state: {
|
state: {
|
||||||
pageSize: 2000
|
pageSize: 2000
|
||||||
},
|
},
|
||||||
|
|
|
@ -23,7 +23,7 @@ define(
|
||||||
var leftVal = left.get(columnName);
|
var leftVal = left.get(columnName);
|
||||||
var rightVal = right.get(columnName);
|
var rightVal = right.get(columnName);
|
||||||
|
|
||||||
return self._comparator(leftVal, rightVal)
|
return self._comparator(leftVal, rightVal);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -31,7 +31,7 @@ define(
|
||||||
var leftVal = left.get(columnName);
|
var leftVal = left.get(columnName);
|
||||||
var rightVal = right.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) {
|
_comparator: function (leftVal, rightVal) {
|
||||||
if (!leftVal && !rightVal) {
|
if (!leftVal && !rightVal) {
|
||||||
return 0
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!leftVal) {
|
if (!leftVal) {
|
||||||
|
@ -47,7 +47,7 @@ define(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rightVal) {
|
if (!rightVal) {
|
||||||
return 1
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leftVal === rightVal) {
|
if (leftVal === rightVal) {
|
||||||
|
|
Loading…
Reference in New Issue