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

Commit 1c5e479

Browse files
Foxandxsswesleycho
authored andcommitted
fix(progressbar): make deprecated controller work with 1.3.x
Closes #4581
1 parent d50e8d2 commit 1c5e479

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

src/progressbar/progressbar.js

+48-4
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,58 @@ angular.module('ui.bootstrap.progressbar')
108108

109109
.value('$progressSuppressWarning', false)
110110

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

116-
return $controller('UibProgressController', {
117-
$scope: $scope,
118-
$attrs: $attrs
116+
var self = this,
117+
animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate;
118+
119+
this.bars = [];
120+
$scope.max = angular.isDefined($scope.max) ? $scope.max : progressConfig.max;
121+
122+
this.addBar = function(bar, element, attrs) {
123+
if (!animate) {
124+
element.css({'transition': 'none'});
125+
}
126+
127+
this.bars.push(bar);
128+
129+
bar.max = $scope.max;
130+
bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar';
131+
132+
bar.$watch('value', function(value) {
133+
bar.recalculatePercentage();
134+
});
135+
136+
bar.recalculatePercentage = function() {
137+
bar.percent = +(100 * bar.value / bar.max).toFixed(2);
138+
139+
var totalPercentage = self.bars.reduce(function(total, bar) {
140+
return total + bar.percent;
141+
}, 0);
142+
143+
if (totalPercentage > 100) {
144+
bar.percent -= totalPercentage - 100;
145+
}
146+
};
147+
148+
bar.$on('$destroy', function() {
149+
element = null;
150+
self.removeBar(bar);
151+
});
152+
};
153+
154+
this.removeBar = function(bar) {
155+
this.bars.splice(this.bars.indexOf(bar), 1);
156+
};
157+
158+
$scope.$watch('max', function(max) {
159+
self.bars.forEach(function(bar) {
160+
bar.max = $scope.max;
161+
bar.recalculatePercentage();
162+
});
119163
});
120164
}])
121165

0 commit comments

Comments
 (0)