support display completed piece count and total piece count

This commit is contained in:
MaysWind 2016-07-16 22:15:37 +08:00
parent 14cb3080ac
commit 0a7ac30142
4 changed files with 100 additions and 92 deletions

View file

@ -160,6 +160,7 @@
"time.minutes": "{{value}} 分钟",
"time.hour": "{{value}} 小时",
"time.hours": "{{value}} 小时",
"task.pieceinfo": "已完成: {{completed}}, 共计: {{total}} 块",
"task.error-occurred": "发生错误 ({{errorcode}})",
"settings.file-count": "({{count}} 个文件)",
"settings.total-count": "(共计: {{count}}个)"

View file

@ -164,6 +164,7 @@
'time.minutes': '{{value}} Minutes',
'time.hour': '{{value}} Hour',
'time.hours': '{{value}} Hours',
'task.pieceinfo': 'Completed: {{completed}}, Total: {{total}}',
'task.error-occurred': 'Error Occurred ({{errorcode}})',
'settings.file-count': '({{count}} Files)',
'settings.total-count': '(Total Count: {{count}})'

View file

@ -53,11 +53,64 @@
};
};
var getPieceStatus = function (bitField, pieceCount) {
var pieces = [];
for (var i = 0; i < pieceCount; i++) {
pieces.push(false);
}
if (!bitField) {
return pieces;
}
var pieceIndex = 0;
for (var i = 0; i < bitField.length; i++) {
var bitSet = parseInt(bitField[i], 16);
for (var j = 1; j <= 4; j++) {
var bit = (1 << (4 - j));
var isCompleted = (bitSet & bit) == bit;
pieces[pieceIndex++] = isCompleted;
if (pieceIndex >= pieceCount) {
return pieces;
}
}
}
return pieces;
};
var getCombinedPieces = function (bitField, pieceCount) {
var pieces = getPieceStatus(bitField, pieceCount);
var combinedPieces = [];
for (var i = 0; i < pieces.length; i++) {
var isCompleted = pieces[i];
if (combinedPieces.length > 0 && combinedPieces[combinedPieces.length - 1].isCompleted == isCompleted) {
combinedPieces[combinedPieces.length - 1].count++;
} else {
combinedPieces.push({
isCompleted: isCompleted,
count: 1
});
}
}
return combinedPieces;
};
var processDownloadTask = function (task) {
if (!task) {
return task;
}
var pieceStatus = getPieceStatus(task.bitfield, task.numPieces);
task.totalLength = parseInt(task.totalLength);
task.completedLength = parseInt(task.completedLength);
task.completePercent = (task.totalLength > 0 ? task.completedLength / task.totalLength * 100 : 0);
@ -69,6 +122,10 @@
task.uploadSpeed = parseInt(task.uploadSpeed);
task.downloadSpeed = parseInt(task.downloadSpeed);
task.numPieces = parseInt(task.numPieces);
task.completedPieces = ariaNgCommonService.countArray(pieceStatus, true);
task.pieceLength = parseInt(task.pieceLength);
task.idle = task.downloadSpeed == 0;
task.remainTime = calculateDownloadRemainTime(task.remainLength, task.downloadSpeed);
task.seeder = (task.seeder === true || task.seeder === 'true');
@ -143,57 +200,6 @@
return peers;
};
var getPieceStatus = function (bitField, pieceCount) {
var pieces = [];
for (var i = 0; i < pieceCount; i++) {
pieces.push(false);
}
if (!bitField) {
return pieces;
}
var pieceIndex = 0;
for (var i = 0; i < bitField.length; i++) {
var bitSet = parseInt(bitField[i], 16);
for (var j = 1; j <= 4; j++) {
var bit = (1 << (4 - j));
var isCompleted = (bitSet & bit) == bit;
pieces[pieceIndex++] = isCompleted;
if (pieceIndex >= pieceCount) {
return pieces;
}
}
}
return pieces;
};
var getCombinedPieces = function (bitField, pieceCount) {
var pieces = getPieceStatus(bitField, pieceCount);
var combinedPieces = [];
for (var i = 0; i < pieces.length; i++) {
var isCompleted = pieces[i];
if (combinedPieces.length > 0 && combinedPieces[combinedPieces.length - 1].isCompleted == isCompleted) {
combinedPieces[combinedPieces.length - 1].count++;
} else {
combinedPieces.push({
isCompleted: isCompleted,
count: 1
});
}
}
return combinedPieces;
};
var createEventCallback = function (getTaskStatusFunc, callback, type) {
return function (event) {
var context = {

View file

@ -152,10 +152,10 @@
</div>
<div class="tab-pane" ng-class="{'active': context.currentTab == 'blocks'}">
<div class="piece-legends">
<div class="piece-legend">
<div class="piece-legend" ng-tooltip="{{('format.task.pieceinfo' | translate: {completed: task.completedPieces, total: task.numPieces})}}" ng-tooltip-container="body">
<div class="piece piece-completed"></div><span translate>Completed</span>
</div>
<div class="piece-legend">
<div class="piece-legend" ng-tooltip="{{('format.task.pieceinfo' | translate: {completed: task.completedPieces, total: task.numPieces})}}" ng-tooltip-container="body">
<div class="piece"></div><span translate>Uncompleted</span>
</div>
</div>