improve the torrents grid, updating existing entries rather than just

reloading the whole grid
This commit is contained in:
Damien Churchill 2009-04-28 08:35:27 +00:00
parent 7b72d79d32
commit 78b5c06776
3 changed files with 169 additions and 141 deletions

View File

@ -72,123 +72,123 @@ Copyright:
* @constructor * @constructor
* @param {Object} config Configuration options * @param {Object} config Configuration options
*/ */
Ext.deluge.TorrentGrid = function(config) { Ext.deluge.TorrentGrid = Ext.extend(Ext.grid.GridPanel, {
config = Ext.apply({ constructor: function(config) {
id: 'torrentGrid', config = Ext.apply({
store: new Ext.data.SimpleStore({ id: 'torrentGrid',
fields: [ store: new Ext.data.SimpleStore({
{name: 'queue'}, fields: [
{name: 'name'}, {name: 'queue'},
{name: 'size', type: 'int'}, {name: 'name'},
{name: 'state'}, {name: 'size', type: 'int'},
{name: 'progress', type: 'float'}, {name: 'state'},
{name: 'seeds', type: 'int'}, {name: 'progress', type: 'float'},
{name: 'total_seeds', type: 'int'}, {name: 'seeds', type: 'int'},
{name: 'peers', type: 'int'}, {name: 'total_seeds', type: 'int'},
{name: 'total_peers', type: 'int'}, {name: 'peers', type: 'int'},
{name: 'downspeed', type: 'int'}, {name: 'total_peers', type: 'int'},
{name: 'upspeed', type: 'int'}, {name: 'downspeed', type: 'int'},
{name: 'eta', type: 'int'}, {name: 'upspeed', type: 'int'},
{name: 'ratio', type: 'float'}, {name: 'eta', type: 'int'},
{name: 'avail', type: 'float'}, {name: 'ratio', type: 'float'},
{name: 'added', type: 'int'}, {name: 'avail', type: 'float'},
{name: 'tracker'} {name: 'added', type: 'int'},
], {name: 'tracker'}
id: 16 ],
}), id: 16
columns: [{ }),
id:'queue', columns: [{
header: _('#'), id:'queue',
width: 30, header: _('#'),
sortable: true, width: 30,
renderer: queueRenderer, sortable: true,
dataIndex: 'queue' renderer: queueRenderer,
}, { dataIndex: 'queue'
id:'name', }, {
header: _('Name'), id:'name',
width: 150, header: _('Name'),
sortable: true, width: 150,
renderer: torrentNameRenderer, sortable: true,
dataIndex: 'name' renderer: torrentNameRenderer,
}, { dataIndex: 'name'
header: _('Size'), }, {
width: 75, header: _('Size'),
sortable: true, width: 75,
renderer: fsize, sortable: true,
dataIndex: 'size' renderer: fsize,
}, { dataIndex: 'size'
header: _('Progress'), }, {
width: 150, header: _('Progress'),
sortable: true, width: 150,
renderer: torrentProgressRenderer, sortable: true,
dataIndex: 'progress' renderer: torrentProgressRenderer,
}, { dataIndex: 'progress'
header: _('Seeders'), }, {
width: 60, header: _('Seeders'),
sortable: true, width: 60,
renderer: seedsRenderer, sortable: true,
dataIndex: 'seeds' renderer: seedsRenderer,
}, { dataIndex: 'seeds'
header: _('Peers'), }, {
width: 60, header: _('Peers'),
sortable: true, width: 60,
renderer: peersRenderer, sortable: true,
dataIndex: 'peers' renderer: peersRenderer,
}, { dataIndex: 'peers'
header: _('Down Speed'), }, {
width: 80, header: _('Down Speed'),
sortable: true, width: 80,
renderer: torrentSpeedRenderer, sortable: true,
dataIndex: 'downspeed' renderer: torrentSpeedRenderer,
}, { dataIndex: 'downspeed'
header: _('Up Speed'), }, {
width: 80, header: _('Up Speed'),
sortable: true, width: 80,
renderer: torrentSpeedRenderer, sortable: true,
dataIndex: 'upspeed' renderer: torrentSpeedRenderer,
}, { dataIndex: 'upspeed'
header: _('ETA'), }, {
width: 60, header: _('ETA'),
sortable: true, width: 60,
renderer: ftime, sortable: true,
dataIndex: 'eta' renderer: ftime,
}, { dataIndex: 'eta'
header: _('Ratio'), }, {
width: 60, header: _('Ratio'),
sortable: true, width: 60,
renderer: availRenderer, sortable: true,
dataIndex: 'ratio' renderer: availRenderer,
}, { dataIndex: 'ratio'
header: _('Avail'), }, {
width: 60, header: _('Avail'),
sortable: true, width: 60,
renderer: availRenderer, sortable: true,
dataIndex: 'avail' renderer: availRenderer,
}, { dataIndex: 'avail'
header: _('Added'), }, {
width: 80, header: _('Added'),
sortable: true, width: 80,
renderer: fdate, sortable: true,
dataIndex: 'added' renderer: fdate,
}, { dataIndex: 'added'
header: _('Tracker'), }, {
width: 120, header: _('Tracker'),
sortable: true, width: 120,
renderer: trackerRenderer, sortable: true,
dataIndex: 'tracker' renderer: trackerRenderer,
}], dataIndex: 'tracker'
region: 'center', }],
cls: 'deluge-torrents', region: 'center',
stripeRows: true, cls: 'deluge-torrents',
autoExpandColumn: 'name', stripeRows: true,
deferredRender:false, autoExpandColumn: 'name',
autoScroll:true, deferredRender:false,
margins: '5 5 0 0' autoScroll:true,
}, config); margins: '5 5 0 0'
Ext.deluge.TorrentGrid.superclass.constructor.call(this, config); }, config);
} Ext.deluge.TorrentGrid.superclass.constructor.call(this, config);
},
Ext.extend(Ext.deluge.TorrentGrid, Ext.grid.GridPanel, {
initComponent: function() { initComponent: function() {
Ext.deluge.TorrentGrid.superclass.initComponent.call(this); Ext.deluge.TorrentGrid.superclass.initComponent.call(this);
Deluge.Events.on('torrentRemoved', this.onTorrentRemoved, this); Deluge.Events.on('torrentRemoved', this.onTorrentRemoved, this);
@ -220,6 +220,56 @@ Copyright:
return this.getSelectionModel().getSelections(); return this.getSelectionModel().getSelections();
}, },
update: function(torrents) {
//var torrents = [];
var store = this.getStore();
for (var torrentId in torrents) {
var record = store.getById(torrentId);
var torrent = torrents[torrentId];
if (!record) {
// We need to create a new record
var data = [
torrent.queue,
torrent.name,
torrent.total_size,
torrent.state,
torrent.progress,
torrent.num_seeds,
torrent.total_seeds,
torrent.num_peers,
torrent.total_peers,
torrent.download_payload_rate,
torrent.upload_payload_rate,
torrent.eta,
torrent.ratio,
torrent.distributed_copies,
torrent.time_added,
torrent.tracker_host,
torrentId
];
store.loadData([data], true);
} else {
// We just need to do an update
record.set('queue', torrent.queue);
record.set('name', torrent.name);
record.set('size', torrent.total_size);
record.set('state', torrent.state);
record.set('progress', torrent.progress);
record.set('seeds', torrent.num_seeds);
record.set('total_seeds', torrent.total_seeds);
record.set('peers', torrent.num_peers);
record.set('total_peers', torrent.total_peers);
record.set('downspeed', torrent.download_payload_rate);
record.set('upspeed', torrent.upload_payload_rate);
record.set('eta', torrent.eta);
record.set('ratio', torrent.ratio);
record.set('avail', torrent.distributed_copies);
record.set('added', torrent.time_added);
record.set('tracker', torrent.tracker_host);
}
}
},
// private // private
onTorrentRemoved: function(torrentIds) { onTorrentRemoved: function(torrentIds) {
var selModel = this.getSelectionModel(); var selModel = this.getSelectionModel();

View File

@ -93,29 +93,7 @@ Deluge.UI = {
}, },
onUpdate: function(data) { onUpdate: function(data) {
var torrents = []; Deluge.Torrents.update(data['torrents']);
for (var torrentId in data['torrents']) {
var torrent = data['torrents'][torrentId];
torrents.push([torrent.queue,
torrent.name,
torrent.total_size,
torrent.state,
torrent.progress,
torrent.num_seeds,
torrent.total_seeds,
torrent.num_peers,
torrent.total_peers,
torrent.download_payload_rate,
torrent.upload_payload_rate,
torrent.eta,
torrent.ratio,
torrent.distributed_copies,
torrent.time_added,
torrent.tracker_host,
torrentId
]);
}
Deluge.Torrents.getStore().loadData(torrents);
Deluge.Statusbar.update(data['stats']); Deluge.Statusbar.update(data['stats']);
Deluge.Sidebar.update(data['filters']); Deluge.Sidebar.update(data['filters']);
this.errorCount = 0; this.errorCount = 0;

File diff suppressed because one or more lines are too long