diff --git a/vipra-ui/app/html/articles/index.html b/vipra-ui/app/html/articles/index.html index 5560bfaff51ace0ddeb7c818e2d572d2fa7270fd..cece9c1853b073d5c5a442c3fa5296b27fa989f8 100644 --- a/vipra-ui/app/html/articles/index.html +++ b/vipra-ui/app/html/articles/index.html @@ -8,4 +8,4 @@ </li> </ul> -<pagination total="articlesMeta.total" page="page" limit="limit"/> \ No newline at end of file +<pagination total="articlesMeta.total" page="page" limit="limit" change="change"/> \ No newline at end of file diff --git a/vipra-ui/app/js/controllers.js b/vipra-ui/app/js/controllers.js index ddfd22e2af1b6ee2b77f9e09784bfdba42aa76a2..15d687b1e0ed4c6e6312dcd1d3f67bd6414d5a1a 100644 --- a/vipra-ui/app/js/controllers.js +++ b/vipra-ui/app/js/controllers.js @@ -79,20 +79,18 @@ $scope.page = Math.max($stateParams.page || 1, 1); $scope.limit = pageSize; - var loadedOnce = false; - $scope.$watch('page', function(newVal, oldVal) { - if(newVal != oldVal || !loadedOnce) { - loadedOnce = true; - ArticleFactory.query({ - skip: ($scope.page-1)*pageSize, - limit: pageSize - }, function(response) { - $scope.articles = response.data; - $scope.articlesMeta = response.meta; - $scope.queryTime = response.$queryTime; - }); - } - }); + $scope.change = function(page) { + ArticleFactory.query({ + skip: (page-1)*pageSize, + limit: pageSize + }, function(response) { + $scope.articles = response.data; + $scope.articlesMeta = response.meta; + $scope.queryTime = response.$queryTime; + }); + }; + + $scope.change($scope.page); }]); @@ -200,6 +198,9 @@ app.controller('PaginationController', ['$scope', function($scope) { + if(!$scope.page) + $scope.page = 1; + $scope.calculatePages = function() { var pages = [], max = Math.ceil($scope.total/$scope.limit*1.0), @@ -220,8 +221,11 @@ $scope.calculatePages(); + var change = $scope.change() || function() {}; + $scope.changePage = function(page) { $scope.page = page; + change(page); }; }]); diff --git a/vipra-ui/app/js/directives.js b/vipra-ui/app/js/directives.js index 007d8c2ff02265bf50b27c1cb7edc72fc2cadb11..4b0c64c862b840683e9ba829ff3f78f6719ea5c1 100644 --- a/vipra-ui/app/js/directives.js +++ b/vipra-ui/app/js/directives.js @@ -49,7 +49,8 @@ scope: { total: '=', page: '=', - limit: '=' + limit: '=', + change: '&' }, controller: 'PaginationController', templateUrl: 'html/directives/pagination.html'