Merge pull request #2485 from calmh/scantime

Add remaining scanning time (fixes #2484)
This commit is contained in:
Audrius Butkevicius 2015-11-18 11:17:36 +00:00
commit 66bf524394
5 changed files with 72 additions and 9 deletions

View File

@ -138,6 +138,7 @@
"Resume": "Resume",
"Reused": "Reused",
"Save": "Save",
"Scan Time Remaining": "Scan Time Remaining",
"Scanning": "Scanning",
"Select the devices to share this folder with.": "Select the devices to share this folder with.",
"Select the folders to share with this device.": "Select the folders to share with this device.",

View File

@ -228,7 +228,7 @@
<span ng-switch-when="scanning">
<span class="hidden-xs" translate>Scanning</span>
<span class="hidden-xs" ng-if="scanPercentage(folder.id) != undefined">
(<span class="hidden-xs" ng-if="scanRate(folder.id) > 0">{{scanRate(folder.id) | binary}}B/s, </span>{{scanPercentage(folder.id)}}%)
{{scanPercentage(folder.id)}}%
</span>
<span class="visible-xs">&#9724;</span>
</span>
@ -267,6 +267,12 @@
<a href="" ng-click="showNeed(folder.id)">{{model[folder.id].needFiles | alwaysNumber}} <span translate>items</span>, ~{{model[folder.id].needBytes | binary}}B</a>
</td>
</tr>
<tr ng-if="folderStatus(folder) === 'scanning' && scanRate(folder.id) > 0">
<th><span class="fa fa-fw fa-hourglass-2"></span>&nbsp;<span translate>Scan Time Remaining</span></th>
<td class="text-right">
<span title="{{scanRate(folder.id) | binary}}B/s">~ {{scanRemaining(folder.id)}}</span>
</td>
</tr>
<tr ng-if="!folder.readOnly && (folderStatus(folder) === 'outofsync' || hasFailedFiles(folder.id))">
<th><span class="fa fa-fw fa-exclamation-circle"></span>&nbsp;<span translate>Failed Items</span></th>
<!-- Show the number of failed items as a link to bring up the list. -->

View File

@ -2,7 +2,7 @@ angular.module('syncthing.core')
.config(function($locationProvider) {
$locationProvider.html5Mode(true).hashPrefix('!');
})
.controller('SyncthingController', function ($scope, $http, $location, LocaleService, Events) {
.controller('SyncthingController', function ($scope, $http, $location, LocaleService, Events, $filter) {
'use strict';
// private/helper definitions
@ -676,6 +676,62 @@ angular.module('syncthing.core')
return $scope.scanProgress[folder].rate;
}
$scope.scanRemaining = function (folder) {
// Formats the remaining scan time as a string. Includes days and
// hours only when relevant, resulting in time stamps like:
// 00m 40s
// 32m 40s
// 2h 32m
// 4d 2h
var res = [];
if (!$scope.scanProgress[folder]) {
return "";
}
// Calculate remaining bytes and seconds based on our current
// rate.
var remainingBytes = $scope.scanProgress[folder].total - $scope.scanProgress[folder].current;
var seconds = remainingBytes / $scope.scanProgress[folder].rate;
// Round up to closest ten seconds to avoid flapping too much to
// and fro.
seconds = Math.ceil(seconds / 10) * 10;
// Separate out the number of days.
var days = 0;
if (seconds >= 86400) {
days = Math.floor(seconds / 86400);
res.push('' + days + 'd')
seconds = seconds % 86400;
}
// Separate out the number of hours.
var hours = 0;
if (seconds > 3600) {
hours = Math.floor(seconds / 3600);
res.push('' + hours + 'h')
seconds = seconds % 3600;
}
var d = new Date(1970, 0, 1).setSeconds(seconds);
if (days == 0) {
// Format minutes only if we're within a day of completion.
var f = $filter('date')(d, "m'm'");
res.push(f);
}
if (days == 0 && hours == 0) {
// Format seconds only when we're within an hour of completion.
var f = $filter('date')(d, "ss's'");
res.push(f);
}
return res.join(' ');
}
$scope.deviceStatus = function (deviceCfg) {
if ($scope.deviceFolders(deviceCfg).length === 0) {
return 'unused';

File diff suppressed because one or more lines are too long

View File

@ -146,9 +146,6 @@ func (w *Walker) Walk() (chan protocol.FileInfo, error) {
var filesToHash []protocol.FileInfo
var total int64 = 1
progress := newByteCounter()
defer progress.Close()
for file := range toHashChan {
filesToHash = append(filesToHash, file)
total += int64(file.CachedSize)
@ -156,6 +153,9 @@ func (w *Walker) Walk() (chan protocol.FileInfo, error) {
realToHashChan := make(chan protocol.FileInfo)
done := make(chan struct{})
progress := newByteCounter()
defer progress.Close()
newParallelHasher(w.Dir, w.BlockSize, w.Hashers, finishedChan, realToHashChan, progress, done, w.Cancel)
// A routine which actually emits the FolderScanProgress events