From 4659cf2438639ede3a550c45533fcfaa517dcbad Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Sat, 21 Feb 2009 02:31:56 +0000 Subject: [PATCH] fix speed renderer alias fspeed, fsize and ftime to the corresponding formatters improve the peers grid (flags, fixed renders etc.) --- deluge/ui/web/js/deluge-details.js | 40 ++++++++++++++++++++++++------ deluge/ui/web/js/deluge.js | 5 ++++ 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/deluge/ui/web/js/deluge-details.js b/deluge/ui/web/js/deluge-details.js index c59749345..2cc91a538 100644 --- a/deluge/ui/web/js/deluge-details.js +++ b/deluge/ui/web/js/deluge-details.js @@ -97,7 +97,6 @@ Deluge.Details.Status = { }, onRequestComplete: function(status) { - var fsize = Deluge.Formatters.size, ftime = Deluge.Formatters.timeRemaining, fspeed = Deluge.Formatters.speed; var data = { downloaded: fsize(status.total_done) + ' (' + fsize(status.total_payload_download) + ')', uploaded: fsize(status.total_uploaded) + ' (' + fsize(status.total_payload_upload) + ')', @@ -160,7 +159,6 @@ Deluge.Details.Details = { }, onRequestComplete: function(torrent, torrentId) { - var fsize = Deluge.Formatters.size; var data = { torrent_name: torrent.name, hash: torrentId, @@ -202,7 +200,32 @@ Deluge.Details.Files = { } Deluge.Details.Peers = { + onRender: function(panel) { + this.panel = panel; + this.panel.update = this.update.bind(this); + }, + onRequestComplete: function(torrent) { + var peers = new Array(); + torrent.peers.each(function(peer) { + peers.include([peer.country, peer.ip, peer.client, peer.down_speed, peer.up_speed]); + }, this); + this.Store.loadData(peers); + }, + + update: function(torrentId) { + Deluge.Client.core.get_torrent_status(torrentId, Deluge.Keys.Peers, { + onSuccess: this.onRequestComplete.bindWithEvent(this, torrentId) + }); + } +} + +function flag(val) { + return String.format('', val); +} + +function progress(val) { + return val.toFixed(1); } Deluge.Details.Peers.Store = new Ext.data.SimpleStore({ @@ -266,17 +289,18 @@ Deluge.Details.Panel = new Ext.TabPanel({ title: _('Peers'), store: Deluge.Details.Peers.Store, columns: [ - {width: 30, renderer: Deluge.Formatters.plain, dataIndex: 'country'}, + {header: ' ', width: 30, renderer: flag, dataIndex: 'country'}, {header: 'Address', width: 125, sortable: true, renderer: Deluge.Formatters.plain, dataIndex: 'address'}, - {header: 'Client', width: 125, sortable: true, renderer: renderHost, dataIndex: 'client'}, - {header: 'Progress', width: 150, sortable: true, renderer: Deluge.Formatters.plain, dataIndex: 'progress'}, - {header: 'Down Speed', width: 100, sortable: true, renderer: Deluge.Formatters.speed, dataIndex: 'downspeed'}, - {header: 'Up Speed', width: 100, sortable: true, renderer: Deluge.Formatters.speed, dataIndex: 'upspeed'} + {header: 'Client', width: 125, sortable: true, renderer: Deluge.Formatters.plain, dataIndex: 'client'}, + {header: 'Progress', width: 150, sortable: true, renderer: progress, dataIndex: 'progress'}, + {header: 'Down Speed', width: 100, sortable: true, renderer: fspeed, dataIndex: 'downspeed'}, + {header: 'Up Speed', width: 100, sortable: true, renderer: fspeed, dataIndex: 'upspeed'} ], stripeRows: true, deferredRender:false, autoScroll:true, - margins: '0 0 0 0' + margins: '0 0 0 0', + listeners: {'render': {fn: Deluge.Details.Peers.onRender, scope: Deluge.Details.Peers}} }),{ id: 'options', title: _('Options') diff --git a/deluge/ui/web/js/deluge.js b/deluge/ui/web/js/deluge.js index f44cc5285..e4d4914e2 100644 --- a/deluge/ui/web/js/deluge.js +++ b/deluge/ui/web/js/deluge.js @@ -66,6 +66,7 @@ Deluge.Formatters = { }, speed: function(bits) { + if (!bits || bits == 0) return ''; if (bits < 1024) { return bits.toFixed(1) + ' b/s'; } else { bits = bits / 1024; } @@ -115,6 +116,10 @@ Deluge.Formatters = { } } +var fsize = Deluge.Formatters.size; +var fspeed = Deluge.Formatters.speed; +var ftime = Deluge.Formatters.timeRemaining; + Deluge.Keys = { Grid: [ 'queue', 'name', 'total_size', 'state', 'progress', 'num_seeds',