Skip to content
This repository has been archived by the owner on May 29, 2019. It is now read-only.

Commit

Permalink
feat(progressbar): remove deprecated code
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Remove deprecated non-prefixed directives

Closes #4722
  • Loading branch information
Foxandxss authored and wesleycho committed Oct 23, 2015
1 parent 42fa28f commit 0669b06
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 197 deletions.
119 changes: 0 additions & 119 deletions src/progressbar/progressbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,122 +103,3 @@ angular.module('ui.bootstrap.progressbar', [])
}
};
});

/* Deprecated progressbar below */

angular.module('ui.bootstrap.progressbar')

.value('$progressSuppressWarning', false)

.controller('ProgressController', ['$scope', '$attrs', 'uibProgressConfig', '$log', '$progressSuppressWarning', function($scope, $attrs, progressConfig, $log, $progressSuppressWarning) {
if (!$progressSuppressWarning) {
$log.warn('ProgressController is now deprecated. Use UibProgressController instead.');
}

var self = this,
animate = angular.isDefined($attrs.animate) ? $scope.$parent.$eval($attrs.animate) : progressConfig.animate;

this.bars = [];
$scope.max = angular.isDefined($scope.max) ? $scope.max : progressConfig.max;

this.addBar = function(bar, element, attrs) {
if (!animate) {
element.css({'transition': 'none'});
}

this.bars.push(bar);

bar.max = $scope.max;
bar.title = attrs && angular.isDefined(attrs.title) ? attrs.title : 'progressbar';

bar.$watch('value', function(value) {
bar.recalculatePercentage();
});

bar.recalculatePercentage = function() {
bar.percent = +(100 * bar.value / bar.max).toFixed(2);

var totalPercentage = self.bars.reduce(function(total, bar) {
return total + bar.percent;
}, 0);

if (totalPercentage > 100) {
bar.percent -= totalPercentage - 100;
}
};

bar.$on('$destroy', function() {
element = null;
self.removeBar(bar);
});
};

this.removeBar = function(bar) {
this.bars.splice(this.bars.indexOf(bar), 1);
};

$scope.$watch('max', function(max) {
self.bars.forEach(function(bar) {
bar.max = $scope.max;
bar.recalculatePercentage();
});
});
}])

.directive('progress', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) {
return {
replace: true,
transclude: true,
controller: 'ProgressController',
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 {
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', ['$log', '$progressSuppressWarning', function($log, $progressSuppressWarning) {
return {
replace: true,
transclude: true,
controller: 'ProgressController',
scope: {
value: '=',
max: '=?',
type: '@'
},
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});
}
};
}]);
78 changes: 0 additions & 78 deletions src/progressbar/test/progressbar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,81 +341,3 @@ 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('<progress animate="false"><bar ng-repeat="o in objects" value="o.value" type="{{o.type}}">{{o.value}}</bar></progress>')($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('<progress animate="false"><bar ng-repeat="o in objects" value="o.value" type="{{o.type}}">{{o.value}}</bar></progress>')($rootScope);
$rootScope.$digest();

expect($log.warn.calls.count()).toBe(5);
expect($log.warn.calls.argsFor(0)).toEqual(['ProgressController is now deprecated. Use UibProgressController instead.']);
expect($log.warn.calls.argsFor(1)).toEqual(['progress is now deprecated. Use uib-progress 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.']);
expect($log.warn.calls.argsFor(4)).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('<progressbar animate="false" value="value" title="foo">{{value}} %</progressbar>')($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('<progressbar animate="false" value="value" title="foo">{{value}} %</progressbar>')($rootScope);
$rootScope.$digest();

expect($log.warn.calls.count()).toBe(2);
expect($log.warn.calls.argsFor(0)).toEqual(['ProgressController is now deprecated. Use UibProgressController instead.']);
expect($log.warn.calls.argsFor(1)).toEqual(['progressbar is now deprecated. Use uib-progressbar instead.']);
}));
});
});

0 comments on commit 0669b06

Please sign in to comment.