unstable commit for a new and smart algorithm for piece progress bar, not usable,

This commit is contained in:
Hamza Zia 2012-08-02 11:42:03 +08:00
parent 72208fe579
commit bebf4e7741
2 changed files with 43 additions and 11 deletions

View File

@ -111,7 +111,7 @@
<div class="span11 active_chunks"> <div class="span11 active_chunks">
{{#chunks}} {{#chunks}}
<div class="progress progress-chunk" style="width:{{width}}%;"> <div class="progress progress-chunk" style="width:{{width}}%;">
<div class="bar chunk_{{id}}" style="width: {{progress}}%;"></div> <div class="bar" style="width: {{progress}}%;"></div>
</div> </div>
{{/chunks}} {{/chunks}}
</div> </div>

View File

@ -423,19 +423,24 @@ function changeTime(time) {
} }
function getChunksFromHex(bitfield, numOfPieces) { function getChunksFromHex(bitfield, numOfPieces) {
var chunks = [], numPieces = parseInt(numOfPieces); var chunks = [], len = 0, numPieces = parseInt(numOfPieces);
if (numPieces > 1) { if (numPieces > 1) {
var chunk_width = 100 / numPieces; var chunk_width = 100 / numPieces;
for (var i = 0; i < bitfield.length; i++) { for (var i = 0; i < bitfield.length; i++) {
var hex = parseInt(bitfield[i], 16); var hex = parseInt(bitfield[i], 16);
for (var j = 1; j <= 4; j++) { for (var j = 1; j <= 4; j++) {
var bit = hex & (1 << (4 - j)); var bit = hex & (1 << (4 - j));
var len = chunks.length; var prog = bit ? 100 : 0;
if (len && chunks[len - 1].progress == prog) {
chunks[len - 1].width += chunk_width;
}
else {
chunks.push({ chunks.push({
width: chunk_width, width: chunk_width,
progress: bit ? 100 : 0, progress: bit ? 100 : 0
id: len
}); });
len++;
}
} }
} }
} }
@ -480,11 +485,38 @@ function updateDownloadTemplates(elem, ctx) {
elem.find('.tmp_' + i).text(ctx[i]); elem.find('.tmp_' + i).text(ctx[i]);
} }
elem.find('.full-progress .bar').css('width', ctx.percentage + '%'); elem.find('.full-progress .bar').css('width', ctx.percentage + '%');
for (var j = 0; j < ctx.chunks; j++) { var partialNodes = elem.find(".progress-chunk .bar");
if (ctx.chunks[j].progress == 100) { var chunks = ctx.chunks;
elem.find(".chunk_" + ctx.id.toString()).css(width, "100%"); var diff = partialNodes.length - chunks.length;
if (diff > 0) {
partialNodes.slice(0, diff).remove();
partialNodes = elem.find(".progress-chunk .bar")
diff = (partialNodes.length - chunks.length);
if (diff != 0) {
console.log(diff);
console.log("diff error in deleting!!!");
return;
} }
} }
else if (diff < 0){
diff = (-1) * diff;
var html = '<div class="progress progress-chunk" style="width:'
+ chunks[0].width + '%;"><div class="bar" style="width: 0%;"></div></div>';
var oldlen = partialNodes.length;
partialNodes.parents('.active_chunks').first().append((new Array(diff + 1)).join(html));
partialNodes = elem.find(".progress-chunk .bar");
var newlen = partialNodes.length;
console.log("diff between lengts:" + (newlen - oldlen - diff).toString());
diff = (partialNodes.length - chunks.length);
if (diff != 0) {
console.log(diff);
console.log("diff error in appending!!!");
return;
}
}
partialNodes.each(function(index, node) {
$(node).css("width", chunks[index].progress.toString() + "%");
});
} }
function deleteDownloadTemplates(top_elem, data) { function deleteDownloadTemplates(top_elem, data) {
if(!data) { if(!data) {