From 5e3a87a91e221fbd06703b7b0c75c78daeab32d5 Mon Sep 17 00:00:00 2001 From: Jesus Rodriguez Date: Fri, 11 Sep 2015 17:12:04 +0200 Subject: [PATCH] feat(alert): use uib- prefix Closes #4406 --- src/alert/alert.js | 33 ++++++++++++++++++++--- src/alert/docs/demo.html | 4 +-- src/alert/docs/readme.md | 10 +++---- src/alert/test/alert.spec.js | 51 +++++++++++++++++++++++++++++------- 4 files changed, 79 insertions(+), 19 deletions(-) diff --git a/src/alert/alert.js b/src/alert/alert.js index 23d3aa592f..b94e438793 100644 --- a/src/alert/alert.js +++ b/src/alert/alert.js @@ -1,6 +1,6 @@ angular.module('ui.bootstrap.alert', []) -.controller('AlertController', ['$scope', '$attrs', '$timeout', function($scope, $attrs, $timeout) { +.controller('UibAlertController', ['$scope', '$attrs', '$timeout', function($scope, $attrs, $timeout) { $scope.closeable = !!$attrs.close; if (angular.isDefined($attrs.dismissOnTimeout)) { @@ -10,9 +10,9 @@ angular.module('ui.bootstrap.alert', []) } }]) -.directive('alert', function() { +.directive('uibAlert', function() { return { - controller: 'AlertController', + controller: 'UibAlertController', controllerAs: 'alert', templateUrl: function(element, attrs) { return attrs.templateUrl || 'template/alert/alert.html'; @@ -25,3 +25,30 @@ angular.module('ui.bootstrap.alert', []) } }; }); + +/* Deprecated alert below */ + +angular.module('ui.bootstrap.alert') + + .value('$alertSuppressWarning', false) + + .directive('alert', ['$log', '$alertSuppressWarning', function($log, $alertSuppressWarning) { + return { + controller: 'UibAlertController', + controllerAs: 'alert', + templateUrl: function(element, attrs) { + return attrs.templateUrl || 'template/alert/alert.html'; + }, + transclude: true, + replace: true, + scope: { + type: '@', + close: '&' + }, + link: function() { + if (!$alertSuppressWarning) { + $log.warn('alert is now deprecated. Use uib-alert instead.'); + } + } + }; + }]); diff --git a/src/alert/docs/demo.html b/src/alert/docs/demo.html index ce7d00d7b1..e2ce4b3870 100644 --- a/src/alert/docs/demo.html +++ b/src/alert/docs/demo.html @@ -5,7 +5,7 @@ - {{alert.msg}} - A happy alert! + {{alert.msg}} + A happy alert! diff --git a/src/alert/docs/readme.md b/src/alert/docs/readme.md index f3793ebe20..6d81bd43f9 100644 --- a/src/alert/docs/readme.md +++ b/src/alert/docs/readme.md @@ -1,12 +1,12 @@ This directive can be used both to generate alerts from static and dynamic model data (using the `ng-repeat` directive). -### Alert settings +### uib-alert settings - * `close` (Defaults: none): + * `close` _(Default: `none`)_ - A callback function that gets fired when an `alert` is closed. If the attribute exists, a close button is displayed as well. - * `dismiss-on-timeout` (Defaults: none)(Optional): + * `dismiss-on-timeout` _(Default: `none`)(Optional)_ - Takes the number of milliseconds that specify the timeout duration, after which the alert will be closed. This attribute requires the presence of the `close` attribute. - * `template-url` (Defaults: `template/alert/alert.html`): + * `template-url` _(Default: `template/alert/alert.html`)_ - Add the ability to override the template used in the component. - * `type` (Defaults: `warning`): + * `type` _(Default: `warning`)_ - Defines the type of the alert. Go to [bootstrap page](http://getbootstrap.com/components/#alerts) to see the type of alerts available. diff --git a/src/alert/test/alert.spec.js b/src/alert/test/alert.spec.js index 7f87de81da..6073bfdef0 100644 --- a/src/alert/test/alert.spec.js +++ b/src/alert/test/alert.spec.js @@ -1,4 +1,4 @@ -describe('alert', function() { +describe('uib-alert', function() { var element, scope, $compile, $templateCache, $timeout; beforeEach(module('ui.bootstrap.alert')); @@ -12,9 +12,9 @@ describe('alert', function() { element = angular.element( '
' + - '{{alert.msg}}' + - '' + + '' + '
'); scope.alerts = [ @@ -41,10 +41,10 @@ describe('alert', function() { it('should expose the controller to the view', function() { $templateCache.put('template/alert/alert.html', '
{{alert.text}}
'); - element = $compile('')(scope); + element = $compile('')(scope); scope.$digest(); - var ctrl = element.controller('alert'); + var ctrl = element.controller('uib-alert'); expect(ctrl).toBeDefined(); ctrl.text = 'foo'; @@ -56,7 +56,7 @@ describe('alert', function() { it('should support custom templates', function() { $templateCache.put('foo/bar.html', '
baz
'); - element = $compile('')(scope); + element = $compile('')(scope); scope.$digest(); expect(element.html()).toBe('baz'); @@ -115,14 +115,14 @@ describe('alert', function() { }); it('should not show close button and have the dismissible class if no close callback specified', function() { - element = $compile('No close')(scope); + element = $compile('No close')(scope); scope.$digest(); expect(findCloseButton(0)).toBeHidden(); expect(element).not.toHaveClass('alert-dismissible'); }); it('should be possible to add additional classes for alert', function() { - var element = $compile('Default alert!')(scope); + var element = $compile('Default alert!')(scope); scope.$digest(); expect(element).toHaveClass('alert-block'); expect(element).toHaveClass('alert-info'); @@ -130,10 +130,43 @@ describe('alert', function() { it('should close automatically if dismiss-on-timeout is defined on the element', function() { scope.removeAlert = jasmine.createSpy(); - $compile('Default alert!')(scope); + $compile('Default alert!')(scope); scope.$digest(); $timeout.flush(); expect(scope.removeAlert).toHaveBeenCalled(); }); }); + +/* Deprecation tests below */ + +describe('alert deprecation', function() { + beforeEach(module('ui.bootstrap.alert')); + beforeEach(module('template/alert/alert.html')); + + it('should suppress warning', function() { + module(function($provide) { + $provide.value('$alertSuppressWarning', true); + }); + + inject(function($compile, $log, $rootScope) { + spyOn($log, 'warn'); + + var element = ''; + element = $compile(element)($rootScope); + $rootScope.$digest(); + expect($log.warn.calls.count()).toBe(0); + }); + }); + + it('should give warning by default', inject(function($compile, $log, $rootScope) { + spyOn($log, 'warn'); + + var element = ''; + element = $compile(element)($rootScope); + $rootScope.$digest(); + + expect($log.warn.calls.count()).toBe(1); + expect($log.warn.calls.argsFor(0)).toEqual(['alert is now deprecated. Use uib-alert instead.']); + })); +});