Add remaining scanning time (fixes #2484)
This commit is contained in:
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user