Commit 3ab4d3a8a5b1d2f2dd7f1835464a1a71635f72d1
1 parent
8028dbc69a
Exists in
master
and in
1 other branch
tareas para concatenar archivos spec
Showing
3 changed files
with
19 additions
and
6 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-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'); | ||
13 | const footer = require('gulp-footer'); | ||
12 | 14 | ||
13 | var paths = { | 15 | var paths = { |
14 | srcJS: 'src/js/*.js', | 16 | srcJS: 'src/js/*.js', |
15 | srcViews: 'src/views/*.html', | 17 | srcViews: 'src/views/*.html', |
18 | specs: 'spec/*.js', | ||
16 | tmp: 'tmp', | 19 | tmp: 'tmp', |
17 | dist: 'dist/' | 20 | dist: 'dist/' |
18 | }; | 21 | }; |
19 | 22 | ||
20 | gulp.task('templates', function() { | 23 | gulp.task('templates', function() { |
21 | return pump( | 24 | return pump( |
22 | [ | 25 | [ |
23 | gulp.src(paths.srcViews), | 26 | gulp.src(paths.srcViews), |
24 | replace('views/', ''), | 27 | replace('views/', ''), |
25 | htmlmin(), | 28 | htmlmin(), |
26 | templateCache('views.js', { | 29 | templateCache('views.js', { |
27 | module: 'focaAbmVehiculo', | 30 | module: 'focaAbmVehiculo', |
28 | root: '' | 31 | root: '' |
29 | }), | 32 | }), |
30 | gulp.dest(paths.tmp) | 33 | gulp.dest(paths.tmp) |
31 | ] | 34 | ] |
32 | ); | 35 | ); |
33 | }); | 36 | }); |
34 | 37 | ||
35 | gulp.task('uglify', ['templates'], function() { | 38 | gulp.task('uglify', ['templates'], function() { |
36 | return pump( | 39 | return pump( |
37 | [ | 40 | [ |
38 | gulp.src([ | 41 | gulp.src([ |
39 | paths.srcJS, | 42 | paths.srcJS, |
40 | 'tmp/views.js' | 43 | 'tmp/views.js' |
41 | ]), | 44 | ]), |
42 | concat('foca-abm-vehiculo.js'), | 45 | concat('foca-abm-vehiculo.js'), |
43 | replace("['ngRoute', 'focaModal', 'ui.bootstrap', 'focaBotoneraLateral']", '[]'), | ||
44 | replace("src/views/", ''), | 46 | replace("src/views/", ''), |
47 | replace("'ngRoute'", ''), | ||
45 | gulp.dest(paths.tmp), | 48 | gulp.dest(paths.tmp), |
46 | rename('foca-abm-vehiculo.min.js'), | 49 | rename('foca-abm-vehiculo.min.js'), |
47 | uglify(), | 50 | uglify(), |
48 | gulp.dest(paths.dist) | 51 | gulp.dest(paths.dist) |
49 | ] | 52 | ] |
50 | ); | 53 | ); |
51 | }); | 54 | }); |
52 | 55 | ||
56 | gulp.task('uglify-spec', function() { | ||
57 | return pump([ | ||
58 | gulp.src(paths.specs), | ||
59 | concat('foca-abm-vehiculo.spec.js'), | ||
60 | header("describe('Módulo foca-abm-vehiculo', function() { \n"), | ||
61 | footer("});"), | ||
62 | gulp.dest(paths.dist) | ||
63 | ]); | ||
64 | }) | ||
65 | |||
53 | gulp.task('clean', function() { | 66 | gulp.task('clean', function() { |
54 | return gulp.src(['tmp', 'dist'], {read: false}) | 67 | return gulp.src(['tmp', 'dist'], {read: false}) |
55 | .pipe(clean()); | 68 | .pipe(clean()); |
56 | }); | 69 | }); |
57 | 70 | ||
58 | gulp.task('pre-commit', function() { | 71 | gulp.task('pre-commit', function() { |
59 | return pump( | 72 | return pump( |
60 | [ | 73 | [ |
61 | gulp.src(paths.srcJS), | 74 | gulp.src([paths.srcJS, paths.specs]), |
62 | jshint('.jshintrc'), | 75 | jshint('.jshintrc'), |
63 | jshint.reporter('default'), | 76 | jshint.reporter('default'), |
64 | jshint.reporter('fail') | 77 | jshint.reporter('fail') |
65 | ] | 78 | ] |
66 | ); | 79 | ); |
67 | }); | 80 | }); |
68 | 81 | ||
69 | gulp.task('clean-post-install', function() { | 82 | gulp.task('clean-post-install', function() { |
70 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | 83 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', |
71 | 'index.html'], {read: false}) | 84 | 'index.html'], {read: false}) |
72 | .pipe(clean()); | 85 | .pipe(clean()); |
73 | }); | 86 | }); |
74 | 87 | ||
75 | gulp.task('compile', ['templates', 'uglify']); | 88 | gulp.task('compile', ['templates', 'uglify']); |
76 | 89 | ||
77 | gulp.task('watch', function() { | 90 | gulp.task('watch', function() { |
78 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); | 91 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); |
79 | }); | 92 | }); |
80 | 93 | ||
81 | gulp.task('webserver', function() { | 94 | gulp.task('webserver', function() { |
82 | pump [ | 95 | pump [ |
83 | connect.server({port: 3000}) | 96 | connect.server({port: 3000}) |
84 | ] | 97 | ] |
85 | }); | 98 | }); |
86 | 99 | ||
87 | gulp.task('default', ['webserver']); | 100 | gulp.task('default', ['webserver']); |
src/js/app.js
1 | angular.module('focaAbmVehiculo', ['ngRoute', 'focaModal', 'ui.bootstrap', 'focaBotoneraLateral']); | 1 | angular.module('focaAbmVehiculo', ['ngRoute']); |
2 | 2 |
src/js/controller.js
1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') |
2 | .controller('focaAbmVehiculosController', [ | 2 | .controller('focaAbmVehiculosController', [ |
3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', | 3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', |
4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', | 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', |
5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, |
6 | $uibModal, focaBotoneraLateralService, $timeout) { | 6 | $uibModal, focaBotoneraLateralService, $timeout) { |
7 | 7 | ||
8 | $scope.now = new Date(); | 8 | $scope.now = new Date(); |
9 | $scope.botonera = [{ | 9 | $scope.botonera = [{ |
10 | label: 'Transportista', | 10 | label: 'Transportista', |
11 | image: 'cliente.png' | 11 | image: 'cliente.png' |
12 | }]; | 12 | }]; |
13 | 13 | ||
14 | focaAbmVehiculoService.cleanCisternas(); | 14 | focaAbmVehiculoService.cleanCisternas(); |
15 | 15 | ||
16 | //SETEO BOTONERA LATERAL | 16 | //SETEO BOTONERA LATERAL |
17 | focaBotoneraLateralService.showSalir(false); | 17 | focaBotoneraLateralService.showSalir(false); |
18 | focaBotoneraLateralService.showPausar(false); | 18 | focaBotoneraLateralService.showPausar(false); |
19 | focaBotoneraLateralService.showCancelar(false); | 19 | focaBotoneraLateralService.showCancelar(false); |
20 | focaBotoneraLateralService.showGuardar(false); | 20 | focaBotoneraLateralService.showGuardar(false); |
21 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 21 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
22 | 22 | ||
23 | if(focaAbmVehiculoService.transportistaSeleccionado.COD) { | 23 | if(focaAbmVehiculoService.transportistaSeleccionado.COD) { |
24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); |
25 | } | 25 | } |
26 | $scope.editar = function(id) { | 26 | $scope.editar = function(id) { |
27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); |
28 | }; | 28 | }; |
29 | $scope.solicitarConfirmacion = function(vehiculo) { | 29 | $scope.solicitarConfirmacion = function(vehiculo) { |
30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + |
31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( |
32 | function(data) { | 32 | function(data) { |
33 | if(data) { | 33 | if(data) { |
34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); |
35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
36 | } | 36 | } |
37 | } | 37 | } |
38 | ); | 38 | ); |
39 | }; | 39 | }; |
40 | $scope.seleccionarTransportista = function() { | 40 | $scope.seleccionarTransportista = function() { |
41 | var parametrosModal = { | 41 | var parametrosModal = { |
42 | titulo: 'Búsqueda de Transportista', | 42 | titulo: 'Búsqueda de Transportista', |
43 | query: '/transportista', | 43 | query: '/transportista', |
44 | columnas: [ | 44 | columnas: [ |
45 | { | 45 | { |
46 | nombre: 'Código', | 46 | nombre: 'Código', |
47 | propiedad: 'COD' | 47 | propiedad: 'COD' |
48 | }, | 48 | }, |
49 | { | 49 | { |
50 | nombre: 'Nombre', | 50 | nombre: 'Nombre', |
51 | propiedad: 'NOM' | 51 | propiedad: 'NOM' |
52 | }, | 52 | }, |
53 | { | 53 | { |
54 | nombre: 'CUIT', | 54 | nombre: 'CUIT', |
55 | propiedad: 'CUIT' | 55 | propiedad: 'CUIT' |
56 | } | 56 | } |
57 | ] | 57 | ] |
58 | }; | 58 | }; |
59 | focaModalService.modal(parametrosModal).then( | 59 | focaModalService.modal(parametrosModal).then( |
60 | function(transportista) { | 60 | function(transportista) { |
61 | elegirTransportista(transportista); | 61 | elegirTransportista(transportista); |
62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; |
63 | }, function() { | 63 | }, function() { |
64 | 64 | ||
65 | } | 65 | } |
66 | ); | 66 | ); |
67 | }; | 67 | }; |
68 | 68 | ||
69 | function elegirTransportista(transportista) { | 69 | function elegirTransportista(transportista) { |
70 | var codigo = ('00000' + transportista.COD).slice(-5); | 70 | var codigo = ('00000' + transportista.COD).slice(-5); |
71 | $scope.idTransportista = transportista.COD; | 71 | $scope.idTransportista = transportista.COD; |
72 | $scope.filtros = transportista.NOM.trim(); | 72 | $scope.filtros = transportista.NOM.trim(); |
73 | $timeout(function() { | 73 | $timeout(function() { |
74 | $scope.$broadcast('addCabecera', { | 74 | $scope.$broadcast('addCabecera', { |
75 | label: 'Transportista:', | 75 | label: 'Transportista:', |
76 | valor: codigo + ' - ' + transportista.NOM | 76 | valor: codigo + ' - ' + transportista.NOM |
77 | }); | 77 | }); |
78 | }); | 78 | }); |
79 | buscar(transportista.COD); | 79 | buscar(transportista.COD); |
80 | } | 80 | } |
81 | 81 | ||
82 | function buscar(idTransportista) { | 82 | function buscar(idTransportista) { |
83 | focaAbmVehiculoService | 83 | focaAbmVehiculoService |
84 | .getVehiculosPorTransportista(idTransportista) | 84 | .getVehiculosPorTransportista(idTransportista) |
85 | .then(function(datos) { | 85 | .then(function(datos) { |
86 | $scope.vehiculos = datos.data; | 86 | $scope.vehiculos = datos.data; |
87 | }); | 87 | }); |
88 | } | 88 | } |
89 | function salir() { | 89 | function salir() { |
90 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 90 | focaAbmVehiculoService.transportistaSeleccionado = {}; |
91 | $location.path('/'); | 91 | $location.path('/'); |
92 | } | 92 | } |
93 | } | 93 | } |
94 | ]) | 94 | ]) |
95 | .controller('focaAbmVehiculoController', [ | 95 | .controller('focaAbmVehiculoController', [ |
96 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 96 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
97 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', | 97 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', |
98 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 98 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
99 | focaModalService, $timeout, focaBotoneraLateralService, $window) { | 99 | focaModalService, $timeout, focaBotoneraLateralService, $window) { |
100 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 100 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
101 | $scope.now = new Date(); | 101 | $scope.now = new Date(); |
102 | $scope.focused = 1; | 102 | $scope.focused = 1; |
103 | $scope.transportistaStamp = ''; | 103 | $scope.transportistaStamp = ''; |
104 | $scope.cisternas = []; | 104 | $scope.cisternas = []; |
105 | 105 | ||
106 | $timeout(function() { | 106 | $timeout(function() { |
107 | focaBotoneraLateralService.showSalir(false); | 107 | focaBotoneraLateralService.showSalir(false); |
108 | focaBotoneraLateralService.showPausar(false); | 108 | focaBotoneraLateralService.showPausar(false); |
109 | focaBotoneraLateralService.showCancelar(false); | 109 | focaBotoneraLateralService.showCancelar(false); |
110 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 110 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
111 | focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); | 111 | focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); |
112 | }); | 112 | }); |
113 | 113 | ||
114 | if($scope.nuevo) { | 114 | if($scope.nuevo) { |
115 | focaAbmVehiculoService | 115 | focaAbmVehiculoService |
116 | .getTransportistaPorId($routeParams.idTransportista) | 116 | .getTransportistaPorId($routeParams.idTransportista) |
117 | .then(function(res) { | 117 | .then(function(res) { |
118 | var codigo = ('00000' + res.data.COD).slice(-5); | 118 | var codigo = ('00000' + res.data.COD).slice(-5); |
119 | $scope.vehiculo.idTransportista = res.data.COD; | 119 | $scope.vehiculo.idTransportista = res.data.COD; |
120 | $scope.vehiculo.transportista = res.data; | 120 | $scope.vehiculo.transportista = res.data; |
121 | $scope.$broadcast('addCabecera', { | 121 | $scope.$broadcast('addCabecera', { |
122 | label: 'Transportista:', | 122 | label: 'Transportista:', |
123 | valor: codigo + ' - ' + res.data.NOM | 123 | valor: codigo + ' - ' + res.data.NOM |
124 | }); | 124 | }); |
125 | }); | 125 | }); |
126 | } | 126 | } |
127 | $scope.vehiculo = {}; | 127 | $scope.vehiculo = {}; |
128 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 128 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
129 | if(res.data) { | 129 | if(res.data) { |
130 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 130 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); |
131 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 131 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; |
132 | 132 | ||
133 | $scope.vehiculo = res.data; | 133 | $scope.vehiculo = res.data; |
134 | $scope.$broadcast('addCabecera', { | 134 | $scope.$broadcast('addCabecera', { |
135 | label: 'Transportista:', | 135 | label: 'Transportista:', |
136 | valor: $scope.transportistaStamp | 136 | valor: $scope.transportistaStamp |
137 | }); | 137 | }); |
138 | $scope.$broadcast('addCabecera', { | 138 | $scope.$broadcast('addCabecera', { |
139 | label: 'Unidad:', | 139 | label: 'Unidad:', |
140 | valor: res.data.codigo | 140 | valor: res.data.codigo |
141 | }); | 141 | }); |
142 | focaAbmVehiculoService | 142 | focaAbmVehiculoService |
143 | .getCisternas($routeParams.idVehiculo) | 143 | .getCisternas($routeParams.idVehiculo) |
144 | .then(function(res) { | 144 | .then(function(res) { |
145 | $scope.cisternas = res; | 145 | $scope.cisternas = res; |
146 | $scope.$apply(); | 146 | $scope.$apply(); |
147 | }); | 147 | }); |
148 | } | 148 | } |
149 | }); | 149 | }); |
150 | 150 | ||
151 | $scope.next = function(key) { | 151 | $scope.next = function(key) { |
152 | if (key === 13) $scope.focused++; | 152 | if (key === 13) $scope.focused++; |
153 | }; | 153 | }; |
154 | $scope.cancelar = function() { | 154 | $scope.cancelar = function() { |
155 | $location.path('/vehiculo'); | 155 | $location.path('/vehiculo'); |
156 | }; | 156 | }; |
157 | $scope.editar = function(key) { | 157 | $scope.editar = function(key) { |
158 | if(key) { | 158 | if(key) { |
159 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 159 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
160 | '/cisterna/' + key); | 160 | '/cisterna/' + key); |
161 | }else { | 161 | } else { |
162 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 162 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); |
163 | } | 163 | } |
164 | }; | 164 | }; |
165 | $scope.guardar = function(key) { | 165 | $scope.guardar = function(key) { |
166 | key = (typeof key === 'undefined') ? 13 : key; | 166 | key = (typeof key === 'undefined') ? 13 : key; |
167 | if(key === 13) { | 167 | if(key === 13) { |
168 | //Valida si existe numero de unidad | 168 | //Valida si existe numero de unidad |
169 | if(!validaTotalCargas() && !$scope.nuevo) { | 169 | if(!validaTotalCargas() && !$scope.nuevo) { |
170 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 170 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
171 | ' debe ser igual a la capacidad total del vehículo'); | 171 | ' debe ser igual a la capacidad total del vehículo'); |
172 | return; | 172 | return; |
173 | } | 173 | } |
174 | validaCodigoUnidad().then(function() { | 174 | validaCodigoUnidad().then(function() { |
175 | delete $scope.vehiculo.transportista; | 175 | delete $scope.vehiculo.transportista; |
176 | delete $scope.vehiculo.cisternas; | 176 | delete $scope.vehiculo.cisternas; |
177 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 177 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) |
178 | .then(function(res) { | 178 | .then(function(res) { |
179 | if($scope.nuevo) { | 179 | if($scope.nuevo) { |
180 | $location.path('/vehiculo/' + res.data.id + | 180 | $location.path('/vehiculo/' + res.data.id + |
181 | '/' + res.data.idTransportista); | 181 | '/' + res.data.idTransportista); |
182 | }else { | 182 | }else { |
183 | guardarCisternas().then(function() { | 183 | guardarCisternas().then(function() { |
184 | $window.location.assign('/#!/vehiculo'); | 184 | $window.location.assign('/#!/vehiculo'); |
185 | }); | 185 | }); |
186 | } | 186 | } |
187 | }); | 187 | }); |
188 | }, function() { | 188 | }, function() { |
189 | focaModalService.alert('Código de unidad existente'); | 189 | focaModalService.alert('Código de unidad existente'); |
190 | }); | 190 | }); |
191 | } | 191 | } |
192 | 192 | ||
193 | }; | 193 | }; |
194 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 194 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { |
195 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 195 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + |
196 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 196 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( |
197 | function(data) { | 197 | function(data) { |
198 | if(data) { | 198 | if(data) { |
199 | focaAbmVehiculoService.deleteCisterna(idx); | 199 | focaAbmVehiculoService.deleteCisterna(idx); |
200 | focaAbmVehiculoService | 200 | focaAbmVehiculoService |
201 | .getCisternas($routeParams.idVehiculo) | 201 | .getCisternas($routeParams.idVehiculo) |
202 | .then(function(res) { | 202 | .then(function(res) { |
203 | $scope.cisternas = res; | 203 | $scope.cisternas = res; |
204 | }); | 204 | }); |
205 | } | 205 | } |
206 | } | 206 | } |
207 | ); | 207 | ); |
208 | }; | 208 | }; |
209 | 209 | ||
210 | function validaCodigoUnidad() { | 210 | function validaCodigoUnidad() { |
211 | return new Promise(function(resolve, reject) { | 211 | return new Promise(function(resolve, reject) { |
212 | focaAbmVehiculoService | 212 | focaAbmVehiculoService |
213 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 213 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) |
214 | .then(function(res) { | 214 | .then(function(res) { |
215 | //Valida si existe numero de unidad | 215 | //Valida si existe numero de unidad |
216 | var existe = res.data.filter(function(vehiculo) { | 216 | var existe = res.data.filter(function(vehiculo) { |
217 | return vehiculo.codigo === $scope.vehiculo.codigo && | 217 | return vehiculo.codigo === $scope.vehiculo.codigo && |
218 | vehiculo.id !== $scope.vehiculo.id; | 218 | vehiculo.id !== $scope.vehiculo.id; |
219 | }); | 219 | }); |
220 | 220 | ||
221 | if(existe.length) { | 221 | if(existe.length) { |
222 | reject(existe); | 222 | reject(existe); |
223 | }else { | 223 | }else { |
224 | resolve(); | 224 | resolve(); |
225 | } | 225 | } |
226 | }); | 226 | }); |
227 | }); | 227 | }); |
228 | } | 228 | } |
229 | 229 | ||
230 | function validaTotalCargas() { | 230 | function validaTotalCargas() { |
231 | var total = 0; | 231 | var total = 0; |
232 | $scope.cisternas.forEach(function(cisterna) { | 232 | $scope.cisternas.forEach(function(cisterna) { |
233 | if(!cisterna.desactivado) { | 233 | if(!cisterna.desactivado) { |
234 | total += parseInt(cisterna.capacidad); | 234 | total += parseInt(cisterna.capacidad); |
235 | } | 235 | } |
236 | }); | 236 | }); |
237 | return $scope.vehiculo.capacidad === total; | 237 | return $scope.vehiculo.capacidad === total; |
238 | } | 238 | } |
239 | 239 | ||
240 | function guardarCisternas() { | 240 | function guardarCisternas() { |
241 | var cisternas = $scope.cisternas.map(function(cisterna) { | 241 | var cisternas = $scope.cisternas.map(function(cisterna) { |
242 | return { | 242 | return { |
243 | id: cisterna.id, | 243 | id: cisterna.id, |
244 | capacidad: parseFloat(cisterna.capacidad), | 244 | capacidad: parseFloat(cisterna.capacidad), |
245 | codigo: cisterna.codigo, | 245 | codigo: cisterna.codigo, |
246 | idUnidadMedida: cisterna.idUnidadMedida, | 246 | idUnidadMedida: cisterna.idUnidadMedida, |
247 | idVehiculo: $routeParams.idVehiculo, | 247 | idVehiculo: $routeParams.idVehiculo, |
248 | desactivado: cisterna.desactivado | 248 | desactivado: cisterna.desactivado |
249 | }; | 249 | }; |
250 | }); | 250 | }); |
251 | 251 | ||
252 | return focaAbmVehiculoService.guardarCisternas(cisternas); | 252 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
253 | } | 253 | } |
254 | } | 254 | } |
255 | ]); | 255 | ]); |
256 | 256 |