From 56fdebb8530801040112ef9848c8323d6f3d196d Mon Sep 17 00:00:00 2001 From: Stacey Gammon Date: Thu, 11 May 2017 14:39:53 -0400 Subject: [PATCH] Fix bug in dashboard Add panel pager where it always said `x of x` (#11617) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * pagination fixed * pagination label changed * Variations on the pager implementation * Add a safety check since this relies on inherited scope. * Don't use noop function It’s possible a parent could mess with the function after we set it to a noop (maybe delete it)? --- src/ui/public/directives/paginate.js | 10 ++++++++++ src/ui/public/directives/saved_object_finder.js | 7 +++++++ src/ui/public/partials/saved_object_finder.html | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/ui/public/directives/paginate.js b/src/ui/public/directives/paginate.js index 8140b17d2b380..8894229fec1e0 100644 --- a/src/ui/public/directives/paginate.js +++ b/src/ui/public/directives/paginate.js @@ -122,6 +122,8 @@ uiModules.get('kibana') page.count = count; page.first = page.number === 1; page.last = page.number === count; + page.firstItem = (page.number - 1) * perPage + 1; + page.lastItem = Math.min(page.number * perPage, $scope.list.length); page.prev = $scope.pages[i - 1]; if (page.prev) page.prev.next = page; @@ -135,6 +137,10 @@ uiModules.get('kibana') } else { $scope.page = $scope.pages[0]; } + + if ($scope.page && $scope.onPageChanged) { + $scope.onPageChanged($scope.page); + } }; self.changePage = function (page) { @@ -171,6 +177,10 @@ uiModules.get('kibana') if (other.last) $scope.otherPages.containsLast = true; if (other.first) $scope.otherPages.containsFirst = true; } + + if ($scope.onPageChanged) { + $scope.onPageChanged($scope.page); + } }; function setPerPage(val) { diff --git a/src/ui/public/directives/saved_object_finder.js b/src/ui/public/directives/saved_object_finder.js index 3114aa7bba629..ddb50664fd59b 100644 --- a/src/ui/public/directives/saved_object_finder.js +++ b/src/ui/public/directives/saved_object_finder.js @@ -119,6 +119,13 @@ module.directive('savedObjectFinder', function ($location, $injector, kbnUrl, Pr filterResults(); }); + $scope.pageFirstItem = 0; + $scope.pageLastItem = 0; + $scope.onPageChanged = (page) => { + $scope.pageFirstItem = page.firstItem; + $scope.pageLastItem = page.lastItem; + }; + //manages the state of the keyboard selector self.selector = { enabled: false, diff --git a/src/ui/public/partials/saved_object_finder.html b/src/ui/public/partials/saved_object_finder.html index 11e9687ec3cce..ffeb0693e4e8b 100644 --- a/src/ui/public/partials/saved_object_finder.html +++ b/src/ui/public/partials/saved_object_finder.html @@ -21,7 +21,7 @@

- {{ finder.hitCount }} of {{ finder.hitCount }} + {{ pageFirstItem }}-{{ pageLastItem }} of {{ finder.hitCount }}