From b460273d5619846b618fcba5b6483d75561a4b99 Mon Sep 17 00:00:00 2001 From: Eric Fernandez Date: Mon, 8 Oct 2018 17:18:06 -0300 Subject: [PATCH] paginacion --- src/js/controller.js | 97 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 92 insertions(+), 5 deletions(-) diff --git a/src/js/controller.js b/src/js/controller.js index f51051e..94beece 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -19,7 +19,7 @@ angular.module('focaModalVendedores') $scope.currentPage = 1; $scope.filteredVendedores = []; $scope.currentPageVendedores = []; - $scope.selectVendedores = 0; + $scope.selectVendedores = -1; $scope.search = function () { $scope.filteredVendedores = $filter('filter')($scope.vendedores, { $: $scope.filters }); @@ -37,17 +37,104 @@ angular.module('focaModalVendedores') $scope.currentPageVendedores = $scope.filteredVendedores.slice(start, end); } - $scope.select = function(vendedor) { + $scope.select = function (vendedor) { $uibModalInstance.close(vendedor); } - $scope.cancel = function() { + $scope.cancel = function () { $uibModalInstance.dismiss('cancel'); } + $scope.busquedaDown = function (key) { + if (key === 40) { + primera(key); + } + }; - $scope.enter = function(key) { + $scope.busquedaPress = function (key) { if (key === 13) { - console.table($scope.currentPageVendedores); + primera(key); + } + }; + + $scope.itemProducto = function (key) { + if (key === 38) { + anterior(key); + } + + if (key === 40) { + siguiente(key); + } + + if (key === 37) { + retrocederPagina(); + } + + if (key === 39) { + avanzarPagina(); + } + }; + + function calcularPages(paginaActual) { + var paginas = []; + paginas.push(paginaActual); + + if (paginaActual - 1 > 1) { + + paginas.unshift(paginaActual - 1); + if (paginaActual - 2 > 1) { + paginas.unshift(paginaActual - 2); + } + } + + if (paginaActual + 1 < $scope.lastPage) { + paginas.push(paginaActual + 1); + if (paginaActual + 2 < $scope.lastPage) { + paginas.push(paginaActual + 2); + } + } + + if (paginaActual !== 1) { + paginas.unshift(1); + } + + if (paginaActual !== $scope.lastPage) { + paginas.push($scope.lastPage); + } + + return paginas; + } + + function primera() { + $scope.selectedProducto = 0; + } + + function anterior() { + if ($scope.selectedProducto === 0 && $scope.currentPage > 1) { + retrocederPagina(); + } else { + $scope.selectedProducto--; + } + } + + function siguiente() { + if ($scope.selectedProducto < $scope.currentPageProductos.length - 1) { + $scope.selectedProducto++; + } else { + avanzarPagina(); + } + } + + function retrocederPagina() { + if ($scope.currentPage > 1) { + $scope.selectPage($scope.currentPage - 1); + $scope.selectedProducto = $scope.numPerPage - 1; + } + } + + function avanzarPagina() { + if ($scope.currentPage < $scope.lastPage) { + $scope.selectPage($scope.currentPage + 1); + $scope.selectedProducto = 0; } } }] -- 1.9.1