2017-02-21 10:36:43 +00:00
|
|
|
import {module} from '../module';
|
|
|
|
import './style.scss';
|
|
|
|
|
|
|
|
export default class Paging {
|
|
|
|
get numPages() {
|
|
|
|
return Math.ceil(this.numItems / this.numPerPage);
|
|
|
|
}
|
|
|
|
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-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-05-17 12:58:23 +00:00
|
|
|
if(changes.total)
|
|
|
|
this.numItems = changes.total.currentValue;
|
2017-02-21 10:36:43 +00:00
|
|
|
}
|
|
|
|
onModelUpdated() {
|
|
|
|
let index = this.index;
|
|
|
|
let filter = index.filter;
|
|
|
|
|
2017-05-16 10:37:48 +00:00
|
|
|
if (filter.page >= this.numPages
|
2017-02-21 10:36:43 +00:00
|
|
|
&& index.model.length >= this.numPerPage)
|
|
|
|
this.numItems = filter.page * filter.size + 1;
|
|
|
|
}
|
|
|
|
onPageChange(page) {
|
|
|
|
this.index.filter.page = page;
|
|
|
|
this.index.accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Paging.$inject = ['$http', '$scope'];
|
|
|
|
|
|
|
|
export const NAME = 'vnPaging';
|
|
|
|
export const COMPONENT = {
|
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: '<',
|
|
|
|
total: '<'
|
2017-02-21 10:36:43 +00:00
|
|
|
},
|
|
|
|
controller: Paging
|
|
|
|
};
|
|
|
|
module.component(NAME, COMPONENT);
|