diff --git a/src/progressbar/docs/demo.html b/src/progressbar/docs/demo.html index dd5f4db47d..7e19d74486 100644 --- a/src/progressbar/docs/demo.html +++ b/src/progressbar/docs/demo.html @@ -19,6 +19,6 @@

Dynamic

- {{bar.value}}% + {{bar.value}}% \ No newline at end of file diff --git a/src/progressbar/docs/readme.md b/src/progressbar/docs/readme.md index a50766d11b..92f1f3c4d5 100644 --- a/src/progressbar/docs/readme.md +++ b/src/progressbar/docs/readme.md @@ -1,6 +1,6 @@ A progress bar directive that is focused on providing feedback on the progress of a workflow or action. -It supports multiple (stacked) bars into the same `` element or a single `` elemtnt with optional `max` attribute and transition animations. +It supports multiple (stacked) bars into the same `` element or a single `` elemtnt with optional `max` attribute and transition animations. ### Settings ### @@ -25,5 +25,5 @@ It supports multiple (stacked) bars into the same `` element or a sing ### Stacked ### -Place multiple `` into the same `` element to stack them. -`` supports `max` and `animate` & `` supports `value` and `type` attributes. +Place multiple ``s into the same `` element to stack them. +`` supports `max` and `animate` & `` supports `value` and `type` attributes. diff --git a/src/progressbar/progressbar.js b/src/progressbar/progressbar.js index 9f83a20ed6..064ca3ca54 100644 --- a/src/progressbar/progressbar.js +++ b/src/progressbar/progressbar.js @@ -5,6 +5,8 @@ angular.module('ui.bootstrap.progressbar', []) max: 100 }) +.value('$progressSuppressWarning', false) + .controller('ProgressController', ['$scope', '$attrs', 'progressConfig', function($scope, $attrs, progressConfig) { var self = this, animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate; @@ -55,13 +57,13 @@ angular.module('ui.bootstrap.progressbar', []) }); }]) -.directive('progress', function() { +.directive('uibProgress', function() { return { restrict: 'EA', replace: true, transclude: true, controller: 'ProgressController', - require: 'progress', + require: 'uibProgress', scope: { max: '=?' }, @@ -69,12 +71,31 @@ angular.module('ui.bootstrap.progressbar', []) }; }) -.directive('bar', function() { +.directive('progress', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) { return { restrict: 'EA', replace: true, transclude: true, - require: '^progress', + controller: 'ProgressController', + require: 'progress', + scope: { + max: '=?' + }, + templateUrl: 'template/progressbar/progress.html', + link: function() { + if ($progressSuppressWarning) { + $log.warn('progress is now deprecated. Use uib-progress instead'); + } + } + }; +}]) + +.directive('uibBar', function() { + return { + restrict: 'EA', + replace: true, + transclude: true, + require: '^uibProgress', scope: { value: '=', type: '@' @@ -86,6 +107,26 @@ angular.module('ui.bootstrap.progressbar', []) }; }) +.directive('bar', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) { + return { + restrict: 'EA', + replace: true, + transclude: true, + require: '^progress', + scope: { + value: '=', + type: '@' + }, + templateUrl: 'template/progressbar/bar.html', + link: function(scope, element, attrs, progressCtrl) { + if ($progressSuppressWarning) { + $log.warn('bar is now deprecated. Use uib-bar instead'); + } + progressCtrl.addBar(scope, element); + } + }; +}]) + .directive('progressbar', function() { return { restrict: 'EA', diff --git a/src/progressbar/test/progressbar.spec.js b/src/progressbar/test/progressbar.spec.js index d0a1620910..3b412358ca 100644 --- a/src/progressbar/test/progressbar.spec.js +++ b/src/progressbar/test/progressbar.spec.js @@ -1,3 +1,48 @@ +describe('progressbar directive', function() { + describe('$progressSuppressWarning', function() { + beforeEach(module('ui.bootstrap.progressbar')); + beforeEach(module('template/progressbar/progress.html', 'template/progressbar/bar.html')); + + it('should give warning', inject(function($compile, $log, $rootScope) { + spyOn($log, 'warn'); + + $rootScope.objects = [ + { value: 10, type: 'success' }, + { value: 50, type: 'warning' }, + { value: 20 } + ]; + var element = $compile('{{o.value}}')($rootScope); + $rootScope.$digest(); + + expect($log.warn.calls.count()).toBe(0); + })); + + it('should suppress warning', function() { + module(function($provide) { + $provide.value('$progressSuppressWarning', true); + }); + + inject(function($compile, $log, $rootScope) { + spyOn($log, 'warn'); + + $rootScope.objects = [ + { value: 10, type: 'success' }, + { value: 50, type: 'warning' }, + { value: 20 } + ]; + var element = $compile('{{o.value}}')($rootScope); + $rootScope.$digest(); + + expect($log.warn.calls.count()).toBe(4); + expect($log.warn.calls.argsFor(0)).toEqual(['progress is now deprecated. Use uib-progress instead']); + expect($log.warn.calls.argsFor(1)).toEqual(['bar is now deprecated. Use uib-bar instead']); + expect($log.warn.calls.argsFor(2)).toEqual(['bar is now deprecated. Use uib-bar instead']); + expect($log.warn.calls.argsFor(3)).toEqual(['bar is now deprecated. Use uib-bar instead']); + }); + }); + }); +}); + describe('progressbar directive', function() { var $rootScope, $compile, element; beforeEach(module('ui.bootstrap.progressbar')); @@ -156,7 +201,7 @@ describe('progressbar directive', function() { { value: 50, type: 'warning' }, { value: 20 } ]; - element = $compile('{{o.value}}')($rootScope); + element = $compile('{{o.value}}')($rootScope); $rootScope.$digest(); })); @@ -219,7 +264,7 @@ describe('progressbar directive', function() { describe('"max" attribute', function() { beforeEach(inject(function() { $rootScope.max = 200; - element = $compile('{{o.value}}/{{max}}')($rootScope); + element = $compile('{{o.value}}/{{max}}')($rootScope); $rootScope.$digest(); }));