Skip to content

Commit

Permalink
add peers tab
Browse files Browse the repository at this point in the history
  • Loading branch information
Binux committed Jan 29, 2014
1 parent 8930f5c commit 5290b20
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 4 deletions.
7 changes: 6 additions & 1 deletion css/main.css
Expand Up @@ -328,7 +328,8 @@
}
#ib-status,
#ib-files,
#ib-options {
#ib-options,
#ib-peers {
position: relative;
margin: 18px 0;
}
Expand Down Expand Up @@ -380,6 +381,10 @@
#ib-options li > * {
float: left;
}
#ib-peers .ip_port {
display: inline-block;
width: 250px;
}

/* task-contextmenu */

Expand Down
8 changes: 8 additions & 0 deletions index.html
Expand Up @@ -305,11 +305,13 @@ <h2>Settings</h2>
<li class="active"><a href="#ib-status" data-toggle="tab">Status</a></li>
<li><a href="#ib-files" data-toggle="tab">Files</a></li>
<li><a id="ib-options-a" href="#ib-options" data-toggle="tab">Options</a></li>
<li><a id="ib-peers-a" class="hide" style="display:none;" href="#ib-peers" data-toggle="tab">Peers</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="ib-status"> </div>
<div class="tab-pane" id="ib-files"> </div>
<div class="tab-pane" id="ib-options"> </div>
<div class="tab-pane hide" style="display:none;" id="ib-peers"> </div>
</div>
</div>
</div>
Expand Down Expand Up @@ -359,6 +361,12 @@ <h2>Settings</h2>
</form>
</script>

<script id="ib-peers-tpl" type="text/mustache-template">
{{#.}}
<li><span class="ip_port">{{ip}}:{{port}}</span> <b>{{#_v.bitfield_to_percent}}{{bitfield}}{{/_v.bitfield_to_percent}}%</b> <i class="icon-download"></i>{{#_v.format_size}}{{downloadSpeed}}{{/_v.format_size}}/s <i class="icon-upload"></i>{{#_v.format_size}}{{uploadSpeed}}{{/_v.format_size}}/s</li>
{{/.}}
</script>

<script id="other-task-empty" type="text/mustache-template">
<li>
<div class="empty-tasks">
Expand Down
16 changes: 15 additions & 1 deletion js/aria2.js
Expand Up @@ -558,7 +558,7 @@ if (typeof ARIA2=="undefined"||!ARIA2) var ARIA2=(function(){
get_options: function(gid) {
ARIA2.request("getOption", [gid],
function(result) {
console.debug(result);
//console.debug(result);

$("#ib-options").empty().append(YAAW.tpl.ib_options(result.result));
if ($("#task-gid-"+gid).attr("data-status") == "active")
Expand All @@ -577,6 +577,16 @@ if (typeof ARIA2=="undefined"||!ARIA2) var ARIA2=(function(){
);
},

get_peers: function(gid) {
ARIA2.request("getPeers", [gid],
function(result) {
console.debug(result);

$("#ib-peers").empty().append(YAAW.tpl.ib_peers(result.result));
}
);
},

pause_all: function() {
ARIA2.request("pauseAll", [],
function(result) {
Expand Down Expand Up @@ -700,6 +710,10 @@ if (typeof ARIA2=="undefined"||!ARIA2) var ARIA2=(function(){
};
$("#ib-status").empty().append(YAAW.tpl.ib_status(result));
$("#ib-files").empty().append(YAAW.tpl.ib_files(result));
if (result.bittorrent) {
$("#ib-peers").show();
$("#ib-peers-a").show();
}
}
);
},
Expand Down
41 changes: 40 additions & 1 deletion js/yaaw.js
Expand Up @@ -105,6 +105,10 @@ var YAAW = (function() {
ARIA2.get_options($(".info-box").attr("data-gid"));
});

$("#ib-peers-a").live("click", function() {
ARIA2.get_peers($(".info-box").attr("data-gid"));
});

var active_task_allowed_options = ["max-download-limit", "max-upload-limit"];
$("#ib-options-save").live("click", function() {
var options = {};
Expand Down Expand Up @@ -195,16 +199,51 @@ var YAAW = (function() {

view: {
bitfield: function() {
var graphic = "░▒▓█";
return function(text) {
var len = text.length;
var result = "";
var graphic = "░▒▓█";
for (var i=0; i<len; i++)
result += graphic[Math.floor(parseInt(text[i], 16)/4)] + "&#8203;";
return result;
};
},

bitfield_to_10: function() {
var graphic = "░▒▓█";
return function(text) {
var len = text.length;
var part_len = Math.ceil(len/10);
var result = "";
for (var i=0; i<10; i++) {
p = 0;
for (var j=0; j<part_len; j++) {
if (i*part_len+j >= len)
p += 16;
else
p += parseInt(text[i*part_len+j], 16);
}
result += graphic[Math.floor(p/part_len/4)] + "&#8203;";
}
return result;
};
},

bitfield_to_percent: function() {
return function(text) {
var len = text.length - 1;
var p, one = 0;
for (var i=0; i<len; i++) {
p = parseInt(text[i], 16);
for (var j=0; j<4; j++) {
one += (p & 1);
p >>= 1;
}
}
return Math.floor(one/(4*len)*100).toString();
};
},

format_size: function() {
var format_text = ["B", "KB", "MB", "GB", "TB", ];
return function format_size(size) {
Expand Down
2 changes: 1 addition & 1 deletion offline.appcache
@@ -1,5 +1,5 @@
CACHE MANIFEST
#2013-8-16 15:38
#2014-1-29 21:06

CACHE:
index.html
Expand Down

0 comments on commit 5290b20

Please sign in to comment.