mirror of
https://github.com/transmission/transmission
synced 2025-02-20 21:26:53 +00:00
(trunk web) some cleanup for r12770 -- better handling of the rebuildEverything flag in Transmission.refiler().
This commit is contained in:
parent
c639211f66
commit
02c0f7355b
1 changed files with 28 additions and 25 deletions
|
@ -1986,25 +1986,35 @@ Transmission.prototype =
|
||||||
|
|
||||||
refilter: function(rebuildEverything)
|
refilter: function(rebuildEverything)
|
||||||
{
|
{
|
||||||
var i, id, t, row, sel;
|
var i, e, id, t, row, tmp, sel, rows, clean_rows, dirty_rows,
|
||||||
|
sort_mode = this[Prefs._SortMethod],
|
||||||
|
sort_direction = this[Prefs._SortDirection],
|
||||||
|
filter_mode = this[Prefs._FilterMode],
|
||||||
|
filter_text = this.filterText,
|
||||||
|
filter_tracker = this.filterTracker,
|
||||||
|
renderer = this.torrentRenderer,
|
||||||
|
list = this._torrent_list;
|
||||||
|
|
||||||
clearTimeout(this.refilterTimer);
|
clearTimeout(this.refilterTimer);
|
||||||
delete this.refilterTimer;
|
delete this.refilterTimer;
|
||||||
|
|
||||||
// get a temporary lookup table of selected torrent ids
|
// build a temporary lookup table of selected torrent ids
|
||||||
sel = { };
|
sel = { };
|
||||||
for (i=0; row=this._rows[i]; ++i)
|
for (i=0; row=this._rows[i]; ++i)
|
||||||
if (row.isSelected())
|
if (row.isSelected())
|
||||||
sel[row.getTorrentId()] = row;
|
sel[row.getTorrentId()] = row;
|
||||||
|
|
||||||
if (rebuildEverything)
|
if (rebuildEverything) {
|
||||||
|
$(list).empty();
|
||||||
|
this._rows = [];
|
||||||
for (id in this._torrents)
|
for (id in this._torrents)
|
||||||
this.dirtyTorrents[id] = ~0;
|
this.dirtyTorrents[id] = true;
|
||||||
|
}
|
||||||
|
|
||||||
// rows that overlap with dirtyTorrents need to be refiltered.
|
// rows that overlap with dirtyTorrents need to be refiltered.
|
||||||
// those that don't are 'clean' and don't need refiltering.
|
// those that don't are 'clean' and don't need refiltering.
|
||||||
var dirty_rows = [];
|
clean_rows = [];
|
||||||
var clean_rows = [];
|
dirty_rows = [];
|
||||||
for (i=0; row=this._rows[i]; ++i) {
|
for (i=0; row=this._rows[i]; ++i) {
|
||||||
if(row.getTorrentId() in this.dirtyTorrents)
|
if(row.getTorrentId() in this.dirtyTorrents)
|
||||||
dirty_rows.push(row);
|
dirty_rows.push(row);
|
||||||
|
@ -2013,16 +2023,13 @@ Transmission.prototype =
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the dirty rows from the dom
|
// remove the dirty rows from the dom
|
||||||
var elementsToRemove = $.map(dirty_rows.slice(0), function(r) {
|
e = $.map(dirty_rows.slice(0), function(r) {
|
||||||
return r.getElement();
|
return r.getElement();
|
||||||
});
|
});
|
||||||
$(elementsToRemove).remove();
|
$(e).remove();
|
||||||
|
|
||||||
// drop any dirty rows that don't pass the filter test
|
// drop any dirty rows that don't pass the filter test
|
||||||
var tmp = [];
|
tmp = [];
|
||||||
var filter_mode = this[Prefs._FilterMode];
|
|
||||||
var filter_text = this.filterText;
|
|
||||||
var filter_tracker = this.filterTracker;
|
|
||||||
for (i=0; row=dirty_rows[i]; ++i) {
|
for (i=0; row=dirty_rows[i]; ++i) {
|
||||||
t = row.getTorrent();
|
t = row.getTorrent();
|
||||||
if (t.test(filter_mode, filter_text, filter_tracker))
|
if (t.test(filter_mode, filter_text, filter_tracker))
|
||||||
|
@ -2033,7 +2040,6 @@ Transmission.prototype =
|
||||||
|
|
||||||
// make new rows for dirty torrents that pass the filter test
|
// make new rows for dirty torrents that pass the filter test
|
||||||
// but don't already have a row
|
// but don't already have a row
|
||||||
var renderer = this.torrentRenderer;
|
|
||||||
for (id in this.dirtyTorrents) {
|
for (id in this.dirtyTorrents) {
|
||||||
t = this._torrents[id];
|
t = this._torrents[id];
|
||||||
if (t.test(filter_mode, filter_text, filter_tracker)) {
|
if (t.test(filter_mode, filter_text, filter_tracker)) {
|
||||||
|
@ -2049,12 +2055,9 @@ Transmission.prototype =
|
||||||
|
|
||||||
// now we have two sorted arrays of rows
|
// now we have two sorted arrays of rows
|
||||||
// and can do a simple two-way sorted merge.
|
// and can do a simple two-way sorted merge.
|
||||||
var rows = []
|
rows = [];
|
||||||
var ci=0, cmax=clean_rows.length;
|
var ci=0, cmax=clean_rows.length;
|
||||||
var di=0, dmax=dirty_rows.length;
|
var di=0, dmax=dirty_rows.length;
|
||||||
var sort_method = this[Prefs._SortMethod];
|
|
||||||
var sort_direction = this[Prefs._SortDirection];
|
|
||||||
var list = this._torrent_list;
|
|
||||||
while (ci!=cmax || di!=dmax)
|
while (ci!=cmax || di!=dmax)
|
||||||
{
|
{
|
||||||
var push_clean;
|
var push_clean;
|
||||||
|
@ -2064,17 +2067,17 @@ Transmission.prototype =
|
||||||
else if (di==dmax)
|
else if (di==dmax)
|
||||||
push_clean = true;
|
push_clean = true;
|
||||||
else {
|
else {
|
||||||
var ctor = clean_rows[ci].getTorrent();
|
var c = Torrent.compareTorrents(clean_rows[ci].getTorrent(),
|
||||||
var dtor = dirty_rows[di].getTorrent();
|
dirty_rows[di].getTorrent(),
|
||||||
var c = Torrent.compareTorrents(ctor, dtor, sort_method, sort_direction);
|
sort_mode, sort_direction);
|
||||||
push_clean = (c < 0);
|
push_clean = (c < 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (push_clean)
|
if (push_clean)
|
||||||
rows.push(clean_rows[ci++]);
|
rows.push(clean_rows[ci++]);
|
||||||
else {
|
else {
|
||||||
var row = dirty_rows[di++];
|
row = dirty_rows[di++];
|
||||||
var e = row.getElement();
|
e = row.getElement();
|
||||||
if (ci !== cmax)
|
if (ci !== cmax)
|
||||||
list.insertBefore(e, clean_rows[ci].getElement());
|
list.insertBefore(e, clean_rows[ci].getElement());
|
||||||
else
|
else
|
||||||
|
@ -2088,9 +2091,9 @@ Transmission.prototype =
|
||||||
this.dirtyTorrents = { };
|
this.dirtyTorrents = { };
|
||||||
|
|
||||||
// jquery's even/odd starts with 1 rather than 0, so invert the logic here
|
// jquery's even/odd starts with 1 rather than 0, so invert the logic here
|
||||||
var elements = $.map(rows.slice(0), function(r){return r.getElement();});
|
e = $.map(rows.slice(0), function(r){return r.getElement();});
|
||||||
$(elements).filter(":odd").addClass('even');
|
$(e).filter(":odd").addClass('even');
|
||||||
$(elements).filter(":even").removeClass('even');
|
$(e).filter(":even").removeClass('even');
|
||||||
|
|
||||||
// sync gui
|
// sync gui
|
||||||
this.updateStatusbar();
|
this.updateStatusbar();
|
||||||
|
|
Loading…
Reference in a new issue