updates for paginator toggling previous and next.

This commit is contained in:
kunw 2016-08-06 17:19:29 +08:00
parent 066d108012
commit 8245eeaec9
2 changed files with 36 additions and 23 deletions

View File

@ -101,7 +101,7 @@
vm.queryParams.beginTimestamp = toUTCSeconds(vm.fromDate, 0, 0, 0); vm.queryParams.beginTimestamp = toUTCSeconds(vm.fromDate, 0, 0, 0);
vm.queryParams.endTimestamp = toUTCSeconds(vm.toDate, 23, 59, 59); vm.queryParams.endTimestamp = toUTCSeconds(vm.toDate, 23, 59, 59);
vm.page = 1;
retrieve(vm.queryParams, vm.page, vm.pageSize); retrieve(vm.queryParams, vm.page, vm.pageSize);
} }

View File

@ -33,21 +33,25 @@
function link(scope, element, attrs, ctrl) { function link(scope, element, attrs, ctrl) {
var tc;
scope.$watch('vm.totalCount', function(current) { scope.$watch('vm.totalCount', function(current) {
if(current) { if(current) {
var totalCount = current; var totalCount = current;
var pageSize = parseInt(ctrl.pageSize);
var displayCount = parseInt(ctrl.displayCount);
console.log('Total Count:' + totalCount + ', Page Size:' + pageSize + ', Display Count:' + displayCount); element.find('ul li:first a').off('click');
element.find('ul li:last a').off('click');
var buttonCount = Math.ceil(totalCount / pageSize); tc = new TimeCounter();
ctrl.buttonCount = buttonCount;
if(buttonCount <= displayCount) { console.log('Total Count:' + totalCount + ', Page Size:' + ctrl.pageSize + ', Display Count:' + ctrl.displayCount + ', Page:' + ctrl.page);
ctrl.buttonCount = Math.ceil(totalCount / ctrl.pageSize);
if(ctrl.buttonCount <= ctrl.displayCount) {
tc.setMaximum(0); tc.setMaximum(0);
}else{ }else{
tc.setMaximum(Math.floor(buttonCount / displayCount)); tc.setMaximum(Math.floor(ctrl.buttonCount / ctrl.displayCount));
} }
element.find('ul li:first a').on('click', previous); element.find('ul li:first a').on('click', previous);
@ -71,45 +75,54 @@
TimeCounter.prototype.setMaximum = function(maximum) { TimeCounter.prototype.setMaximum = function(maximum) {
this.maximum = maximum; this.maximum = maximum;
} };
TimeCounter.prototype.increment = function() { TimeCounter.prototype.increment = function() {
if(this.time < this.maximum) { if(this.time < this.maximum) {
++this.time; ++this.time;
if((ctrl.page % ctrl.displayCount) != 0) {
ctrl.page = this.time * ctrl.displayCount;
}
++ctrl.page; ++ctrl.page;
console.log('Increment Page:' + ctrl.page + ', DisplayCount:' + ctrl.displayCount + ',Time:' + this.time);
} }
scope.$apply(); scope.$apply();
} };
TimeCounter.prototype.canIncrement = function() { TimeCounter.prototype.canIncrement = function() {
if(this.time < this.maximum) { if(this.time < this.maximum) {
return true; return true;
} }
return false; return false;
} };
TimeCounter.prototype.decrement = function() { TimeCounter.prototype.decrement = function() {
if(this.time > this.minimum) { if(this.time > this.minimum) {
--this.time; --this.time;
--ctrl.page; --ctrl.page;
if(this.time === 0) {
ctrl.page = ctrl.displayCount;
}else if((ctrl.page % ctrl.displayCount) != 0) {
ctrl.page = this.time * ctrl.displayCount;
}
console.log('Decrement Page:' + ctrl.page + ', DisplayCount:' + ctrl.displayCount + ',Time:' + this.time);
} }
scope.$apply(); scope.$apply();
} };
TimeCounter.prototype.canDecrement = function() { TimeCounter.prototype.canDecrement = function() {
if(this.time > this.minimum) { if(this.time > this.minimum) {
return true; return true;
} }
return false; return false;
} };
TimeCounter.prototype.getTime = function() { TimeCounter.prototype.getTime = function() {
return this.time; return this.time;
} };
var tc = new TimeCounter(); function drawButtons(time) {
function drawButtons(time, displayCount, buttonCount) {
element.find('li[tag="pagination-button"]').remove(); element.find('li[tag="pagination-button"]').remove();
var buttons = []; var buttons = [];
for(var i = 1; i <= ctrl.displayCount; i++) { for(var i = 1; i <= ctrl.displayCount; i++) {