GUAC-928: Add progress bar to notifications.

This commit is contained in:
Michael Jumper
2014-12-05 10:47:22 -08:00
parent 4636a1994a
commit 6c96affbd8
6 changed files with 60 additions and 3 deletions

View File

@@ -367,17 +367,19 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams',
* returned. * returned.
* *
* @param {Number} bytes The number of bytes. * @param {Number} bytes The number of bytes.
* @param {Number} [length] The file length, in bytes, if known.
* *
* @returns {Object} * @returns {Object}
* A progress object, as required by $scope.addNotification(). * A progress object, as required by $scope.addNotification().
*/ */
var getFileProgress = function getFileProgress(text, bytes) { var getFileProgress = function getFileProgress(text, bytes, length) {
// Gigabytes // Gigabytes
if (bytes > 1000000000) if (bytes > 1000000000)
return { return {
text : text, text : text,
value : (bytes / 1000000000).toFixed(1), value : (bytes / 1000000000).toFixed(1),
ratio : bytes / length,
unit : "gb" unit : "gb"
}; };
@@ -386,6 +388,7 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams',
return { return {
text : text, text : text,
value : (bytes / 1000000).toFixed(1), value : (bytes / 1000000).toFixed(1),
ratio : bytes / length,
unit : "mb" unit : "mb"
}; };
@@ -394,6 +397,7 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams',
return { return {
text : text, text : text,
value : (bytes / 1000).toFixed(1), value : (bytes / 1000).toFixed(1),
ratio : bytes / length,
unit : "kb" unit : "kb"
}; };
@@ -401,6 +405,7 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams',
return { return {
text : text, text : text,
value : bytes, value : bytes,
ratio : bytes / length,
unit : "b" unit : "b"
}; };
@@ -493,7 +498,7 @@ angular.module('home').controller('clientController', ['$scope', '$routeParams',
var notification = uploadNotifications[streamIndex]; var notification = uploadNotifications[streamIndex];
if (notification) if (notification)
notification.progress = getFileProgress('client.fileTransfer.progressText', offset); notification.progress = getFileProgress('client.fileTransfer.progressText', offset, length);
}); });
}); });

View File

@@ -93,6 +93,22 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
* The number of seconds remaining before the countdown callback is * The number of seconds remaining before the countdown callback is
* called. * called.
* *
* @param {String} [status.progress.text]
* If this notification has associated progress, the text to display
* while the operation is occurring.
*
* @param {String} [status.progress.value]
* The current state of operation progress, as an arbitrary number
* which increases as the operation continues.
*
* @param {String} [status.progress.unit]
* The unit of the arbitrary status.progress.value, if that value has
* an associated unit.
*
* @param {String} [status.progress.ratio]
* If known, the current status of the operation as a value between
* 0 and 1 inclusive, where 0 is not yet started, and 1 is complete.
*
* @param {Object[]} [status.actions] * @param {Object[]} [status.actions]
* Array of action objects which contain an action name and callback to * Array of action objects which contain an action name and callback to
* be executed when that action is invoked. * be executed when that action is invoked.
@@ -138,6 +154,22 @@ angular.module('index').controller('indexController', ['$scope', '$injector',
* The number of seconds remaining before the countdown callback is * The number of seconds remaining before the countdown callback is
* called. * called.
* *
* @param {String} [notification.progress.text]
* If this notification has associated progress, the text to display
* while the operation is occurring.
*
* @param {String} [notification.progress.value]
* The current state of operation progress, as an arbitrary number
* which increases as the operation continues.
*
* @param {String} [notification.progress.unit]
* The unit of the arbitrary notification.progress.value, if that value
* has an associated unit.
*
* @param {String} [notification.progress.ratio]
* If known, the current status of the operation as a value between
* 0 and 1 inclusive, where 0 is not yet started, and 1 is complete.
*
* @param {Object[]} [notification.actions] * @param {Object[]} [notification.actions]
* Array of action objects which contain an action name and callback to * Array of action objects which contain an action name and callback to
* be executed when that action is invoked. * be executed when that action is invoked.

View File

@@ -108,6 +108,15 @@ angular.module('notification').directive('guacNotification', [function guacNotif
*/ */
progress : '=', progress : '=',
/**
* Value between 0 and 1 denoting what proportion of the operation
* has completed. If known, this value should be 0 if the operation
* has not started, and 1 if the operation is complete.
*
* @type Number
*/
progressRatio : '=',
/** /**
* Array of name/callback pairs for each action the user is allowed * Array of name/callback pairs for each action the user is allowed
* to take once the notification is shown. * to take once the notification is shown.
@@ -132,6 +141,11 @@ angular.module('notification').directive('guacNotification', [function guacNotif
templateUrl: 'app/notification/templates/guacNotification.html', templateUrl: 'app/notification/templates/guacNotification.html',
controller: ['$scope', '$interval', function guacNotificationController($scope, $interval) { controller: ['$scope', '$interval', function guacNotificationController($scope, $interval) {
// Update progress bar if end known
$scope.$watch("progressRatio", function updateProgress(ratio) {
$scope.progressPercent = ratio * 100;
});
// Set countdown interval when associated property is set // Set countdown interval when associated property is set
$scope.$watch("countdown", function resetTimeRemaining(countdown) { $scope.$watch("countdown", function resetTimeRemaining(countdown) {

View File

@@ -104,3 +104,7 @@
position: relative; position: relative;
} }
.notification .progress .text {
position: relative;
}

View File

@@ -32,7 +32,7 @@
<p ng-show="text" class="text">{{text | translate}}</p> <p ng-show="text" class="text">{{text | translate}}</p>
<!-- Current progress --> <!-- Current progress -->
<div ng-show="progressText" class="progress">{{progressText | translate:"{ PROGRESS: progress, UNIT: progressUnit }"}}</div> <div ng-show="progressText" class="progress"><div ng-show="progressPercent" ng-style="{'width': progressPercent + '%'}" class="bar"></div><div class="text">{{progressText | translate:"{ PROGRESS: progress, UNIT: progressUnit }"}}</div></div>
<!-- Default action countdown text --> <!-- Default action countdown text -->
<p ng-show="countdownText" class="countdown-text">{{countdownText | translate:"{ REMAINING: timeRemaining }"}}</p> <p ng-show="countdownText" class="countdown-text">{{countdownText | translate:"{ REMAINING: timeRemaining }"}}</p>

View File

@@ -44,6 +44,7 @@ THE SOFTWARE.
text="status.text" text="status.text"
progress-text="status.progress.text" progress-text="status.progress.text"
progress-unit="status.progress.unit" progress-unit="status.progress.unit"
progress-ratio="status.progress.ratio"
progress="status.progress.value" progress="status.progress.value"
actions="status.actions" actions="status.actions"
countdown-text="status.countdown.text" countdown-text="status.countdown.text"
@@ -66,6 +67,7 @@ THE SOFTWARE.
text="wrapper.notification.text" text="wrapper.notification.text"
progress-text="wrapper.notification.progress.text" progress-text="wrapper.notification.progress.text"
progress-unit="wrapper.notification.progress.unit" progress-unit="wrapper.notification.progress.unit"
progress-ratio="wrapper.notification.progress.ratio"
progress="wrapper.notification.progress.value" progress="wrapper.notification.progress.value"
actions="wrapper.notification.actions" actions="wrapper.notification.actions"
countdown-text="wrapper.notification.countdown.text" countdown-text="wrapper.notification.countdown.text"