add helper methods for adding and removing columns to the torrent status grid

This commit is contained in:
Damien Churchill 2010-04-26 00:10:10 +01:00
parent c3290b4ac2
commit bfdaa47aff
2 changed files with 157 additions and 110 deletions

View File

@ -78,6 +78,49 @@ Deluge.Plugin = Ext.extend(Ext.util.Observable, {
enable: function() { enable: function() {
this.fireEvent("enable", this); this.fireEvent("enable", this);
if (this.onEnable) this.onEnable(); if (this.onEnable) this.onEnable();
},
registerTorrentStatus: function(key, header, options) {
options = options || {};
var cc = options.colCfg || {}, sc = options.storeCfg || {};
sc = Ext.apply(sc, {name: key});
deluge.torrents.meta.fields.push(sc);
deluge.torrents.getStore().reader.onMetaChange(deluge.torrents.meta);
cc = Ext.apply(cc, {
header: header,
dataIndex: key
});
var cols = deluge.torrents.columns.slice(0);
cols.push(cc);
deluge.torrents.colModel.setConfig(cols);
deluge.torrents.columns = cols;
Deluge.Keys.Grid.push(key);
deluge.torrents.getView().refresh(true);
},
deregisterTorrentStatus: function(key) {
var fields = [];
Ext.each(deluge.torrents.meta.fields, function(field) {
if (field.name != key) fields.push(field);
});
deluge.torrents.meta.fields = fields;
deluge.torrents.getStore().reader.onMetaChange(deluge.torrents.meta);
var cols = [];
Ext.each(deluge.torrents.columns, function(col) {
if (col.dataIndex != key) cols.push(col);
});
deluge.torrents.colModel.setConfig(cols);
deluge.torrents.columns = cols;
var keys = [];
Ext.each(Deluge.Keys.Grid, function(k) {
if (k == key) keys.push(k);
});
Deluge.Keys.Grid = keys;
deluge.torrents.getView().refresh(true);
} }
}); });

View File

@ -91,119 +91,123 @@
// object to store contained torrent ids // object to store contained torrent ids
torrents: {}, torrents: {},
columns: [{
id:'queue',
header: _('#'),
width: 30,
sortable: true,
renderer: queueRenderer,
dataIndex: 'queue'
}, {
id:'name',
header: _('Name'),
width: 150,
sortable: true,
renderer: torrentNameRenderer,
dataIndex: 'name'
}, {
header: _('Size'),
width: 75,
sortable: true,
renderer: fsize,
dataIndex: 'total_size'
}, {
header: _('Progress'),
width: 150,
sortable: true,
renderer: torrentProgressRenderer,
dataIndex: 'progress'
}, {
header: _('Seeders'),
width: 60,
sortable: true,
renderer: seedsRenderer,
dataIndex: 'num_seeds'
}, {
header: _('Peers'),
width: 60,
sortable: true,
renderer: peersRenderer,
dataIndex: 'num_peers'
}, {
header: _('Down Speed'),
width: 80,
sortable: true,
renderer: torrentSpeedRenderer,
dataIndex: 'download_payload_rate'
}, {
header: _('Up Speed'),
width: 80,
sortable: true,
renderer: torrentSpeedRenderer,
dataIndex: 'upload_payload_rate'
}, {
header: _('ETA'),
width: 60,
sortable: true,
renderer: ftime,
dataIndex: 'eta'
}, {
header: _('Ratio'),
width: 60,
sortable: true,
renderer: availRenderer,
dataIndex: 'ratio'
}, {
header: _('Avail'),
width: 60,
sortable: true,
renderer: availRenderer,
dataIndex: 'distributed_copies'
}, {
header: _('Added'),
width: 80,
sortable: true,
renderer: fdate,
dataIndex: 'time_added'
}, {
header: _('Tracker'),
width: 120,
sortable: true,
renderer: trackerRenderer,
dataIndex: 'tracker_host'
}, {
header: _('Save Path'),
width: 120,
sortable: true,
renderer: fplain,
dataIndex: 'save_path'
}],
meta: {
root: 'torrents',
idProperty: 'id',
fields: [
{name: 'queue', sortType: Deluge.data.SortTypes.asQueuePosition},
{name: 'name'},
{name: 'total_size', type: 'int'},
{name: 'state'},
{name: 'progress', type: 'float'},
{name: 'num_seeds', type: 'int'},
{name: 'total_seeds', type: 'int'},
{name: 'num_peers', type: 'int'},
{name: 'total_peers', type: 'int'},
{name: 'download_payload_rate', type: 'int'},
{name: 'upload_payload_speed', type: 'int'},
{name: 'eta', type: 'int', sortType: etaSorter},
{name: 'ratio', type: 'float'},
{name: 'distributed_copies', type: 'float'},
{name: 'time_added', type: 'int'},
{name: 'tracker_host'},
{name: 'save_path'}
]
},
constructor: function(config) { constructor: function(config) {
config = Ext.apply({ config = Ext.apply({
id: 'torrentGrid', id: 'torrentGrid',
store: new Ext.data.JsonStore({ store: new Ext.data.JsonStore(this.meta),
root: 'torrents', columns: this.columns,
idProperty: 'id',
fields: [
{name: 'queue', sortType: Deluge.data.SortTypes.asQueuePosition},
{name: 'name'},
{name: 'total_size', type: 'int'},
{name: 'state'},
{name: 'progress', type: 'float'},
{name: 'num_seeds', type: 'int'},
{name: 'total_seeds', type: 'int'},
{name: 'num_peers', type: 'int'},
{name: 'total_peers', type: 'int'},
{name: 'download_payload_rate', type: 'int'},
{name: 'upload_payload_speed', type: 'int'},
{name: 'eta', type: 'int', sortType: etaSorter},
{name: 'ratio', type: 'float'},
{name: 'distributed_copies', type: 'float'},
{name: 'time_added', type: 'int'},
{name: 'tracker_host'},
{name: 'save_path'}
]
}),
columns: [{
id:'queue',
header: _('#'),
width: 30,
sortable: true,
renderer: queueRenderer,
dataIndex: 'queue'
}, {
id:'name',
header: _('Name'),
width: 150,
sortable: true,
renderer: torrentNameRenderer,
dataIndex: 'name'
}, {
header: _('Size'),
width: 75,
sortable: true,
renderer: fsize,
dataIndex: 'total_size'
}, {
header: _('Progress'),
width: 150,
sortable: true,
renderer: torrentProgressRenderer,
dataIndex: 'progress'
}, {
header: _('Seeders'),
width: 60,
sortable: true,
renderer: seedsRenderer,
dataIndex: 'num_seeds'
}, {
header: _('Peers'),
width: 60,
sortable: true,
renderer: peersRenderer,
dataIndex: 'num_peers'
}, {
header: _('Down Speed'),
width: 80,
sortable: true,
renderer: torrentSpeedRenderer,
dataIndex: 'download_payload_rate'
}, {
header: _('Up Speed'),
width: 80,
sortable: true,
renderer: torrentSpeedRenderer,
dataIndex: 'upload_payload_rate'
}, {
header: _('ETA'),
width: 60,
sortable: true,
renderer: ftime,
dataIndex: 'eta'
}, {
header: _('Ratio'),
width: 60,
sortable: true,
renderer: availRenderer,
dataIndex: 'ratio'
}, {
header: _('Avail'),
width: 60,
sortable: true,
renderer: availRenderer,
dataIndex: 'distributed_copies'
}, {
header: _('Added'),
width: 80,
sortable: true,
renderer: fdate,
dataIndex: 'time_added'
}, {
header: _('Tracker'),
width: 120,
sortable: true,
renderer: trackerRenderer,
dataIndex: 'tracker_host'
}, {
header: _('Save Path'),
width: 120,
sortable: true,
renderer: fplain,
dataIndex: 'save_path'
}],
region: 'center', region: 'center',
cls: 'deluge-torrents', cls: 'deluge-torrents',
stripeRows: true, stripeRows: true,