Commit a67e491ef513d4716eb8b8b70b54fb236b3ff0b6
Exists in
master
Merge branch 'master' into 'master'
Master See merge request !5
Showing
2 changed files
Show diff stats
src/js/controller.js
| ... | ... | @@ -4,10 +4,9 @@ angular.module('focaCrearLogin') |
| 4 | 4 | function($scope, $timeout, $uibModal, focaCrearLoginService, focaBotoneraLateralService) { |
| 5 | 5 | config(); |
| 6 | 6 | |
| 7 | - | |
| 8 | - | |
| 9 | 7 | //METODOS |
| 10 | 8 | function init() { |
| 9 | + $scope.numPerPage = 9; | |
| 11 | 10 | $scope.now = new Date(); |
| 12 | 11 | $scope.seleccionado = ''; |
| 13 | 12 | $scope.cuentas = []; |
| ... | ... | @@ -65,7 +64,7 @@ angular.module('focaCrearLogin') |
| 65 | 64 | var parametros = { |
| 66 | 65 | cuenta: cuenta, |
| 67 | 66 | tipo: $scope.seleccionado |
| 68 | - } | |
| 67 | + }; | |
| 69 | 68 | |
| 70 | 69 | var modalInstance = $uibModal.open( |
| 71 | 70 | { |
| ... | ... | @@ -86,11 +85,31 @@ angular.module('focaCrearLogin') |
| 86 | 85 | init(); |
| 87 | 86 | }, function() {} |
| 88 | 87 | ); |
| 89 | - } | |
| 88 | + }; | |
| 89 | + | |
| 90 | + $scope.selectPage = function(page) { | |
| 91 | + var start = (page - 1) * $scope.numPerPage; | |
| 92 | + var end = start + $scope.numPerPage; | |
| 93 | + $scope.paginas = []; | |
| 94 | + $scope.paginas = calcularPages(page); | |
| 95 | + $scope.currentPageUsuarios = | |
| 96 | + $scope.cuentas.slice(start, end); | |
| 97 | + $scope.currentPage = page; | |
| 98 | + }; | |
| 99 | + | |
| 100 | + $scope.resetPage = function() { | |
| 101 | + $scope.currentPage = 1; | |
| 102 | + $scope.selectPage(1); | |
| 103 | + }; | |
| 90 | 104 | |
| 91 | 105 | function setearTabla(datos) { |
| 92 | 106 | $scope.cuentas = datos.data; |
| 93 | 107 | |
| 108 | + $scope.lastPage = Math.ceil( | |
| 109 | + $scope.cuentas.length / $scope.numPerPage | |
| 110 | + ); | |
| 111 | + $scope.resetPage(); | |
| 112 | + | |
| 94 | 113 | if ($scope.seleccionado == 'Cobradores' || |
| 95 | 114 | $scope.seleccionado == 'Vendedores' |
| 96 | 115 | ) { |
| ... | ... | @@ -107,5 +126,69 @@ angular.module('focaCrearLogin') |
| 107 | 126 | valor: $scope.seleccionado |
| 108 | 127 | }); |
| 109 | 128 | } |
| 129 | + | |
| 130 | + function calcularPages(paginaActual) { | |
| 131 | + var paginas = []; | |
| 132 | + paginas.push(paginaActual); | |
| 133 | + | |
| 134 | + if(paginaActual - 1 > 1) { | |
| 135 | + | |
| 136 | + paginas.unshift(paginaActual - 1); | |
| 137 | + if(paginaActual - 2 > 1) { | |
| 138 | + paginas.unshift(paginaActual - 2); | |
| 139 | + } | |
| 140 | + } | |
| 141 | + | |
| 142 | + if(paginaActual + 1 < $scope.lastPage) { | |
| 143 | + paginas.push(paginaActual + 1); | |
| 144 | + if(paginaActual + 2 < $scope.lastPage) { | |
| 145 | + paginas.push(paginaActual + 2); | |
| 146 | + } | |
| 147 | + } | |
| 148 | + | |
| 149 | + if(paginaActual !== 1) { | |
| 150 | + paginas.unshift(1); | |
| 151 | + } | |
| 152 | + | |
| 153 | + if(paginaActual !== $scope.lastPage) { | |
| 154 | + paginas.push($scope.lastPage); | |
| 155 | + } | |
| 156 | + | |
| 157 | + return paginas; | |
| 158 | + } | |
| 159 | + | |
| 160 | + function primera() { | |
| 161 | + $scope.selectedUsuarios = 0; | |
| 162 | + } | |
| 163 | + | |
| 164 | + function anterior() { | |
| 165 | + if ($scope.selectedUsuarios === 0 && $scope.currentPage > 1) { | |
| 166 | + retrocederPagina(); | |
| 167 | + } else { | |
| 168 | + $scope.selectedUsuarios--; | |
| 169 | + } | |
| 170 | + } | |
| 171 | + | |
| 172 | + function siguiente() { | |
| 173 | + if ($scope.selectedUsuarios < $scope.currentPageUsuarios.length - 1 ) { | |
| 174 | + $scope.selectedUsuarios++; | |
| 175 | + } else { | |
| 176 | + avanzarPagina(); | |
| 177 | + } | |
| 178 | + } | |
| 179 | + | |
| 180 | + function retrocederPagina() { | |
| 181 | + if ($scope.currentPage > 1) { | |
| 182 | + $scope.selectPage($scope.currentPage - 1); | |
| 183 | + $scope.selectedUsuarios = $scope.numPerPage - 1; | |
| 184 | + } | |
| 185 | + } | |
| 186 | + | |
| 187 | + function avanzarPagina() { | |
| 188 | + if ($scope.currentPage < $scope.lastPage) { | |
| 189 | + $scope.selectPage($scope.currentPage + 1); | |
| 190 | + $scope.selectedUsuarios = 0; | |
| 191 | + } | |
| 192 | + } | |
| 110 | 193 | } |
| 111 | 194 | ]); |
src/views/foca-crear-login.html
| ... | ... | @@ -9,7 +9,7 @@ |
| 9 | 9 | <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> |
| 10 | 10 | <div class="row px-5 py-2 botonera-secundaria"> |
| 11 | 11 | <div class="col-12"> |
| 12 | - <foca-botonera-facturador botones="botonera" extra="3" class="row"></foca-botonera-facturador> | |
| 12 | + <foca-botonera-facturador botones="botonera" max="6" class="row"></foca-botonera-facturador> | |
| 13 | 13 | </div> |
| 14 | 14 | </div> |
| 15 | 15 | <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> |
| ... | ... | @@ -24,7 +24,7 @@ |
| 24 | 24 | </tr> |
| 25 | 25 | </thead> |
| 26 | 26 | <tbody> |
| 27 | - <tr ng-repeat="cuenta in cuentas | filter:filters"> | |
| 27 | + <tr ng-repeat="cuenta in currentPageUsuarios"> | |
| 28 | 28 | <td ng-bind="cuenta.id"></td> |
| 29 | 29 | <td ng-bind="cuenta.nombre"></td> |
| 30 | 30 | <td ng-bind="cuenta.dni"></td> |
| ... | ... | @@ -43,3 +43,33 @@ |
| 43 | 43 | </table> |
| 44 | 44 | </div> |
| 45 | 45 | </div> |
| 46 | +<div class="row"> | |
| 47 | + <nav ng-show="currentPageUsuarios.length > 0" class="mr-auto"> | |
| 48 | + <ul class="pagination pagination-sm mb-0"> | |
| 49 | + <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | |
| 50 | + <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage - 1)"> | |
| 51 | + <span aria-hidden="true">«</span> | |
| 52 | + <span class="sr-only">Anterior</span> | |
| 53 | + </a> | |
| 54 | + </li> | |
| 55 | + <li | |
| 56 | + class="page-item" | |
| 57 | + ng-repeat="pagina in paginas" | |
| 58 | + ng-class="{'active': pagina == currentPage}" | |
| 59 | + > | |
| 60 | + <a | |
| 61 | + class="page-link" | |
| 62 | + href="javascript:void()" | |
| 63 | + ng-click="selectPage(pagina)" | |
| 64 | + ng-bind="pagina" | |
| 65 | + ></a> | |
| 66 | + </li> | |
| 67 | + <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | |
| 68 | + <a class="page-link" href="javascript:void()" ng-click="selectPage(currentPage + 1)"> | |
| 69 | + <span aria-hidden="true">»</span> | |
| 70 | + <span class="sr-only">Siguiente</span> | |
| 71 | + </a> | |
| 72 | + </li> | |
| 73 | + </ul> | |
| 74 | + </nav> | |
| 75 | +</div> |