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

Commit 2a3314d

Browse files
committed
feat(pager): move to separate component
- Separate pager into its own component Closes #4935
1 parent 2cd7f4f commit 2a3314d

File tree

9 files changed

+74
-68
lines changed

9 files changed

+74
-68
lines changed

src/pager/docs/demo.html

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div ng-controller="PagerDemoController">
2+
<h4>Pager</h4>
3+
<uib-pager total-items="totalItems" ng-model="currentPage"></uib-pager>
4+
</div>

src/pager/docs/demo.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
angular.module('ui.bootstrap.demo').controller('PagerDemoCtrl', function($scope) {
2+
$scope.totalItems = 64;
3+
$scope.currentPage = 4;
4+
});

src/pager/docs/readme.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
A lightweight pager directive that is focused on providing previous/next paging functionality
2+
3+
### Pager Settings ###
4+
5+
Settings can be provided as attributes in the `<uib-pager>` or globally configured through the `uibPagerConfig`.
6+
For `ng-model`, `total-items`, `items-per-page` and `num-pages` see pagination settings. Other settings are:
7+
8+
* `align`
9+
_(Default: true)_ :
10+
Whether to align each link to the sides.
11+
12+
* `previous-text`
13+
_(Default: '« Previous')_ :
14+
Text for Previous button.
15+
16+
* `next-text`
17+
_(Default: 'Next »')_ :
18+
Text for Next button.
19+
20+
* `template-url`
21+
_(Default: 'template/pagination/pager.html') :
22+
Override the template for the component with a custom provided template
23+
24+
* `ng-disabled` <i class="glyphicon glyphicon-eye-open"></i>
25+
:
26+
Used to disable the pager component

src/pager/pager.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
angular.module('ui.bootstrap.pager', ['ui.bootstrap.pagination'])
2+
3+
.constant('uibPagerConfig', {
4+
itemsPerPage: 10,
5+
previousText: '« Previous',
6+
nextText: 'Next »',
7+
align: true
8+
})
9+
10+
.directive('uibPager', ['uibPagerConfig', function(pagerConfig) {
11+
return {
12+
restrict: 'EA',
13+
scope: {
14+
totalItems: '=',
15+
previousText: '@',
16+
nextText: '@',
17+
ngDisabled: '='
18+
},
19+
require: ['uibPager', '?ngModel'],
20+
controller: 'UibPaginationController',
21+
controllerAs: 'pagination',
22+
templateUrl: function(element, attrs) {
23+
return attrs.templateUrl || 'uib/template/pager/pager.html';
24+
},
25+
replace: true,
26+
link: function(scope, element, attrs, ctrls) {
27+
var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];
28+
29+
if (!ngModelCtrl) {
30+
return; // do nothing if no ng-model
31+
}
32+
33+
scope.align = angular.isDefined(attrs.align) ? scope.$parent.$eval(attrs.align) : pagerConfig.align;
34+
paginationCtrl.init(ngModelCtrl, pagerConfig);
35+
}
36+
};
37+
}]);

src/pagination/test/pager.spec.js src/pager/test/pager.spec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
describe('pager directive', function() {
22
var $compile, $rootScope, $document, $templateCache, body, element;
3-
beforeEach(module('ui.bootstrap.pagination'));
4-
beforeEach(module('uib/template/pagination/pager.html'));
3+
beforeEach(module('ui.bootstrap.pager'));
4+
beforeEach(module('uib/template/pager/pager.html'));
55
beforeEach(inject(function(_$compile_, _$rootScope_, _$document_, _$templateCache_) {
66
$compile = _$compile_;
77
$rootScope = _$rootScope_;
@@ -54,7 +54,7 @@ describe('pager directive', function() {
5454
});
5555

5656
it('exposes the controller on the template', function() {
57-
$templateCache.put('uib/template/pagination/pager.html', '<div>{{pagination.text}}</div>');
57+
$templateCache.put('uib/template/pager/pager.html', '<div>{{pagination.text}}</div>');
5858

5959
element = $compile('<uib-pager></uib-pager>')($rootScope);
6060
$rootScope.$digest();

src/pagination/docs/demo.html

-4
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,4 @@ <h6><code>boundary-link-numbers</code> set to <code>true</code> and <code>rotate
2121
<uib-pagination total-items="bigTotalItems" ng-model="bigCurrentPage" max-size="maxSize" class="pagination-sm" boundary-link-numbers="true" rotate="false"></uib-pagination>
2222
<pre>Page: {{bigCurrentPage}} / {{numPages}}</pre>
2323

24-
<hr />
25-
<h4>Pager</h4>
26-
<uib-pager total-items="totalItems" ng-model="currentPage"></uib-pager>
27-
2824
</div>

src/pagination/docs/readme.md

-25
Original file line numberDiff line numberDiff line change
@@ -72,28 +72,3 @@ Settings can be provided as attributes in the `<uib-pagination>` or globally con
7272
* `template-url`
7373
_(Default: 'uib/template/pagination/pagination.html')_ :
7474
Override the template for the component with a custom provided template
75-
76-
### Pager Settings ###
77-
78-
Settings can be provided as attributes in the `<uib-pager>` or globally configured through the `uibPagerConfig`.
79-
For `ng-model`, `total-items`, `items-per-page` and `num-pages` see pagination settings. Other settings are:
80-
81-
* `align`
82-
_(Default: true)_ :
83-
Whether to align each link to the sides.
84-
85-
* `previous-text`
86-
_(Default: '« Previous')_ :
87-
Text for Previous button.
88-
89-
* `next-text`
90-
_(Default: 'Next »')_ :
91-
Text for Next button.
92-
93-
* `template-url`
94-
_(Default: 'template/pagination/pager.html') :
95-
Override the template for the component with a custom provided template
96-
97-
* `ng-disabled` <i class="glyphicon glyphicon-eye-open"></i>
98-
:
99-
Used to disable the pager component

src/pagination/pagination.js

-36
Original file line numberDiff line numberDiff line change
@@ -221,40 +221,4 @@ angular.module('ui.bootstrap.pagination', [])
221221
};
222222
}
223223
};
224-
}])
225-
226-
.constant('uibPagerConfig', {
227-
itemsPerPage: 10,
228-
previousText: '« Previous',
229-
nextText: 'Next »',
230-
align: true
231-
})
232-
233-
.directive('uibPager', ['uibPagerConfig', function(pagerConfig) {
234-
return {
235-
restrict: 'EA',
236-
scope: {
237-
totalItems: '=',
238-
previousText: '@',
239-
nextText: '@',
240-
ngDisabled: '='
241-
},
242-
require: ['uibPager', '?ngModel'],
243-
controller: 'UibPaginationController',
244-
controllerAs: 'pagination',
245-
templateUrl: function(element, attrs) {
246-
return attrs.templateUrl || 'uib/template/pagination/pager.html';
247-
},
248-
replace: true,
249-
link: function(scope, element, attrs, ctrls) {
250-
var paginationCtrl = ctrls[0], ngModelCtrl = ctrls[1];
251-
252-
if (!ngModelCtrl) {
253-
return; // do nothing if no ng-model
254-
}
255-
256-
scope.align = angular.isDefined(attrs.align) ? scope.$parent.$eval(attrs.align) : pagerConfig.align;
257-
paginationCtrl.init(ngModelCtrl, pagerConfig);
258-
}
259-
};
260224
}]);
File renamed without changes.

0 commit comments

Comments
 (0)