2018-02-10 15:18:01 +00:00
|
|
|
import ngModule from '../../module';
|
2017-02-21 10:36:43 +00:00
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
export default class Paging {
|
|
|
|
get numPages() {
|
|
|
|
return Math.ceil(this.numItems / this.numPerPage);
|
|
|
|
}
|
2017-10-04 11:27:39 +00:00
|
|
|
|
2017-02-21 10:36:43 +00:00
|
|
|
constructor($http, $scope) {
|
|
|
|
this.$http = $http;
|
|
|
|
this.$scope = $scope;
|
|
|
|
this.where = this.filter;
|
|
|
|
this.numPerPage = null;
|
|
|
|
this.numItems = 0;
|
|
|
|
$scope.$watch('$ctrl.index.model.length', () => this.onModelUpdated());
|
|
|
|
}
|
2017-10-04 11:27:39 +00:00
|
|
|
|
2017-05-17 12:58:23 +00:00
|
|
|
$onChanges(changes) {
|
2017-05-16 10:37:48 +00:00
|
|
|
if (!this.index) return;
|
2017-02-21 10:36:43 +00:00
|
|
|
this.numPerPage = this.index.filter.size;
|
2017-06-22 10:03:01 +00:00
|
|
|
this.currentPage = this.index.filter.page;
|
|
|
|
if (changes.total)
|
2017-05-17 12:58:23 +00:00
|
|
|
this.numItems = changes.total.currentValue;
|
2017-02-21 10:36:43 +00:00
|
|
|
}
|
2017-10-04 11:27:39 +00:00
|
|
|
|
2017-02-21 10:36:43 +00:00
|
|
|
onModelUpdated() {
|
|
|
|
let index = this.index;
|
|
|
|
let filter = index.filter;
|
|
|
|
|
2017-10-04 11:27:39 +00:00
|
|
|
if (filter.page >= this.numPages && index.model.length >= this.numPerPage)
|
2017-02-21 10:36:43 +00:00
|
|
|
this.numItems = filter.page * filter.size + 1;
|
|
|
|
}
|
2017-10-04 11:27:39 +00:00
|
|
|
|
2017-02-21 10:36:43 +00:00
|
|
|
onPageChange(page) {
|
|
|
|
this.index.filter.page = page;
|
2017-06-22 10:03:01 +00:00
|
|
|
if (typeof this.pageChange === 'undefined') {
|
|
|
|
this.index.accept();
|
|
|
|
} else {
|
|
|
|
this.pageChange();
|
|
|
|
}
|
2017-02-21 10:36:43 +00:00
|
|
|
}
|
2017-11-15 07:41:54 +00:00
|
|
|
$doCheck() {
|
|
|
|
if (this.index && this.index.filter && this.index.filter.page && this.index.filter.page != this.currentPage) {
|
|
|
|
this.currentPage = this.index.filter.page;
|
|
|
|
}
|
|
|
|
}
|
2017-02-21 10:36:43 +00:00
|
|
|
}
|
|
|
|
Paging.$inject = ['$http', '$scope'];
|
|
|
|
|
2018-02-10 15:18:01 +00:00
|
|
|
ngModule.component('vnPaging', {
|
2017-05-31 08:28:39 +00:00
|
|
|
template: require('./paging.html'),
|
2017-02-21 10:36:43 +00:00
|
|
|
bindings: {
|
2017-05-17 12:58:23 +00:00
|
|
|
index: '<',
|
2017-06-22 10:03:01 +00:00
|
|
|
pageChange: '&?',
|
2017-05-17 12:58:23 +00:00
|
|
|
total: '<'
|
2017-02-21 10:36:43 +00:00
|
|
|
},
|
|
|
|
controller: Paging
|
2018-02-10 15:18:01 +00:00
|
|
|
});
|