Commit fc26605fa756d8c58ca01a46743bfddcb3f2dca8
1 parent
31d2d74a10
Exists in
master
and in
1 other branch
arreglos pre-commit
Showing
3 changed files
with
93 additions
and
81 deletions
Show diff stats
package.json
| 1 | { | 1 | { |
| 2 | "name": "foca-modal-busqueda-productos", | 2 | "name": "foca-modal-busqueda-productos", |
| 3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
| 4 | "description": "Menu de navegacion de doble entrada", | 4 | "description": "Menu de navegacion de doble entrada", |
| 5 | "main": "index.js", | 5 | "main": "index.js", |
| 6 | "scripts": { | 6 | "scripts": { |
| 7 | "test": "echo \"Error: no test specified\" && exit 1", | 7 | "test": "echo \"Error: no test specified\" && exit 1", |
| 8 | "compile": "gulp templates && gulp uglify", | 8 | "compile": "gulp templates && gulp uglify", |
| 9 | "pre-commit": [ | 9 | "gulp-pre-commit": "gulp pre-commit", |
| 10 | "gulp-pre-commit" | 10 | "postinstall": "npm run compile && rm -R src && rm index.html && rm .jshintrc && rm gulpfile.js", |
| 11 | ], | 11 | "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" |
| 12 | "postinstall": "npm run compile && rm -R src && rm index.html && rm .jshintrc && rm gulpfile.js", | 12 | }, |
| 13 | "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" | 13 | "pre-commit": [ |
| 14 | }, | 14 | "gulp-pre-commit" |
| 15 | "repository": { | 15 | ], |
| 16 | "type": "git", | 16 | "repository": { |
| 17 | "url": "https://192.168.0.11/modulos-npm/foca-navegacion-doble" | 17 | "type": "git", |
| 18 | }, | 18 | "url": "https://192.168.0.11/modulos-npm/foca-navegacion-doble" |
| 19 | "author": "Nicolás Guarnieri", | 19 | }, |
| 20 | "license": "ISC", | 20 | "author": "Nicolás Guarnieri", |
| 21 | "peerDependencies": { | 21 | "license": "ISC", |
| 22 | "angular": "^1.7.4", | 22 | "peerDependencies": { |
| 23 | "bootstrap": "^4.1.3", | 23 | "angular": "^1.7.4", |
| 24 | "font-awesome": "^4.7.0", | 24 | "bootstrap": "^4.1.3", |
| 25 | "ui-bootstrap4": "^3.0.4", | 25 | "font-awesome": "^4.7.0", |
| 26 | "gulp": "^3.9.1", | 26 | "ui-bootstrap4": "^3.0.4", |
| 27 | "gulp-angular-templatecache": "^2.2.1", | 27 | "gulp": "^3.9.1", |
| 28 | "gulp-concat": "^2.6.1", | 28 | "gulp-angular-templatecache": "^2.2.1", |
| 29 | "gulp-connect": "^5.6.1", | 29 | "gulp-concat": "^2.6.1", |
| 30 | "gulp-htmlmin": "^5.0.1", | 30 | "gulp-connect": "^5.6.1", |
| 31 | "gulp-rename": "^1.4.0", | 31 | "gulp-htmlmin": "^5.0.1", |
| 32 | "gulp-replace": "^1.0.0", | 32 | "gulp-rename": "^1.4.0", |
| 33 | "gulp-uglify": "^3.0.1", | 33 | "gulp-replace": "^1.0.0", |
| 34 | "jquery": "^3.3.1", | 34 | "gulp-uglify": "^3.0.1", |
| 35 | "pump": "^3.0.0", | 35 | "jquery": "^3.3.1", |
| 36 | "foca-directivas": "git+https://192.168.0.11/modulos-npm/foca-directivas", | 36 | "pump": "^3.0.0", |
| 37 | }, | 37 | "foca-directivas": "git+https://192.168.0.11/modulos-npm/foca-directivas" |
| 38 | "devDependencies": { | 38 | }, |
| 39 | "angular": "^1.7.4", | 39 | "devDependencies": { |
| 40 | "bootstrap": "^4.1.3", | 40 | "angular": "^1.7.4", |
| 41 | "foca-directivas": "git+https://192.168.0.11/modulos-npm/foca-directivas", | 41 | "bootstrap": "^4.1.3", |
| 42 | "font-awesome": "^4.7.0", | 42 | "foca-directivas": "git+https://192.168.0.11/modulos-npm/foca-directivas", |
| 43 | "gulp": "^3.9.1", | 43 | "font-awesome": "^4.7.0", |
| 44 | "gulp-angular-templatecache": "^2.2.1", | 44 | "gulp": "^3.9.1", |
| 45 | "gulp-concat": "^2.6.1", | 45 | "gulp-angular-templatecache": "^2.2.1", |
| 46 | "gulp-connect": "^5.6.1", | 46 | "gulp-concat": "^2.6.1", |
| 47 | "gulp-htmlmin": "^5.0.1", | 47 | "gulp-connect": "^5.6.1", |
| 48 | "gulp-jshint": "^2.1.0", | 48 | "gulp-htmlmin": "^5.0.1", |
| 49 | "gulp-rename": "^1.4.0", | 49 | "gulp-jshint": "^2.1.0", |
| 50 | "gulp-replace": "^1.0.0", | 50 | "gulp-rename": "^1.4.0", |
| 51 | "gulp-uglify": "^3.0.1", | 51 | "gulp-replace": "^1.0.0", |
| 52 | "jasmine-core": "^3.2.1", | 52 | "gulp-uglify": "^3.0.1", |
| 53 | "jquery": "^3.3.1", | 53 | "jasmine-core": "^3.2.1", |
| 54 | "jshint": "^2.9.6", | 54 | "jquery": "^3.3.1", |
| 55 | "pre-commit": "^1.2.2", | 55 | "jshint": "^2.9.6", |
| 56 | "pump": "^3.0.0", | 56 | "pre-commit": "^1.2.2", |
| 57 | "ui-bootstrap4": "^3.0.4" | 57 | "pump": "^3.0.0", |
| 58 | } | 58 | "ui-bootstrap4": "^3.0.4" |
| 59 | } | ||
| 59 | } | 60 | } |
| 60 | 61 |
src/js/controller.js
| 1 | angular.module('focaBusquedaProductos') | 1 | angular.module('focaBusquedaProductos') |
| 2 | .controller('modalBusquedaProductosCtrl', | 2 | .controller('modalBusquedaProductosCtrl', |
| 3 | [ | 3 | [ |
| 4 | '$filter', | 4 | '$filter', |
| 5 | '$scope', | 5 | '$scope', |
| 6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
| 7 | 'focaBusquedaProductosService', | 7 | 'focaBusquedaProductosService', |
| 8 | function($filter, $scope, $uibModalInstance, focaBusquedaProductosService) { | 8 | function($filter, $scope, $uibModalInstance, focaBusquedaProductosService) { |
| 9 | focaBusquedaProductosService.getProductos().then( | 9 | focaBusquedaProductosService.getProductos().then( |
| 10 | function(res) { | 10 | function(res) { |
| 11 | $scope.productos = res.data; | 11 | $scope.productos = res.data; |
| 12 | $scope.search(); | 12 | $scope.search(); |
| 13 | } | 13 | } |
| 14 | ); | 14 | ); |
| 15 | 15 | ||
| 16 | // pagination | 16 | // pagination |
| 17 | $scope.numPerPage = 10; | 17 | $scope.numPerPage = 10; |
| 18 | $scope.currentPage = 1; | 18 | $scope.currentPage = 1; |
| 19 | $scope.filteredProductos = []; | 19 | $scope.filteredProductos = []; |
| 20 | $scope.currentPageProductos = []; | 20 | $scope.currentPageProductos = []; |
| 21 | $scope.selectedProducto = -1; | 21 | $scope.selectedProducto = -1; |
| 22 | 22 | ||
| 23 | //METODOS | 23 | //METODOS |
| 24 | $scope.search = function() { | 24 | $scope.search = function() { |
| 25 | $scope.filteredProductos = $filter('filter')($scope.productos, {$: $scope.filters}); | 25 | $scope.filteredProductos = $filter('filter')( |
| 26 | $scope.lastPage = Math.ceil($scope.filteredProductos.length / $scope.numPerPage); | 26 | $scope.productos, |
| 27 | {$: $scope.filters} | ||
| 28 | ); | ||
| 29 | |||
| 30 | $scope.lastPage = Math.ceil( | ||
| 31 | $scope.filteredProductos.length / $scope.numPerPage | ||
| 32 | ); | ||
| 33 | |||
| 27 | $scope.resetPage(); | 34 | $scope.resetPage(); |
| 28 | } | 35 | }; |
| 29 | 36 | ||
| 30 | $scope.resetPage = function() { | 37 | $scope.resetPage = function() { |
| 31 | $scope.currentPage = 1; | 38 | $scope.currentPage = 1; |
| 32 | $scope.selectPage(1); | 39 | $scope.selectPage(1); |
| 33 | } | 40 | }; |
| 34 | 41 | ||
| 35 | $scope.selectPage = function(page) { | 42 | $scope.selectPage = function(page) { |
| 36 | var start = (page - 1) * $scope.numPerPage; | 43 | var start = (page - 1) * $scope.numPerPage; |
| 37 | var end = start + $scope.numPerPage; | 44 | var end = start + $scope.numPerPage; |
| 38 | $scope.paginas = []; | 45 | $scope.paginas = []; |
| 39 | $scope.paginas = calcularPages(page); | 46 | $scope.paginas = calcularPages(page); |
| 40 | $scope.currentPageProductos = $scope.filteredProductos.slice(start, end); | 47 | $scope.currentPageProductos = $scope.filteredProductos.slice(start, end); |
| 41 | $scope.currentPage = page; | 48 | $scope.currentPage = page; |
| 42 | } | 49 | }; |
| 43 | 50 | ||
| 44 | $scope.select = function(producto) { | 51 | $scope.select = function(producto) { |
| 45 | $uibModalInstance.close(producto); | 52 | $uibModalInstance.close(producto); |
| 46 | } | 53 | }; |
| 47 | 54 | ||
| 48 | $scope.cancel = function() { | 55 | $scope.cancel = function() { |
| 49 | $uibModalInstance.dismiss('cancel'); | 56 | $uibModalInstance.dismiss('cancel'); |
| 50 | } | 57 | }; |
| 51 | 58 | ||
| 52 | $scope.busquedaDown = function(key) { | 59 | $scope.busquedaDown = function(key) { |
| 53 | if (key === 40) { | 60 | if (key === 40) { |
| 54 | primera(key); | 61 | primera(key); |
| 55 | } | 62 | } |
| 56 | } | 63 | }; |
| 57 | 64 | ||
| 58 | $scope.busquedaPress = function(key) { | 65 | $scope.busquedaPress = function(key) { |
| 59 | if (key === 13) { | 66 | if (key === 13) { |
| 60 | primera(key); | 67 | primera(key); |
| 61 | } | 68 | } |
| 62 | } | 69 | }; |
| 63 | 70 | ||
| 64 | $scope.itemProducto = function(key) { | 71 | $scope.itemProducto = function(key) { |
| 65 | if (key == 38) { | 72 | if (key === 38) { |
| 66 | anterior(key); | 73 | anterior(key); |
| 67 | } | 74 | } |
| 68 | 75 | ||
| 69 | if (key == 40) { | 76 | if (key === 40) { |
| 70 | siguiente(key); | 77 | siguiente(key); |
| 71 | } | 78 | } |
| 72 | 79 | ||
| 73 | if (key == 37) { | 80 | if (key === 37) { |
| 74 | retrocederPagina(); | 81 | retrocederPagina(); |
| 75 | } | 82 | } |
| 76 | 83 | ||
| 77 | if (key == 39) { | 84 | if (key === 39) { |
| 78 | avanzarPagina(); | 85 | avanzarPagina(); |
| 79 | } | 86 | } |
| 80 | } | 87 | }; |
| 81 | 88 | ||
| 82 | function calcularPages(paginaActual) { | 89 | function calcularPages(paginaActual) { |
| 83 | var paginas = []; | 90 | var paginas = []; |
| 84 | paginas.push(paginaActual); | 91 | paginas.push(paginaActual); |
| 85 | 92 | ||
| 86 | if (paginaActual - 1 > 1) { | 93 | if (paginaActual - 1 > 1) { |
| 87 | 94 | ||
| 88 | paginas.unshift(paginaActual - 1); | 95 | paginas.unshift(paginaActual - 1); |
| 89 | if (paginaActual - 2 > 1) { | 96 | if (paginaActual - 2 > 1) { |
| 90 | paginas.unshift(paginaActual - 2); | 97 | paginas.unshift(paginaActual - 2); |
| 91 | } | 98 | } |
| 92 | } | 99 | } |
| 93 | 100 | ||
| 94 | if (paginaActual + 1 < $scope.lastPage) { | 101 | if (paginaActual + 1 < $scope.lastPage) { |
| 95 | paginas.push(paginaActual + 1); | 102 | paginas.push(paginaActual + 1); |
| 96 | if (paginaActual + 2 < $scope.lastPage) { | 103 | if (paginaActual + 2 < $scope.lastPage) { |
| 97 | paginas.push(paginaActual + 2); | 104 | paginas.push(paginaActual + 2); |
| 98 | } | 105 | } |
| 99 | } | 106 | } |
| 100 | 107 | ||
| 101 | if (paginaActual !== 1) { | 108 | if (paginaActual !== 1) { |
| 102 | paginas.unshift(1); | 109 | paginas.unshift(1); |
| 103 | } | 110 | } |
| 104 | 111 | ||
| 105 | if (paginaActual !== $scope.lastPage) { | 112 | if (paginaActual !== $scope.lastPage) { |
| 106 | paginas.push($scope.lastPage); | 113 | paginas.push($scope.lastPage); |
| 107 | } | 114 | } |
| 108 | 115 | ||
| 109 | return paginas; | 116 | return paginas; |
| 110 | } | 117 | } |
| 111 | 118 | ||
| 112 | function primera(key) { | 119 | function primera() { |
| 113 | $scope.selectedProducto = 0; | 120 | $scope.selectedProducto = 0; |
| 114 | } | 121 | } |
| 115 | 122 | ||
| 116 | function anterior(key) { | 123 | function anterior() { |
| 117 | if ($scope.selectedProducto === 0 && $scope.currentPage > 1) { | 124 | if ($scope.selectedProducto === 0 && $scope.currentPage > 1) { |
| 118 | retrocederPagina(); | 125 | retrocederPagina(); |
| 119 | } else { | 126 | } else { |
| 120 | $scope.selectedProducto--; | 127 | $scope.selectedProducto--; |
| 121 | } | 128 | } |
| 122 | } | 129 | } |
| 123 | 130 | ||
| 124 | function siguiente(key) { | 131 | function siguiente() { |
| 125 | if ($scope.selectedProducto < $scope.currentPageProductos.length - 1 ) { | 132 | if ($scope.selectedProducto < $scope.currentPageProductos.length - 1 ) { |
| 126 | $scope.selectedProducto++; | 133 | $scope.selectedProducto++; |
| 127 | } else { | 134 | } else { |
| 128 | avanzarPagina(); | 135 | avanzarPagina(); |
| 129 | } | 136 | } |
| 130 | } | 137 | } |
| 131 | 138 | ||
| 132 | function retrocederPagina() { | 139 | function retrocederPagina() { |
| 133 | if ($scope.currentPage > 1) { | 140 | if ($scope.currentPage > 1) { |
| 134 | $scope.selectPage($scope.currentPage - 1); | 141 | $scope.selectPage($scope.currentPage - 1); |
| 135 | $scope.selectedProducto = $scope.numPerPage - 1; | 142 | $scope.selectedProducto = $scope.numPerPage - 1; |
| 136 | } | 143 | } |
| 137 | } | 144 | } |
| 138 | 145 | ||
| 139 | function avanzarPagina() { | 146 | function avanzarPagina() { |
| 140 | if ($scope.currentPage < $scope.lastPage) { | 147 | if ($scope.currentPage < $scope.lastPage) { |
| 141 | $scope.selectPage($scope.currentPage + 1); | 148 | $scope.selectPage($scope.currentPage + 1); |
| 142 | $scope.selectedProducto = 0; | 149 | $scope.selectedProducto = 0; |
| 143 | } | 150 | } |
| 144 | } | 151 | } |
| 145 | } | 152 | } |
| 146 | ] | 153 | ] |
| 147 | ) | 154 | ); |
| 148 | 155 |
src/js/service.js
| 1 | angular.module('focaBusquedaProductos') | 1 | angular.module('focaBusquedaProductos') |
| 2 | .service('focaBusquedaProductosService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .service('focaBusquedaProductosService', [ |
| 3 | return { | 3 | '$http', |
| 4 | getProductos: function(filtro) { | 4 | 'API_ENDPOINT', |
| 5 | return $http.get(API_ENDPOINT.URL + '/articulos'); | 5 | function($http, API_ENDPOINT) { |
| 6 | } | 6 | return { |
| 7 | getProductos: function() { | ||
| 8 | return $http.get(API_ENDPOINT.URL + '/articulos'); | ||
| 9 | } | ||
| 10 | }; | ||
| 7 | } | 11 | } |
| 8 | }]) | 12 | ]); |
| 9 | 13 |