Commit cf88a79951aebc13b9d561228ca725a9c7091e3f

Authored by Mauricio Cattafi
Exists in master and in 1 other branch develop

Merge branch 'develop' into 'master'

Develop

See merge request !24
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-es').default; 5 const uglify = require('gulp-uglify-es').default;
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 const header = require('gulp-header'); 12 const header = require('gulp-header');
13 const footer =require('gulp-footer'); 13 const footer =require('gulp-footer');
14 14
15 var paths = { 15 var paths = {
16 srcJS: 'src/js/*.js', 16 srcJS: 'src/js/*.js',
17 srcViews: 'src/views/*.html', 17 srcViews: 'src/views/*.html',
18 specs: 'spec/*.js', 18 specs: 'spec/*.js',
19 tmp: 'tmp', 19 tmp: 'tmp',
20 dist: 'dist/' 20 dist: 'dist/'
21 }; 21 };
22 22
23 gulp.task('templates', function() { 23 gulp.task('templates', function() {
24 return pump( 24 return pump(
25 [ 25 [
26 gulp.src(paths.srcViews), 26 gulp.src(paths.srcViews),
27 replace('views/', ''), 27 replace('views/', ''),
28 htmlmin(), 28 htmlmin(),
29 templateCache('views.js', { 29 templateCache('views.js', {
30 module: 'focaAbmChofer', 30 module: 'focaAbmChofer',
31 root: '' 31 root: ''
32 }), 32 }),
33 gulp.dest(paths.tmp) 33 gulp.dest(paths.tmp)
34 ] 34 ]
35 ); 35 );
36 }); 36 });
37 37
38 gulp.task('uglify', ['templates', 'uglify-spec'], function() { 38 gulp.task('uglify', ['templates', 'uglify-spec'], function() {
39 return pump( 39 return pump(
40 [ 40 [
41 gulp.src([ 41 gulp.src([
42 paths.srcJS, 42 paths.srcJS,
43 'tmp/views.js' 43 'tmp/views.js'
44 ]), 44 ]),
45 concat('foca-abm-chofer.js'), 45 concat('foca-abm-chofer.js'),
46 replace("src/views/", ''), 46 replace("src/views/", ''),
47 gulp.dest(paths.tmp), 47 gulp.dest(paths.tmp),
48 rename('foca-abm-chofer.min.js'), 48 rename('foca-abm-chofer.min.js'),
49 uglify(), 49 uglify(),
50 gulp.dest(paths.dist) 50 gulp.dest(paths.dist)
51 ] 51 ]
52 ); 52 );
53 }); 53 });
54 54
55 gulp.task('uglify-spec', function() { 55 gulp.task('uglify-spec', function() {
56 return pump([ 56 return pump([
57 gulp.src(paths.specs), 57 gulp.src(paths.specs),
58 concat('foca-abm-chofer.spec.js'), 58 concat('foca-abm-chofer.spec.js'),
59 replace("src/views/", ''), 59 replace("src/views/", ''),
60 header("describe('Módulo foca-abm-chofer', function() { \n"), 60 header("describe('Módulo foca-abm-chofer', function() { \n"),
61 footer("});"), 61 footer("});"),
62 gulp.dest(paths.dist) 62 gulp.dest(paths.dist)
63 ]); 63 ]);
64 }); 64 });
65 65
66 gulp.task('clean', function() { 66 gulp.task('clean', function() {
67 return gulp.src(['tmp', 'dist'], {read: false}) 67 return gulp.src(['tmp', 'dist'], {read: false})
68 .pipe(clean()); 68 .pipe(clean());
69 }); 69 });
70 70
71 gulp.task('pre-commit', function() { 71 gulp.task('pre-commit', function() {
72 pump( 72 return pump(
73 [ 73 [
74 gulp.src([paths.srcJS, paths.specs]), 74 gulp.src([paths.srcJS, paths.specs]),
75 jshint('.jshintrc'), 75 jshint('.jshintrc'),
76 jshint.reporter('default'), 76 jshint.reporter('default'),
77 jshint.reporter('fail') 77 jshint.reporter('fail')
78 ] 78 ]
79 ); 79 );
80 80
81 gulp.start('uglify'); 81 gulp.start('uglify');
82 }); 82 });
83 83
84 gulp.task('clean-post-install', function() { 84 gulp.task('clean-post-install', function() {
85 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', 85 return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js',
86 'index.html', 'spec', 'test.html'], {read: false}) 86 'index.html', 'spec', 'test.html'], {read: false})
87 .pipe(clean()); 87 .pipe(clean());
88 }); 88 });
89 89
90 gulp.task('compile', ['templates', 'uglify']); 90 gulp.task('compile', ['templates', 'uglify']);
91 91
92 gulp.task('watch', function() { 92 gulp.task('watch', function() {
93 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); 93 gulp.watch([paths.srcJS, paths.srcViews], ['uglify']);
94 }); 94 });
95 95
96 gulp.task('webserver', function() { 96 gulp.task('webserver', function() {
97 pump [ 97 pump [
98 connect.server({port: 3000}) 98 connect.server({port: 3000})
99 ] 99 ]
100 }); 100 });
101 101
102 gulp.task('default', ['webserver']); 102 gulp.task('default', ['webserver']);
103 103
src/js/controller.js
1 angular.module('focaAbmChofer') 1 angular.module('focaAbmChofer')
2 .controller('focaAbmChoferesController', [ 2 .controller('focaAbmChoferesController', [
3 '$scope', 'focaAbmChoferService', '$location', '$uibModal', 3 '$scope', 'focaAbmChoferService', '$location', '$uibModal',
4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$localStorage',
5 '$routeParams', '$filter', 5 '$routeParams',
6 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService, 6 function($scope, focaAbmChoferService, $location, $uibModal, focaModalService,
7 focaBotoneraLateralService, $timeout, $localStorage, $routeParams, $filter) { 7 focaBotoneraLateralService, $timeout, $localStorage, $routeParams) {
8 8
9 $scope.focused = 1; 9 $scope.focused = 1;
10 $scope.now = new Date(); 10 $scope.now = new Date();
11 $scope.nuevo = $routeParams.id === '0'; 11 $scope.nuevo = $routeParams.id === '0';
12 $scope.filters = ''; 12 $scope.filters = '';
13 $scope.choferes = []; 13 $scope.choferes = [];
14 $scope.creando = false; 14 $scope.creando = false;
15 $scope.crear = false; 15 $scope.crear = false;
16 $scope.transportistas = []; 16 $scope.transportistas = [];
17 $scope.botonera = [{ 17 $scope.botonera = [{
18 label: 'Transportista', 18 label: 'Transportista',
19 image: 'cliente.png' 19 image: 'cliente.png'
20 }]; 20 }];
21 $scope.next = function(key) { 21 $scope.next = function(key) {
22 if (key === 13) $scope.focused++; 22 if (key === 13) $scope.focused++;
23 }; 23 };
24 24
25 //SETEO BOTONERA LATERAL 25 //SETEO BOTONERA LATERAL
26 $timeout(function() { 26 $timeout(function() {
27 focaBotoneraLateralService.showSalir(false); 27 focaBotoneraLateralService.showSalir(false);
28 focaBotoneraLateralService.showPausar(false); 28 focaBotoneraLateralService.showPausar(false);
29 focaBotoneraLateralService.showCancelar(false); 29 focaBotoneraLateralService.showCancelar(false);
30 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 30 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
31 focaBotoneraLateralService.addCustomButton('Salir', salir); 31 focaBotoneraLateralService.addCustomButton('Salir', salir);
32 }); 32 });
33 33
34 if (focaAbmChoferService.transportistaSeleccionado.COD) { 34 if (focaAbmChoferService.transportistaSeleccionado.COD) {
35 elegirTransportista(focaAbmChoferService.transportistaSeleccionado); 35 elegirTransportista(focaAbmChoferService.transportistaSeleccionado);
36 } 36 }
37 37
38 focaAbmChoferService.getTiposDocumento().then(function(res) { 38 focaAbmChoferService.getTiposDocumento().then(function(res) {
39 $scope.tiposDocumento = res.data; 39 $scope.tiposDocumento = res.data;
40 }); 40 });
41 41
42 $scope.crearChofer = function () { 42 $scope.crearChofer = function () {
43 var chofer = { 43 var chofer = {
44 id: 0, 44 id: 0,
45 nombre: '', 45 nombre: '',
46 telefono: '', 46 telefono: '',
47 editando: true, 47 editando: true,
48 desactivado: false
48 }; 49 };
49 $scope.choferes.unshift(chofer); 50 $scope.choferes.unshift(chofer);
50 $scope.crear = false; 51 $scope.crear = false;
51 }; 52 };
52 53
53 $scope.editar = function(chofer) { 54 $scope.editar = function(chofer) {
54 $scope.choferes.forEach(function(chofer) { 55 $scope.choferes.forEach(function(chofer) {
55 chofer.editando = false; 56 chofer.editando = false;
56 $scope.crear = false; 57 $scope.crear = false;
57 }); 58 });
58 chofer.editando = true; 59 chofer.editando = true;
59 $scope.inicial = angular.copy(chofer); 60 $scope.inicial = angular.copy(chofer);
60 }; 61 };
61 62
62 $scope.agregarChofer = function (chofer) { 63 $scope.agregarChofer = function (chofer) {
63 if (!chofer.nombre) { 64 if (!chofer.nombre) {
64 focaModalService.alert('Ingrese nombre'); 65 focaModalService.alert('Ingrese nombre');
65 return; 66 return;
66 } else if (!chofer.idTipoDocumento) { 67 } else if (!chofer.idTipoDocumento) {
67 focaModalService.alert('Ingrese tipo documento'); 68 focaModalService.alert('Ingrese tipo documento');
68 return; 69 return;
69 } 70 }
70 validaDni(chofer); 71 validaDni(chofer);
71 }; 72 };
72 73
73 $scope.tipoDocumento = function (idTipoDocumento) { 74 $scope.tipoDocumento = function (idTipoDocumento) {
74 var value = ''; 75 var value = '';
75 switch (parseInt(idTipoDocumento)) { 76 switch (parseInt(idTipoDocumento)) {
76 case 96 : 77 case 96 :
77 value = 'DNI'; 78 value = 'DNI';
78 break; 79 break;
79 case 80 : 80 case 80 :
80 value = 'CUIT'; 81 value = 'CUIT';
81 break; 82 break;
82 case 86 : 83 case 86 :
83 value = 'CUIL'; 84 value = 'CUIL';
84 break; 85 break;
85 default: 86 default:
86 value = ''; 87 value = '';
87 break; 88 break;
88 } 89 }
89 return value; 90 return value;
90 }; 91 };
91 92
92 $scope.volver = function (chofer, key) { 93 $scope.volver = function (chofer, key) {
93 if (chofer.idTransportista === undefined) { 94 if (chofer.idTransportista === undefined) {
94 $scope.choferes.shift(); 95 $scope.choferes.shift();
95 $scope.crear = true; 96 $scope.crear = true;
96 chofer.editando = false; 97 chofer.editando = false;
97 return; 98 return;
98 } else if (chofer.id !== 0 || !$scope.crear) { 99 } else if (chofer.id !== 0 || !$scope.crear) {
99 $scope.choferes[key] = $scope.inicial; 100 $scope.choferes[key] = $scope.inicial;
100 $scope.choferes[key].editando = false; 101 $scope.choferes[key].editando = false;
101 } 102 }
102 $scope.crear = true; 103 $scope.crear = true;
103 }; 104 };
104 105
105 $scope.guardar = function() { 106 $scope.guardar = function() {
106 $scope.choferes.forEach( function (chofer) { 107 $scope.choferes.forEach( function (chofer) {
107 if (chofer.id === 0) { 108 if (chofer.id === 0) {
108 delete chofer.id; 109 delete chofer.id;
109 } 110 }
110 delete chofer.transportista; 111 delete chofer.transportista;
111 delete chofer.editando; 112 delete chofer.editando;
112 }); 113 });
113 focaAbmChoferService.guardarChoferes($scope.choferes); 114 focaAbmChoferService
115 .guardarChoferes($scope.choferes)
116 .then(salir)
117 .catch(e => {
118 console.error(e);
119 focaModalService.alert('Hubo un error al guardar');
120 });
114 }; 121 };
115 122
116 $scope.solicitarConfirmacion = function(chofer) { 123 $scope.solicitarConfirmacion = function(chofer) {
117 focaModalService.confirm('¿Está seguro que desea borrar el chofer ' + 124 focaModalService.confirm('¿Está seguro que desea borrar el chofer ' +
118 chofer.nombre + ' ?').then(function(confirmed) { 125 chofer.nombre + ' ?').then(function(confirmed) {
119 if (confirmed) { 126 if (confirmed) {
120 chofer.desactivado = true; 127 chofer.desactivado = true;
121 } 128 }
122 }); 129 });
123 }; 130 };
124 131
125 $scope.seleccionarTransportista = function() { 132 $scope.seleccionarTransportista = function() {
126 var parametrosModal = { 133 var parametrosModal = {
127 titulo: 'Búsqueda de Transportista', 134 titulo: 'Búsqueda de Transportista',
128 query: '/transportista', 135 query: '/transportista',
129 columnas: [ 136 columnas: [
130 { 137 {
131 nombre: 'Código', 138 nombre: 'Código',
132 propiedad: 'COD' 139 propiedad: 'COD'
133 }, 140 },
134 { 141 {
135 nombre: 'Nombre', 142 nombre: 'Nombre',
136 propiedad: 'NOM' 143 propiedad: 'NOM'
137 }, 144 },
138 { 145 {
139 nombre: 'CUIT', 146 nombre: 'CUIT',
140 propiedad: 'CUIT' 147 propiedad: 'CUIT'
141 } 148 }
142 ] 149 ]
143 }; 150 };
144 focaModalService.modal(parametrosModal).then( 151 focaModalService.modal(parametrosModal).then(
145 function(transportista) { 152 function(transportista) {
146 $scope.crear = true; 153 $scope.crear = true;
147 elegirTransportista(transportista); 154 elegirTransportista(transportista);
148 focaAbmChoferService.transportistaSeleccionado = transportista; 155 focaAbmChoferService.transportistaSeleccionado = transportista;
149 }, function() {} 156 }, function() {}
150 ); 157 );
151 }; 158 };
152 159
153 function elegirTransportista(transportista) { 160 function elegirTransportista(transportista) {
154 buscar(transportista.COD); 161 buscar(transportista.COD);
155 var codigo = ('00000' + transportista.COD).slice(-5); 162 var codigo = ('00000' + transportista.COD).slice(-5);
156 $scope.idTransportista = transportista.COD; 163 $scope.idTransportista = transportista.COD;
157 $timeout(function() { 164 $timeout(function() {
158 $scope.$broadcast('addCabecera', { 165 $scope.$broadcast('addCabecera', {
159 label: 'Transportista:', 166 label: 'Transportista:',
160 valor: codigo + ' - ' + transportista.NOM 167 valor: codigo + ' - ' + transportista.NOM
161 }); 168 });
162 }); 169 });
163 } 170 }
164 171
165 function buscar(id) { 172 function buscar(id) {
166 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) { 173 focaAbmChoferService.getChoferPorTransportista(id).then(function(res) {
167 $scope.choferes = res.data; 174 $scope.choferes = res.data;
168 }); 175 });
169 } 176 }
170 177
171 function salir() { 178 function salir() {
172 focaAbmChoferService.transportistaSeleccionado = {}; 179 focaAbmChoferService.transportistaSeleccionado = {};
173 $location.path('/'); 180 $location.path('/');
174 } 181 }
175 182
176 function validaDni(chofer) { 183 function validaDni(chofer) {
177 if (!chofer.dni) { 184 if (!chofer.dni) {
178 focaModalService.alert('Ingrese DNI'); 185 focaModalService.alert('Ingrese DNI');
179 return; 186 return;
180 } else if (!chofer.telefono) { 187 } else if (!chofer.telefono) {
181 focaModalService.alert('Ingrese teléfono'); 188 focaModalService.alert('Ingrese teléfono');
182 return; 189 return;
183 } 190 }
184 191
185 return new Promise(function(resolve, reject) { 192 return new Promise(function(resolve, reject) {
186 focaAbmChoferService 193 focaAbmChoferService
187 .getChoferPorDni(chofer.dni) 194 .getChoferPorDni(chofer.dni)
188 .then(function(res) { 195 .then(function(res) {
189 if (res.data.id && 196 if (res.data.id &&
190 chofer.id !== res.data.id) { 197 chofer.id !== res.data.id) {
191 reject(res.data); 198 reject(res.data);
192 } else { 199 } else {
193 resolve(); 200 resolve();
194 } 201 }
195 }) 202 })
196 .then(function() { 203 .then(function() {
197 chofer.idTransportista = focaAbmChoferService.transportistaSeleccionado.COD; 204 chofer.idTransportista = focaAbmChoferService
205 .transportistaSeleccionado.COD;
198 delete chofer.transportista; 206 delete chofer.transportista;
199 }, function() { 207 }, function() {
200 focaModalService.alert('Dni existente'); 208 focaModalService.alert('Dni existente');
201 $scope.editando = true; 209 $scope.editando = true;
202 }); 210 });
203 $scope.crear = true; 211 $scope.crear = true;
204 chofer.editando = false; 212 chofer.editando = false;
205 }); 213 });
206 } 214 }
207 215
208 if ($localStorage.chofer) { 216 if ($localStorage.chofer) {
209 var chofer = JSON.parse($localStorage.chofer); 217 var chofer = JSON.parse($localStorage.chofer);
210 if (!chofer.id) { chofer.id = 0; } 218 if (!chofer.id) { chofer.id = 0; }
211 $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista); 219 $location.path('/chofer/' + chofer.id + '/' + chofer.idTransportista);
212 } 220 }
213 } 221 }
214 ]); 222 ]);
215 223