Browse Source

Draft of index

Antoine Leroyer 11 years ago
parent
commit
f461c337e4
4 changed files with 52 additions and 31 deletions
  1. 1 1
      config.ru
  2. 11 5
      lib/rSeed/server.rb
  3. 39 24
      views/index.haml
  4. 1 1
      views/layout.haml

+ 1 - 1
config.ru

@@ -1,7 +1,7 @@
 require "./lib/rSeed"
 
 app = RSeed::Server.new do
-  # set :environment, :development
+  set :environment, :development
   set :data_path, File.join(File.dirname(__FILE__), "data")
 end
 

+ 11 - 5
lib/rSeed/server.rb

@@ -66,13 +66,19 @@ module RSeed
     # ----- 
     get '/' do
       rtorrent = XMLRPC::Client.new("seed.aonoscantrad.fr", "/RPC2", 80)
+      stats = Hash.new
       begin
-        results = rtorrent.call("d.multicall", "main", "d.name=", "d.completed_bytes=", "d.size_bytes=", "d.ratio=", "d.up.rate=", "d.down.rate=")
-      rescue
-        puts "Shit happened"
+        results = rtorrent.call("d.multicall", "main", "d.name=", "d.completed_bytes=", "d.size_bytes=", "d.ratio=", "d.up.rate=", "d.down.rate=", "d.hash=")
+        down = rtorrent.call("get_download_rate").to_i / 1024
+        up = rtorrent.call("system", "upload_rate").to_i / 1024
+        stats = { "down" => down, "up" => up }
+      rescue XMLRPC::FaultException => e
+        puts "Error:"
+        puts e.faultCode
+        puts e.faultString
       end
-      puts "#{results}"
-      haml :index, :locals => { :result => results }
+      puts "#{stats}"
+      haml :index, :locals => { :result => results, :stats => stats }
     end
   end
 end

+ 39 - 24
views/index.haml

@@ -1,36 +1,51 @@
 -# coding: utf-8
-%h1 rSeed
+%h1= "rSeed <small>#{stats["down"]} / #{stats["up"]}</small>"
 %ul{:class => "nav nav-tabs"}
   %li.active
     %a 
       Active
-      %span.badge 2
+      %span.badge= result.size
   %li 
     %a 
       Complete
-      %span.badge 5
+      %span.badge 0
   %li 
     %a 
       Inactive
-      %span.badge 3
-  
-%table{:class => "table table-hover"}
-  %thead
-    %tr
-      %th Name
-      %th Progress
-      %th Ratio
-      %th Up / Down
-      %th Share
-  %tbody
-    - result.each do |t|
-      %tr
-        %td= t[0] 
-        %td
-          .progress
-            %div{:class => "progress-bar progress-bar-success", :style => "width: #{(t[1].to_i/t[2].to_i)*100}%"}
+      %span.badge 0
+
+%br
+/- result.sort.each do |t|
+/  %td= t[0] 
+/  %td
+/    .progress{:style => "margin-bottom: 0px;"}
+/      %div{:class => "progress-bar progress-bar-success", :style => "width: #{(t[1].to_i/t[2].to_i)*100}%;"}
+/        %span.sr-only "#{(t[1].to_i/t[2].to_i)*100}%"
+/  %td= "#{t[3].to_f/1000}"
+/  %td= "#{t[4].to_i/1024} ko/s"
+/  %td= "#{t[5].to_i/1024} ko/s"
+/  %td
+/    %span.glyphicon{:class => "glyphicon-globe"}
+
+#accordion.panel-group
+  - result.each do |t|
+    .panel.panel-success 
+      .panel-heading
+        %h4.panel-title
+          %a{data: {toggle: "collapse", parent: "#accordion"}, href: "##{t[6][0,5]}"}= t[0]
+      .panel-collapse.collapse{id: "#{t[6][0,5]}"}
+        .panel-body
+          .progress{:style => "margin-bottom: 0px;"}
+            %div{:class => "progress-bar progress-bar-success", :style => "width: #{(t[1].to_i/t[2].to_i)*100}%;"}
               %span.sr-only "#{(t[1].to_i/t[2].to_i)*100}%"
-        %td= "#{t[3].to_f/1000}"
-        %td= "#{t[4].to_i/1024} ko/s"
-        %td
-          %span.glyphicon{:class => "glyphicon-globe"}
+        %table.table.table-bordered
+          %thead
+            %tr
+              %th Ratio
+              %th Upload Speed
+              %th Download Speed
+          %tbody
+            %tr
+              %td= "#{t[3].to_f/1000}"
+              %td= "#{t[4].to_i/1024} ko/s"
+              %td= "#{t[5].to_i/1024} ko/s"

+ 1 - 1
views/layout.haml

@@ -3,8 +3,8 @@
     %title rSeed
     %meta{'http-equiv' => 'content-type', :content => 'text/html; charset=utf-8'}
     %link{:rel => :stylesheet, :href => "/css/bootstrap.min.css", :type => "text/css"}
-    %script{:type => 'text/javascript', :src => '/js/bootstrap.min.js'}
     %script{:type => 'text/javascript', :src => '/js/jquery.min.js'}
+    %script{:type => 'text/javascript', :src => '/js/bootstrap.min.js'}
     %body
       .container
         = yield