Browse Source

Label for space, change round for speed/size, fix ratio

Antoine Leroyer 11 years ago
parent
commit
104385e7ca
4 changed files with 59 additions and 59 deletions
  1. 3 3
      lib/rSeed/rtorrent.rb
  2. 2 10
      lib/rSeed/server.rb
  3. 28 17
      public/js/custom.js
  4. 26 29
      views/index.haml

+ 3 - 3
lib/rSeed/rtorrent.rb

@@ -49,12 +49,12 @@ module RSeed
       return formated_response
     end
 
-    def getUpDown()
+    def getUpDown
       torrents = self.getAll
       stats = { :up => 0, :down => 0}
       torrents.each do |t|
-        stats[:up] += t["up"] / 1024
-        stats[:down] += t["down"] / 1024
+        stats[:up] += t["up"] 
+        stats[:down] += t["down"]
       end
       return stats
     end

+ 2 - 10
lib/rSeed/server.rb

@@ -77,15 +77,7 @@ module RSeed
     # ----- 
     get '/' do
       tlist = @rtorrent.getAll
-      up = 0
-      down = 0
-      tlist.each do |torrent|
-        up = up + torrent['up'] / 1024
-        down = down + torrent['down'] / 1024
-      end
-      stats = Hash.new
-      stats = { "down" => down, "up" => up }
-      haml :index, :locals => { :tlist => tlist, :stats => stats }
+      haml :index, :locals => { :tlist => tlist }
     end
 
     # DDL
@@ -133,7 +125,7 @@ module RSeed
       content_type :json
       case params[:request]
       when 'get_updown_total'
-        @rtorrent.getUpDown().to_json
+        @rtorrent.getUpDown.to_json
       when 'get_list'
         @rtorrent.getAll.to_json
       else

+ 28 - 17
public/js/custom.js

@@ -3,8 +3,6 @@ window.setInterval(function(){
   refreshList();
 }, 5000);
 
-$(document).ready(function() {
-  $.ajaxSetup({ cache: false });
   $("a[data-torrent-id]").click(function() {
       var hash = $(this).attr("data-torrent-id");
       $.ajax({
@@ -17,16 +15,15 @@ $(document).ready(function() {
       });
   });
 
-  $("td[data-torrent-percent]").css({
-    "background": "linear-gradient(to right, #43ac6a 100%, #f9f9f9 100%, #f9f9f9)"
-  });
-
+$(document).ready(function() {
+  $.ajaxSetup({ cache: false });
+  refreshList();
 });
 
 function refreshUpDownTotal() {
   $.getJSON( "api/get_updown_total", function( data ) {
-    $("#up-info").text( data["up"] + " ko/s" );
-    $("#down-info").text( data["down"] + " ko/s" );
+    $("#up-info").text(bytesToSize(data["up"], true));
+    $("#down-info").text(bytesToSize(data["down"], true));
   });
 }
 
@@ -35,19 +32,33 @@ function refreshList(){
   $.getJSON( "api/get_list", function ( data ) {
     $.each( data, function( key, val ) {
       percent = (val['completed_bytes'] / val['size_bytes']) * 100;
-      html = '<td style="background: linear-gradient(to right, #43ac6a ' + percent + '%, #f9f9f9 ' + percent + '%, #f9f9f9)"><h5>' + val['name'] + '</h5></td>';
-      html += '<td class="text-center">' + (val['ratio'] / 100) + '</td>';
-      html += '<td class="text-center">' + bytesToSize(val['up']) + '</td>';
-      html += '<td class="text-center">' + bytesToSize(val['down']) + '</td>';
+      if(percent == 100) {
+        space = bytesToSize(val['size_bytes'], false);
+      } else {
+        space = bytesToSize(val['completed_bytes'], false) + ' | ' + bytesToSize(val['size_bytes'], false);
+      }
+      html = '<td style="background: linear-gradient(to right, #43ac6a ' + percent + '%, #f9f9f9 ' + percent + '%, #f9f9f9)">'
+      html += val['name'];
+      html += '<span class="secondary round label right">' + space + '<span>';
+      html += '</td>';
+      html += '<td class="text-center">' + (val['ratio'] / 1000) + '</td>';
+      html += '<td class="text-center">' + bytesToSize(val['up'], true) + '</td>';
+      html += '<td class="text-center">' + bytesToSize(val['down'], true) + '</td>';
       html += '<td class="text-center"><a href="#" data-torrent-id="' + val['hash'].substr(0,10) + '">SHARE</a></td>';
       $("tr[data-torrent-id='" + val['hash'] + "']").html(html);
     });
   });
+
 }
 
-function bytesToSize(bytes) {
-  var sizes = ['o/s', 'ko/s', 'mo/s', 'go/s', 'to/s'];
-  if (bytes == 0) return '0 o/s';
-  var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
-  return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
+function bytesToSize(bytes, speed) {
+  var sizes = ['o', 'Ko', 'Mo', 'Go', 'To'];
+  var speeds = ['o/s', 'Ko/s', 'Mo/s'];
+  if (bytes == 0) return '-';
+  var i = parseFloat(Math.floor(Math.log(bytes) / Math.log(1024)));
+  if(speed) {
+    return Math.round(bytes / Math.pow(1024, i) * 10) / 10 + ' ' + speeds[i];
+  } else {
+    return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];
+  }
 };

+ 26 - 29
views/index.haml

@@ -13,43 +13,40 @@
         %section.top-bar-section
           %ul.right
             %li.has-form
-              %a.button.radius.success= "&#8593; <strong id='up-info'>#{stats["up"]} ko/s</strong>"
+              %a.button.radius.success= "&#8593; <strong id='up-info'></strong>"
             %li.divider
             %li.has-form
-              %a.button.radius= "&#8595; <strong id='down-info'>#{stats["down"]} ko/s</strong>"
+              %a.button.radius= "&#8595; <strong id='down-info'></strong>"
           %ul.left
             %li
               %a.button.radius.alert{href: "#"} Add
-    %section.main-section{style: "margin-top : 50px;"}
-      .row
-        .large-12.columns
-          %table
-            %thead
-              %tr
-                %th.large-8 Torrent
-                %th Ratio
-                %th Upload
-                %th Download
-                %th Publish
-            %tbody
-              - tlist.each do |t|
-                %tr{data: {:torrent_id => "#{t["hash"]}"}} 
-                  %td{data: {:torrent_percent => "#{(t["completed_bytes"].to_f / t["size_bytes"].to_f * 100).round(1)}%"}}
-                    %h5= t["name"]
-                  %td.text-center= "#{t["ratio"].to_f/1000}"      
-                  %td.text-center= "#{t["up"].to_i/1024} ko/s"
-                  %td.text-center= "#{t["down"].to_i/1024} ko/s"
-                  %td.text-center
-                    .button-bar
-                      %ul.button-group.radius
-                        / %li
-                        /  %a.tiny.button.alert{href: "#"} &#10060;
-                        %li
-                          %a{href: "#", data: {:torrent_id => "#{t["hash"][0,10]}"} } Share
+    %section.main-section{style: "margin: 50px 10px"}
+      %table{style: "width: 100%;"}
+        %thead
+          %tr
+            %th Torrent
+            %th Ratio
+            %th Upload
+            %th Download
+            %th Publish
+        %tbody
+          - tlist.each do |t|
+            %tr{data: {:torrent_id => "#{t["hash"]}"}} 
+              %td
+                %h5= t["name"]
+              %td.text-center= "#{t["ratio"].to_f/1000}"      
+              %td.text-center= "#{t["up"].to_i/1024} ko/s"
+              %td.text-center= "#{t["down"].to_i/1024} ko/s"
+              %td.text-center
+                .button-bar
+                  %ul.button-group.radius
+                    / %li
+                    /  %a.tiny.button.alert{href: "#"} &#10060;
+                    %li
+                      %a{href: "#", data: {:torrent_id => "#{t["hash"][0,10]}"} } Share
     %a.exit-off-canvas
 
 %script{:src => '/js/vendor/jquery.js'}
-%script{:src => 'https://cdnjs.cloudflare.com/ajax/libs/css3finalize/3.4.0/jquery.css3finalize.min.js'}
 %script{:src => '/js/foundation.min.js'}
 %script{:src => '/js/notify-combined.min.js'}
 %script{:src => '/js/custom.js'}