Commit 21e3d532b2487bad32696986a944663ce4cc79d9
1 parent
fde949b260
Exists in
develop
Fix
Agrupado de listado
Showing
2 changed files
with
9 additions
and
1 deletions
Show diff stats
package.json
1 | { | 1 | { |
2 | "name": "foca-modal-lista-precio", | 2 | "name": "foca-modal-lista-precio", |
3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
4 | "description": "Modal para seleccionar lista de precios", | 4 | "description": "Modal para seleccionar lista de precios", |
5 | "main": "index.js", | 5 | "main": "index.js", |
6 | "scripts": { | 6 | "scripts": { |
7 | "refresh": "gulp uglify && cp tmp/foca-modal-lista-precio.js ../wrapper-demo/node_modules/foca-modal-lista-precio/dist/foca-modal-lista-precio.min.js", | ||
7 | "test": "echo \"Error: no test specified\" && exit 1", | 8 | "test": "echo \"Error: no test specified\" && exit 1", |
8 | "gulp-pre-commit": "gulp pre-commit", | 9 | "gulp-pre-commit": "gulp pre-commit", |
9 | "compile": "gulp uglify", | 10 | "compile": "gulp uglify", |
10 | "postinstall": "npm run compile && gulp clean-post-install", | 11 | "postinstall": "npm run compile && gulp clean-post-install", |
11 | "install-dev": "npm install -D angular angular-ladda ladda@1.0.6 bootstrap font-awesome gulp gulp-angular-templatecache gulp-concat gulp-connect gulp-htmlmin gulp-jshint gulp-rename gulp-clean gulp-replace gulp-uglify jasmine-core jquery jshint pre-commit pump ui-bootstrap4 && npm i -D git+ssh://git@debonline.dyndns.org:npm/foca-directivas.git" | 12 | "install-dev": "npm install -D angular angular-ladda ladda@1.0.6 bootstrap font-awesome gulp gulp-angular-templatecache gulp-concat gulp-connect gulp-htmlmin gulp-jshint gulp-rename gulp-clean gulp-replace gulp-uglify jasmine-core jquery jshint pre-commit pump ui-bootstrap4 && npm i -D git+ssh://git@debonline.dyndns.org:npm/foca-directivas.git" |
12 | }, | 13 | }, |
13 | "pre-commit": [ | 14 | "pre-commit": [ |
14 | "gulp-pre-commit" | 15 | "gulp-pre-commit" |
15 | ], | 16 | ], |
16 | "repository": { | 17 | "repository": { |
17 | "type": "git", | 18 | "type": "git", |
18 | "url": "http://git.focasoftware.com/npm/foca-modal-lista-precio.git" | 19 | "url": "http://git.focasoftware.com/npm/foca-modal-lista-precio.git" |
19 | }, | 20 | }, |
20 | "author": "Foca Software", | 21 | "author": "Foca Software", |
21 | "license": "ISC", | 22 | "license": "ISC", |
22 | "peerDependencies": { | 23 | "peerDependencies": { |
23 | "angular": "^1.7.4", | 24 | "angular": "^1.7.4", |
24 | "bootstrap": "^4.1.3", | 25 | "bootstrap": "^4.1.3", |
25 | "font-awesome": "^4.7.0", | 26 | "font-awesome": "^4.7.0", |
26 | "ui-bootstrap4": "^3.0.4", | 27 | "ui-bootstrap4": "^3.0.4", |
27 | "gulp": "^3.9.1", | 28 | "gulp": "^3.9.1", |
28 | "gulp-angular-templatecache": "^2.2.1", | 29 | "gulp-angular-templatecache": "^2.2.1", |
29 | "gulp-concat": "^2.6.1", | 30 | "gulp-concat": "^2.6.1", |
30 | "gulp-connect": "^5.6.1", | 31 | "gulp-connect": "^5.6.1", |
31 | "gulp-htmlmin": "^5.0.1", | 32 | "gulp-htmlmin": "^5.0.1", |
32 | "gulp-rename": "^1.4.0", | 33 | "gulp-rename": "^1.4.0", |
33 | "gulp-replace": "^1.0.0", | 34 | "gulp-replace": "^1.0.0", |
34 | "gulp-uglify": "^3.0.1", | 35 | "gulp-uglify": "^3.0.1", |
35 | "jquery": "^3.3.1", | 36 | "jquery": "^3.3.1", |
36 | "pump": "^3.0.0", | 37 | "pump": "^3.0.0", |
37 | "foca-directivas": "git+ssh://git@debonline.dyndns.org:npm/foca-directivas" | 38 | "foca-directivas": "git+ssh://git@debonline.dyndns.org:npm/foca-directivas" |
38 | }, | 39 | }, |
39 | "devDependencies": { | 40 | "devDependencies": { |
40 | "angular": "^1.7.5", | 41 | "angular": "^1.7.5", |
41 | "angular-ladda": "^0.4.3", | 42 | "angular-ladda": "^0.4.3", |
42 | "bootstrap": "^4.1.3", | 43 | "bootstrap": "^4.1.3", |
43 | "foca-directivas": "git+ssh://git@debonline.dyndns.org:npm/foca-directivas.git", | 44 | "foca-directivas": "git+ssh://git@debonline.dyndns.org:npm/foca-directivas.git", |
44 | "font-awesome": "^4.7.0", | 45 | "font-awesome": "^4.7.0", |
45 | "gulp": "^3.9.1", | 46 | "gulp": "^3.9.1", |
46 | "gulp-angular-templatecache": "^2.2.5", | 47 | "gulp-angular-templatecache": "^2.2.5", |
47 | "gulp-clean": "^0.4.0", | 48 | "gulp-clean": "^0.4.0", |
48 | "gulp-concat": "^2.6.1", | 49 | "gulp-concat": "^2.6.1", |
49 | "gulp-connect": "^5.6.1", | 50 | "gulp-connect": "^5.6.1", |
50 | "gulp-htmlmin": "^5.0.1", | 51 | "gulp-htmlmin": "^5.0.1", |
51 | "gulp-jshint": "^2.1.0", | 52 | "gulp-jshint": "^2.1.0", |
52 | "gulp-rename": "^1.4.0", | 53 | "gulp-rename": "^1.4.0", |
53 | "gulp-replace": "^1.0.0", | 54 | "gulp-replace": "^1.0.0", |
54 | "gulp-uglify": "^3.0.1", | 55 | "gulp-uglify": "^3.0.1", |
55 | "jasmine-core": "^3.3.0", | 56 | "jasmine-core": "^3.3.0", |
56 | "jquery": "^3.3.1", | 57 | "jquery": "^3.3.1", |
57 | "jshint": "^2.9.6", | 58 | "jshint": "^2.9.6", |
58 | "ladda": "^1.0.6", | 59 | "ladda": "^1.0.6", |
59 | "pre-commit": "^1.2.2", | 60 | "pre-commit": "^1.2.2", |
60 | "pump": "^3.0.0", | 61 | "pump": "^3.0.0", |
61 | "ui-bootstrap4": "^3.0.5" | 62 | "ui-bootstrap4": "^3.0.5" |
62 | } | 63 | } |
63 | } | 64 | } |
64 | 65 |
src/js/controller.js
1 | angular.module('focaModalListaPrecio') | 1 | angular.module('focaModalListaPrecio') |
2 | .controller('focaModalListaPrecioCtrl', [ | 2 | .controller('focaModalListaPrecioCtrl', [ |
3 | '$timeout', | 3 | '$timeout', |
4 | '$filter', | 4 | '$filter', |
5 | '$scope', | 5 | '$scope', |
6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
7 | 'focaModalListaPrecioService', | 7 | 'focaModalListaPrecioService', |
8 | function($timeout, $filter, $scope, $uibModalInstance, focaModalListaPrecioService) { | 8 | function($timeout, $filter, $scope, $uibModalInstance, focaModalListaPrecioService) { |
9 | 9 | ||
10 | $scope.filters = ''; | 10 | $scope.filters = ''; |
11 | $scope.listasPrecio = []; | 11 | $scope.listasPrecio = []; |
12 | $scope.primerBusqueda = false; | 12 | $scope.primerBusqueda = false; |
13 | $scope.searchLoading = false; | 13 | $scope.searchLoading = false; |
14 | // pagination | 14 | // pagination |
15 | $scope.numPerPage = 10; | 15 | $scope.numPerPage = 10; |
16 | $scope.currentPage = 1; | 16 | $scope.currentPage = 1; |
17 | $scope.filteredListasPrecio = []; | 17 | $scope.filteredListasPrecio = []; |
18 | $scope.currentPageListasPrecio = []; | 18 | $scope.currentPageListasPrecio = []; |
19 | $scope.selectedListaPrecio = -1; | 19 | $scope.selectedListaPrecio = -1; |
20 | 20 | ||
21 | $scope.busquedaPress = function(key) { | 21 | $scope.busquedaPress = function(key) { |
22 | if(key === 13) { | 22 | if(key === 13) { |
23 | $scope.searchLoading = true; | 23 | $scope.searchLoading = true; |
24 | focaModalListaPrecioService.getListasPrecio($scope.filters).then( | 24 | focaModalListaPrecioService.getListasPrecio($scope.filters).then( |
25 | function(res) { | 25 | function(res) { |
26 | $scope.searchLoading = false; | 26 | $scope.searchLoading = false; |
27 | $scope.primerBusqueda = true; | 27 | $scope.primerBusqueda = true; |
28 | $scope.listasPrecio = res.data; | 28 | $scope.listasPrecio = res.data.reduce(function (acc, current) { |
29 | var x = acc.find(function (item) { return item.ID === current.ID }); | ||
30 | if (!x) { | ||
31 | return acc.concat([current]); | ||
32 | } else { | ||
33 | return acc; | ||
34 | } | ||
35 | }, []); | ||
29 | $scope.search(true); | 36 | $scope.search(true); |
30 | primera(); | 37 | primera(); |
31 | } | 38 | } |
32 | ); | 39 | ); |
33 | } | 40 | } |
34 | }; | 41 | }; |
35 | 42 | ||
36 | $scope.busquedaPress(13); | 43 | $scope.busquedaPress(13); |
37 | $scope.search = function(pressed) { | 44 | $scope.search = function(pressed) { |
38 | if($scope.listasPrecio.length > 0) { | 45 | if($scope.listasPrecio.length > 0) { |
39 | $scope.filteredListasPrecio = $filter('filter')( | 46 | $scope.filteredListasPrecio = $filter('filter')( |
40 | $scope.listasPrecio, { $: $scope.filters } | 47 | $scope.listasPrecio, { $: $scope.filters } |
41 | ); | 48 | ); |
42 | $scope.lastPage = Math.ceil( | 49 | $scope.lastPage = Math.ceil( |
43 | $scope.filteredListasPrecio.length / $scope.numPerPage | 50 | $scope.filteredListasPrecio.length / $scope.numPerPage |
44 | ); | 51 | ); |
45 | $scope.resetPage(); | 52 | $scope.resetPage(); |
46 | }else if(pressed) { | 53 | }else if(pressed) { |
47 | $timeout(function() { | 54 | $timeout(function() { |
48 | angular.element('#search')[0].focus(); | 55 | angular.element('#search')[0].focus(); |
49 | $scope.filters = ''; | 56 | $scope.filters = ''; |
50 | }); | 57 | }); |
51 | } | 58 | } |
52 | }; | 59 | }; |
53 | 60 | ||
54 | $scope.resetPage = function() { | 61 | $scope.resetPage = function() { |
55 | $scope.currentPage = 1; | 62 | $scope.currentPage = 1; |
56 | $scope.selectPage(1); | 63 | $scope.selectPage(1); |
57 | }; | 64 | }; |
58 | 65 | ||
59 | $scope.selectPage = function(page) { | 66 | $scope.selectPage = function(page) { |
60 | var start = (page - 1) * $scope.numPerPage; | 67 | var start = (page - 1) * $scope.numPerPage; |
61 | var end = start + $scope.numPerPage; | 68 | var end = start + $scope.numPerPage; |
62 | $scope.paginas = []; | 69 | $scope.paginas = []; |
63 | $scope.paginas = calcularPages(page); | 70 | $scope.paginas = calcularPages(page); |
64 | $scope.currentPageListasPrecio = $scope.filteredListasPrecio.slice(start, end); | 71 | $scope.currentPageListasPrecio = $scope.filteredListasPrecio.slice(start, end); |
65 | $scope.currentPage = page; | 72 | $scope.currentPage = page; |
66 | }; | 73 | }; |
67 | 74 | ||
68 | $scope.select = function(vendedor) { | 75 | $scope.select = function(vendedor) { |
69 | $uibModalInstance.close(vendedor); | 76 | $uibModalInstance.close(vendedor); |
70 | }; | 77 | }; |
71 | 78 | ||
72 | $scope.cancel = function() { | 79 | $scope.cancel = function() { |
73 | $uibModalInstance.dismiss('cancel'); | 80 | $uibModalInstance.dismiss('cancel'); |
74 | }; | 81 | }; |
75 | 82 | ||
76 | $scope.busquedaDown = function(key) { | 83 | $scope.busquedaDown = function(key) { |
77 | if(key === 40) { | 84 | if(key === 40) { |
78 | primera(key); | 85 | primera(key); |
79 | } | 86 | } |
80 | }; | 87 | }; |
81 | 88 | ||
82 | $scope.itemListaPrecio = function(key) { | 89 | $scope.itemListaPrecio = function(key) { |
83 | if(key === 38) { | 90 | if(key === 38) { |
84 | anterior(key); | 91 | anterior(key); |
85 | } | 92 | } |
86 | 93 | ||
87 | if(key === 40) { | 94 | if(key === 40) { |
88 | siguiente(key); | 95 | siguiente(key); |
89 | } | 96 | } |
90 | 97 | ||
91 | if(key === 37) { | 98 | if(key === 37) { |
92 | retrocederPagina(); | 99 | retrocederPagina(); |
93 | } | 100 | } |
94 | 101 | ||
95 | if(key === 39) { | 102 | if(key === 39) { |
96 | avanzarPagina(); | 103 | avanzarPagina(); |
97 | } | 104 | } |
98 | }; | 105 | }; |
99 | 106 | ||
100 | function calcularPages(paginaActual) { | 107 | function calcularPages(paginaActual) { |
101 | var paginas = []; | 108 | var paginas = []; |
102 | paginas.push(paginaActual); | 109 | paginas.push(paginaActual); |
103 | 110 | ||
104 | if(paginaActual - 1 > 1) { | 111 | if(paginaActual - 1 > 1) { |
105 | paginas.unshift(paginaActual - 1); | 112 | paginas.unshift(paginaActual - 1); |
106 | if(paginaActual - 2 > 1) { | 113 | if(paginaActual - 2 > 1) { |
107 | paginas.unshift(paginaActual - 2); | 114 | paginas.unshift(paginaActual - 2); |
108 | } | 115 | } |
109 | } | 116 | } |
110 | 117 | ||
111 | if(paginaActual + 1 < $scope.lastPage) { | 118 | if(paginaActual + 1 < $scope.lastPage) { |
112 | paginas.push(paginaActual + 1); | 119 | paginas.push(paginaActual + 1); |
113 | if(paginaActual + 2 < $scope.lastPage) { | 120 | if(paginaActual + 2 < $scope.lastPage) { |
114 | paginas.push(paginaActual + 2); | 121 | paginas.push(paginaActual + 2); |
115 | } | 122 | } |
116 | } | 123 | } |
117 | 124 | ||
118 | if(paginaActual !== 1) { | 125 | if(paginaActual !== 1) { |
119 | paginas.unshift(1); | 126 | paginas.unshift(1); |
120 | } | 127 | } |
121 | 128 | ||
122 | if(paginaActual !== $scope.lastPage) { | 129 | if(paginaActual !== $scope.lastPage) { |
123 | paginas.push($scope.lastPage); | 130 | paginas.push($scope.lastPage); |
124 | } | 131 | } |
125 | 132 | ||
126 | return paginas; | 133 | return paginas; |
127 | } | 134 | } |
128 | 135 | ||
129 | function primera() { | 136 | function primera() { |
130 | $scope.selectedListaPrecio = 0; | 137 | $scope.selectedListaPrecio = 0; |
131 | } | 138 | } |
132 | 139 | ||
133 | function anterior() { | 140 | function anterior() { |
134 | if($scope.selectedListaPrecio === 0 && $scope.currentPage > 1) { | 141 | if($scope.selectedListaPrecio === 0 && $scope.currentPage > 1) { |
135 | retrocederPagina(); | 142 | retrocederPagina(); |
136 | }else { | 143 | }else { |
137 | $scope.selectedListaPrecio--; | 144 | $scope.selectedListaPrecio--; |
138 | } | 145 | } |
139 | } | 146 | } |
140 | 147 | ||
141 | function siguiente() { | 148 | function siguiente() { |
142 | if($scope.selectedListaPrecio < $scope.currentPageListasPrecio.length - 1) { | 149 | if($scope.selectedListaPrecio < $scope.currentPageListasPrecio.length - 1) { |
143 | $scope.selectedListaPrecio++; | 150 | $scope.selectedListaPrecio++; |
144 | }else { | 151 | }else { |
145 | avanzarPagina(); | 152 | avanzarPagina(); |
146 | } | 153 | } |
147 | } | 154 | } |
148 | 155 | ||
149 | function retrocederPagina() { | 156 | function retrocederPagina() { |
150 | if($scope.currentPage > 1) { | 157 | if($scope.currentPage > 1) { |
151 | $scope.selectPage($scope.currentPage - 1); | 158 | $scope.selectPage($scope.currentPage - 1); |
152 | $scope.selectedListaPrecio = $scope.numPerPage - 1; | 159 | $scope.selectedListaPrecio = $scope.numPerPage - 1; |
153 | } | 160 | } |
154 | } | 161 | } |
155 | 162 | ||
156 | function avanzarPagina() { | 163 | function avanzarPagina() { |
157 | if($scope.currentPage < $scope.lastPage) { | 164 | if($scope.currentPage < $scope.lastPage) { |
158 | $scope.selectPage($scope.currentPage + 1); | 165 | $scope.selectPage($scope.currentPage + 1); |
159 | $scope.selectedListaPrecio = 0; | 166 | $scope.selectedListaPrecio = 0; |
160 | } | 167 | } |
161 | } | 168 | } |
162 | }] | 169 | }] |
163 | ); | 170 | ); |
164 | 171 |