From 298ec8cf2024950a43d81a15e5e93bf381a4b107 Mon Sep 17 00:00:00 2001 From: Wesley Cho Date: Thu, 1 Oct 2015 16:07:56 -0700 Subject: [PATCH] feat(accordion): use uib- prefix Closes #4503 --- src/progressbar/docs/demo.html | 12 +-- src/progressbar/progressbar.js | 75 ++++++++----- src/progressbar/test/progressbar.spec.js | 129 ++++++++++++++--------- 3 files changed, 136 insertions(+), 80 deletions(-) diff --git a/src/progressbar/docs/demo.html b/src/progressbar/docs/demo.html index 7e19d74486..3073be7c1b 100644 --- a/src/progressbar/docs/demo.html +++ b/src/progressbar/docs/demo.html @@ -2,20 +2,20 @@

Static

-
-
22%
-
166 / 200
+
+
22%
+
166 / 200

Dynamic

- {{dynamic}} / {{max}} + {{dynamic}} / {{max}} No animation - {{dynamic}}% + {{dynamic}}% Object (changes type based on value) - {{type}} !!! Watch out !!! + {{type}} !!! Watch out !!!

Stacked

diff --git a/src/progressbar/progressbar.js b/src/progressbar/progressbar.js index 6affa08fca..e64551919e 100644 --- a/src/progressbar/progressbar.js +++ b/src/progressbar/progressbar.js @@ -1,13 +1,11 @@ angular.module('ui.bootstrap.progressbar', []) -.constant('progressConfig', { +.constant('uibProgressConfig', { animate: true, max: 100 }) -.value('$progressSuppressWarning', false) - -.controller('ProgressController', ['$scope', '$attrs', 'progressConfig', function($scope, $attrs, progressConfig) { +.controller('UibProgressController', ['$scope', '$attrs', 'uibProgressConfig', function($scope, $attrs, progressConfig) { var self = this, animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate; @@ -63,7 +61,7 @@ angular.module('ui.bootstrap.progressbar', []) restrict: 'EA', replace: true, transclude: true, - controller: 'ProgressController', + controller: 'UibProgressController', require: 'uibProgress', scope: { max: '=?' @@ -72,42 +70,66 @@ angular.module('ui.bootstrap.progressbar', []) }; }) -.directive('progress', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) { +.directive('uibBar', function() { return { restrict: 'EA', replace: true, transclude: true, - controller: 'ProgressController', - require: 'progress', + require: '^uibProgress', scope: { - max: '=?', - title: '@?' + value: '=', + type: '@' }, - templateUrl: 'template/progressbar/progress.html', - link: function() { - if (!$progressSuppressWarning) { - $log.warn('progress is now deprecated. Use uib-progress instead'); - } + templateUrl: 'template/progressbar/bar.html', + link: function(scope, element, attrs, progressCtrl) { + progressCtrl.addBar(scope, element, attrs); } }; -}]) +}) -.directive('uibBar', function() { +.directive('uibProgressbar', function() { return { restrict: 'EA', replace: true, transclude: true, - require: '^uibProgress', + controller: 'UibProgressController', scope: { value: '=', + max: '=?', type: '@' }, - templateUrl: 'template/progressbar/bar.html', + templateUrl: 'template/progressbar/progressbar.html', link: function(scope, element, attrs, progressCtrl) { - progressCtrl.addBar(scope, element, attrs); + progressCtrl.addBar(scope, angular.element(element.children()[0]), {title: attrs.title}); } }; -}) +}); + +/* Deprecated progressbar below */ + +angular.module('ui.bootstrap.progressbar') + +.value('$progressSuppressWarning', false) + +.directive('progress', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) { + return { + restrict: 'EA', + replace: true, + transclude: true, + controller: 'UibProgressController', + require: 'progress', + scope: { + max: '=?', + title: '@?' + }, + templateUrl: 'template/progressbar/progress.html', + link: function() { + if (!$progressSuppressWarning) { + $log.warn('progress is now deprecated. Use uib-progress instead.'); + } + } + }; +}]) .directive('bar', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) { return { @@ -122,19 +144,19 @@ angular.module('ui.bootstrap.progressbar', []) templateUrl: 'template/progressbar/bar.html', link: function(scope, element, attrs, progressCtrl) { if (!$progressSuppressWarning) { - $log.warn('bar is now deprecated. Use uib-bar instead'); + $log.warn('bar is now deprecated. Use uib-bar instead.'); } progressCtrl.addBar(scope, element); } }; }]) -.directive('progressbar', function() { +.directive('progressbar', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) { return { restrict: 'EA', replace: true, transclude: true, - controller: 'ProgressController', + controller: 'UibProgressController', scope: { value: '=', max: '=?', @@ -142,7 +164,10 @@ angular.module('ui.bootstrap.progressbar', []) }, templateUrl: 'template/progressbar/progressbar.html', link: function(scope, element, attrs, progressCtrl) { + if (!$progressSuppressWarning) { + $log.warn('progressbar is now deprecated. Use uib-progressbar instead.'); + } progressCtrl.addBar(scope, angular.element(element.children()[0]), {title: attrs.title}); } }; -}); +}]); diff --git a/src/progressbar/test/progressbar.spec.js b/src/progressbar/test/progressbar.spec.js index 7ea59ac8b0..2cc88c0cc8 100644 --- a/src/progressbar/test/progressbar.spec.js +++ b/src/progressbar/test/progressbar.spec.js @@ -1,48 +1,3 @@ -describe('progressbar directive', function() { - describe('$progressSuppressWarning', function() { - beforeEach(module('ui.bootstrap.progressbar')); - beforeEach(module('template/progressbar/progress.html', 'template/progressbar/bar.html')); - - 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(0); - }); - }); - - it('should give warning by default', 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')); @@ -51,7 +6,7 @@ describe('progressbar directive', function() { $compile = _$compile_; $rootScope = _$rootScope_; $rootScope.value = 22; - element = $compile('{{value}} %')($rootScope); + element = $compile('{{value}} %')($rootScope); $rootScope.$digest(); })); @@ -85,7 +40,7 @@ describe('progressbar directive', function() { }); it('has the default aria-labelledby value of `progressbar`', function() { - element = $compile('{{value}} %')($rootScope); + element = $compile('{{value}} %')($rootScope); $rootScope.$digest(); var bar = getBar(0); expect(bar.attr('aria-labelledby')).toBe('progressbar'); @@ -140,7 +95,7 @@ describe('progressbar directive', function() { describe('"max" attribute', function() { beforeEach(inject(function() { $rootScope.max = 200; - element = $compile('{{value}}/{{max}}')($rootScope); + element = $compile('{{value}}/{{max}}')($rootScope); $rootScope.$digest(); })); @@ -181,7 +136,7 @@ describe('progressbar directive', function() { describe('"type" attribute', function() { beforeEach(inject(function() { $rootScope.type = 'success'; - element = $compile('')($rootScope); + element = $compile('')($rootScope); $rootScope.$digest(); })); @@ -363,3 +318,79 @@ describe('progressbar directive', function() { }); }); }); + +/* Deprecation tests below */ + +describe('progressbar deprecation', function() { + beforeEach(module('ui.bootstrap.progressbar')); + beforeEach(module('template/progressbar/progress.html', 'template/progressbar/bar.html', 'template/progressbar/progressbar.html')); + + describe('progress & bar directives', function() { + 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(0); + }); + }); + + it('should give warning by default', 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() { + it('should suppress warning', function() { + module(function($provide) { + $provide.value('$progressSuppressWarning', true); + }); + + inject(function($compile, $log, $rootScope) { + spyOn($log, 'warn'); + + $rootScope.value = 22; + var element = $compile('{{value}} %')($rootScope); + $rootScope.$digest(); + + expect($log.warn.calls.count()).toBe(0); + }); + }); + + it('should give warning by default', inject(function($compile, $log, $rootScope) { + spyOn($log, 'warn'); + + $rootScope.value = 22; + var element = $compile('{{value}} %')($rootScope); + $rootScope.$digest(); + + expect($log.warn.calls.count()).toBe(1); + expect($log.warn.calls.argsFor(0)).toEqual(['progressbar is now deprecated. Use uib-progressbar instead.']); + })); + }); +});