Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 28 additions & 8 deletions interfaces/default/html/transmission.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,34 @@ <h1 class="page-header page-title">
<i>Both magnet URL's and (server located) .torrent files are accepted.</i>
</div>

<table class="table table-striped table-hover">
<table id="torrent-table" class="table table-striped table-hover">
<thead>
<tr>
<th>File</th>
<th class="span1">Ratio</th>
<th class="span1">ETA</th>
<th class="span2">Status</th>
<th class="span3">Progress</th>
<tr class="sort-fields">
<th>
<a class="btn btn-default" data-sort-field="name">
File&nbsp;<i></i>
</a>
</th>
<th>
<a class="btn btn-default" data-sort-field="uploadRatio">
Ratio&nbsp;<i></i>
</a>
</th>
<th>
<a class="btn btn-default" data-sort-field="eta">
ETA&nbsp;<i></i>
</a>
</th>
<th>
<a class="btn btn-default" data-sort-field="status">
Status&nbsp;<i></i>
</a>
</th>
<th>
<a class="btn btn-default" data-sort-field="percentDone">
Progress&nbsp;<i></i>
</a>
</th>
<th class="span1"></th>
</tr>
</thead>
Expand All @@ -42,4 +62,4 @@ <h1 class="page-header page-title">

<i class="icon-spinner icon-spin spinner"></i>
</div>
</div>
</div>
82 changes: 79 additions & 3 deletions interfaces/default/js/transmission.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// Last time we checked, was there a problem connecting to transmission?
var transmissionConnectionError = false;

htpc = {
transmission: {
}
};

$(document).ready(function(){
$('.spinner').show();
getTorrents();
Expand All @@ -10,6 +15,41 @@ $(document).ready(function(){
getStatus();
}, 4000);

// sort fields
$(document.body).off('click', '#torrent-table .sort-fields a');
$(document.body).on('click', '#torrent-table .sort-fields a', function(event) {
event.preventDefault();
var $this = $(this);
var sort_on = $this.attr('data-sort-field');

var $i = $this.children('i');
if ($i.hasClass('icon-chevron-down')) {
$i.removeClass('icon-chevron-down');
$i.addClass('icon-chevron-up');
sort_on += ':asc';
} else if ($i.hasClass('icon-chevron-up')) {
$i.removeClass('icon-chevron-up');
$i.addClass('icon-chevron-down');
sort_on += ':desc';
} else {
$i.addClass('icon-chevron-down');
sort_on += ':desc';
}

$('#torrent-table .sort-fields a').each(function(x, a) {
var $a = $(a);
if ($a.attr('data-sort-field') != $this.attr('data-sort-field')) {
var $i = $a.children('i');
$i
.removeClass('icon-chevron-up')
.removeClass('icon-chevron-down');
}
});

getTorrents({sort_on: sort_on});
});


// Torrent button ajax load
$(document.body).off('click', '#torrent-queue .torrent-action a');
$(document.body).on('click', '#torrent-queue .torrent-action a', function(event) {
Expand Down Expand Up @@ -60,7 +100,10 @@ $(document).ready(function(){
});
});

function getTorrents(){
function getTorrents(kwargs) {
if (kwargs == null)
kwargs = {};

$.ajax({
url: WEBDIR + 'transmission/queue',
success: function(response){
Expand All @@ -72,7 +115,40 @@ function getTorrents(){
$('#torrent-queue').html('<tr><td colspan="5">Queue is empty</td></tr>');
}

$.each(response.arguments.torrents, function(index, torrent){
var torrents = response.arguments.torrents;

var sort_on = kwargs.sort_on;
if (sort_on == null && htpc.transmission.last_sort_on != null)
sort_on = htpc.transmission.last_sort_on;

if (sort_on != null)
htpc.transmission.last_sort_on = sort_on;

if (sort_on) {
var split = sort_on.split(':');
if (split.length == 1)
split.push('desc');

var field = split[0];
var ordering = split[1];

torrents.sort(function(first, second) {
var x = first;
var y = second;
if (ordering == 'asc') {
x = second
y = first;
}

if (x[field] < y[field])
return -1;
if (x[field] > y[field])
return 1;
return 0;
});
}

$.each(torrents, function(index, torrent){
tr = $('<tr>');

var progressBar = $('<div>');
Expand Down Expand Up @@ -213,4 +289,4 @@ function getReadableTime(timeInSeconds) {
function torrentStatus(statusNr) {
states = ['Paused', 'unkown 1', 'unknown 2', 'Queued', 'Downloading', 'unknown 5', 'Seeding']
return states[statusNr]
}
}