Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
fix(progressbar): make deprecated controller work with 1.3.x
Browse files Browse the repository at this point in the history
Closes #4581
  • Loading branch information
Foxandxss authored and wesleycho committed Oct 11, 2015
1 parent d50e8d2 commit 1c5e479
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions src/progressbar/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,58 @@ angular.module('ui.bootstrap.progressbar')

.value('$progressSuppressWarning', false)

.controller('ProgressController', ['$scope', '$attrs', '$controller', '$log', '$progressSuppressWarning', function($scope, $attrs, $controller, $log, $progressSuppressWarning) {
.controller('ProgressController', ['$scope', '$attrs', 'uibProgressConfig', '$log', '$progressSuppressWarning', function($scope, $attrs, progressConfig, $log, $progressSuppressWarning) {
if (!$progressSuppressWarning) {
$log.warn('ProgressController is now deprecated. Use UibProgressController instead.');
}

return $controller('UibProgressController', {
$scope: $scope,
$attrs: $attrs
var self = this,
animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate;

this.bars = [];
$scope.max = angular.isDefined($scope.max) ? $scope.max : progressConfig.max;

this.addBar = function(bar, element, attrs) {
if (!animate) {
element.css({'transition': 'none'});
}

this.bars.push(bar);

bar.max = $scope.max;
bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar';

bar.$watch('value', function(value) {
bar.recalculatePercentage();
});

bar.recalculatePercentage = function() {
bar.percent = +(100 * bar.value / bar.max).toFixed(2);

var totalPercentage = self.bars.reduce(function(total, bar) {
return total + bar.percent;
}, 0);

if (totalPercentage > 100) {
bar.percent -= totalPercentage - 100;
}
};

bar.$on('$destroy', function() {
element = null;
self.removeBar(bar);
});
};

this.removeBar = function(bar) {
this.bars.splice(this.bars.indexOf(bar), 1);
};

$scope.$watch('max', function(max) {
self.bars.forEach(function(bar) {
bar.max = $scope.max;
bar.recalculatePercentage();
});
});
}])

Expand Down

0 comments on commit 1c5e479

Please sign in to comment.