From d4035e0ec336d61ff3e1e17ff2c6c3851916d083 Mon Sep 17 00:00:00 2001 From: kunw Date: Sat, 6 Aug 2016 15:11:20 +0800 Subject: [PATCH] updates for paginator and pagination in logs. --- .../js/components/log/list-log.directive.html | 2 +- .../js/components/log/list-log.directive.js | 2 +- .../paginator/paginator.directive.js | 45 +++++++------------ 3 files changed, 19 insertions(+), 30 deletions(-) diff --git a/static/resources/js/components/log/list-log.directive.html b/static/resources/js/components/log/list-log.directive.html index d0804e8b7..498129f2b 100644 --- a/static/resources/js/components/log/list-log.directive.html +++ b/static/resources/js/components/log/list-log.directive.html @@ -47,8 +47,8 @@ - + diff --git a/static/resources/js/components/log/list-log.directive.js b/static/resources/js/components/log/list-log.directive.js index a345cdb93..9daad971c 100644 --- a/static/resources/js/components/log/list-log.directive.js +++ b/static/resources/js/components/log/list-log.directive.js @@ -53,7 +53,7 @@ }; vm.page = 1; - vm.pageSize = 1; + vm.pageSize = 2; $scope.$watch('vm.totalCount', function(current) { if(current) { diff --git a/static/resources/js/components/paginator/paginator.directive.js b/static/resources/js/components/paginator/paginator.directive.js index c71bba9e6..a224730a6 100644 --- a/static/resources/js/components/paginator/paginator.directive.js +++ b/static/resources/js/components/paginator/paginator.directive.js @@ -22,8 +22,7 @@ 'totalCount': '@', 'pageSize': '@', 'page': '=', - 'displayCount': '@', - 'retrieve': '&' + 'displayCount': '@' }, 'link': link, 'controller': PaginatorController, @@ -57,6 +56,7 @@ ++this.time; ++ctrl.page; } + scope.$apply(); } TimeCounter.prototype.canIncrement = function() { @@ -71,6 +71,7 @@ --this.time; --ctrl.page; } + scope.$apply(); } TimeCounter.prototype.canDecrement = function() { @@ -93,11 +94,8 @@ tc.setMaximum(Math.floor(buttonCount / displayCount)); } - element.find('ul li:first a').on('click', previous); - ctrl.showPrevious = false; - + element.find('ul li:first a').on('click', previous); element.find('ul li:last a').on('click', next); - ctrl.showNext = (buttonCount > displayCount); var drawButtons = function(time) { element.find('li[tag="pagination-button"]').remove(); @@ -114,12 +112,12 @@ } drawButtons(tc.getTime()); - togglePrevious(false); - toggleNext((buttonCount > displayCount)); + + togglePrevious(tc.canDecrement()); + toggleNext(tc.canIncrement()); togglePageButton(); - function togglePrevious(status) { if(status){ element.find('ul li:first').removeClass('disabled'); @@ -133,38 +131,29 @@ element.find('ul li:last').removeClass('disabled'); }else{ element.find('ul li:last').addClass('disabled'); - } + } } function buttonClickHandler(e) { ctrl.page = $(e.target).attr('page'); - togglePageButton(); - ctrl.retrieve(); - - if(tc.canIncrement()) { - toggleNext(true); - }else { - toggleNext(false); - } - - if(tc.canDecrement()) { - togglePrevious(true); - }else{ - togglePrevious(false); - } + togglePageButton(); + togglePrevious(tc.canDecrement()); + toggleNext(tc.canIncrement()); + scope.$apply(); } function togglePageButton() { - element.find('li[tag="pagination-button"]').removeClass('active'); - element.find('li[tag="pagination-button"] a[page="' + ctrl.page + '"]').parent().addClass('active'); + element.find('li[tag="pagination-button"]').removeClass('active'); + element.find('li[tag="pagination-button"] a[page="' + ctrl.page + '"]').parent().addClass('active'); } function previous() { if(tc.canDecrement()) { tc.decrement(); drawButtons(tc.getTime()); - element.find('li[tag="pagination-button"] a[page="' + ctrl.page + '"]').trigger('click'); + element.find('li[tag="pagination-button"] a[page="' + ctrl.page + '"]').trigger('click'); } + scope.$apply(); } function next() { @@ -172,8 +161,8 @@ tc.increment(); drawButtons(tc.getTime()); element.find('li[tag="pagination-button"] a[page="' + ctrl.page + '"]').trigger('click'); - } + scope.$apply(); } } });