Commit 1145922d7d45063eca7001635a0c047a35b1ebbb
1 parent
74ebda12d1
Exists in
master
and in
1 other branch
Refactor para sacar propiedad no usada.
Showing
1 changed file
with
1 additions
and
6 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaModalRemito') | 1 | angular.module('focaModalRemito') |
2 | .controller('focaModalRemitoController', | 2 | .controller('focaModalRemitoController', |
3 | [ | 3 | [ |
4 | '$filter', | 4 | '$filter', |
5 | '$scope', | 5 | '$scope', |
6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
7 | 'parametroRemito', | ||
8 | 'focaModalRemitoService', | 7 | 'focaModalRemitoService', |
9 | function($filter, $scope, $uibModalInstance, parametroRemito, | 8 | function($filter, $scope, $uibModalInstance, |
10 | focaModalRemitoService | 9 | focaModalRemitoService |
11 | ) { | 10 | ) { |
12 | 11 | ||
13 | $scope.simbolo = parametroRemito.simbolo; | ||
14 | $scope.filters = ''; | 12 | $scope.filters = ''; |
15 | $scope.remitos = []; | 13 | $scope.remitos = []; |
16 | $scope.primerBusqueda = false; | 14 | $scope.primerBusqueda = false; |
17 | $scope.searchLoading = false; | 15 | $scope.searchLoading = false; |
18 | // pagination | 16 | // pagination |
19 | $scope.numPerPage = 10; | 17 | $scope.numPerPage = 10; |
20 | $scope.currentPage = 1; | 18 | $scope.currentPage = 1; |
21 | $scope.filteredRemitos = []; | 19 | $scope.filteredRemitos = []; |
22 | $scope.currentPageRemitos = []; | 20 | $scope.currentPageRemitos = []; |
23 | $scope.selectedRemito = -1; | 21 | $scope.selectedRemito = -1; |
24 | 22 | ||
25 | //METODOS | 23 | //METODOS |
26 | $scope.busquedaPress = function(key) { | 24 | $scope.busquedaPress = function(key) { |
27 | if (key === 13) { | 25 | if (key === 13) { |
28 | $scope.searchLoading = true; | 26 | $scope.searchLoading = true; |
29 | focaModalRemitoService.getRemitos().then(llenarDatos); | 27 | focaModalRemitoService.getRemitos().then(llenarDatos); |
30 | } | 28 | } |
31 | }; | 29 | }; |
32 | function llenarDatos(res) { | 30 | function llenarDatos(res) { |
33 | for(var i = 0; i < res.data.length; i++) { | ||
34 | res.data[i].precio = res.data[i].precio / parametroRemito.cotizacion; | ||
35 | } | ||
36 | $scope.searchLoading = false; | 31 | $scope.searchLoading = false; |
37 | $scope.primerBusqueda = true; | 32 | $scope.primerBusqueda = true; |
38 | $scope.remitos = res.data; | 33 | $scope.remitos = res.data; |
39 | $scope.search(); | 34 | $scope.search(); |
40 | primera(); | 35 | primera(); |
41 | } | 36 | } |
42 | $scope.search = function() { | 37 | $scope.search = function() { |
43 | if($scope.remitos.length > 0) { | 38 | if($scope.remitos.length > 0) { |
44 | $scope.filteredRemitos = $filter('filter')( | 39 | $scope.filteredRemitos = $filter('filter')( |
45 | $scope.remitos, | 40 | $scope.remitos, |
46 | {$: $scope.filters} | 41 | {$: $scope.filters} |
47 | ); | 42 | ); |
48 | 43 | ||
49 | $scope.lastPage = Math.ceil( | 44 | $scope.lastPage = Math.ceil( |
50 | $scope.filteredRemitos.length / $scope.numPerPage | 45 | $scope.filteredRemitos.length / $scope.numPerPage |
51 | ); | 46 | ); |
52 | 47 | ||
53 | $scope.resetPage(); | 48 | $scope.resetPage(); |
54 | } | 49 | } |
55 | }; | 50 | }; |
56 | 51 | ||
57 | $scope.resetPage = function() { | 52 | $scope.resetPage = function() { |
58 | $scope.currentPage = 1; | 53 | $scope.currentPage = 1; |
59 | $scope.selectPage(1); | 54 | $scope.selectPage(1); |
60 | }; | 55 | }; |
61 | 56 | ||
62 | $scope.selectPage = function(page) { | 57 | $scope.selectPage = function(page) { |
63 | var start = (page - 1) * $scope.numPerPage; | 58 | var start = (page - 1) * $scope.numPerPage; |
64 | var end = start + $scope.numPerPage; | 59 | var end = start + $scope.numPerPage; |
65 | $scope.paginas = []; | 60 | $scope.paginas = []; |
66 | $scope.paginas = calcularPages(page); | 61 | $scope.paginas = calcularPages(page); |
67 | $scope.currentPageRemitos = $scope.filteredRemitos.slice(start, end); | 62 | $scope.currentPageRemitos = $scope.filteredRemitos.slice(start, end); |
68 | $scope.currentPage = page; | 63 | $scope.currentPage = page; |
69 | }; | 64 | }; |
70 | 65 | ||
71 | $scope.select = function(remito) { | 66 | $scope.select = function(remito) { |
72 | $uibModalInstance.close(remito); | 67 | $uibModalInstance.close(remito); |
73 | }; | 68 | }; |
74 | 69 | ||
75 | $scope.cancel = function() { | 70 | $scope.cancel = function() { |
76 | $uibModalInstance.dismiss('cancel'); | 71 | $uibModalInstance.dismiss('cancel'); |
77 | }; | 72 | }; |
78 | 73 | ||
79 | $scope.busquedaDown = function(key) { | 74 | $scope.busquedaDown = function(key) { |
80 | if (key === 40) { | 75 | if (key === 40) { |
81 | primera(key); | 76 | primera(key); |
82 | } | 77 | } |
83 | }; | 78 | }; |
84 | 79 | ||
85 | $scope.itemRemito = function(key) { | 80 | $scope.itemRemito = function(key) { |
86 | if (key === 38) { | 81 | if (key === 38) { |
87 | anterior(key); | 82 | anterior(key); |
88 | } | 83 | } |
89 | 84 | ||
90 | if (key === 40) { | 85 | if (key === 40) { |
91 | siguiente(key); | 86 | siguiente(key); |
92 | } | 87 | } |
93 | 88 | ||
94 | if (key === 37) { | 89 | if (key === 37) { |
95 | retrocederPagina(); | 90 | retrocederPagina(); |
96 | } | 91 | } |
97 | 92 | ||
98 | if (key === 39) { | 93 | if (key === 39) { |
99 | avanzarPagina(); | 94 | avanzarPagina(); |
100 | } | 95 | } |
101 | }; | 96 | }; |
102 | 97 | ||
103 | function calcularPages(paginaActual) { | 98 | function calcularPages(paginaActual) { |
104 | var paginas = []; | 99 | var paginas = []; |
105 | paginas.push(paginaActual); | 100 | paginas.push(paginaActual); |
106 | 101 | ||
107 | if (paginaActual - 1 > 1) { | 102 | if (paginaActual - 1 > 1) { |
108 | 103 | ||
109 | paginas.unshift(paginaActual - 1); | 104 | paginas.unshift(paginaActual - 1); |
110 | if (paginaActual - 2 > 1) { | 105 | if (paginaActual - 2 > 1) { |
111 | paginas.unshift(paginaActual - 2); | 106 | paginas.unshift(paginaActual - 2); |
112 | } | 107 | } |
113 | } | 108 | } |
114 | 109 | ||
115 | if (paginaActual + 1 < $scope.lastPage) { | 110 | if (paginaActual + 1 < $scope.lastPage) { |
116 | paginas.push(paginaActual + 1); | 111 | paginas.push(paginaActual + 1); |
117 | if (paginaActual + 2 < $scope.lastPage) { | 112 | if (paginaActual + 2 < $scope.lastPage) { |
118 | paginas.push(paginaActual + 2); | 113 | paginas.push(paginaActual + 2); |
119 | } | 114 | } |
120 | } | 115 | } |
121 | 116 | ||
122 | if (paginaActual !== 1) { | 117 | if (paginaActual !== 1) { |
123 | paginas.unshift(1); | 118 | paginas.unshift(1); |
124 | } | 119 | } |
125 | 120 | ||
126 | if (paginaActual !== $scope.lastPage) { | 121 | if (paginaActual !== $scope.lastPage) { |
127 | paginas.push($scope.lastPage); | 122 | paginas.push($scope.lastPage); |
128 | } | 123 | } |
129 | 124 | ||
130 | return paginas; | 125 | return paginas; |
131 | } | 126 | } |
132 | 127 | ||
133 | function primera() { | 128 | function primera() { |
134 | $scope.selectedRemito = 0; | 129 | $scope.selectedRemito = 0; |
135 | } | 130 | } |
136 | 131 | ||
137 | function anterior() { | 132 | function anterior() { |
138 | if ($scope.selectedRemito === 0 && $scope.currentPage > 1) { | 133 | if ($scope.selectedRemito === 0 && $scope.currentPage > 1) { |
139 | retrocederPagina(); | 134 | retrocederPagina(); |
140 | } else { | 135 | } else { |
141 | $scope.selectedRemito--; | 136 | $scope.selectedRemito--; |
142 | } | 137 | } |
143 | } | 138 | } |
144 | 139 | ||
145 | function siguiente() { | 140 | function siguiente() { |
146 | if ($scope.selectedRemito < $scope.currentPageRemitos.length - 1 ) { | 141 | if ($scope.selectedRemito < $scope.currentPageRemitos.length - 1 ) { |
147 | $scope.selectedRemito++; | 142 | $scope.selectedRemito++; |
148 | } else { | 143 | } else { |
149 | avanzarPagina(); | 144 | avanzarPagina(); |
150 | } | 145 | } |
151 | } | 146 | } |
152 | 147 | ||
153 | function retrocederPagina() { | 148 | function retrocederPagina() { |
154 | if ($scope.currentPage > 1) { | 149 | if ($scope.currentPage > 1) { |
155 | $scope.selectPage($scope.currentPage - 1); | 150 | $scope.selectPage($scope.currentPage - 1); |
156 | $scope.selectedRemito = $scope.numPerPage - 1; | 151 | $scope.selectedRemito = $scope.numPerPage - 1; |
157 | } | 152 | } |
158 | } | 153 | } |
159 | 154 | ||
160 | function avanzarPagina() { | 155 | function avanzarPagina() { |
161 | if ($scope.currentPage < $scope.lastPage) { | 156 | if ($scope.currentPage < $scope.lastPage) { |
162 | $scope.selectPage($scope.currentPage + 1); | 157 | $scope.selectPage($scope.currentPage + 1); |
163 | $scope.selectedRemito = 0; | 158 | $scope.selectedRemito = 0; |
164 | } | 159 | } |
165 | } | 160 | } |
166 | } | 161 | } |
167 | ] | 162 | ] |
168 | ); | 163 | ); |
169 | 164 |