Commit e72617cd09d6887ecaaa7ad790b1290a6a769dd8
Exists in
master
Merge branch 'master' into 'master'
Master See merge request modulos-npm/foca-modal-vendedores!2
Showing
7 changed files
Show diff stats
.gitignore
gulpfile.js
| ... | ... | @@ -23,7 +23,7 @@ gulp.task('templates', function() { |
| 23 | 23 | replace('views/', ''), |
| 24 | 24 | htmlmin(), |
| 25 | 25 | templateCache('views.js', { |
| 26 | - module: 'focaBusquedaProductos', | |
| 26 | + module: 'focaModalVendedores', | |
| 27 | 27 | root: '' |
| 28 | 28 | }), |
| 29 | 29 | gulp.dest(paths.tmp) |
| ... | ... | @@ -38,9 +38,9 @@ gulp.task('uglify', function() { |
| 38 | 38 | paths.srcJS, |
| 39 | 39 | 'tmp/views.js' |
| 40 | 40 | ]), |
| 41 | - concat('foca-busqueda-productos.js'), | |
| 41 | + concat('foca-modal-vendedores.js'), | |
| 42 | 42 | gulp.dest(paths.tmp), |
| 43 | - rename('foca-busqueda-productos.min.js'), | |
| 43 | + rename('foca-modal-vendedores.min.js'), | |
| 44 | 44 | uglify(), |
| 45 | 45 | gulp.dest(paths.dist) |
| 46 | 46 | ] |
index.html
| ... | ... | @@ -13,6 +13,7 @@ |
| 13 | 13 | <script src="node_modules/bootstrap/dist/js/bootstrap.min.js"></script> |
| 14 | 14 | <script src="node_modules/angular/angular.min.js"></script> |
| 15 | 15 | <script src="node_modules/ui-bootstrap4/dist/ui-bootstrap-tpls.js"></script> |
| 16 | + <script src="../foca-directivas/dist/foca-directivas.min.js"></script> | |
| 16 | 17 | |
| 17 | 18 | <!-- BUILD --> |
| 18 | 19 | <script src="src/js/app.js"></script> |
package.json
| 1 | 1 | { |
| 2 | - "name": "foca-navegacion-doble", | |
| 2 | + "name": "foca-modal-vendedores", | |
| 3 | 3 | "version": "0.0.1", |
| 4 | - "description": "Menu de navegacion de doble entrada", | |
| 4 | + "description": "Modal búsqueda de vendedores", | |
| 5 | 5 | "main": "index.js", |
| 6 | 6 | "scripts": { |
| 7 | 7 | "test": "echo \"Error: no test specified\" && exit 1", |
| 8 | - "compile": "gulp templates && gulp uglify", | |
| 9 | - "pre-commit": [ | |
| 10 | - "gulp-pre-commit" | |
| 11 | - ], | |
| 8 | + "compile": "gulp templates && gulp uglify", | |
| 12 | 9 | "postinstall": "npm run compile && rm -R src && rm index.html && rm .jshintrc && rm gulpfile.js", |
| 13 | 10 | "install-dev": "npm install angular bootstrap jquery font-awesome gulp gulp-concat gulp-jshint gulp-rename gulp-replace gulp-uglify-es jshint pump gulp-connect jasmine-core pre-commit" |
| 14 | 11 | }, |
| 15 | 12 | "repository": { |
| 16 | 13 | "type": "git", |
| 17 | - "url": "https://192.168.0.11/modulos-npm/foca-navegacion-doble" | |
| 14 | + "url": "https://192.168.0.11/modulos-npm/foca-modal-vendedores.git" | |
| 18 | 15 | }, |
| 19 | - "author": "Nicolás Guarnieri", | |
| 16 | + "author": "Foca Software", | |
| 20 | 17 | "license": "ISC", |
| 21 | 18 | "peerDependencies": { |
| 22 | 19 | "angular": "^1.7.4", |
src/js/app.js
src/js/controller.js
| ... | ... | @@ -19,7 +19,7 @@ angular.module('focaModalVendedores') |
| 19 | 19 | $scope.currentPage = 1; |
| 20 | 20 | $scope.filteredVendedores = []; |
| 21 | 21 | $scope.currentPageVendedores = []; |
| 22 | - $scope.selectVendedores = 0; | |
| 22 | + $scope.selectVendedores = -1; | |
| 23 | 23 | |
| 24 | 24 | $scope.search = function () { |
| 25 | 25 | $scope.filteredVendedores = $filter('filter')($scope.vendedores, { $: $scope.filters }); |
| ... | ... | @@ -37,17 +37,104 @@ angular.module('focaModalVendedores') |
| 37 | 37 | $scope.currentPageVendedores = $scope.filteredVendedores.slice(start, end); |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - $scope.select = function(vendedor) { | |
| 40 | + $scope.select = function (vendedor) { | |
| 41 | 41 | $uibModalInstance.close(vendedor); |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | - $scope.cancel = function() { | |
| 44 | + $scope.cancel = function () { | |
| 45 | 45 | $uibModalInstance.dismiss('cancel'); |
| 46 | 46 | } |
| 47 | + $scope.busquedaDown = function (key) { | |
| 48 | + if (key === 40) { | |
| 49 | + primera(key); | |
| 50 | + } | |
| 51 | + }; | |
| 47 | 52 | |
| 48 | - $scope.enter = function(key) { | |
| 53 | + $scope.busquedaPress = function (key) { | |
| 49 | 54 | if (key === 13) { |
| 50 | - console.table($scope.currentPageVendedores); | |
| 55 | + primera(key); | |
| 56 | + } | |
| 57 | + }; | |
| 58 | + | |
| 59 | + $scope.itemProducto = function (key) { | |
| 60 | + if (key === 38) { | |
| 61 | + anterior(key); | |
| 62 | + } | |
| 63 | + | |
| 64 | + if (key === 40) { | |
| 65 | + siguiente(key); | |
| 66 | + } | |
| 67 | + | |
| 68 | + if (key === 37) { | |
| 69 | + retrocederPagina(); | |
| 70 | + } | |
| 71 | + | |
| 72 | + if (key === 39) { | |
| 73 | + avanzarPagina(); | |
| 74 | + } | |
| 75 | + }; | |
| 76 | + | |
| 77 | + function calcularPages(paginaActual) { | |
| 78 | + var paginas = []; | |
| 79 | + paginas.push(paginaActual); | |
| 80 | + | |
| 81 | + if (paginaActual - 1 > 1) { | |
| 82 | + | |
| 83 | + paginas.unshift(paginaActual - 1); | |
| 84 | + if (paginaActual - 2 > 1) { | |
| 85 | + paginas.unshift(paginaActual - 2); | |
| 86 | + } | |
| 87 | + } | |
| 88 | + | |
| 89 | + if (paginaActual + 1 < $scope.lastPage) { | |
| 90 | + paginas.push(paginaActual + 1); | |
| 91 | + if (paginaActual + 2 < $scope.lastPage) { | |
| 92 | + paginas.push(paginaActual + 2); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + | |
| 96 | + if (paginaActual !== 1) { | |
| 97 | + paginas.unshift(1); | |
| 98 | + } | |
| 99 | + | |
| 100 | + if (paginaActual !== $scope.lastPage) { | |
| 101 | + paginas.push($scope.lastPage); | |
| 102 | + } | |
| 103 | + | |
| 104 | + return paginas; | |
| 105 | + } | |
| 106 | + | |
| 107 | + function primera() { | |
| 108 | + $scope.selectedProducto = 0; | |
| 109 | + } | |
| 110 | + | |
| 111 | + function anterior() { | |
| 112 | + if ($scope.selectedProducto === 0 && $scope.currentPage > 1) { | |
| 113 | + retrocederPagina(); | |
| 114 | + } else { | |
| 115 | + $scope.selectedProducto--; | |
| 116 | + } | |
| 117 | + } | |
| 118 | + | |
| 119 | + function siguiente() { | |
| 120 | + if ($scope.selectedProducto < $scope.currentPageProductos.length - 1) { | |
| 121 | + $scope.selectedProducto++; | |
| 122 | + } else { | |
| 123 | + avanzarPagina(); | |
| 124 | + } | |
| 125 | + } | |
| 126 | + | |
| 127 | + function retrocederPagina() { | |
| 128 | + if ($scope.currentPage > 1) { | |
| 129 | + $scope.selectPage($scope.currentPage - 1); | |
| 130 | + $scope.selectedProducto = $scope.numPerPage - 1; | |
| 131 | + } | |
| 132 | + } | |
| 133 | + | |
| 134 | + function avanzarPagina() { | |
| 135 | + if ($scope.currentPage < $scope.lastPage) { | |
| 136 | + $scope.selectPage($scope.currentPage + 1); | |
| 137 | + $scope.selectedProducto = 0; | |
| 51 | 138 | } |
| 52 | 139 | } |
| 53 | 140 | }] |
src/views/modal-vendedores.html
| ... | ... | @@ -3,14 +3,8 @@ |
| 3 | 3 | </div> |
| 4 | 4 | <div class="modal-body" id="modal-body"> |
| 5 | 5 | <div class="input-group mb-3"> |
| 6 | - <input | |
| 7 | - type="text" | |
| 8 | - class="form-control" | |
| 9 | - placeholder="Busqueda" | |
| 10 | - ng-model="filters" | |
| 11 | - ng-change="search()" | |
| 12 | - ng-keypress="enter($event.keyCode)" | |
| 13 | - > | |
| 6 | + <input type="text" class="form-control" placeholder="Busqueda" ng-model="filters" ng-change="search()" | |
| 7 | + ng-keypress="enter($event.keyCode)"> | |
| 14 | 8 | <table class="table table-striped table-sm"> |
| 15 | 9 | <thead> |
| 16 | 10 | <tr> |
| ... | ... | @@ -28,15 +22,38 @@ |
| 28 | 22 | <td ng-bind="vendedor.CodVen"></td> |
| 29 | 23 | <td ng-bind="vendedor.NomVen"></td> |
| 30 | 24 | <td> |
| 31 | - <button type="button" class="btn btn-secondary p-5 float-right mr-1" ng-click="select(producto)"> | |
| 32 | - <i class="fa fa-check" aria-hidden="true"></i> | |
| 25 | + <button type="button" class="btn p-2 float-right" ng-class="{ | |
| 26 | + 'btn-secondary': selectVendedores != key, | |
| 27 | + 'btn-primary': selectVendedores == key | |
| 28 | + }" | |
| 29 | + ng-click="select(vendedor)" foca-focus="selectVendedores == {{key}}" ng-keydown="itemProducto($event.keyCode)"> | |
| 30 | + <i class="fa fa-arrow-right" aria-hidden="true"></i> | |
| 33 | 31 | </button> |
| 34 | 32 | </td> |
| 35 | 33 | </tr> |
| 36 | 34 | </tbody> |
| 37 | 35 | </table> |
| 36 | + <nav> | |
| 37 | + <ul class="pagination justify-content-end"> | |
| 38 | + <li class="page-item" ng-class="{'disabled': currentPage == 1}"> | |
| 39 | + <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)"> | |
| 40 | + <span aria-hidden="true">«</span> | |
| 41 | + <span class="sr-only">Anterior</span> | |
| 42 | + </a> | |
| 43 | + </li> | |
| 44 | + <li class="page-item" ng-repeat="pagina in paginas" ng-class="{'active': pagina == currentPage}"> | |
| 45 | + <a class="page-link" href="#" ng-click="selectPage(pagina)" ng-bind="pagina"></a> | |
| 46 | + </li> | |
| 47 | + <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> | |
| 48 | + <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)"> | |
| 49 | + <span aria-hidden="true">»</span> | |
| 50 | + <span class="sr-only">Siguiente</span> | |
| 51 | + </a> | |
| 52 | + </li> | |
| 53 | + </ul> | |
| 54 | + </nav> | |
| 38 | 55 | </div> |
| 39 | 56 | </div> |
| 40 | 57 | <div class="modal-footer"> |
| 41 | - <button class="btn btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | |
| 42 | -</div> | |
| 58 | + <button class="btn btn-secondary" type="button" ng-click="cancel()">Cancelar</button> | |
| 59 | +</div> | |
| 43 | 60 | \ No newline at end of file |