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

Commit 75e493a

Browse files
Foxandxsswesleycho
authored andcommitted
feat(pagination): remove deprecated code
BREAKING CHANGE: Remove deprecated non-prefixed directives Closes #4720
1 parent feb2b73 commit 75e493a

File tree

3 files changed

+1
-287
lines changed

3 files changed

+1
-287
lines changed

Diff for: src/pagination/pagination.js

-226
Original file line numberDiff line numberDiff line change
@@ -229,229 +229,3 @@ angular.module('ui.bootstrap.pagination', [])
229229
}
230230
};
231231
}]);
232-
233-
/* Deprecated Pagination Below */
234-
235-
angular.module('ui.bootstrap.pagination')
236-
.value('$paginationSuppressWarning', false)
237-
.controller('PaginationController', ['$scope', '$attrs', '$parse', '$log', '$paginationSuppressWarning', function($scope, $attrs, $parse, $log, $paginationSuppressWarning) {
238-
if (!$paginationSuppressWarning) {
239-
$log.warn('PaginationController is now deprecated. Use UibPaginationController instead.');
240-
}
241-
242-
var self = this,
243-
ngModelCtrl = { $setViewValue: angular.noop }, // nullModelCtrl
244-
setNumPages = $attrs.numPages ? $parse($attrs.numPages).assign : angular.noop;
245-
246-
this.init = function(ngModelCtrl_, config) {
247-
ngModelCtrl = ngModelCtrl_;
248-
this.config = config;
249-
250-
ngModelCtrl.$render = function() {
251-
self.render();
252-
};
253-
254-
if ($attrs.itemsPerPage) {
255-
$scope.$parent.$watch($parse($attrs.itemsPerPage), function(value) {
256-
self.itemsPerPage = parseInt(value, 10);
257-
$scope.totalPages = self.calculateTotalPages();
258-
});
259-
} else {
260-
this.itemsPerPage = config.itemsPerPage;
261-
}
262-
263-
$scope.$watch('totalItems', function() {
264-
$scope.totalPages = self.calculateTotalPages();
265-
});
266-
267-
$scope.$watch('totalPages', function(value) {
268-
setNumPages($scope.$parent, value); // Readonly variable
269-
270-
if ( $scope.page > value ) {
271-
$scope.selectPage(value);
272-
} else {
273-
ngModelCtrl.$render();
274-
}
275-
});
276-
};
277-
278-
this.calculateTotalPages = function() {
279-
var totalPages = this.itemsPerPage < 1 ? 1 : Math.ceil($scope.totalItems / this.itemsPerPage);
280-
return Math.max(totalPages || 0, 1);
281-
};
282-
283-
this.render = function() {
284-
$scope.page = parseInt(ngModelCtrl.$viewValue, 10) || 1;
285-
};
286-
287-
$scope.selectPage = function(page, evt) {
288-
if (evt) {
289-
evt.preventDefault();
290-
}
291-
292-
var clickAllowed = !$scope.ngDisabled || !evt;
293-
if (clickAllowed && $scope.page !== page && page > 0 && page <= $scope.totalPages) {
294-
if (evt && evt.target) {
295-
evt.target.blur();
296-
}
297-
ngModelCtrl.$setViewValue(page);
298-
ngModelCtrl.$render();
299-
}
300-
};
301-
302-
$scope.getText = function(key) {
303-
return $scope[key + 'Text'] || self.config[key + 'Text'];
304-
};
305-
306-
$scope.noPrevious = function() {
307-
return $scope.page === 1;
308-
};
309-
310-
$scope.noNext = function() {
311-
return $scope.page === $scope.totalPages;
312-
};
313-
}])
314-
.directive('pagination', ['$parse', 'uibPaginationConfig', '$log', '$paginationSuppressWarning', function($parse, paginationConfig, $log, $paginationSuppressWarning) {
315-
return {
316-
restrict: 'EA',
317-
scope: {
318-
totalItems: '=',
319-
firstText: '@',
320-
previousText: '@',
321-
nextText: '@',
322-
lastText: '@',
323-
ngDisabled:'='
324-
},
325-
require: ['pagination', '?ngModel'],
326-
controller: 'PaginationController',
327-
controllerAs: 'pagination',
328-
templateUrl: function(element, attrs) {
329-
return attrs.templateUrl || 'template/pagination/pagination.html';
330-
},
331-
replace: true,
332-
link: function(scope, element, attrs, ctrls) {
333-
if (!$paginationSuppressWarning) {
334-
$log.warn('pagination is now deprecated. Use uib-pagination instead.');
335-
}
336-
var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];
337-
338-
if (!ngModelCtrl) {
339-
return; // do nothing if no ng-model
340-
}
341-
342-
// Setup configuration parameters
343-
var maxSize = angular.isDefined(attrs.maxSize) ? scope.$parent.$eval(attrs.maxSize) : paginationConfig.maxSize,
344-
rotate = angular.isDefined(attrs.rotate) ? scope.$parent.$eval(attrs.rotate) : paginationConfig.rotate;
345-
scope.boundaryLinks = angular.isDefined(attrs.boundaryLinks) ? scope.$parent.$eval(attrs.boundaryLinks) : paginationConfig.boundaryLinks;
346-
scope.directionLinks = angular.isDefined(attrs.directionLinks) ? scope.$parent.$eval(attrs.directionLinks) : paginationConfig.directionLinks;
347-
348-
paginationCtrl.init(ngModelCtrl, paginationConfig);
349-
350-
if (attrs.maxSize) {
351-
scope.$parent.$watch($parse(attrs.maxSize), function(value) {
352-
maxSize = parseInt(value, 10);
353-
paginationCtrl.render();
354-
});
355-
}
356-
357-
// Create page object used in template
358-
function makePage(number, text, isActive) {
359-
return {
360-
number: number,
361-
text: text,
362-
active: isActive
363-
};
364-
}
365-
366-
function getPages(currentPage, totalPages) {
367-
var pages = [];
368-
369-
// Default page limits
370-
var startPage = 1, endPage = totalPages;
371-
var isMaxSized = angular.isDefined(maxSize) && maxSize < totalPages;
372-
373-
// recompute if maxSize
374-
if (isMaxSized) {
375-
if (rotate) {
376-
// Current page is displayed in the middle of the visible ones
377-
startPage = Math.max(currentPage - Math.floor(maxSize/2), 1);
378-
endPage = startPage + maxSize - 1;
379-
380-
// Adjust if limit is exceeded
381-
if (endPage > totalPages) {
382-
endPage = totalPages;
383-
startPage = endPage - maxSize + 1;
384-
}
385-
} else {
386-
// Visible pages are paginated with maxSize
387-
startPage = ((Math.ceil(currentPage / maxSize) - 1) * maxSize) + 1;
388-
389-
// Adjust last page if limit is exceeded
390-
endPage = Math.min(startPage + maxSize - 1, totalPages);
391-
}
392-
}
393-
394-
// Add page number links
395-
for (var number = startPage; number <= endPage; number++) {
396-
var page = makePage(number, number, number === currentPage);
397-
pages.push(page);
398-
}
399-
400-
// Add links to move between page sets
401-
if (isMaxSized && ! rotate) {
402-
if (startPage > 1) {
403-
var previousPageSet = makePage(startPage - 1, '...', false);
404-
pages.unshift(previousPageSet);
405-
}
406-
407-
if (endPage < totalPages) {
408-
var nextPageSet = makePage(endPage + 1, '...', false);
409-
pages.push(nextPageSet);
410-
}
411-
}
412-
413-
return pages;
414-
}
415-
416-
var originalRender = paginationCtrl.render;
417-
paginationCtrl.render = function() {
418-
originalRender();
419-
if (scope.page > 0 && scope.page <= scope.totalPages) {
420-
scope.pages = getPages(scope.page, scope.totalPages);
421-
}
422-
};
423-
}
424-
};
425-
}])
426-
427-
.directive('pager', ['uibPagerConfig', '$log', '$paginationSuppressWarning', function(pagerConfig, $log, $paginationSuppressWarning) {
428-
return {
429-
restrict: 'EA',
430-
scope: {
431-
totalItems: '=',
432-
previousText: '@',
433-
nextText: '@',
434-
ngDisabled: '='
435-
},
436-
require: ['pager', '?ngModel'],
437-
controller: 'PaginationController',
438-
controllerAs: 'pagination',
439-
templateUrl: function(element, attrs) {
440-
return attrs.templateUrl || 'template/pagination/pager.html';
441-
},
442-
replace: true,
443-
link: function(scope, element, attrs, ctrls) {
444-
if (!$paginationSuppressWarning) {
445-
$log.warn('pager is now deprecated. Use uib-pager instead.');
446-
}
447-
var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];
448-
449-
if (!ngModelCtrl) {
450-
return; // do nothing if no ng-model
451-
}
452-
453-
scope.align = angular.isDefined(attrs.align) ? scope.$parent.$eval(attrs.align) : pagerConfig.align;
454-
paginationCtrl.init(ngModelCtrl, pagerConfig);
455-
}
456-
};
457-
}]);

Diff for: src/pagination/test/pager.spec.js

+1-31
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ describe('pager directive', function() {
147147
it('allows custom templates', function() {
148148
$templateCache.put('foo/bar.html', '<div>baz</div>');
149149

150-
element = $compile('<pager template-url="foo/bar.html"></pager>')($rootScope);
150+
element = $compile('<uib-pager template-url="foo/bar.html"></uib-pager>')($rootScope);
151151
$rootScope.$digest();
152152

153153
expect(element.html()).toBe('baz');
@@ -279,33 +279,3 @@ describe('pager directive', function() {
279279
expect(getPaginationEl(-1)).toHaveClass('disabled');
280280
});
281281
});
282-
283-
describe('pager deprecation', function() {
284-
beforeEach(module('ui.bootstrap.pagination'));
285-
beforeEach(module('template/pagination/pager.html'));
286-
287-
it('should suppress warning', function() {
288-
module(function($provide) {
289-
$provide.value('$paginationSuppressWarning', true);
290-
});
291-
292-
inject(function($compile, $log, $rootScope) {
293-
spyOn($log, 'warn');
294-
295-
var element = $compile('<pager total-items="total" ng-model="currentPage"></pager>')($rootScope);
296-
$rootScope.$digest();
297-
expect($log.warn.calls.count()).toBe(0);
298-
});
299-
});
300-
301-
it('should give warning by default', inject(function($compile, $log, $rootScope) {
302-
spyOn($log, 'warn');
303-
304-
var element = $compile('<pager total-items="total" ng-model="currentPage"></pager>')($rootScope);
305-
$rootScope.$digest();
306-
307-
expect($log.warn.calls.count()).toBe(2);
308-
expect($log.warn.calls.argsFor(0)).toEqual(['PaginationController is now deprecated. Use UibPaginationController instead.']);
309-
expect($log.warn.calls.argsFor(1)).toEqual(['pager is now deprecated. Use uib-pager instead.']);
310-
}));
311-
});

Diff for: src/pagination/test/pagination.spec.js

-30
Original file line numberDiff line numberDiff line change
@@ -734,33 +734,3 @@ describe('pagination directive', function() {
734734
});
735735
});
736736
});
737-
738-
describe('pagination deprecation', function() {
739-
beforeEach(module('ui.bootstrap.pagination'));
740-
beforeEach(module('template/pagination/pagination.html'));
741-
742-
it('should suppress warning', function() {
743-
module(function($provide) {
744-
$provide.value('$paginationSuppressWarning', true);
745-
});
746-
747-
inject(function($compile, $log, $rootScope) {
748-
spyOn($log, 'warn');
749-
750-
var element = $compile('<pagination></pagination>')($rootScope);
751-
$rootScope.$digest();
752-
expect($log.warn.calls.count()).toBe(0);
753-
});
754-
});
755-
756-
it('should give warning by default', inject(function($compile, $log, $rootScope) {
757-
spyOn($log, 'warn');
758-
759-
var element = $compile('<pagination></pagination>')($rootScope);
760-
$rootScope.$digest();
761-
762-
expect($log.warn.calls.count()).toBe(2);
763-
expect($log.warn.calls.argsFor(0)).toEqual(['PaginationController is now deprecated. Use UibPaginationController instead.']);
764-
expect($log.warn.calls.argsFor(1)).toEqual(['pagination is now deprecated. Use uib-pagination instead.']);
765-
}));
766-
});

0 commit comments

Comments
 (0)