From 09ba4dfed2e1602d4d9a4142aee1ce1271b29673 Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Wed, 17 Jun 2015 17:44:03 +0300 Subject: [PATCH 1/3] fix(progressbar): use max value on stacked progress bar Fixes #3618 --- src/progressbar/progressbar.js | 21 +++++++++-- src/progressbar/test/progressbar.spec.js | 46 +++++++++++++++++++++++- 2 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/progressbar/progressbar.js b/src/progressbar/progressbar.js index 3cb855e53d..55fbabefb9 100644 --- a/src/progressbar/progressbar.js +++ b/src/progressbar/progressbar.js @@ -19,10 +19,16 @@ angular.module('ui.bootstrap.progressbar', []) this.bars.push(bar); + bar.max = $scope.max; + bar.$watch('value', function( value ) { - bar.percent = +(100 * value / $scope.max).toFixed(2); + bar.recalculatePercentage(); }); + bar.recalculatePercentage = function() { + bar.percent = +(100 * bar.value / bar.max).toFixed(2); + }; + bar.$on('$destroy', function() { element = null; self.removeBar(bar); @@ -32,6 +38,14 @@ angular.module('ui.bootstrap.progressbar', []) this.removeBar = function(bar) { this.bars.splice(this.bars.indexOf(bar), 1); }; + + $scope.$watch('max', (function(self){ + return function(max) { + self.bars.forEach(function (bar) { + bar.max = $scope.max; + bar.recalculatePercentage(); + }); + }})(this)); }]) .directive('progress', function() { @@ -41,7 +55,9 @@ angular.module('ui.bootstrap.progressbar', []) transclude: true, controller: 'ProgressController', require: 'progress', - scope: {}, + scope: { + max: '=?' + }, templateUrl: 'template/progressbar/progress.html' }; }) @@ -54,7 +70,6 @@ angular.module('ui.bootstrap.progressbar', []) require: '^progress', scope: { value: '=', - max: '=?', type: '@' }, templateUrl: 'template/progressbar/bar.html', diff --git a/src/progressbar/test/progressbar.spec.js b/src/progressbar/test/progressbar.spec.js index fef4f4accd..c0500fd931 100644 --- a/src/progressbar/test/progressbar.spec.js +++ b/src/progressbar/test/progressbar.spec.js @@ -116,7 +116,7 @@ describe('progressbar directive', function () { it('transcludes "bar" text', function() { expect(getBar(0).text()).toBe('22/200'); }); - + it('adjusts the valuemax when it changes', function() { expect(getBar(0).attr('aria-valuemax')).toBe('200'); $rootScope.max = 300; @@ -215,5 +215,49 @@ describe('progressbar directive', function () { expect(getBar(0)).not.toHaveClass(BAR_CLASS + '-success'); expect(getBar(0)).not.toHaveClass(BAR_CLASS + '-warning'); }); + + describe('"max" attribute', function() { + beforeEach(inject(function() { + $rootScope.max = 200; + element = $compile('{{o.value}}/{{max}}')($rootScope); + $rootScope.$digest(); + })); + + it('has the appropriate aria markup', function() { + expect(getBar(0).attr('aria-valuemax')).toBe('200'); + }); + + it('adjusts the "bar" width when it changes', function() { + expect(getBar(0).css('width')).toBe('5%'); + $rootScope.max = 250; + $rootScope.$digest(); + expect(getBar(0).css('width')).toBe('4%'); + }); + + it('adjusts the "bar" width when value changes', function() { + $rootScope.objects[0].value = 60; + $rootScope.$digest(); + expect(getBar(0).css('width')).toBe('30%'); + + $rootScope.objects[0].value += 12; + $rootScope.$digest(); + expect(getBar(0).css('width')).toBe('36%'); + + $rootScope.objects[0].value = 0; + $rootScope.$digest(); + expect(getBar(0).css('width')).toBe('0%'); + }); + + it('transcludes "bar" text', function() { + expect(getBar(0).text()).toBe('10/200'); + }); + + it('adjusts the valuemax when it changes', function() { + expect(getBar(0).attr('aria-valuemax')).toBe('200'); + $rootScope.max = 300; + $rootScope.$digest(); + expect(getBar(0).attr('aria-valuemax')).toBe('300'); + }); + }); }); }); From 27b5546ee8ae1415c33d681f01bdea050539ba57 Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Wed, 17 Jun 2015 18:00:41 +0300 Subject: [PATCH 2/3] fix(progressbar): fix jshint error --- src/progressbar/progressbar.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/progressbar/progressbar.js b/src/progressbar/progressbar.js index 55fbabefb9..b74de6955b 100644 --- a/src/progressbar/progressbar.js +++ b/src/progressbar/progressbar.js @@ -45,7 +45,8 @@ angular.module('ui.bootstrap.progressbar', []) bar.max = $scope.max; bar.recalculatePercentage(); }); - }})(this)); + }; + })(this)); }]) .directive('progress', function() { From 2c70a4646f6b929d40c3be3bf49ea489e7b7f203 Mon Sep 17 00:00:00 2001 From: Geno Roupsky Date: Tue, 23 Jun 2015 10:33:51 +0300 Subject: [PATCH 3/3] chore(progressbar): remove extra self reference --- src/progressbar/progressbar.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/progressbar/progressbar.js b/src/progressbar/progressbar.js index b74de6955b..e045f6ab46 100644 --- a/src/progressbar/progressbar.js +++ b/src/progressbar/progressbar.js @@ -39,14 +39,12 @@ angular.module('ui.bootstrap.progressbar', []) this.bars.splice(this.bars.indexOf(bar), 1); }; - $scope.$watch('max', (function(self){ - return function(max) { - self.bars.forEach(function (bar) { - bar.max = $scope.max; - bar.recalculatePercentage(); - }); - }; - })(this)); + $scope.$watch('max', function(max) { + self.bars.forEach(function (bar) { + bar.max = $scope.max; + bar.recalculatePercentage(); + }); + }); }]) .directive('progress', function() {