| @@ 5224-5280 (lines=57) @@ | ||
| 5221 | max: 100 |
|
| 5222 | }) |
|
| 5223 | ||
| 5224 | .controller('UibProgressController', ['$scope', '$attrs', 'uibProgressConfig', function($scope, $attrs, progressConfig) { |
|
| 5225 | var self = this, |
|
| 5226 | animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate; |
|
| 5227 | ||
| 5228 | this.bars = []; |
|
| 5229 | $scope.max = getMaxOrDefault(); |
|
| 5230 | ||
| 5231 | this.addBar = function(bar, element, attrs) { |
|
| 5232 | if (!animate) { |
|
| 5233 | element.css({'transition': 'none'}); |
|
| 5234 | } |
|
| 5235 | ||
| 5236 | this.bars.push(bar); |
|
| 5237 | ||
| 5238 | bar.max = getMaxOrDefault(); |
|
| 5239 | bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar'; |
|
| 5240 | ||
| 5241 | bar.$watch('value', function(value) { |
|
| 5242 | bar.recalculatePercentage(); |
|
| 5243 | }); |
|
| 5244 | ||
| 5245 | bar.recalculatePercentage = function() { |
|
| 5246 | var totalPercentage = self.bars.reduce(function(total, bar) { |
|
| 5247 | bar.percent = +(100 * bar.value / bar.max).toFixed(2); |
|
| 5248 | return total + bar.percent; |
|
| 5249 | }, 0); |
|
| 5250 | ||
| 5251 | if (totalPercentage > 100) { |
|
| 5252 | bar.percent -= totalPercentage - 100; |
|
| 5253 | } |
|
| 5254 | }; |
|
| 5255 | ||
| 5256 | bar.$on('$destroy', function() { |
|
| 5257 | element = null; |
|
| 5258 | self.removeBar(bar); |
|
| 5259 | }); |
|
| 5260 | }; |
|
| 5261 | ||
| 5262 | this.removeBar = function(bar) { |
|
| 5263 | this.bars.splice(this.bars.indexOf(bar), 1); |
|
| 5264 | this.bars.forEach(function (bar) { |
|
| 5265 | bar.recalculatePercentage(); |
|
| 5266 | }); |
|
| 5267 | }; |
|
| 5268 | ||
| 5269 | //$attrs.$observe('maxParam', function(maxParam) { |
|
| 5270 | $scope.$watch('maxParam', function(maxParam) { |
|
| 5271 | self.bars.forEach(function(bar) { |
|
| 5272 | bar.max = getMaxOrDefault(); |
|
| 5273 | bar.recalculatePercentage(); |
|
| 5274 | }); |
|
| 5275 | }); |
|
| 5276 | ||
| 5277 | function getMaxOrDefault () { |
|
| 5278 | return angular.isDefined($scope.maxParam) ? $scope.maxParam : progressConfig.max; |
|
| 5279 | } |
|
| 5280 | }]) |
|
| 5281 | ||
| 5282 | .directive('uibProgress', function() { |
|
| 5283 | return { |
|
| @@ 5223-5279 (lines=57) @@ | ||
| 5220 | max: 100 |
|
| 5221 | }) |
|
| 5222 | ||
| 5223 | .controller('UibProgressController', ['$scope', '$attrs', 'uibProgressConfig', function($scope, $attrs, progressConfig) { |
|
| 5224 | var self = this, |
|
| 5225 | animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate; |
|
| 5226 | ||
| 5227 | this.bars = []; |
|
| 5228 | $scope.max = getMaxOrDefault(); |
|
| 5229 | ||
| 5230 | this.addBar = function(bar, element, attrs) { |
|
| 5231 | if (!animate) { |
|
| 5232 | element.css({'transition': 'none'}); |
|
| 5233 | } |
|
| 5234 | ||
| 5235 | this.bars.push(bar); |
|
| 5236 | ||
| 5237 | bar.max = getMaxOrDefault(); |
|
| 5238 | bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar'; |
|
| 5239 | ||
| 5240 | bar.$watch('value', function(value) { |
|
| 5241 | bar.recalculatePercentage(); |
|
| 5242 | }); |
|
| 5243 | ||
| 5244 | bar.recalculatePercentage = function() { |
|
| 5245 | var totalPercentage = self.bars.reduce(function(total, bar) { |
|
| 5246 | bar.percent = +(100 * bar.value / bar.max).toFixed(2); |
|
| 5247 | return total + bar.percent; |
|
| 5248 | }, 0); |
|
| 5249 | ||
| 5250 | if (totalPercentage > 100) { |
|
| 5251 | bar.percent -= totalPercentage - 100; |
|
| 5252 | } |
|
| 5253 | }; |
|
| 5254 | ||
| 5255 | bar.$on('$destroy', function() { |
|
| 5256 | element = null; |
|
| 5257 | self.removeBar(bar); |
|
| 5258 | }); |
|
| 5259 | }; |
|
| 5260 | ||
| 5261 | this.removeBar = function(bar) { |
|
| 5262 | this.bars.splice(this.bars.indexOf(bar), 1); |
|
| 5263 | this.bars.forEach(function (bar) { |
|
| 5264 | bar.recalculatePercentage(); |
|
| 5265 | }); |
|
| 5266 | }; |
|
| 5267 | ||
| 5268 | //$attrs.$observe('maxParam', function(maxParam) { |
|
| 5269 | $scope.$watch('maxParam', function(maxParam) { |
|
| 5270 | self.bars.forEach(function(bar) { |
|
| 5271 | bar.max = getMaxOrDefault(); |
|
| 5272 | bar.recalculatePercentage(); |
|
| 5273 | }); |
|
| 5274 | }); |
|
| 5275 | ||
| 5276 | function getMaxOrDefault () { |
|
| 5277 | return angular.isDefined($scope.maxParam) ? $scope.maxParam : progressConfig.max; |
|
| 5278 | } |
|
| 5279 | }]) |
|
| 5280 | ||
| 5281 | .directive('uibProgress', function() { |
|
| 5282 | return { |
|