diff --git a/models/client.js b/models/client.js index 96ab628c..3beefda9 100644 --- a/models/client.js +++ b/models/client.js @@ -121,14 +121,20 @@ var mapProps = function(props, data) { return mappedObject; }; -var createMulticallRequest = function(data) { +var createMulticallRequest = function(data, params) { + + params = params || []; var methodCall = []; + if (!util.isArray(data)) { + data = [data]; + } + for (i = 0, len = data.length; i < len; i++) { methodCall.push({ 'methodName': data[i], - 'params': [] + 'params': params }); } @@ -142,15 +148,78 @@ client.prototype.getTorrentList = function(callback) { rTorrent.get('d.multicall', defaults.torrentPropertyMethods) .then(function(data) { - // create torrent array, each item in the array being - // an object with human-readable property values - var torrents = mapProps(defaults.torrentProperties, data, 'torrent-list'); + try { - // add percent complete - Object.keys(torrents).map(function(hash) { + // create torrent array, each item in the array being + // an object with human-readable property values + var torrents = mapProps(defaults.torrentProperties, data, 'torrent-list'); - torrents[hash]['percentComplete'] = (torrents[hash]['bytesDone'] / torrents[hash]['sizeBytes'] * 100).toFixed(2); - }); + // add percent complete + Object.keys(torrents).map(function(hash) { + + var torrent = torrents[hash]; + var percentComplete = (torrent['bytesDone'] / torrent['sizeBytes'] * 100).toFixed(2); + + var eta = function() { + + if (torrent['downloadRate'] > 0) { + + var seconds = (torrent['sizeBytes'] - torrent['bytesDone']) / torrent['downloadRate']; + var years = Math.floor(seconds / 31536000); + var weeks = Math.floor((seconds % 31536000) / 604800); + var days = Math.floor(((seconds % 31536000) % 604800) / 86400); + var hours = Math.floor((((seconds % 31536000) % 604800) % 86400) / 3600); + var minutes = Math.floor(((((seconds % 31536000) % 604800) % 86400) % 3600) / 60); + var wholeSeconds = Math.floor((((((seconds % 31536000) % 604800) % 86400) % 3600) % 60) / 60); + var timeRemaining = {}; + + if (years > 0) { + timeRemaining = { + years: years, + weeks: weeks + } + } else if (weeks > 0) { + timeRemaining = { + weeks: weeks, + days: days + } + } else if (days > 0) { + timeRemaining = { + days: days, + hours: hours + } + } else if (hours > 0) { + timeRemaining = { + hours: hours, + minutes: minutes + } + } else if (minutes > 0) { + timeRemaining = { + minutes: minutes, + seconds: wholeSeconds + } + } else { + timeRemaining = { + seconds: wholeSeconds + } + } + + return timeRemaining; + + } else { + + return 'Infinity'; + } + + } + + torrent['percentComplete'] = percentComplete; + torrent['eta'] = eta(); + }); + + } catch (error) { + console.log(error); + } callback(null, torrents); }, function(error) { @@ -165,31 +234,41 @@ client.prototype.getTorrentList = function(callback) { client.prototype.stopTorrent = function(hash, callback) { + hash = hash.split(','); + if (!util.isArray(hash)) { hash = [hash]; } - rTorrent.get('d.stop', hash).then(function(data) { - callback(null, data); - }, function(error) { - console.log(error); - callback(error, null); - }); + for (i = 0, len = hash.length; i < len; i++) { + + rTorrent.get('d.stop', [hash[i]]).then(function(data) { + callback(null, data); + }, function(error) { + callback(error, null); + }); + + } }; client.prototype.startTorrent = function(hash, callback) { + hash = hash.split(','); + if (!util.isArray(hash)) { hash = [hash]; } - rTorrent.get('d.start', hash).then(function(data) { - callback(null, data); - }, function(error) { - console.log(error); - callback(error, null); - }); + for (i = 0, len = hash.length; i < len; i++) { + + rTorrent.get('d.start', [hash[i]]).then(function(data) { + callback(null, data); + }, function(error) { + callback(error, null); + }); + + } }; diff --git a/source/sass/objects/_torrents.scss b/source/sass/objects/_torrents.scss index c91909fe..182ddfa8 100644 --- a/source/sass/objects/_torrents.scss +++ b/source/sass/objects/_torrents.scss @@ -56,6 +56,7 @@ } &--primary { + flex: 1; .torrent & { color: $torrent--primary--foreground; @@ -66,6 +67,7 @@ &--secondary { display: flex; + flex: 2; font-size: 0.85em; &--sub { diff --git a/source/scripts/actions/TorrentActions.js b/source/scripts/actions/TorrentActions.js index f41f39a9..ce023fd3 100644 --- a/source/scripts/actions/TorrentActions.js +++ b/source/scripts/actions/TorrentActions.js @@ -15,12 +15,12 @@ var performAction = function(action, hash, success, error) { console.error(torrentsData, status, err.toString()); }.bind(this) }); + }; var TorrentActions = { click: function(hash) { - AppDispatcher.dispatch({ actionType: TorrentConstants.TORRENT_CLICK, hash: hash diff --git a/source/scripts/components/action-bar/ActionBar.js b/source/scripts/components/action-bar/ActionBar.js index 38a7248a..6fe6b520 100644 --- a/source/scripts/components/action-bar/ActionBar.js +++ b/source/scripts/components/action-bar/ActionBar.js @@ -1,15 +1,30 @@ var React = require('react'); var Action = require('./Action'); +var UIStore = require('../../stores/UIStore'); +var TorrentActions = require('../../actions/TorrentActions'); + +var getSelectedTorrents = function() { + + return { + selectedTorrents: UIStore.getSelectedTorrents() + } +}; var FilterBar = React.createClass({ getInitialState: function() { - return null; + return { + selectedTorrents: [] + }; }, - handleClick: function(event) { - console.log('click ' + event.target); + componentDidMount: function() { + UIStore.addChangeListener(this._onUIStoreChange); + }, + + componentWillUnmount: function() { + TorrentStore.removeChangeListener(this._onUIStoreChange); }, render: function() { @@ -17,13 +32,30 @@ var FilterBar = React.createClass({ return ( ); + }, + + _pause: function() { + + }, + + _start: function() { + TorrentActions.start(this.state.selectedTorrents); + }, + + _stop: function() { + TorrentActions.stop(this.state.selectedTorrents); + }, + + _onUIStoreChange: function() { + this.setState(getSelectedTorrents); } + }); diff --git a/source/scripts/components/torrent-list/Torrent.js b/source/scripts/components/torrent-list/Torrent.js index c65f0990..4e892aea 100644 --- a/source/scripts/components/torrent-list/Torrent.js +++ b/source/scripts/components/torrent-list/Torrent.js @@ -24,37 +24,95 @@ var Torrent = React.createClass({ var uploadTotal = format.data(torrent.uploadTotal); var downloadRate = format.data(torrent.downloadRate, '/s'); var downloadTotal = format.data(torrent.downloadTotal); + var completed = format.data(torrent.bytesDone); + var totalSize = format.data(torrent.sizeBytes); + + var eta = (function() { + + if (torrent.eta === 'Infinity') { + return '∞'; + } else if (torrent.eta.years > 0) { + return ( + + {torrent.eta.years}y + + ); + } else if (torrent.eta.weeks > 0) { + return ( + + {torrent.eta.weeks}w + {torrent.eta.days}d + + ); + } else if (torrent.eta.days > 0) { + return ( + + {torrent.eta.days}d + {torrent.eta.hours}h + + ); + } else if (torrent.eta.hours > 0) { + return ( + + {torrent.eta.hours}h + {torrent.eta.minutes}m + + ); + } else if (torrent.eta.minutes > 0) { + return ( + + {torrent.eta.minutes}m + {torrent.eta.seconds}s + + ); + } else { + return ( + + {torrent.eta.seconds}s + + ); + } + + })(); return (