Skip to content

Commit

Permalink
Issue #13 - action button
Browse files Browse the repository at this point in the history
pause and resume torrent
  • Loading branch information
styxit committed Aug 14, 2013
1 parent df29e2e commit 37cdc6b
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 14 deletions.
17 changes: 8 additions & 9 deletions interfaces/default/html/transmission.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<h1 class="page-header page-title">
<a href="http://${settings.get('transmission_host')}:${settings.get('transmission_port')}" target="_blank">${settings.get('transmission_name', 'Transmission')}</a>
<small>
<strong>Speed:</strong>
<i class="icon-arrow-up"></i> <span id="queue_upload"></span>
<i class="icon-arrow-down"></i> <span id="queue_download"></span>
</small>
Expand All @@ -14,18 +13,18 @@ <h1 class="page-header page-title">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>Id</th>
<th>File</th>
<th>Ratio</th>
<th>ETA</th>
<th>Status</th>
<th>Progress</th>
<th class="span5">File</th>
<th class="span1">Ratio</th>
<th class="span1">ETA</th>
<th class="span1">Status</th>
<th class="span3">Progress</th>
<th class="span1"></th>
</tr>
</thead>
<tbody id="torrent-queue">
</tbody>
</table>

<div class="spinner"></div>
<i class="icon-spinner icon-spin spinner"></i>
</div>
</div>
</div>
54 changes: 49 additions & 5 deletions interfaces/default/js/transmission.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ $(document).ready(function(){
getTorrents();
getStatus();
}, 4000);

// Torrent button ajax load
$(document.body).off('click', '#torrent-queue .torrent-action a');
$(document.body).on('click', '#torrent-queue .torrent-action a', function(event) {
event.preventDefault();

// set spinner inside button
$(this).html('<i class="icon-spinner icon-spin"></i>');

// do ajax request
$.ajax({
url: $(this).attr('href'),
success: function(response) {
// Refresh torrent list after successfull request with a tiny delay
if (response.result == 'success') {
window.setTimeout(getTorrents, 500);
}
}
});
});
});

function getTorrents(){
Expand All @@ -31,16 +51,19 @@ function getTorrents(){
// Round to 2 decimals
ratio = Math.round(torrent.uploadRatio*100) / 100;

// Action button
actionButton = generateTorrentActionButton(torrent);

tr.append(
$('<td>').text(torrent.id),
$('<td>').html(torrent.name
+'<br><small><i class="icon-arrow-up"></i> ' + getReadableFileSizeString(torrent.rateUpload)
+'/s <i class="icon-arrow-down"></i> ' + getReadableFileSizeString(torrent.rateDownload) + '/s</small>'
+'<br><small><i class="icon-long-arrow-up"></i> ' + getReadableFileSizeString(torrent.rateUpload)
+'/s <i class="icon-long-arrow-down"></i> ' + getReadableFileSizeString(torrent.rateDownload) + '/s</small>'
),
$('<td>').text(ratio),
$('<td>').text(getReadableTime(torrent.eta)),
$('<td>').text(torrentStatus(torrent.status)),
$('<td>').addClass('span3').html(progress)
$('<td>').addClass('span3').html(progress),
$('<td>').addClass('torrent-action').append(actionButton)
);
$('#torrent-queue').append(tr);
});
Expand All @@ -50,6 +73,22 @@ function getTorrents(){
});
}

function generateTorrentActionButton(torrent) {
button = $('<a>').addClass('btn btn-mini');
// Resume button if torrent is paused
if (torrent.status == 0) {
button.html('<i class="icon-play"></i>');
button.attr('href', WEBDIR + 'transmission/start/' + torrent.id);
button.attr('title', 'Resume torrent');
} else { // Pause button
button.html('<i class="icon-pause"></i>');
button.attr('href', WEBDIR + 'transmission/stop/' + torrent.id);
button.attr('title', 'Pause torrent');
}

return button;
}

/**
* Get General transmission stats
*/
Expand Down Expand Up @@ -94,12 +133,17 @@ function getReadableTime(timeInSeconds) {
var minutes = parseInt( timeInSeconds / 60 ) % 60;
var seconds = parseInt(timeInSeconds % 60);

// Add leading 0 and : to seconds
seconds = ':'+ (seconds < 10 ? "0" + seconds : seconds);

if (days < 1) {
days = '';
} else {
days = days + 'd ';
// remove seconds if the eta is 1 day or more
seconds = '';
}
return days + hours + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
return days + hours + ":" + (minutes < 10 ? "0" + minutes : minutes) + seconds;
};

/**
Expand Down

0 comments on commit 37cdc6b

Please sign in to comment.