Commit 0326a1b1994d25bcc128a2f7178a6b3ba9684175
1 parent
3fa566ca2c
Exists in
master
reemplazo alert por modal
Showing
3 changed files
with
15 additions
and
7 deletions
Show diff stats
gulpfile.js
1 | const templateCache = require('gulp-angular-templatecache'); | 1 | const templateCache = require('gulp-angular-templatecache'); |
2 | const concat = require('gulp-concat'); | 2 | const concat = require('gulp-concat'); |
3 | const htmlmin = require('gulp-htmlmin'); | 3 | const htmlmin = require('gulp-htmlmin'); |
4 | const rename = require('gulp-rename'); | 4 | const rename = require('gulp-rename'); |
5 | const uglify = require('gulp-uglify'); | 5 | const uglify = require('gulp-uglify'); |
6 | const gulp = require('gulp'); | 6 | const gulp = require('gulp'); |
7 | const pump = require('pump'); | 7 | const pump = require('pump'); |
8 | const jshint = require('gulp-jshint'); | 8 | const jshint = require('gulp-jshint'); |
9 | const replace = require('gulp-replace'); | 9 | const replace = require('gulp-replace'); |
10 | const connect = require('gulp-connect'); | 10 | const connect = require('gulp-connect'); |
11 | const clean = require('gulp-clean'); | 11 | const clean = require('gulp-clean'); |
12 | 12 | ||
13 | var paths = { | 13 | var paths = { |
14 | srcJS: 'src/js/*.js', | 14 | srcJS: 'src/js/*.js', |
15 | srcViews: 'src/views/*.html', | 15 | srcViews: 'src/views/*.html', |
16 | tmp: 'tmp', | 16 | tmp: 'tmp', |
17 | dist: 'dist/' | 17 | dist: 'dist/' |
18 | }; | 18 | }; |
19 | 19 | ||
20 | gulp.task('clean', function() { | 20 | gulp.task('clean', function() { |
21 | return gulp.src(['tmp', 'dist'], {read: false}) | 21 | return gulp.src(['tmp', 'dist'], {read: false}) |
22 | .pipe(clean()); | 22 | .pipe(clean()); |
23 | }); | 23 | }); |
24 | 24 | ||
25 | gulp.task('templates', ['clean'], function() { | 25 | gulp.task('templates', ['clean'], function() { |
26 | return pump( | 26 | return pump( |
27 | [ | 27 | [ |
28 | gulp.src(paths.srcViews), | 28 | gulp.src(paths.srcViews), |
29 | htmlmin(), | 29 | htmlmin(), |
30 | templateCache('views.js', { | 30 | templateCache('views.js', { |
31 | module: 'focaModalRemito', | 31 | module: 'focaModalRemito', |
32 | root: '' | 32 | root: '' |
33 | }), | 33 | }), |
34 | gulp.dest(paths.tmp) | 34 | gulp.dest(paths.tmp) |
35 | ] | 35 | ] |
36 | ); | 36 | ); |
37 | }); | 37 | }); |
38 | 38 | ||
39 | gulp.task('uglify', ['templates'], function() { | 39 | gulp.task('uglify', ['templates'], function() { |
40 | return pump( | 40 | return pump( |
41 | [ | 41 | [ |
42 | gulp.src([ | 42 | gulp.src([ |
43 | paths.srcJS, | 43 | paths.srcJS, |
44 | 'tmp/views.js' | 44 | 'tmp/views.js' |
45 | ]), | 45 | ]), |
46 | concat('foca-modal-remito.js'), | 46 | concat('foca-modal-remito.js'), |
47 | replace('src/views/', ''), | 47 | replace('src/views/', ''), |
48 | replace("['ui.bootstrap', 'focaDirectivas', 'angular-ladda']", '[]'), | 48 | replace("['ui.bootstrap', 'focaDirectivas', 'angular-ladda', 'focaModal']", '[]'), |
49 | gulp.dest(paths.tmp), | 49 | gulp.dest(paths.tmp), |
50 | rename('foca-modal-remito.min.js'), | 50 | rename('foca-modal-remito.min.js'), |
51 | uglify(), | 51 | uglify(), |
52 | gulp.dest(paths.dist) | 52 | gulp.dest(paths.dist) |
53 | ] | 53 | ] |
54 | ); | 54 | ); |
55 | }); | 55 | }); |
56 | 56 | ||
57 | gulp.task('pre-commit', function() { | 57 | gulp.task('pre-commit', function() { |
58 | return pump( | 58 | return pump( |
59 | [ | 59 | [ |
60 | gulp.src(paths.srcJS), | 60 | gulp.src(paths.srcJS), |
61 | jshint('.jshintrc'), | 61 | jshint('.jshintrc'), |
62 | jshint.reporter('default'), | 62 | jshint.reporter('default'), |
63 | jshint.reporter('fail') | 63 | jshint.reporter('fail') |
64 | ] | 64 | ] |
65 | ); | 65 | ); |
66 | 66 | ||
67 | gulp.start('uglify'); | 67 | gulp.start('uglify'); |
68 | }); | 68 | }); |
69 | 69 | ||
70 | gulp.task('webserver', function() { | 70 | gulp.task('webserver', function() { |
71 | pump [ | 71 | pump [ |
72 | connect.server({port: 3000}) | 72 | connect.server({port: 3000}) |
73 | ] | 73 | ] |
74 | }); | 74 | }); |
75 | 75 | ||
76 | gulp.task('clean-post-install', function(){ | 76 | gulp.task('clean-post-install', function(){ |
77 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | 77 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', |
78 | 'index.html'], {read: false}) | 78 | 'index.html'], {read: false}) |
79 | .pipe(clean()); | 79 | .pipe(clean()); |
80 | }); | 80 | }); |
81 | 81 | ||
82 | gulp.task('default', ['webserver']); | 82 | gulp.task('default', ['webserver']); |
83 | 83 | ||
84 | gulp.task('watch', function() { | 84 | gulp.task('watch', function() { |
85 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']) | 85 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']) |
86 | }); | 86 | }); |
87 | 87 | ||
88 | gulp.task('copy', ['uglify'], function(){ | 88 | gulp.task('copy', ['uglify'], function(){ |
89 | gulp.src('dist/*.js') | 89 | gulp.src('dist/*.js') |
90 | .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-modal-remito/dist')); | 90 | .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-modal-remito/dist')); |
91 | }); | 91 | }); |
92 | 92 | ||
93 | gulp.task('watchAndCopy', function() { | 93 | gulp.task('watchAndCopy', function() { |
94 | gulp.watch([paths.srcJS, paths.srcViews], ['copy']) | 94 | gulp.watch([paths.srcJS, paths.srcViews], ['copy']) |
95 | }); | 95 | }); |
96 | 96 |
src/js/app.js
1 | angular.module('focaModalRemito', ['ui.bootstrap', 'focaDirectivas', 'angular-ladda']); | 1 | angular.module('focaModalRemito', [ |
2 | 'ui.bootstrap', | ||
3 | 'focaDirectivas', | ||
4 | 'angular-ladda', | ||
5 | 'focaModal' | ||
6 | ]); | ||
2 | 7 |
src/js/controller.js
1 | angular.module('focaModalRemito') | 1 | angular.module('focaModalRemito') |
2 | .controller('focaModalRemitoController', | 2 | .controller('focaModalRemitoController', |
3 | [ | 3 | [ |
4 | '$timeout', | 4 | '$timeout', |
5 | '$filter', | 5 | '$filter', |
6 | '$scope', | 6 | '$scope', |
7 | '$uibModalInstance', | 7 | '$uibModalInstance', |
8 | 'focaModalRemitoService', | 8 | 'focaModalRemitoService', |
9 | 'usadoPor', | 9 | 'usadoPor', |
10 | 'focaModalService', | ||
10 | function($timeout, $filter, $scope, $uibModalInstance, | 11 | function($timeout, $filter, $scope, $uibModalInstance, |
11 | focaModalRemitoService, usadoPor | 12 | focaModalRemitoService, usadoPor, focaModalService |
12 | ) { | 13 | ) { |
13 | var fecha = new Date(); | 14 | var fecha = new Date(); |
14 | $scope.fechaHasta = new Date(); | 15 | $scope.fechaHasta = new Date(); |
15 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); | 16 | $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); |
16 | $scope.filters = ''; | 17 | $scope.filters = ''; |
17 | $scope.remitos = []; | 18 | $scope.remitos = []; |
18 | $scope.primerBusqueda = false; | 19 | $scope.primerBusqueda = false; |
19 | $scope.searchLoading = false; | 20 | $scope.searchLoading = false; |
20 | // pagination | 21 | // pagination |
21 | $scope.numPerPage = 10; | 22 | $scope.numPerPage = 10; |
22 | $scope.currentPage = 1; | 23 | $scope.currentPage = 1; |
23 | $scope.filteredRemitos = []; | 24 | $scope.filteredRemitos = []; |
24 | $scope.currentPageRemitos = []; | 25 | $scope.currentPageRemitos = []; |
25 | $scope.selectedRemito = -1; | 26 | $scope.selectedRemito = -1; |
26 | 27 | ||
27 | //METODOS | 28 | //METODOS |
28 | $scope.busquedaPress = function(key) { | 29 | $scope.busquedaPress = function(key) { |
29 | if (key === 13) { | 30 | if (key === 13) { |
30 | //TODO Validaciones con alertas de foca | ||
31 | if(!$scope.fechaDesde) { | 31 | if(!$scope.fechaDesde) { |
32 | alert('INGRESE FECHA DESDE'); | 32 | focaModalService |
33 | .alert('INGRESE FECHA DESDE'); | ||
33 | return; | 34 | return; |
34 | } | 35 | } |
35 | if(!$scope.fechaHasta) { | 36 | if(!$scope.fechaHasta) { |
36 | alert('INGRESE FECHA HASTA'); | 37 | focaModalService |
38 | .alert('INGRESE FECHA HASTA'); | ||
37 | return; | 39 | return; |
38 | } | 40 | } |
39 | if($scope.fechaDesde > $scope.fechaHasta) { | 41 | if($scope.fechaDesde > $scope.fechaHasta) { |
40 | alert('La fecha desde no puede ser mayor a la fecha hasta'); | 42 | focaModalService |
43 | .alert('La fecha desde no puede ser mayor a la fecha hasta'); | ||
41 | return; | 44 | return; |
42 | } | 45 | } |
43 | $scope.searchLoading = true; | 46 | $scope.searchLoading = true; |
44 | //TODO: usar filtros en vez de toISOString | 47 | //TODO: usar filtros en vez de toISOString |
45 | focaModalRemitoService | 48 | focaModalRemitoService |
46 | .getRemitos(usadoPor, $scope.fechaDesde.toISOString().split('.')[0], | 49 | .getRemitos(usadoPor, $scope.fechaDesde.toISOString().split('.')[0], |
47 | $scope.fechaHasta.toISOString().split('.')[0]) | 50 | $scope.fechaHasta.toISOString().split('.')[0]) |
48 | .then(llenarDatos); | 51 | .then(llenarDatos); |
49 | } | 52 | } |
50 | }; | 53 | }; |
51 | function llenarDatos(res) { | 54 | function llenarDatos(res) { |
52 | $scope.remitos = []; | 55 | $scope.remitos = []; |
53 | $scope.filteredRemitos = []; | 56 | $scope.filteredRemitos = []; |
54 | $scope.currentPageRemitos = []; | 57 | $scope.currentPageRemitos = []; |
55 | $scope.selectedRemito = -1; | 58 | $scope.selectedRemito = -1; |
56 | $scope.searchLoading = false; | 59 | $scope.searchLoading = false; |
57 | $scope.primerBusqueda = true; | 60 | $scope.primerBusqueda = true; |
58 | $scope.remitos = res.data; | 61 | $scope.remitos = res.data; |
59 | $scope.search(true); | 62 | $scope.search(true); |
60 | primera(); | 63 | primera(); |
61 | } | 64 | } |
62 | $scope.search = function(pressed) { | 65 | $scope.search = function(pressed) { |
63 | if($scope.remitos.length > 0) { | 66 | if($scope.remitos.length > 0) { |
64 | $scope.filteredRemitos = $filter('filter')( | 67 | $scope.filteredRemitos = $filter('filter')( |
65 | $scope.remitos, | 68 | $scope.remitos, |
66 | {$: $scope.filters} | 69 | {$: $scope.filters} |
67 | ); | 70 | ); |
68 | 71 | ||
69 | if(pressed && $scope.filteredRemitos.length === 0){ | 72 | if(pressed && $scope.filteredRemitos.length === 0){ |
70 | $timeout(function() { | 73 | $timeout(function() { |
71 | angular.element('#search')[0].focus(); | 74 | angular.element('#search')[0].focus(); |
72 | $scope.filters = ''; | 75 | $scope.filters = ''; |
73 | }); | 76 | }); |
74 | } | 77 | } |
75 | 78 | ||
76 | $scope.lastPage = Math.ceil( | 79 | $scope.lastPage = Math.ceil( |
77 | $scope.filteredRemitos.length / $scope.numPerPage | 80 | $scope.filteredRemitos.length / $scope.numPerPage |
78 | ); | 81 | ); |
79 | 82 | ||
80 | $scope.resetPage(); | 83 | $scope.resetPage(); |
81 | } | 84 | } |
82 | }; | 85 | }; |
83 | 86 | ||
84 | $scope.resetPage = function() { | 87 | $scope.resetPage = function() { |
85 | $scope.currentPage = 1; | 88 | $scope.currentPage = 1; |
86 | $scope.selectPage(1); | 89 | $scope.selectPage(1); |
87 | }; | 90 | }; |
88 | 91 | ||
89 | $scope.selectPage = function(page) { | 92 | $scope.selectPage = function(page) { |
90 | var start = (page - 1) * $scope.numPerPage; | 93 | var start = (page - 1) * $scope.numPerPage; |
91 | var end = start + $scope.numPerPage; | 94 | var end = start + $scope.numPerPage; |
92 | $scope.paginas = []; | 95 | $scope.paginas = []; |
93 | $scope.paginas = calcularPages(page); | 96 | $scope.paginas = calcularPages(page); |
94 | $scope.currentPageRemitos = $scope.filteredRemitos.slice(start, end); | 97 | $scope.currentPageRemitos = $scope.filteredRemitos.slice(start, end); |
95 | $scope.currentPage = page; | 98 | $scope.currentPage = page; |
96 | }; | 99 | }; |
97 | 100 | ||
98 | $scope.select = function(remito) { | 101 | $scope.select = function(remito) { |
99 | $uibModalInstance.close(remito); | 102 | $uibModalInstance.close(remito); |
100 | }; | 103 | }; |
101 | 104 | ||
102 | $scope.cancel = function() { | 105 | $scope.cancel = function() { |
103 | $uibModalInstance.dismiss('cancel'); | 106 | $uibModalInstance.dismiss('cancel'); |
104 | }; | 107 | }; |
105 | 108 | ||
106 | $scope.busquedaDown = function(key) { | 109 | $scope.busquedaDown = function(key) { |
107 | if (key === 40) { | 110 | if (key === 40) { |
108 | primera(key); | 111 | primera(key); |
109 | } | 112 | } |
110 | }; | 113 | }; |
111 | 114 | ||
112 | $scope.itemRemito = function(key) { | 115 | $scope.itemRemito = function(key) { |
113 | if (key === 38) { | 116 | if (key === 38) { |
114 | anterior(key); | 117 | anterior(key); |
115 | } | 118 | } |
116 | 119 | ||
117 | if (key === 40) { | 120 | if (key === 40) { |
118 | siguiente(key); | 121 | siguiente(key); |
119 | } | 122 | } |
120 | 123 | ||
121 | if (key === 37) { | 124 | if (key === 37) { |
122 | retrocederPagina(); | 125 | retrocederPagina(); |
123 | } | 126 | } |
124 | 127 | ||
125 | if (key === 39) { | 128 | if (key === 39) { |
126 | avanzarPagina(); | 129 | avanzarPagina(); |
127 | } | 130 | } |
128 | }; | 131 | }; |
129 | 132 | ||
130 | function calcularPages(paginaActual) { | 133 | function calcularPages(paginaActual) { |
131 | var paginas = []; | 134 | var paginas = []; |
132 | paginas.push(paginaActual); | 135 | paginas.push(paginaActual); |
133 | 136 | ||
134 | if (paginaActual - 1 > 1) { | 137 | if (paginaActual - 1 > 1) { |
135 | 138 | ||
136 | paginas.unshift(paginaActual - 1); | 139 | paginas.unshift(paginaActual - 1); |
137 | if (paginaActual - 2 > 1) { | 140 | if (paginaActual - 2 > 1) { |
138 | paginas.unshift(paginaActual - 2); | 141 | paginas.unshift(paginaActual - 2); |
139 | } | 142 | } |
140 | } | 143 | } |
141 | 144 | ||
142 | if (paginaActual + 1 < $scope.lastPage) { | 145 | if (paginaActual + 1 < $scope.lastPage) { |
143 | paginas.push(paginaActual + 1); | 146 | paginas.push(paginaActual + 1); |
144 | if (paginaActual + 2 < $scope.lastPage) { | 147 | if (paginaActual + 2 < $scope.lastPage) { |
145 | paginas.push(paginaActual + 2); | 148 | paginas.push(paginaActual + 2); |
146 | } | 149 | } |
147 | } | 150 | } |
148 | 151 | ||
149 | if (paginaActual !== 1) { | 152 | if (paginaActual !== 1) { |
150 | paginas.unshift(1); | 153 | paginas.unshift(1); |
151 | } | 154 | } |
152 | 155 | ||
153 | if (paginaActual !== $scope.lastPage) { | 156 | if (paginaActual !== $scope.lastPage) { |
154 | paginas.push($scope.lastPage); | 157 | paginas.push($scope.lastPage); |
155 | } | 158 | } |
156 | 159 | ||
157 | return paginas; | 160 | return paginas; |
158 | } | 161 | } |
159 | 162 | ||
160 | function primera() { | 163 | function primera() { |
161 | $scope.selectedRemito = 0; | 164 | $scope.selectedRemito = 0; |
162 | } | 165 | } |
163 | 166 | ||
164 | function anterior() { | 167 | function anterior() { |
165 | if ($scope.selectedRemito === 0 && $scope.currentPage > 1) { | 168 | if ($scope.selectedRemito === 0 && $scope.currentPage > 1) { |
166 | retrocederPagina(); | 169 | retrocederPagina(); |
167 | } else { | 170 | } else { |
168 | $scope.selectedRemito--; | 171 | $scope.selectedRemito--; |
169 | } | 172 | } |
170 | } | 173 | } |
171 | 174 | ||
172 | function siguiente() { | 175 | function siguiente() { |
173 | if ($scope.selectedRemito < $scope.currentPageRemitos.length - 1 ) { | 176 | if ($scope.selectedRemito < $scope.currentPageRemitos.length - 1 ) { |
174 | $scope.selectedRemito++; | 177 | $scope.selectedRemito++; |
175 | } else { | 178 | } else { |
176 | avanzarPagina(); | 179 | avanzarPagina(); |
177 | } | 180 | } |
178 | } | 181 | } |
179 | 182 | ||
180 | function retrocederPagina() { | 183 | function retrocederPagina() { |
181 | if ($scope.currentPage > 1) { | 184 | if ($scope.currentPage > 1) { |
182 | $scope.selectPage($scope.currentPage - 1); | 185 | $scope.selectPage($scope.currentPage - 1); |
183 | $scope.selectedRemito = $scope.numPerPage - 1; | 186 | $scope.selectedRemito = $scope.numPerPage - 1; |
184 | } | 187 | } |
185 | } | 188 | } |
186 | 189 | ||
187 | function avanzarPagina() { | 190 | function avanzarPagina() { |
188 | if ($scope.currentPage < $scope.lastPage) { | 191 | if ($scope.currentPage < $scope.lastPage) { |
189 | $scope.selectPage($scope.currentPage + 1); | 192 | $scope.selectPage($scope.currentPage + 1); |
190 | $scope.selectedRemito = 0; | 193 | $scope.selectedRemito = 0; |
191 | } | 194 | } |
192 | } | 195 | } |
193 | } | 196 | } |
194 | ] | 197 | ] |
195 | ); | 198 | ); |