Commit 21dfafd41b0eabbb94ee9508a8797e2cc842ea1b
Exists in
master
Merge branch 'develop' into 'master'
Develop See merge request !8
Showing
4 changed files
 
Show diff stats
package.json
| ... | ... | @@ -3,6 +3,7 @@ | 
| 3 | 3 | "version": "0.0.1", | 
| 4 | 4 | "description": "Modal para seleccion de productos", | 
| 5 | 5 | "scripts": { | 
| 6 | + "refresh": "gulp uglify && cp tmp/foca-busqueda-productos.js ../wrapper-demo/node_modules/foca-modal-busqueda-productos/dist/foca-busqueda-productos.min.js", | |
| 6 | 7 | "test": "echo \"Error: no test specified\" && exit 1", | 
| 7 | 8 | "gulp-pre-commit": "gulp pre-commit", | 
| 8 | 9 | "compile": "gulp uglify", | 
src/js/controller.js
| 1 | 1 | angular.module('focaBusquedaProductos') | 
| 2 | - .controller('modalBusquedaProductosCtrl', | |
| 2 | + .controller('modalBusquedaProductosCtrl', | |
| 3 | 3 | [ | 
| 4 | 4 | '$timeout', | 
| 5 | 5 | '$filter', | 
| ... | ... | @@ -7,53 +7,77 @@ angular.module('focaBusquedaProductos') | 
| 7 | 7 | '$uibModalInstance', | 
| 8 | 8 | 'parametroProducto', | 
| 9 | 9 | 'focaBusquedaProductosService', | 
| 10 | - function($timeout, $filter, $scope, $uibModalInstance, parametroProducto, | |
| 10 | + function ($timeout, $filter, $scope, $uibModalInstance, parametroProducto, | |
| 11 | 11 | focaBusquedaProductosService | 
| 12 | 12 | ) { | 
| 13 | 13 | |
| 14 | 14 | $scope.simbolo = parametroProducto.simbolo; | 
| 15 | 15 | $scope.filters = ''; | 
| 16 | - $scope.productos = []; | |
| 16 | + $scope.listaProductos = []; | |
| 17 | + $scope.todosProductos = []; | |
| 17 | 18 | $scope.primerBusqueda = false; | 
| 18 | 19 | $scope.searchLoading = false; | 
| 19 | - // pagination | |
| 20 | + $scope.soloMostrar = parametroProducto.soloMostrar; | |
| 21 | + $scope.useAllProducts = false; | |
| 22 | + //#region pagination variables | |
| 20 | 23 | $scope.numPerPage = 10; | 
| 21 | 24 | $scope.currentPage = 1; | 
| 22 | 25 | $scope.filteredProductos = []; | 
| 23 | 26 | $scope.currentPageProductos = []; | 
| 24 | 27 | $scope.selectedProducto = -1; | 
| 28 | + //#endregion | |
| 25 | 29 | |
| 26 | - $scope.soloMostrar = parametroProducto.soloMostrar; | |
| 27 | - | |
| 28 | 30 | //METODOS | 
| 29 | - $scope.busquedaPress = function(key) { | |
| 31 | + $scope.busquedaPress = function (key) { | |
| 30 | 32 | if (key === 13) { | 
| 31 | 33 | $scope.searchLoading = true; | 
| 32 | - if(parametroProducto.idLista > 0) { | |
| 34 | + if (parametroProducto.idLista > 0) { | |
| 33 | 35 | focaBusquedaProductosService | 
| 34 | 36 | .getProductosByIdLista(parametroProducto.idLista, $scope.filters) | 
| 35 | - .then(llenarDatos); | |
| 36 | - } else if(parametroProducto.idLista === -1) { | |
| 37 | - focaBusquedaProductosService.getProductos() | |
| 38 | - .then(llenarDatos); | |
| 37 | + .then(function (data) { | |
| 38 | + llenarDatos(data); | |
| 39 | + focaBusquedaProductosService.getProductos() | |
| 40 | + .then(fillAllProductos); | |
| 41 | + }); | |
| 39 | 42 | } | 
| 40 | 43 | } | 
| 41 | 44 | }; | 
| 42 | 45 | function llenarDatos(res) { | 
| 43 | - for(var i = 0; i < res.data.length; i++) { | |
| 44 | - res.data[i].precio = res.data[i].precio / parametroProducto.cotizacion; | |
| 46 | + for (var i = 0; i < res.data.length; i++) { | |
| 47 | + res.data[i].precio = res.data[i].precio / parametroProducto.cotizacion; | |
| 48 | + } | |
| 49 | + $scope.searchLoading = false; | |
| 50 | + $scope.primerBusqueda = true; | |
| 51 | + $scope.listaProductos = res.data; | |
| 52 | + $scope.search(true); | |
| 53 | + primera(); | |
| 54 | + }; | |
| 55 | + function fillAllProductos(res) { | |
| 56 | + for (var i = 0; i < res.data.length; i++) { | |
| 57 | + var producto = $scope.listaProductos.filter(function(producto) { | |
| 58 | + return producto.id == res.data[i].id; | |
| 59 | + })[0]; | |
| 60 | + | |
| 61 | + if (producto) { | |
| 62 | + res.data[i].precio = producto.precio; | |
| 63 | + } | |
| 45 | 64 | } | 
| 46 | 65 | $scope.searchLoading = false; | 
| 47 | 66 | $scope.primerBusqueda = true; | 
| 48 | - $scope.productos = res.data; | |
| 67 | + $scope.todosProductos = res.data; | |
| 49 | 68 | $scope.search(true); | 
| 50 | 69 | primera(); | 
| 51 | - } | |
| 52 | - $scope.search = function(pressed) { | |
| 53 | - if($scope.productos.length > 0) { | |
| 70 | + }; | |
| 71 | + $scope.changeProductsData = function () { | |
| 72 | + $scope.useAllProducts = !$scope.useAllProducts; | |
| 73 | + $scope.search(false); | |
| 74 | + primera(); | |
| 75 | + }; | |
| 76 | + $scope.search = function (pressed) { | |
| 77 | + if ($scope.listaProductos.length > 0) { | |
| 54 | 78 | $scope.filteredProductos = $filter('filter')( | 
| 55 | - $scope.productos, | |
| 56 | - {$: $scope.filters} | |
| 79 | + ($scope.useAllProducts ? $scope.todosProductos : $scope.listaProductos), | |
| 80 | + { $: $scope.filters } | |
| 57 | 81 | ); | 
| 58 | 82 | |
| 59 | 83 | $scope.lastPage = Math.ceil( | 
| ... | ... | @@ -61,20 +85,18 @@ angular.module('focaBusquedaProductos') | 
| 61 | 85 | ); | 
| 62 | 86 | |
| 63 | 87 | $scope.resetPage(); | 
| 64 | - }else if(pressed) { | |
| 65 | - $timeout(function() { | |
| 88 | + } else if (pressed) { | |
| 89 | + $timeout(function () { | |
| 66 | 90 | angular.element('#search')[0].focus(); | 
| 67 | 91 | $scope.filters = ''; | 
| 68 | 92 | }); | 
| 69 | 93 | } | 
| 70 | 94 | }; | 
| 71 | - | |
| 72 | - $scope.resetPage = function() { | |
| 95 | + $scope.resetPage = function () { | |
| 73 | 96 | $scope.currentPage = 1; | 
| 74 | 97 | $scope.selectPage(1); | 
| 75 | 98 | }; | 
| 76 | - | |
| 77 | - $scope.selectPage = function(page) { | |
| 99 | + $scope.selectPage = function (page) { | |
| 78 | 100 | var start = (page - 1) * $scope.numPerPage; | 
| 79 | 101 | var end = start + $scope.numPerPage; | 
| 80 | 102 | $scope.paginas = []; | 
| ... | ... | @@ -82,22 +104,18 @@ angular.module('focaBusquedaProductos') | 
| 82 | 104 | $scope.currentPageProductos = $scope.filteredProductos.slice(start, end); | 
| 83 | 105 | $scope.currentPage = page; | 
| 84 | 106 | }; | 
| 85 | - | |
| 86 | - $scope.select = function(producto) { | |
| 107 | + $scope.select = function (producto) { | |
| 87 | 108 | $uibModalInstance.close(producto); | 
| 88 | 109 | }; | 
| 89 | - | |
| 90 | - $scope.cancel = function() { | |
| 110 | + $scope.cancel = function () { | |
| 91 | 111 | $uibModalInstance.dismiss('cancel'); | 
| 92 | 112 | }; | 
| 93 | - | |
| 94 | - $scope.busquedaDown = function(key) { | |
| 113 | + $scope.busquedaDown = function (key) { | |
| 95 | 114 | if (key === 40) { | 
| 96 | 115 | primera(key); | 
| 97 | 116 | } | 
| 98 | 117 | }; | 
| 99 | - | |
| 100 | - $scope.itemProducto = function(key) { | |
| 118 | + $scope.itemProducto = function (key) { | |
| 101 | 119 | if (key === 38) { | 
| 102 | 120 | anterior(key); | 
| 103 | 121 | } | 
| ... | ... | @@ -115,12 +133,13 @@ angular.module('focaBusquedaProductos') | 
| 115 | 133 | } | 
| 116 | 134 | }; | 
| 117 | 135 | |
| 136 | + //#region Paginador | |
| 118 | 137 | function calcularPages(paginaActual) { | 
| 119 | 138 | var paginas = []; | 
| 120 | 139 | paginas.push(paginaActual); | 
| 121 | 140 | |
| 122 | 141 | if (paginaActual - 1 > 1) { | 
| 123 | - | |
| 142 | + | |
| 124 | 143 | paginas.unshift(paginaActual - 1); | 
| 125 | 144 | if (paginaActual - 2 > 1) { | 
| 126 | 145 | paginas.unshift(paginaActual - 2); | 
| ... | ... | @@ -143,41 +162,37 @@ angular.module('focaBusquedaProductos') | 
| 143 | 162 | } | 
| 144 | 163 | |
| 145 | 164 | return paginas; | 
| 146 | - } | |
| 147 | - | |
| 165 | + }; | |
| 148 | 166 | function primera() { | 
| 149 | 167 | $scope.selectedProducto = 0; | 
| 150 | - } | |
| 151 | - | |
| 168 | + }; | |
| 152 | 169 | function anterior() { | 
| 153 | 170 | if ($scope.selectedProducto === 0 && $scope.currentPage > 1) { | 
| 154 | 171 | retrocederPagina(); | 
| 155 | 172 | } else { | 
| 156 | 173 | $scope.selectedProducto--; | 
| 157 | 174 | } | 
| 158 | - } | |
| 159 | - | |
| 175 | + }; | |
| 160 | 176 | function siguiente() { | 
| 161 | - if ($scope.selectedProducto < $scope.currentPageProductos.length - 1 ) { | |
| 177 | + if ($scope.selectedProducto < $scope.currentPageProductos.length - 1) { | |
| 162 | 178 | $scope.selectedProducto++; | 
| 163 | 179 | } else { | 
| 164 | - avanzarPagina(); | |
| 180 | + avanzarPagina(); | |
| 165 | 181 | } | 
| 166 | - } | |
| 167 | - | |
| 182 | + }; | |
| 168 | 183 | function retrocederPagina() { | 
| 169 | 184 | if ($scope.currentPage > 1) { | 
| 170 | 185 | $scope.selectPage($scope.currentPage - 1); | 
| 171 | 186 | $scope.selectedProducto = $scope.numPerPage - 1; | 
| 172 | 187 | } | 
| 173 | - } | |
| 174 | - | |
| 188 | + }; | |
| 175 | 189 | function avanzarPagina() { | 
| 176 | 190 | if ($scope.currentPage < $scope.lastPage) { | 
| 177 | 191 | $scope.selectPage($scope.currentPage + 1); | 
| 178 | 192 | $scope.selectedProducto = 0; | 
| 179 | 193 | } | 
| 180 | - } | |
| 194 | + }; | |
| 195 | + //#endregion | |
| 181 | 196 | |
| 182 | 197 | $scope.busquedaPress(13); | 
| 183 | 198 | } | 
src/js/service.js
| ... | ... | @@ -2,14 +2,14 @@ angular.module('focaBusquedaProductos') | 
| 2 | 2 | .service('focaBusquedaProductosService', [ | 
| 3 | 3 | '$http', | 
| 4 | 4 | 'API_ENDPOINT', | 
| 5 | - function($http, API_ENDPOINT) { | |
| 5 | + function ($http, API_ENDPOINT) { | |
| 6 | 6 | return { | 
| 7 | - getProductos: function() { | |
| 7 | + getProductos: function () { | |
| 8 | 8 | return $http.get(API_ENDPOINT.URL + '/articulos'); | 
| 9 | 9 | }, | 
| 10 | - getProductosByIdLista: function(id, filters) { | |
| 10 | + getProductosByIdLista: function (id, filters) { | |
| 11 | 11 | return $http.post(API_ENDPOINT.URL + '/articulos/lista', | 
| 12 | - {filters: filters, id: id}); | |
| 12 | + { filters: filters, id: id }); | |
| 13 | 13 | } | 
| 14 | 14 | }; | 
| 15 | 15 | } | 
src/views/modal-busqueda-productos.html
| ... | ... | @@ -32,6 +32,16 @@ | 
| 32 | 32 | </div> | 
| 33 | 33 | </div> | 
| 34 | 34 | </div> | 
| 35 | + <div class="row"> | |
| 36 | + <div class="col my-1 d-flex justify-content-end"> | |
| 37 | + <div class="custom-control custom-checkbox mt-auto"> | |
| 38 | + <input type="checkbox" class="custom-control-input" id="check" ng-click="changeProductsData()"> | |
| 39 | + <label class="custom-control-label disable-selection" for="check"> | |
| 40 | + Buscar en todos los artículos disponibles | |
| 41 | + </label> | |
| 42 | + </div> | |
| 43 | + </div> | |
| 44 | + </div> | |
| 35 | 45 | </div> | 
| 36 | 46 | <div class="modal-body" id="modal-body"> | 
| 37 | 47 | |
| ... | ... | @@ -44,7 +54,8 @@ | 
| 44 | 54 | <tr> | 
| 45 | 55 | <th ng-hide="soloMostrar">Código</th> | 
| 46 | 56 | <th>Descripción</th> | 
| 47 | - <th class="text-right">P. Base</th> | |
| 57 | + <th class="text-right">P. Lista</th> | |
| 58 | + <th class="text-right" ng-show="useAllProducts">P. Base</th> | |
| 48 | 59 | <th ng-hide="soloMostrar"></th> | 
| 49 | 60 | </tr> | 
| 50 | 61 | </thead> | 
| ... | ... | @@ -60,7 +71,8 @@ | 
| 60 | 71 | <td ng-bind="producto.sector + '-' + producto.codigo" | 
| 61 | 72 | ng-hide="soloMostrar"></td> | 
| 62 | 73 | <td ng-bind="producto.descripcion"></td> | 
| 63 | - <td class="text-right" ng-bind="producto.precio | number: 2"></td> | |
| 74 | + <td class="text-right">{{producto.precioBase == producto.precio ? '' : producto.precio}}</td> | |
| 75 | + <td class="text-right" ng-bind="producto.precioBase | number: 2" ng-show="useAllProducts"></td> | |
| 64 | 76 | <td class="d-md-none text-primary"> | 
| 65 | 77 | <i class="fa fa-circle-thin" aria-hidden="true"></i> | 
| 66 | 78 | </td> | 
| ... | ... | @@ -113,5 +125,5 @@ | 
| 113 | 125 | </li> | 
| 114 | 126 | </ul> | 
| 115 | 127 | </nav> | 
| 116 | - <button class="btn btn-sm btn-secondary my-1" type="button" ng-click="cancel()">Cancelar</button> | |
| 128 | + <button class="btn btn-sm btn-secondary my-1" type="button" ng-click="cancel()">Volver</button> | |
| 117 | 129 | </div> |