Commit 1f343e7653db07e2557230cffefebd3c11e9667c

Authored by Pablo Marco del Pont
Exists in master

Merge branch 'master' into 'master'

Master (pmarco)

See merge request modulos-npm/foca-modal-nota-pedido!1
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']", '[]'),
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], ['copy']) 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
93 gulp.task('watchAndCopy', function() {
94 return gulp.watch([paths.srcJS, paths.srcViews], ['copy']);
95 });
92 96
src/js/controller.js
1 angular.module('focaModalNotaPedido') 1 angular.module('focaModalNotaPedido')
2 .controller('focaModalNotaPedidoController', 2 .controller('focaModalNotaPedidoController',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'parametroNotaPedido', 7 'parametroNotaPedido',
8 'focaModalNotaPedidoService', 8 'focaModalNotaPedidoService',
9 function($filter, $scope, $uibModalInstance, parametroNotaPedido, 9 function($filter, $scope, $uibModalInstance, parametroNotaPedido,
10 focaModalNotaPedidoService 10 focaModalNotaPedidoService
11 ) { 11 ) {
12 12
13 $scope.simbolo = parametroNotaPedido.simbolo; 13 $scope.simbolo = parametroNotaPedido.simbolo;
14 $scope.filters = ''; 14 $scope.filters = '';
15 $scope.notasPedido = []; 15 $scope.notasPedido = [];
16 $scope.primerBusqueda = false; 16 $scope.primerBusqueda = false;
17 $scope.searchLoading = false; 17 $scope.searchLoading = false;
18 // pagination 18 // pagination
19 $scope.numPerPage = 10; 19 $scope.numPerPage = 10;
20 $scope.currentPage = 1; 20 $scope.currentPage = 1;
21 $scope.filteredNotasPedido = []; 21 $scope.filteredNotasPedido = [];
22 $scope.currentPageNotasPedido = []; 22 $scope.currentPageNotasPedido = [];
23 $scope.selectedNotaPedido = -1; 23 $scope.selectedNotaPedido = -1;
24 24
25 //METODOS 25 //METODOS
26 $scope.busquedaPress = function(key) { 26 $scope.busquedaPress = function(key) {
27 if (key === 13) { 27 if (key === 13) {
28 $scope.searchLoading = true; 28 $scope.searchLoading = true;
29 if(parametroNotaPedido.idLista > 0) { 29 focaModalNotaPedidoService.getNotasPedido().then(llenarDatos);
30 focaModalNotaPedidoService
31 .getNotasPedidoByIdLista(parametroNotaPedido.idLista, $scope.filters)
32 .then(llenarDatos);
33 } else if(parametroNotaPedido.idLista === -1) {
34 focaModalNotaPedidoService.getNotasPedido()
35 .then(llenarDatos);
36 }
37 } 30 }
38 }; 31 };
39 function llenarDatos(res) { 32 function llenarDatos(res) {
40 for(var i = 0; i < res.data.length; i++) { 33 for(var i = 0; i < res.data.length; i++) {
41 res.data[i].precio = res.data[i].precio / parametroNotaPedido.cotizacion; 34 res.data[i].precio =
35 res.data[i].precio / parametroNotaPedido.cotizacion;
42 } 36 }
43 $scope.searchLoading = false; 37 $scope.searchLoading = false;
44 $scope.primerBusqueda = true; 38 $scope.primerBusqueda = true;
45 $scope.notasPedido = res.data; 39 $scope.notasPedido = res.data;
46 $scope.search(); 40 $scope.search();
47 primera(); 41 primera();
48 } 42 }
49 $scope.search = function() { 43 $scope.search = function() {
50 if($scope.notasPedido.length > 0) { 44 if($scope.notasPedido.length > 0) {
51 $scope.filteredNotasPedido = $filter('filter')( 45 $scope.filteredNotasPedido = $filter('filter')(
52 $scope.notasPedido, 46 $scope.notasPedido,
53 {$: $scope.filters} 47 {$: $scope.filters}
54 ); 48 );
55 49
56 $scope.lastPage = Math.ceil( 50 $scope.lastPage = Math.ceil(
57 $scope.filteredNotasPedido.length / $scope.numPerPage 51 $scope.filteredNotasPedido.length / $scope.numPerPage
58 ); 52 );
59 53
60 $scope.resetPage(); 54 $scope.resetPage();
61 } 55 }
62 }; 56 };
63 57
64 $scope.resetPage = function() { 58 $scope.resetPage = function() {
65 $scope.currentPage = 1; 59 $scope.currentPage = 1;
66 $scope.selectPage(1); 60 $scope.selectPage(1);
67 }; 61 };
68 62
69 $scope.selectPage = function(page) { 63 $scope.selectPage = function(page) {
70 var start = (page - 1) * $scope.numPerPage; 64 var start = (page - 1) * $scope.numPerPage;
71 var end = start + $scope.numPerPage; 65 var end = start + $scope.numPerPage;
72 $scope.paginas = []; 66 $scope.paginas = [];
73 $scope.paginas = calcularPages(page); 67 $scope.paginas = calcularPages(page);
74 $scope.currentPageNotasPedido = $scope.filteredNotasPedido.slice(start, end); 68 $scope.currentPageNotasPedido = $scope.filteredNotasPedido.slice(start, end);
75 $scope.currentPage = page; 69 $scope.currentPage = page;
76 }; 70 };
77 71
78 $scope.select = function(notaPedido) { 72 $scope.select = function(notaPedido) {
79 $uibModalInstance.close(notaPedido); 73 $uibModalInstance.close(notaPedido);
80 }; 74 };
81 75
82 $scope.cancel = function() { 76 $scope.cancel = function() {
83 $uibModalInstance.dismiss('cancel'); 77 $uibModalInstance.dismiss('cancel');
84 }; 78 };
85 79
86 $scope.busquedaDown = function(key) { 80 $scope.busquedaDown = function(key) {
87 if (key === 40) { 81 if (key === 40) {
88 primera(key); 82 primera(key);
89 } 83 }
90 }; 84 };
91 85
92 $scope.itemNotaPedido = function(key) { 86 $scope.itemNotaPedido = function(key) {
93 if (key === 38) { 87 if (key === 38) {
94 anterior(key); 88 anterior(key);
95 } 89 }
96 90
97 if (key === 40) { 91 if (key === 40) {
98 siguiente(key); 92 siguiente(key);
99 } 93 }
100 94
101 if (key === 37) { 95 if (key === 37) {
102 retrocederPagina(); 96 retrocederPagina();
103 } 97 }
104 98
105 if (key === 39) { 99 if (key === 39) {
106 avanzarPagina(); 100 avanzarPagina();
107 } 101 }
108 }; 102 };
109 103
110 function calcularPages(paginaActual) { 104 function calcularPages(paginaActual) {
111 var paginas = []; 105 var paginas = [];
112 paginas.push(paginaActual); 106 paginas.push(paginaActual);
113 107
114 if (paginaActual - 1 > 1) { 108 if (paginaActual - 1 > 1) {
115 109
116 paginas.unshift(paginaActual - 1); 110 paginas.unshift(paginaActual - 1);
117 if (paginaActual - 2 > 1) { 111 if (paginaActual - 2 > 1) {
118 paginas.unshift(paginaActual - 2); 112 paginas.unshift(paginaActual - 2);
119 } 113 }
120 } 114 }
121 115
122 if (paginaActual + 1 < $scope.lastPage) { 116 if (paginaActual + 1 < $scope.lastPage) {
123 paginas.push(paginaActual + 1); 117 paginas.push(paginaActual + 1);
124 if (paginaActual + 2 < $scope.lastPage) { 118 if (paginaActual + 2 < $scope.lastPage) {
125 paginas.push(paginaActual + 2); 119 paginas.push(paginaActual + 2);
126 } 120 }
127 } 121 }
128 122
129 if (paginaActual !== 1) { 123 if (paginaActual !== 1) {
130 paginas.unshift(1); 124 paginas.unshift(1);
131 } 125 }
132 126
133 if (paginaActual !== $scope.lastPage) { 127 if (paginaActual !== $scope.lastPage) {
134 paginas.push($scope.lastPage); 128 paginas.push($scope.lastPage);
135 } 129 }
136 130
137 return paginas; 131 return paginas;
138 } 132 }
139 133
140 function primera() { 134 function primera() {
141 $scope.selectedNotaPedido = 0; 135 $scope.selectedNotaPedido = 0;
142 } 136 }
143 137
144 function anterior() { 138 function anterior() {
145 if ($scope.selectedNotaPedido === 0 && $scope.currentPage > 1) { 139 if ($scope.selectedNotaPedido === 0 && $scope.currentPage > 1) {
146 retrocederPagina(); 140 retrocederPagina();
147 } else { 141 } else {
148 $scope.selectedNotaPedido--; 142 $scope.selectedNotaPedido--;
149 } 143 }
150 } 144 }
151 145
152 function siguiente() { 146 function siguiente() {
153 if ($scope.selectedNotaPedido < $scope.currentPageNotasPedido.length - 1 ) { 147 if ($scope.selectedNotaPedido < $scope.currentPageNotasPedido.length - 1 ) {
154 $scope.selectedNotaPedido++; 148 $scope.selectedNotaPedido++;
155 } else { 149 } else {
156 avanzarPagina(); 150 avanzarPagina();
157 } 151 }
158 } 152 }
159 153
160 function retrocederPagina() { 154 function retrocederPagina() {
161 if ($scope.currentPage > 1) { 155 if ($scope.currentPage > 1) {
162 $scope.selectPage($scope.currentPage - 1); 156 $scope.selectPage($scope.currentPage - 1);
163 $scope.selectedNotaPedido = $scope.numPerPage - 1; 157 $scope.selectedNotaPedido = $scope.numPerPage - 1;
164 } 158 }
165 } 159 }
166 160
167 function avanzarPagina() { 161 function avanzarPagina() {
168 if ($scope.currentPage < $scope.lastPage) { 162 if ($scope.currentPage < $scope.lastPage) {
169 $scope.selectPage($scope.currentPage + 1); 163 $scope.selectPage($scope.currentPage + 1);
170 $scope.selectedNotaPedido = 0; 164 $scope.selectedNotaPedido = 0;
171 } 165 }
172 } 166 }
173 } 167 }
174 ] 168 ]
175 ); 169 );
1 angular.module('focaModalNotaPedido') 1 angular.module('focaModalNotaPedido')
2 .service('focaModalNotaPedidoService', [ 2 .service('focaModalNotaPedidoService', [
3 '$http', 3 '$http',
4 'API_ENDPOINT', 4 'API_ENDPOINT',
5 function($http, API_ENDPOINT) { 5 function($http, API_ENDPOINT) {
6 return { 6 return {
7 getNotasPedido: function() { 7 getNotasPedido: function() {
8 return $http.get(API_ENDPOINT.URL + '/articulos'); 8 return $http.get(API_ENDPOINT.URL + '/nota-pedido');
9 },
10 getNotasPedidoByIdLista: function(id, filters) {
11 return $http.post(API_ENDPOINT.URL + '/articulos/lista',
12 {filters: filters, id: id});
13 } 9 }
14 }; 10 };
15 } 11 }
16 ]); 12 ]);
17 13
src/views/foca-modal-nota-pedido.html
1 <div class="modal-header py-1"> 1 <div class="modal-header py-1">
2 <h5 class="modal-title">Busqueda de Nota de Pedido</h5> 2 <h5 class="modal-title">Busqueda de Nota de Pedido</h5>
3 </div> 3 </div>
4 <div class="modal-body" id="modal-body"> 4 <div class="modal-body" id="modal-body">
5 <div class="input-group"> 5 <div class="input-group">
6 <input 6 <input
7 ladda="searchLoading" 7 ladda="searchLoading"
8 type="text" 8 type="text"
9 class="form-control" 9 class="form-control"
10 placeholder="Busqueda" 10 placeholder="Busqueda"
11 ng-model="filters" 11 ng-model="filters"
12 ng-change="search()" 12 ng-change="search()"
13 ng-keydown="busquedaDown($event.keyCode)" 13 ng-keydown="busquedaDown($event.keyCode)"
14 ng-keypress="busquedaPress($event.keyCode)" 14 ng-keypress="busquedaPress($event.keyCode)"
15 foca-focus="selectedNotaPedido == -1" 15 foca-focus="selectedNotaPedido == -1"
16 ng-focus="selectedNotaPedido = -1" 16 ng-focus="selectedNotaPedido = -1"
17 > 17 >
18 <div class="input-group-append"> 18 <div class="input-group-append">
19 <button 19 <button
20 ladda="searchLoading" 20 ladda="searchLoading"
21 class="btn btn-outline-secondary" 21 class="btn btn-outline-secondary"
22 type="button" 22 type="button"
23 ng-click="busquedaPress(13)" 23 ng-click="busquedaPress(13)"
24 > 24 >
25 <i class="fa fa-search" aria-hidden="true"></i> 25 <i class="fa fa-search" aria-hidden="true"></i>
26 </button> 26 </button>
27 </div> 27 </div>
28 </div> 28 </div>
29 <table ng-show="primerBusqueda" class="table table-striped table-sm"> 29 <table ng-show="primerBusqueda" class="table table-striped table-sm">
30 <thead> 30 <thead>
31 <tr> 31 <tr>
32 <th>Sec.</th> 32 <th>Fecha</th>
33 <th>Cod.</th> 33 <th>Cliente</th>
34 <th>Descripción</th> 34 <th>Comprobante</th>
35 <th>P. Base</th>
36 <th></th> 35 <th></th>
37 </tr> 36 </tr>
38 </thead> 37 </thead>
39 <tbody> 38 <tbody>
40 <tr ng-show="currentPageNotasPedido.length == 0 && primerBusqueda"> 39 <tr ng-show="currentPageNotasPedido.length == 0 && primerBusqueda">
41 <td colspan="5"> 40 <td colspan="5">
42 No se encontraron resultados. 41 No se encontraron resultados.
43 </td> 42 </td>
44 </tr> 43 </tr>
45 <tr class="selectable" 44 <tr class="selectable"
46 ng-repeat="(key,notaPedido) in currentPageNotasPedido" 45 ng-repeat="(key,notaPedido) in currentPageNotasPedido"
47 ng-click="select(notaPedido)"> 46 ng-click="select(notaPedido)">
48 <td ng-bind="notaPedido.sector"></td> 47 <td ng-bind="notaPedido.fechaCarga | date : 'dd/MM/yyyy'"></td>
49 <td ng-bind="notaPedido.codigo"></td> 48 <td ng-bind="notaPedido.nombreCliente"></td>
50 <td ng-bind="notaPedido.descripcion"></td> 49 <td ng-bind="[notaPedido.sucursal, notaPedido.numeroNotaPedido] | comprobante"></td>
51 <td ng-bind="notaPedido.precio | currency: simbolo : 4"></td>
52 <td> 50 <td>
53 <button 51 <button
54 type="button" 52 type="button"
55 class="btn btn-xs p-1 float-right" 53 class="btn btn-xs p-1 float-right"
56 ng-class="{ 54 ng-class="{
57 'btn-secondary': selectedNotaPedido != key, 55 'btn-secondary': selectedNotaPedido != key,
58 'btn-primary': selectedNotaPedido == key 56 'btn-primary': selectedNotaPedido == key
59 }" 57 }"
60 foca-focus="selectedNotaPedido == {{key}}" 58 foca-focus="selectedNotaPedido == {{key}}"
61 ng-keydown="itemNotaPedido($event.keyCode)" 59 ng-keydown="itemNotaPedido($event.keyCode)"
62 > 60 >
63 <i class="fa fa-arrow-right" aria-hidden="true"></i> 61 <i class="fa fa-arrow-right" aria-hidden="true"></i>
64 </button> 62 </button>
65 </td> 63 </td>
66 </tr> 64 </tr>
67 </tbody> 65 </tbody>
68 </table> 66 </table>
69 <nav ng-show="currentPageNotasPedido.length > 0 && primerBusqueda"> 67 <nav ng-show="currentPageNotasPedido.length > 0 && primerBusqueda">
70 <ul class="pagination pagination-sm justify-content mb-0"> 68 <ul class="pagination pagination-sm justify-content mb-0">
71 <li class="page-item" ng-class="{'disabled': currentPage == 1}"> 69 <li class="page-item" ng-class="{'disabled': currentPage == 1}">
72 <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)"> 70 <a class="page-link" href="#" ng-click="selectPage(currentPage - 1)">
73 <span aria-hidden="true">&laquo;</span> 71 <span aria-hidden="true">&laquo;</span>
74 <span class="sr-only">Anterior</span> 72 <span class="sr-only">Anterior</span>
75 </a> 73 </a>
76 </li> 74 </li>
77 <li 75 <li
78 class="page-item" 76 class="page-item"
79 ng-repeat="pagina in paginas" 77 ng-repeat="pagina in paginas"
80 ng-class="{'active': pagina == currentPage}" 78 ng-class="{'active': pagina == currentPage}"
81 > 79 >
82 <a 80 <a
83 class="page-link" 81 class="page-link"
84 href="#" 82 href="#"
85 ng-click="selectPage(pagina)" 83 ng-click="selectPage(pagina)"
86 ng-bind="pagina" 84 ng-bind="pagina"
87 ></a> 85 ></a>
88 </li> 86 </li>
89 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}"> 87 <li class="page-item" ng-class="{'disabled': currentPage == lastPage}">
90 <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)"> 88 <a class="page-link" href="#" ng-click="selectPage(currentPage + 1)">
91 <span aria-hidden="true">&raquo;</span> 89 <span aria-hidden="true">&raquo;</span>
92 <span class="sr-only">Siguiente</span> 90 <span class="sr-only">Siguiente</span>
93 </a> 91 </a>
94 </li> 92 </li>
95 </ul> 93 </ul>
96 </nav> 94 </nav>
97 </div> 95 </div>
98 <div class="modal-footer py-1"> 96 <div class="modal-footer py-1">
99 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button> 97 <button class="btn btn-sm btn-secondary" type="button" ng-click="cancel()">Cancelar</button>
100 </div> 98 </div>
101 99