mirror of
https://github.com/transmission/transmission
synced 2024-12-24 08:43:27 +00:00
(trunk web) Reduce the torrent-get RPC wrapper down to a single function. Annotate the torrent bootstrap process in Transmission.js.
This commit is contained in:
parent
6f8be90491
commit
5715bae7fd
2 changed files with 36 additions and 67 deletions
|
@ -132,7 +132,7 @@ Transmission.prototype =
|
|||
var async = false;
|
||||
this.loadDaemonPrefs(async);
|
||||
this.loadDaemonStats(async);
|
||||
this.initializeAllTorrents();
|
||||
this.initializeTorrents();
|
||||
this.refreshTorrents();
|
||||
this.togglePeriodicSessionRefresh(true);
|
||||
|
||||
|
@ -1055,15 +1055,17 @@ Transmission.prototype =
|
|||
if ((t = this._torrents[id]))
|
||||
t.refresh(o);
|
||||
else {
|
||||
t = this._torrents[id] = new Torrent(o);
|
||||
var tr = this;
|
||||
t = tr._torrents[id] = new Torrent(o);
|
||||
$(t).bind('dataChanged',function(ev) {tr.onTorrentChanged(ev);});
|
||||
new_ids.push(id);
|
||||
}
|
||||
}
|
||||
|
||||
if (new_ids.length) {
|
||||
var tr = this;
|
||||
this.remote.getTorrentInitial(new_ids, function(a,b){tr.updateFromTorrentGet(a,b);});
|
||||
// whee, new torrents! get their initial information.
|
||||
var fields = ['id'].concat(Torrent.Fields.Metadata, Torrent.Fields.Stats);
|
||||
this.remote.updateTorrents(new_ids, fields, this.updateFromTorrentGet, this);
|
||||
this.refilterSoon();
|
||||
}
|
||||
|
||||
|
@ -1076,26 +1078,33 @@ Transmission.prototype =
|
|||
refreshTorrents: function()
|
||||
{
|
||||
// send a request right now
|
||||
var tr = this;
|
||||
this.remote.getTorrentStats('recently-active', function(a,b){tr.updateFromTorrentGet(a,b);});
|
||||
var fields = ['id'].concat(Torrent.Fields.Stats);
|
||||
this.remote.updateTorrents('recently-active', fields, this.updateFromTorrentGet, this);
|
||||
|
||||
// schedule the next request
|
||||
clearTimeout(this.refreshTorrentsTimeout);
|
||||
this.refreshTorrentsTimeout = setTimeout(function(){tr.refreshTorrents();}, tr[Prefs._RefreshRate]*1000);
|
||||
},
|
||||
initializeAllTorrents: function() {
|
||||
var tr = this;
|
||||
this.remote.getTorrentInitial(null, function(a,b){tr.updateFromTorrentGet(a,b);});
|
||||
this.refreshTorrentsTimeout = setTimeout(function(){tr.refreshTorrents();}, tr[Prefs._RefreshRate]*1000);
|
||||
},
|
||||
refreshMetadata: function(ids) {
|
||||
var tr = this;
|
||||
this.remote.getTorrentMetadata(ids, function(a,b){tr.updateFromTorrentGet(a,b);});
|
||||
|
||||
initializeTorrents: function()
|
||||
{
|
||||
// to bootstrap, we only need to ask for the servers's torrents' ids.
|
||||
// updateFromTorrentGet() automatically asks for the rest of the info when it gets a new id.
|
||||
this.remote.updateTorrents(null, ['id'], this.updateFromTorrentGet, this);
|
||||
},
|
||||
refreshInspectorTorrents: function(full) {
|
||||
var tr = this;
|
||||
var ids = tr.getSelectedTorrentIds();
|
||||
if (ids.length > 0)
|
||||
this.remote.getTorrentDetails(ids, full, function(a,b){tr.updateFromTorrentGet(a,b);});
|
||||
|
||||
refreshInspectorTorrents: function(full)
|
||||
{
|
||||
// some torrent fields are only used by the inspector, so we defer loading them
|
||||
// until the user is viewing the torrent in the inspector.
|
||||
if ($('#torrent_inspector').is(':visible')) {
|
||||
var ids = this.getSelectedTorrentIds();
|
||||
if (ids && ids.length) {
|
||||
var fields = ['id'].concat(Torrent.Fields.StatsExtra);
|
||||
this.remote.updateTorrents(ids, fields, this.updateFromTorrentGet, this);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
onRowClicked: function(ev, row)
|
||||
|
|
|
@ -133,59 +133,19 @@ TransmissionRemote.prototype =
|
|||
this.sendRequest(o, callback, async);
|
||||
},
|
||||
|
||||
getTorrentInitial: function(torrent_ids, callback) {
|
||||
updateTorrents: function(torrentIds, fields, callback, context) {
|
||||
var o = {
|
||||
method: 'torrent-get',
|
||||
arguments: {
|
||||
fields: ['id'].concat(Torrent.Fields.Metadata, Torrent.Fields.Stats)
|
||||
'arguments': {
|
||||
'fields': fields,
|
||||
}
|
||||
};
|
||||
|
||||
if (torrent_ids)
|
||||
o.arguments.ids = torrent_ids;
|
||||
|
||||
this.sendRequest(o, function(data){ callback(data.arguments.torrents, data.arguments.removed);});
|
||||
},
|
||||
|
||||
getTorrentMetadata: function(torrent_ids, callback) {
|
||||
var o = {
|
||||
method: 'torrent-get',
|
||||
arguments: {
|
||||
fields: ['id'].concat(Torrent.Fields.Metadata)
|
||||
}
|
||||
};
|
||||
|
||||
if (torrent_ids)
|
||||
o.arguments.ids = torrent_ids;
|
||||
|
||||
this.sendRequest(o, function(data) {callback(data.arguments.torrents)});
|
||||
},
|
||||
|
||||
getTorrentStats: function(torrent_ids, callback) {
|
||||
var o = {
|
||||
method: 'torrent-get',
|
||||
arguments: {
|
||||
'ids': torrent_ids,
|
||||
fields: ['id'].concat(Torrent.Fields.Stats)
|
||||
}
|
||||
};
|
||||
|
||||
this.sendRequest(o, function(data) {callback(data.arguments.torrents, data.arguments.removed);});
|
||||
},
|
||||
|
||||
/* called for the torrents in the inspector aka details dialog */
|
||||
getTorrentDetails: function(torrent_ids, full, callback) {
|
||||
var f = ['id'].concat(Torrent.Fields.StatsExtra);
|
||||
if (full) // these only need to be loaded once...
|
||||
f = f.concat(Torrent.Fields.InfoExtra);
|
||||
var o = {
|
||||
method: 'torrent-get',
|
||||
arguments: {
|
||||
'ids': torrent_ids,
|
||||
fields: f,
|
||||
}
|
||||
};
|
||||
this.sendRequest(o, function(data) {callback(data.arguments.torrents,null)});
|
||||
if (torrentIds)
|
||||
o['arguments'].ids = torrentIds;
|
||||
this.sendRequest(o, function(response) {
|
||||
var args = response['arguments'];
|
||||
callback.call(context,args.torrents,args.removed);
|
||||
});
|
||||
},
|
||||
|
||||
changeFileCommand: function(command, rows) {
|
||||
|
|
Loading…
Reference in a new issue