From 37c4db459f6d88bdf1babe9693d9709829a6abed Mon Sep 17 00:00:00 2001 From: Rocky Burt Date: Sat, 3 May 2014 11:35:07 -0230 Subject: [PATCH] Added sorting ability to transmission torrents --- interfaces/default/html/transmission.html | 36 +++++++--- interfaces/default/js/transmission.js | 82 ++++++++++++++++++++++- 2 files changed, 107 insertions(+), 11 deletions(-) diff --git a/interfaces/default/html/transmission.html b/interfaces/default/html/transmission.html index d6d27feb1..a9ceabc7a 100644 --- a/interfaces/default/html/transmission.html +++ b/interfaces/default/html/transmission.html @@ -25,14 +25,34 @@

Both magnet URL's and (server located) .torrent files are accepted. - +
- - - - - - + + + + + + @@ -42,4 +62,4 @@

- \ No newline at end of file + diff --git a/interfaces/default/js/transmission.js b/interfaces/default/js/transmission.js index f5d51eb1d..b54ca01c0 100644 --- a/interfaces/default/js/transmission.js +++ b/interfaces/default/js/transmission.js @@ -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(); @@ -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) { @@ -60,7 +100,10 @@ $(document).ready(function(){ }); }); -function getTorrents(){ +function getTorrents(kwargs) { + if (kwargs == null) + kwargs = {}; + $.ajax({ url: WEBDIR + 'transmission/queue', success: function(response){ @@ -72,7 +115,40 @@ function getTorrents(){ $('#torrent-queue').html('

'); } - $.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 = $(''); var progressBar = $('
'); @@ -213,4 +289,4 @@ function getReadableTime(timeInSeconds) { function torrentStatus(statusNr) { states = ['Paused', 'unkown 1', 'unknown 2', 'Queued', 'Downloading', 'unknown 5', 'Seeding'] return states[statusNr] -} \ No newline at end of file +}
FileRatioETAStatusProgress
+ + File  + + + + Ratio  + + + + ETA  + + + + Status  + + + + Progress  + +
Queue is empty