Commit 911d429af64dc32660fcf0449d91401497be200c

Authored by Eric Fernandez
Exists in master and in 1 other branch develop

Merge branch 'master' into 'master'

Master

See merge request !6
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: 'focaModalNotaPedido', 31 module: 'focaModalNotaPedido',
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-nota-pedido.js'), 46 concat('foca-modal-nota-pedido.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-nota-pedido.min.js'), 50 rename('foca-modal-nota-pedido.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-nota-pedido/dist')); 90 .pipe(gulp.dest('../../wrapper-demo/node_modules/foca-modal-nota-pedido/dist'));
91 }); 91 });
92 92
93 gulp.task('watchAndCopy', function() { 93 gulp.task('watchAndCopy', function() {
94 return gulp.watch([paths.srcJS, paths.srcViews], ['copy']); 94 return gulp.watch([paths.srcJS, paths.srcViews], ['copy']);
95 }); 95 });
96 96
1 angular.module('focaModalNotaPedido', ['ui.bootstrap', 'focaDirectivas', 'angular-ladda']); 1 angular.module('focaModalNotaPedido', [
2 'ui.bootstrap',
3 'focaDirectivas',
4 'angular-ladda',
5 'focaModal'
6 ]);
2 7
src/js/controller.js
1 angular.module('focaModalNotaPedido') 1 angular.module('focaModalNotaPedido')
2 .controller('focaModalNotaPedidoController', 2 .controller('focaModalNotaPedidoController',
3 [ 3 [
4 '$timeout', 4 '$timeout',
5 '$filter', 5 '$filter',
6 '$scope', 6 '$scope',
7 '$uibModalInstance', 7 '$uibModalInstance',
8 'focaModalNotaPedidoService', 8 'focaModalNotaPedidoService',
9 'usadoPor', 9 'usadoPor',
10 'focaModalService',
10 function($timeout, $filter, $scope, $uibModalInstance, 11 function($timeout, $filter, $scope, $uibModalInstance,
11 focaModalNotaPedidoService, usadoPor 12 focaModalNotaPedidoService, 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.notasPedido = []; 18 $scope.notasPedido = [];
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.filteredNotasPedido = []; 24 $scope.filteredNotasPedido = [];
24 $scope.currentPageNotasPedido = []; 25 $scope.currentPageNotasPedido = [];
25 $scope.selectedNotaPedido = -1; 26 $scope.selectedNotaPedido = -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
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 hacer filtro de fecha 47 //TODO hacer filtro de fecha
45 focaModalNotaPedidoService 48 focaModalNotaPedidoService
46 .getNotasPedido(usadoPor, $scope.fechaDesde.toISOString().split('.')[0], 49 .getNotasPedido(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.notasPedido = []; 55 $scope.notasPedido = [];
53 $scope.filteredNotasPedido = []; 56 $scope.filteredNotasPedido = [];
54 $scope.currentPageNotasPedido = []; 57 $scope.currentPageNotasPedido = [];
55 $scope.selectedNotaPedido = -1; 58 $scope.selectedNotaPedido = -1;
56 $scope.searchLoading = false; 59 $scope.searchLoading = false;
57 $scope.primerBusqueda = true; 60 $scope.primerBusqueda = true;
58 $scope.notasPedido = res.data; 61 $scope.notasPedido = 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.notasPedido.length > 0) { 66 if($scope.notasPedido.length > 0) {
64 $scope.filteredNotasPedido = $filter('filter')( 67 $scope.filteredNotasPedido = $filter('filter')(
65 $scope.notasPedido, 68 $scope.notasPedido,
66 {$: $scope.filters} 69 {$: $scope.filters}
67 ); 70 );
68 71
69 $scope.lastPage = Math.ceil( 72 $scope.lastPage = Math.ceil(
70 $scope.filteredNotasPedido.length / $scope.numPerPage 73 $scope.filteredNotasPedido.length / $scope.numPerPage
71 ); 74 );
72 75
73 $scope.resetPage(); 76 $scope.resetPage();
74 if(pressed && $scope.filteredNotasPedido.length === 0){ 77 if(pressed && $scope.filteredNotasPedido.length === 0){
75 $timeout(function() { 78 $timeout(function() {
76 angular.element('#search')[0].focus(); 79 angular.element('#search')[0].focus();
77 $scope.filters = ''; 80 $scope.filters = '';
78 }); 81 });
79 } 82 }
80 } 83 }
81 }; 84 };
82 85
83 $scope.resetPage = function() { 86 $scope.resetPage = function() {
84 $scope.currentPage = 1; 87 $scope.currentPage = 1;
85 $scope.selectPage(1); 88 $scope.selectPage(1);
86 }; 89 };
87 90
88 $scope.selectPage = function(page) { 91 $scope.selectPage = function(page) {
89 var start = (page - 1) * $scope.numPerPage; 92 var start = (page - 1) * $scope.numPerPage;
90 var end = start + $scope.numPerPage; 93 var end = start + $scope.numPerPage;
91 $scope.paginas = []; 94 $scope.paginas = [];
92 $scope.paginas = calcularPages(page); 95 $scope.paginas = calcularPages(page);
93 $scope.currentPageNotasPedido = $scope.filteredNotasPedido.slice(start, end); 96 $scope.currentPageNotasPedido = $scope.filteredNotasPedido.slice(start, end);
94 $scope.currentPage = page; 97 $scope.currentPage = page;
95 }; 98 };
96 99
97 $scope.select = function(notaPedido) { 100 $scope.select = function(notaPedido) {
98 $uibModalInstance.close(notaPedido); 101 $uibModalInstance.close(notaPedido);
99 }; 102 };
100 103
101 $scope.cancel = function() { 104 $scope.cancel = function() {
102 $uibModalInstance.dismiss('cancel'); 105 $uibModalInstance.dismiss('cancel');
103 }; 106 };
104 107
105 $scope.busquedaDown = function(key) { 108 $scope.busquedaDown = function(key) {
106 if (key === 40) { 109 if (key === 40) {
107 primera(key); 110 primera(key);
108 } 111 }
109 }; 112 };
110 113
111 $scope.itemNotaPedido = function(key) { 114 $scope.itemNotaPedido = function(key) {
112 if (key === 38) { 115 if (key === 38) {
113 anterior(key); 116 anterior(key);
114 } 117 }
115 118
116 if (key === 40) { 119 if (key === 40) {
117 siguiente(key); 120 siguiente(key);
118 } 121 }
119 122
120 if (key === 37) { 123 if (key === 37) {
121 retrocederPagina(); 124 retrocederPagina();
122 } 125 }
123 126
124 if (key === 39) { 127 if (key === 39) {
125 avanzarPagina(); 128 avanzarPagina();
126 } 129 }
127 }; 130 };
128 131
129 function calcularPages(paginaActual) { 132 function calcularPages(paginaActual) {
130 var paginas = []; 133 var paginas = [];
131 paginas.push(paginaActual); 134 paginas.push(paginaActual);
132 135
133 if (paginaActual - 1 > 1) { 136 if (paginaActual - 1 > 1) {
134 137
135 paginas.unshift(paginaActual - 1); 138 paginas.unshift(paginaActual - 1);
136 if (paginaActual - 2 > 1) { 139 if (paginaActual - 2 > 1) {
137 paginas.unshift(paginaActual - 2); 140 paginas.unshift(paginaActual - 2);
138 } 141 }
139 } 142 }
140 143
141 if (paginaActual + 1 < $scope.lastPage) { 144 if (paginaActual + 1 < $scope.lastPage) {
142 paginas.push(paginaActual + 1); 145 paginas.push(paginaActual + 1);
143 if (paginaActual + 2 < $scope.lastPage) { 146 if (paginaActual + 2 < $scope.lastPage) {
144 paginas.push(paginaActual + 2); 147 paginas.push(paginaActual + 2);
145 } 148 }
146 } 149 }
147 150
148 if (paginaActual !== 1) { 151 if (paginaActual !== 1) {
149 paginas.unshift(1); 152 paginas.unshift(1);
150 } 153 }
151 154
152 if (paginaActual !== $scope.lastPage) { 155 if (paginaActual !== $scope.lastPage) {
153 paginas.push($scope.lastPage); 156 paginas.push($scope.lastPage);
154 } 157 }
155 158
156 return paginas; 159 return paginas;
157 } 160 }
158 161
159 function primera() { 162 function primera() {
160 $scope.selectedNotaPedido = 0; 163 $scope.selectedNotaPedido = 0;
161 } 164 }
162 165
163 function anterior() { 166 function anterior() {
164 if ($scope.selectedNotaPedido === 0 && $scope.currentPage > 1) { 167 if ($scope.selectedNotaPedido === 0 && $scope.currentPage > 1) {
165 retrocederPagina(); 168 retrocederPagina();
166 } else { 169 } else {
167 $scope.selectedNotaPedido--; 170 $scope.selectedNotaPedido--;
168 } 171 }
169 } 172 }
170 173
171 function siguiente() { 174 function siguiente() {
172 if ($scope.selectedNotaPedido < $scope.currentPageNotasPedido.length - 1 ) { 175 if ($scope.selectedNotaPedido < $scope.currentPageNotasPedido.length - 1 ) {
173 $scope.selectedNotaPedido++; 176 $scope.selectedNotaPedido++;
174 } else { 177 } else {
175 avanzarPagina(); 178 avanzarPagina();
176 } 179 }
177 } 180 }
178 181
179 function retrocederPagina() { 182 function retrocederPagina() {
180 if ($scope.currentPage > 1) { 183 if ($scope.currentPage > 1) {
181 $scope.selectPage($scope.currentPage - 1); 184 $scope.selectPage($scope.currentPage - 1);
182 $scope.selectedNotaPedido = $scope.numPerPage - 1; 185 $scope.selectedNotaPedido = $scope.numPerPage - 1;
183 } 186 }
184 } 187 }
185 188
186 function avanzarPagina() { 189 function avanzarPagina() {
187 if ($scope.currentPage < $scope.lastPage) { 190 if ($scope.currentPage < $scope.lastPage) {
188 $scope.selectPage($scope.currentPage + 1); 191 $scope.selectPage($scope.currentPage + 1);
189 $scope.selectedNotaPedido = 0; 192 $scope.selectedNotaPedido = 0;
190 } 193 }
191 } 194 }
192 } 195 }
193 ] 196 ]
194 ); 197 );