Commit e430dcddd3105c954ef4631fd81ed334c8897cad
Exists in
master
and in
1 other branch
Merge branch 'master' into 'develop'
Master(mpuebla) See merge request !6
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,69 @@ 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 | 37 | .then(llenarDatos); |
36 | - } else if(parametroProducto.idLista === -1) { | |
37 | 38 | focaBusquedaProductosService.getProductos() |
38 | - .then(llenarDatos); | |
39 | + .then(fillAllProductos); | |
39 | 40 | } |
40 | 41 | } |
41 | 42 | }; |
42 | 43 | function llenarDatos(res) { |
43 | - for(var i = 0; i < res.data.length; i++) { | |
44 | - res.data[i].precio = res.data[i].precio / parametroProducto.cotizacion; | |
44 | + for (var i = 0; i < res.data.length; i++) { | |
45 | + res.data[i].precio = res.data[i].precio / parametroProducto.cotizacion; | |
46 | + } | |
47 | + $scope.searchLoading = false; | |
48 | + $scope.primerBusqueda = true; | |
49 | + $scope.listaProductos = res.data; | |
50 | + $scope.search(true); | |
51 | + primera(); | |
52 | + }; | |
53 | + function fillAllProductos(res) { | |
54 | + for (var i = 0; i < res.data.length; i++) { | |
55 | + res.data[i].precio = res.data[i].precio / parametroProducto.cotizacion; | |
45 | 56 | } |
46 | 57 | $scope.searchLoading = false; |
47 | 58 | $scope.primerBusqueda = true; |
48 | - $scope.productos = res.data; | |
59 | + $scope.todosProductos = res.data; | |
49 | 60 | $scope.search(true); |
50 | 61 | primera(); |
51 | - } | |
52 | - $scope.search = function(pressed) { | |
53 | - if($scope.productos.length > 0) { | |
62 | + }; | |
63 | + $scope.changeProductsData = function () { | |
64 | + $scope.useAllProducts = !$scope.useAllProducts; | |
65 | + $scope.search(false); | |
66 | + primera(); | |
67 | + }; | |
68 | + $scope.search = function (pressed) { | |
69 | + if ($scope.listaProductos.length > 0) { | |
54 | 70 | $scope.filteredProductos = $filter('filter')( |
55 | - $scope.productos, | |
56 | - {$: $scope.filters} | |
71 | + ($scope.useAllProducts ? $scope.todosProductos : $scope.listaProductos), | |
72 | + { $: $scope.filters } | |
57 | 73 | ); |
58 | 74 | |
59 | 75 | $scope.lastPage = Math.ceil( |
... | ... | @@ -61,20 +77,18 @@ angular.module('focaBusquedaProductos') |
61 | 77 | ); |
62 | 78 | |
63 | 79 | $scope.resetPage(); |
64 | - }else if(pressed) { | |
65 | - $timeout(function() { | |
80 | + } else if (pressed) { | |
81 | + $timeout(function () { | |
66 | 82 | angular.element('#search')[0].focus(); |
67 | 83 | $scope.filters = ''; |
68 | 84 | }); |
69 | 85 | } |
70 | 86 | }; |
71 | - | |
72 | - $scope.resetPage = function() { | |
87 | + $scope.resetPage = function () { | |
73 | 88 | $scope.currentPage = 1; |
74 | 89 | $scope.selectPage(1); |
75 | 90 | }; |
76 | - | |
77 | - $scope.selectPage = function(page) { | |
91 | + $scope.selectPage = function (page) { | |
78 | 92 | var start = (page - 1) * $scope.numPerPage; |
79 | 93 | var end = start + $scope.numPerPage; |
80 | 94 | $scope.paginas = []; |
... | ... | @@ -82,22 +96,20 @@ angular.module('focaBusquedaProductos') |
82 | 96 | $scope.currentPageProductos = $scope.filteredProductos.slice(start, end); |
83 | 97 | $scope.currentPage = page; |
84 | 98 | }; |
85 | - | |
86 | - $scope.select = function(producto) { | |
99 | + $scope.select = function (producto) { | |
100 | + // if ($scope.useAllProducts) | |
101 | + // producto.precio = producto.precioBase; | |
87 | 102 | $uibModalInstance.close(producto); |
88 | 103 | }; |
89 | - | |
90 | - $scope.cancel = function() { | |
104 | + $scope.cancel = function () { | |
91 | 105 | $uibModalInstance.dismiss('cancel'); |
92 | 106 | }; |
93 | - | |
94 | - $scope.busquedaDown = function(key) { | |
107 | + $scope.busquedaDown = function (key) { | |
95 | 108 | if (key === 40) { |
96 | 109 | primera(key); |
97 | 110 | } |
98 | 111 | }; |
99 | - | |
100 | - $scope.itemProducto = function(key) { | |
112 | + $scope.itemProducto = function (key) { | |
101 | 113 | if (key === 38) { |
102 | 114 | anterior(key); |
103 | 115 | } |
... | ... | @@ -115,12 +127,13 @@ angular.module('focaBusquedaProductos') |
115 | 127 | } |
116 | 128 | }; |
117 | 129 | |
130 | + //#region Paginador | |
118 | 131 | function calcularPages(paginaActual) { |
119 | 132 | var paginas = []; |
120 | 133 | paginas.push(paginaActual); |
121 | 134 | |
122 | 135 | if (paginaActual - 1 > 1) { |
123 | - | |
136 | + | |
124 | 137 | paginas.unshift(paginaActual - 1); |
125 | 138 | if (paginaActual - 2 > 1) { |
126 | 139 | paginas.unshift(paginaActual - 2); |
... | ... | @@ -143,41 +156,37 @@ angular.module('focaBusquedaProductos') |
143 | 156 | } |
144 | 157 | |
145 | 158 | return paginas; |
146 | - } | |
147 | - | |
159 | + }; | |
148 | 160 | function primera() { |
149 | 161 | $scope.selectedProducto = 0; |
150 | - } | |
151 | - | |
162 | + }; | |
152 | 163 | function anterior() { |
153 | 164 | if ($scope.selectedProducto === 0 && $scope.currentPage > 1) { |
154 | 165 | retrocederPagina(); |
155 | 166 | } else { |
156 | 167 | $scope.selectedProducto--; |
157 | 168 | } |
158 | - } | |
159 | - | |
169 | + }; | |
160 | 170 | function siguiente() { |
161 | - if ($scope.selectedProducto < $scope.currentPageProductos.length - 1 ) { | |
171 | + if ($scope.selectedProducto < $scope.currentPageProductos.length - 1) { | |
162 | 172 | $scope.selectedProducto++; |
163 | 173 | } else { |
164 | - avanzarPagina(); | |
174 | + avanzarPagina(); | |
165 | 175 | } |
166 | - } | |
167 | - | |
176 | + }; | |
168 | 177 | function retrocederPagina() { |
169 | 178 | if ($scope.currentPage > 1) { |
170 | 179 | $scope.selectPage($scope.currentPage - 1); |
171 | 180 | $scope.selectedProducto = $scope.numPerPage - 1; |
172 | 181 | } |
173 | - } | |
174 | - | |
182 | + }; | |
175 | 183 | function avanzarPagina() { |
176 | 184 | if ($scope.currentPage < $scope.lastPage) { |
177 | 185 | $scope.selectPage($scope.currentPage + 1); |
178 | 186 | $scope.selectedProducto = 0; |
179 | 187 | } |
180 | - } | |
188 | + }; | |
189 | + //#endregion | |
181 | 190 | |
182 | 191 | $scope.busquedaPress(13); |
183 | 192 | } |
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,14 @@ |
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" for="check">Buscar en todos los artículos disponibles</label> | |
40 | + </div> | |
41 | + </div> | |
42 | + </div> | |
35 | 43 | </div> |
36 | 44 | <div class="modal-body" id="modal-body"> |
37 | 45 | |
... | ... | @@ -44,7 +52,8 @@ |
44 | 52 | <tr> |
45 | 53 | <th ng-hide="soloMostrar">Código</th> |
46 | 54 | <th>Descripción</th> |
47 | - <th class="text-right">P. Base</th> | |
55 | + <th class="text-right">P. Lista</th> | |
56 | + <th class="text-right" ng-show="useAllProducts">P. Base</th> | |
48 | 57 | <th ng-hide="soloMostrar"></th> |
49 | 58 | </tr> |
50 | 59 | </thead> |
... | ... | @@ -61,6 +70,7 @@ |
61 | 70 | ng-hide="soloMostrar"></td> |
62 | 71 | <td ng-bind="producto.descripcion"></td> |
63 | 72 | <td class="text-right" ng-bind="producto.precio | number: 2"></td> |
73 | + <td class="text-right" ng-bind="producto.precioBase | number: 2" ng-show="useAllProducts"></td> | |
64 | 74 | <td class="d-md-none text-primary"> |
65 | 75 | <i class="fa fa-circle-thin" aria-hidden="true"></i> |
66 | 76 | </td> |