Commit 98d3e2b2fdd469366860dc38e3452941d0f43c47
Merge branch 'develop' into 'master'
Develop See merge request !48
Showing
8 changed files
Show diff stats
package.json
... | ... | @@ -35,14 +35,14 @@ |
35 | 35 | "pump": "^3.0.x" |
36 | 36 | }, |
37 | 37 | "devDependencies": { |
38 | - "angular": "^1.7.5", | |
38 | + "angular": "^1.7.8", | |
39 | 39 | "angular-mocks": "^1.7.8", |
40 | - "angular-route": "^1.7.7", | |
40 | + "angular-route": "^1.7.8", | |
41 | 41 | "bootstrap": "^4.1.3", |
42 | 42 | "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", |
43 | 43 | "font-awesome": "^4.7.0", |
44 | 44 | "gulp": "^3.9.1", |
45 | - "gulp-angular-templatecache": "^2.2.5", | |
45 | + "gulp-angular-templatecache": "^2.2.7", | |
46 | 46 | "gulp-clean": "^0.4.0", |
47 | 47 | "gulp-connect": "^5.6.1", |
48 | 48 | "gulp-footer": "^2.0.2", |
... | ... | @@ -53,10 +53,10 @@ |
53 | 53 | "gulp-replace": "^1.0.0", |
54 | 54 | "gulp-uglify": "^3.0.1", |
55 | 55 | "gulp-uglify-es": "^1.0.4", |
56 | - "jasmine": "^3.3.1", | |
57 | - "jasmine-core": "^3.3.0", | |
58 | - "jquery": "^3.3.1", | |
59 | - "jshint": "^2.9.6", | |
56 | + "jasmine": "^3.4.0", | |
57 | + "jasmine-core": "^3.4.0", | |
58 | + "jquery": "^3.4.1", | |
59 | + "jshint": "^2.10.2", | |
60 | 60 | "pre-commit": "^1.2.2", |
61 | 61 | "pump": "^3.0.0", |
62 | 62 | "ui-bootstrap4": "^3.0.5" |
spec/controllerSpec.js
... | ... | @@ -325,6 +325,11 @@ describe('Controladores abm vehículo', function() { |
325 | 325 | $watch: function() {} |
326 | 326 | }, |
327 | 327 | focaAbmVehiculoService: { |
328 | + getCisternas: function() { | |
329 | + return { | |
330 | + then: function() { return; } | |
331 | + }; | |
332 | + }, | |
328 | 333 | getVehiculo: function() { |
329 | 334 | return { |
330 | 335 | then: function() { return; } |
... | ... | @@ -359,6 +364,12 @@ describe('Controladores abm vehículo', function() { |
359 | 364 | $watch: function() {} |
360 | 365 | }; |
361 | 366 | var focaAbmVehiculoService = { |
367 | + | |
368 | + getCisternas: function() { | |
369 | + return { | |
370 | + then: function() { return; } | |
371 | + }; | |
372 | + }, | |
362 | 373 | getVehiculo: function() { |
363 | 374 | return { |
364 | 375 | then: function() { return; } |
... | ... | @@ -403,6 +414,13 @@ describe('Controladores abm vehículo', function() { |
403 | 414 | $watch: function() {} |
404 | 415 | }; |
405 | 416 | var focaAbmVehiculoService = { |
417 | + | |
418 | + getCisternas: function() { | |
419 | + return { | |
420 | + then: function() { return; } | |
421 | + }; | |
422 | + }, | |
423 | + | |
406 | 424 | getVehiculo: function() { |
407 | 425 | return { |
408 | 426 | then: function() { return; } |
... | ... | @@ -452,6 +470,11 @@ describe('Controladores abm vehículo', function() { |
452 | 470 | var controller = $controller('focaAbmVehiculoController', { |
453 | 471 | $scope: scope, |
454 | 472 | focaAbmVehiculoService: { |
473 | + getCisternas: function() { | |
474 | + return { | |
475 | + then: function() { return; } | |
476 | + }; | |
477 | + }, | |
455 | 478 | getVehiculo: function() { |
456 | 479 | return { |
457 | 480 | then: function() { return; } |
... | ... | @@ -493,6 +516,11 @@ describe('Controladores abm vehículo', function() { |
493 | 516 | var controller = $controller('focaAbmVehiculoController', { |
494 | 517 | $scope: scope, |
495 | 518 | focaAbmVehiculoService: { |
519 | + getCisternas: function() { | |
520 | + return { | |
521 | + then: function() { return; } | |
522 | + }; | |
523 | + }, | |
496 | 524 | getVehiculo: function() { |
497 | 525 | return { |
498 | 526 | then: function() { return; } |
... | ... | @@ -536,6 +564,11 @@ describe('Controladores abm vehículo', function() { |
536 | 564 | var controller = $controller('focaAbmVehiculoController', { |
537 | 565 | $scope: scope, |
538 | 566 | focaAbmVehiculoService: { |
567 | + getCisternas: function() { | |
568 | + return { | |
569 | + then: function() { return; } | |
570 | + }; | |
571 | + }, | |
539 | 572 | getVehiculo: function() { |
540 | 573 | return { |
541 | 574 | then: function() { return; } |
... | ... | @@ -581,6 +614,11 @@ describe('Controladores abm vehículo', function() { |
581 | 614 | var controller = $controller('focaAbmVehiculoController', { |
582 | 615 | $scope: scope, |
583 | 616 | focaAbmVehiculoService: { |
617 | + getCisternas: function() { | |
618 | + return { | |
619 | + then: function() { return; } | |
620 | + }; | |
621 | + }, | |
584 | 622 | getVehiculo: function() { |
585 | 623 | return { |
586 | 624 | then: function() { return; } |
... | ... | @@ -602,7 +640,7 @@ describe('Controladores abm vehículo', function() { |
602 | 640 | addCustomButton: function() { return; } |
603 | 641 | }, |
604 | 642 | $localStorage: {}, |
605 | - $window: {} | |
643 | + $window: {}, | |
606 | 644 | }); |
607 | 645 | |
608 | 646 | //act |
... | ... | @@ -628,7 +666,11 @@ describe('Controladores abm vehículo', function() { |
628 | 666 | then: function() { return; } |
629 | 667 | }; |
630 | 668 | }, |
631 | - getCisternas: function() { return; }, | |
669 | + getCisternas: function() { | |
670 | + return { | |
671 | + then: function() { return; } | |
672 | + }; | |
673 | + }, | |
632 | 674 | deleteCisterna: function() { return; } |
633 | 675 | }; |
634 | 676 | var controller = $controller('focaAbmVehiculoController', { |
src/js/controller.js
... | ... | @@ -2,10 +2,11 @@ angular.module('focaAbmVehiculo') |
2 | 2 | .controller('focaAbmVehiculosController', [ |
3 | 3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', |
4 | 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', |
5 | - function($scope, focaAbmVehiculoService, $location, focaModalService, | |
5 | + function ($scope, focaAbmVehiculoService, $location, focaModalService, | |
6 | 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { |
7 | 7 | |
8 | 8 | $scope.now = new Date(); |
9 | + $scope.tipo = ''; | |
9 | 10 | $scope.botonera = [{ |
10 | 11 | label: 'Transportista', |
11 | 12 | image: 'cliente.png' |
... | ... | @@ -23,13 +24,14 @@ angular.module('focaAbmVehiculo') |
23 | 24 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { |
24 | 25 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); |
25 | 26 | } |
26 | - $scope.editar = function(id) { | |
27 | + $scope.editar = function (id) { | |
27 | 28 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); |
28 | 29 | }; |
29 | - $scope.solicitarConfirmacion = function(vehiculo) { | |
30 | + | |
31 | + $scope.solicitarConfirmacion = function (vehiculo) { | |
30 | 32 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + |
31 | 33 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( |
32 | - function(data) { | |
34 | + function (data) { | |
33 | 35 | if (data) { |
34 | 36 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); |
35 | 37 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
... | ... | @@ -37,7 +39,7 @@ angular.module('focaAbmVehiculo') |
37 | 39 | } |
38 | 40 | ); |
39 | 41 | }; |
40 | - $scope.seleccionarTransportista = function() { | |
42 | + $scope.seleccionarTransportista = function () { | |
41 | 43 | var parametrosModal = { |
42 | 44 | titulo: 'Búsqueda de Transportista', |
43 | 45 | query: '/transportista', |
... | ... | @@ -57,10 +59,10 @@ angular.module('focaAbmVehiculo') |
57 | 59 | ] |
58 | 60 | }; |
59 | 61 | focaModalService.modal(parametrosModal).then( |
60 | - function(transportista) { | |
62 | + function (transportista) { | |
61 | 63 | elegirTransportista(transportista); |
62 | 64 | focaAbmVehiculoService.transportistaSeleccionado = transportista; |
63 | - }, function() { | |
65 | + }, function () { | |
64 | 66 | |
65 | 67 | } |
66 | 68 | ); |
... | ... | @@ -69,7 +71,7 @@ angular.module('focaAbmVehiculo') |
69 | 71 | var codigo = ('00000' + transportista.COD).slice(-5); |
70 | 72 | $scope.idTransportista = transportista.COD; |
71 | 73 | $scope.filtros = transportista.NOM.trim(); |
72 | - $timeout(function() { | |
74 | + $timeout(function () { | |
73 | 75 | $scope.$broadcast('addCabecera', { |
74 | 76 | label: 'Transportista:', |
75 | 77 | valor: codigo + ' - ' + transportista.NOM |
... | ... | @@ -81,7 +83,7 @@ angular.module('focaAbmVehiculo') |
81 | 83 | function buscar(idTransportista) { |
82 | 84 | focaAbmVehiculoService |
83 | 85 | .getVehiculosPorTransportista(idTransportista) |
84 | - .then(function(datos) { | |
86 | + .then(function (datos) { | |
85 | 87 | $scope.vehiculos = datos.data; |
86 | 88 | }); |
87 | 89 | } |
... | ... | @@ -94,70 +96,84 @@ angular.module('focaAbmVehiculo') |
94 | 96 | .controller('focaAbmVehiculoController', [ |
95 | 97 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
96 | 98 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', |
97 | - function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | |
98 | - focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | |
99 | + function ($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | |
100 | + focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | |
99 | 101 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
102 | + $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; | |
100 | 103 | $scope.now = new Date(); |
101 | 104 | $scope.focused = 1; |
105 | + $scope.tipo = ''; | |
106 | + $scope.creando = false; | |
107 | + $scope.crear = false; | |
102 | 108 | $scope.transportistaStamp = ''; |
103 | 109 | $scope.cisternas = []; |
104 | 110 | |
105 | - $timeout(function() { | |
111 | + $timeout(function () { | |
106 | 112 | focaBotoneraLateralService.showSalir(false); |
107 | 113 | focaBotoneraLateralService.showPausar(true); |
108 | 114 | focaBotoneraLateralService.showCancelar(false); |
109 | 115 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
110 | 116 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); |
111 | 117 | }); |
112 | - | |
113 | - $timeout(function() {getLSVehiculo();}); | |
114 | 118 | |
115 | 119 | if ($scope.nuevo) { |
120 | + $scope.tipo = 'Crear Vehiculo'; | |
116 | 121 | focaAbmVehiculoService |
117 | 122 | .getTransportistaPorId($routeParams.idTransportista) |
118 | - .then(function(res) { | |
119 | - var codigo = ('00000' + res.data.COD).slice(-5); | |
120 | - $scope.vehiculo.idTransportista = res.data.COD; | |
123 | + .then(function (res) { | |
124 | + var codigo = ('00000' + res.data[0].COD).slice(-5); | |
125 | + $scope.vehiculo.idTransportista = res.data[0].COD; | |
121 | 126 | $scope.vehiculo.transportista = res.data; |
122 | 127 | $scope.$broadcast('addCabecera', { |
123 | 128 | label: 'Transportista:', |
124 | - valor: codigo + ' - ' + res.data.NOM | |
129 | + valor: codigo + ' - ' + res.data[0].ALI | |
130 | + }); | |
131 | + $scope.$broadcast('addCabecera', { | |
132 | + label: 'Unidad:', | |
133 | + valor: 'NUEVO' | |
125 | 134 | }); |
126 | 135 | }); |
136 | + } else { | |
137 | + $scope.tipo = 'Editar Vehiculo'; | |
127 | 138 | } |
128 | 139 | $scope.vehiculo = {}; |
129 | - focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | |
140 | + | |
141 | + focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function (res) { | |
130 | 142 | if (res.data) { |
131 | - $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | |
132 | - $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | |
143 | + var vehiculoSeteado = getLSVehiculo(); | |
144 | + if (vehiculoSeteado === false) { | |
145 | + $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | |
146 | + $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | |
147 | + | |
148 | + $scope.vehiculo = res.data; | |
149 | + $scope.$broadcast('addCabecera', { | |
150 | + label: 'Transportista:', | |
151 | + valor: $scope.transportistaStamp | |
152 | + }); | |
153 | + $scope.$broadcast('addCabecera', { | |
154 | + label: 'Unidad:', | |
155 | + valor: res.data.codigo | |
156 | + }); | |
157 | + } | |
133 | 158 | |
134 | - $scope.vehiculo = res.data; | |
135 | - $scope.$broadcast('addCabecera', { | |
136 | - label: 'Transportista:', | |
137 | - valor: $scope.transportistaStamp | |
138 | - }); | |
139 | - $scope.$broadcast('addCabecera', { | |
140 | - label: 'Unidad:', | |
141 | - valor: res.data.codigo | |
142 | - }); | |
143 | 159 | focaAbmVehiculoService |
144 | 160 | .getCisternas($routeParams.idVehiculo) |
145 | - .then(function(res) { | |
161 | + .then(function (res) { | |
146 | 162 | $scope.cisternas = res; |
147 | 163 | $scope.$apply(); |
148 | 164 | }); |
149 | 165 | } |
150 | 166 | }); |
151 | 167 | |
152 | - $scope.next = function(key) { | |
168 | + $scope.next = function (key) { | |
153 | 169 | if (key === 13) $scope.focused++; |
154 | 170 | }; |
155 | 171 | |
156 | - $scope.salir = function() { | |
172 | + $scope.salir = function () { | |
157 | 173 | if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { |
158 | 174 | focaModalService.confirm( |
159 | 175 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
160 | - ).then(function(data) { | |
176 | + ).then(function (data) { | |
161 | 177 | if (data) { |
162 | 178 | $location.path('/vehiculo'); |
163 | 179 | } |
... | ... | @@ -165,19 +181,59 @@ angular.module('focaAbmVehiculo') |
165 | 181 | } else { |
166 | 182 | $location.path('/vehiculo'); |
167 | 183 | } |
168 | - } | |
184 | + }; | |
169 | 185 | |
170 | - $scope.editar = function(key) { | |
171 | - if (key) { | |
172 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + | |
173 | - '/cisterna/' + key); | |
174 | - } else { | |
175 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | |
186 | + $scope.editar = function (cisterna) { | |
187 | + $scope.cisternas.forEach(function (cisterna) { | |
188 | + cisterna.editando = false; | |
189 | + $scope.crear = true; | |
190 | + }); | |
191 | + cisterna.editando = true; | |
192 | + $scope.inicial = angular.copy(cisterna); | |
193 | + }; | |
194 | + | |
195 | + $scope.volver = function (cisterna, key) { | |
196 | + if (cisterna.id === undefined || !$scope.crear) { | |
197 | + $scope.cisternas.shift(cisterna); | |
198 | + $scope.crear = false; | |
199 | + return; | |
176 | 200 | } |
201 | + if (cisterna.id !== undefined) { | |
202 | + $scope.cisternas[key] = $scope.inicial; | |
203 | + $scope.cisternas[key].editando = false; | |
204 | + } | |
205 | + $scope.crear = false; | |
206 | + }; | |
207 | + | |
208 | + $scope.crearCisterna = function () { | |
209 | + var cisterna = { | |
210 | + codigo: '', | |
211 | + capacidad: '', | |
212 | + idUnidadMedida: 0, | |
213 | + unidadMedida: {}, | |
214 | + editando: true, | |
215 | + }; | |
216 | + $scope.cisternas.unshift(cisterna); | |
217 | + $scope.crear = true; | |
218 | + }; | |
219 | + | |
220 | + $scope.seleccionarUnidadMedida = function (cisterna) { | |
221 | + var modalInstance = $uibModal.open( | |
222 | + { | |
223 | + ariaLabelledBy: 'Busqueda de Unidades de medida', | |
224 | + templateUrl: 'modal-unidad-medida.html', | |
225 | + controller: 'focaModalUnidadMedidaCtrl', | |
226 | + size: 'lg' | |
227 | + } | |
228 | + ); | |
229 | + modalInstance.result.then(function (unidaMedida) { | |
230 | + cisterna.idUnidadMedida = unidaMedida.ID; | |
231 | + cisterna.unidadMedida = unidaMedida; | |
232 | + }); | |
177 | 233 | }; |
178 | - $scope.guardar = function(key) { | |
179 | 234 | |
180 | - key = (typeof key === 'undefined') ? 13 : key; | |
235 | + $scope.guardar = function (key) { | |
236 | + key = (typeof key === 'undefined') ? 13 : key; | |
181 | 237 | |
182 | 238 | if (key === 13) { |
183 | 239 | |
... | ... | @@ -185,6 +241,9 @@ angular.module('focaAbmVehiculo') |
185 | 241 | $scope.salir(); |
186 | 242 | return; |
187 | 243 | } |
244 | + $scope.cisternas.forEach(function (cisterna) { | |
245 | + if (cisterna.id === 0) cisterna.id = undefined; | |
246 | + }); | |
188 | 247 | |
189 | 248 | if (!$scope.vehiculo.codigo) { |
190 | 249 | focaModalService.alert('Ingrese unidad'); |
... | ... | @@ -205,30 +264,33 @@ angular.module('focaAbmVehiculo') |
205 | 264 | ' debe ser igual a la capacidad total del vehículo'); |
206 | 265 | return; |
207 | 266 | } |
208 | - validaCodigoUnidad().then(function() { | |
209 | - delete $scope.vehiculo.transportista; | |
210 | - delete $scope.vehiculo.cisternas; | |
211 | - focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | |
212 | - .then(function(res) { | |
213 | - if ($scope.nuevo) { | |
214 | - $location.path('/vehiculo/' + res.data.id + | |
215 | - '/' + res.data.idTransportista); | |
216 | - } else { | |
217 | - guardarCisternas().then(function() { | |
218 | - $location.path('/vehiculo'); | |
267 | + | |
268 | + if ($scope.nuevo) { | |
269 | + validaCodigoUnidad().then(function () { | |
270 | + delete $scope.vehiculo.transportista; | |
271 | + focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | |
272 | + .then(function (res) { | |
273 | + $routeParams.idVehiculo = res.data.id; | |
274 | + guardarCisternas($scope.cisternas).then(function () { | |
275 | + angular.element('#guardar').addClass('guardado'); | |
276 | + $timeout(function () {$location.path('/vehiculo');},300); | |
219 | 277 | }); |
220 | - } | |
221 | - }); | |
222 | - }, function() { | |
223 | - focaModalService.alert('Código de unidad existente'); | |
224 | - }); | |
278 | + }); | |
279 | + }, function () { | |
280 | + focaModalService.alert('Código de unidad existente'); | |
281 | + }); | |
282 | + } else { | |
283 | + guardarCisternas($scope.cisternas).then(function () { | |
284 | + angular.element('#guardar').addClass('guardado'); | |
285 | + $timeout(function () {$location.path('/vehiculo');},500); | |
286 | + }); | |
287 | + } | |
225 | 288 | } |
226 | - | |
227 | 289 | }; |
228 | - | |
229 | - $scope.$watch('vehiculo', function(newValue) { | |
290 | + //Agregar propiedades de cisterna | |
291 | + $scope.$watch('vehiculo', function (newValue) { | |
230 | 292 | focaBotoneraLateralService.setPausarData({ |
231 | - label:'vehiculo', | |
293 | + label: 'vehiculo', | |
232 | 294 | val: { |
233 | 295 | codigo: newValue.codigo, |
234 | 296 | tractor: newValue.tractor, |
... | ... | @@ -241,11 +303,13 @@ angular.module('focaAbmVehiculo') |
241 | 303 | }, true); |
242 | 304 | |
243 | 305 | function getLSVehiculo() { |
244 | - var vehiculo = JSON.parse($localStorage.vehiculo|| null); | |
306 | + var vehiculo = JSON.parse($localStorage.vehiculo || null); | |
245 | 307 | if (vehiculo) { |
246 | 308 | setearVehiculo(vehiculo); |
247 | 309 | delete $localStorage.vehiculo; |
310 | + return true; | |
248 | 311 | } |
312 | + return false; | |
249 | 313 | } |
250 | 314 | |
251 | 315 | function setearVehiculo(vehiculo) { |
... | ... | @@ -256,29 +320,23 @@ angular.module('focaAbmVehiculo') |
256 | 320 | }); |
257 | 321 | } |
258 | 322 | |
259 | - $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | |
260 | - focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | |
261 | - cisterna.id + ' ' + cisterna.codigo + ' ?').then( | |
262 | - function(data) { | |
263 | - if (data) { | |
264 | - focaAbmVehiculoService.deleteCisterna(idx); | |
265 | - focaAbmVehiculoService | |
266 | - .getCisternas($routeParams.idVehiculo) | |
267 | - .then(function(res) { | |
268 | - $scope.cisternas = res; | |
269 | - }); | |
270 | - } | |
323 | + $scope.solicitarConfirmacionTabla = function (cisterna) { | |
324 | + focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?') | |
325 | + .then(function (data) { | |
326 | + if (data) { | |
327 | + cisterna.desactivado = true; | |
271 | 328 | } |
272 | - ); | |
329 | + }); | |
330 | + return; | |
273 | 331 | }; |
274 | 332 | |
275 | 333 | function validaCodigoUnidad() { |
276 | - return new Promise(function(resolve, reject) { | |
334 | + return new Promise(function (resolve, reject) { | |
277 | 335 | focaAbmVehiculoService |
278 | 336 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) |
279 | - .then(function(res) { | |
337 | + .then(function (res) { | |
280 | 338 | //Valida si existe numero de unidad |
281 | - var existe = res.data.filter(function(vehiculo) { | |
339 | + var existe = res.data.filter(function (vehiculo) { | |
282 | 340 | return vehiculo.codigo === $scope.vehiculo.codigo && |
283 | 341 | vehiculo.id !== $scope.vehiculo.id; |
284 | 342 | }); |
... | ... | @@ -294,16 +352,16 @@ angular.module('focaAbmVehiculo') |
294 | 352 | |
295 | 353 | function validaTotalCargas() { |
296 | 354 | var total = 0; |
297 | - $scope.cisternas.forEach(function(cisterna) { | |
355 | + $scope.cisternas.forEach(function (cisterna) { | |
298 | 356 | if (!cisterna.desactivado) { |
299 | 357 | total += parseInt(cisterna.capacidad); |
300 | 358 | } |
301 | 359 | }); |
302 | - return $scope.vehiculo.capacidad == total; | |
360 | + return $scope.vehiculo.capacidad >= total; | |
303 | 361 | } |
304 | - | |
305 | 362 | function guardarCisternas() { |
306 | - var cisternas = $scope.cisternas.map(function(cisterna) { | |
363 | + | |
364 | + var cisternas = $scope.cisternas.map(function (cisterna) { | |
307 | 365 | return { |
308 | 366 | id: cisterna.id, |
309 | 367 | capacidad: parseFloat(cisterna.capacidad), |
... | ... | @@ -317,5 +375,63 @@ angular.module('focaAbmVehiculo') |
317 | 375 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
318 | 376 | } |
319 | 377 | |
378 | + $scope.agregarCisterna = function (cisterna) { | |
379 | + if (!cisterna) { | |
380 | + focaModalService.alert('Ingrese valores'); | |
381 | + return; | |
382 | + } else if (!cisterna.codigo) { | |
383 | + focaModalService.alert('Ingrese codigo de cisterna'); | |
384 | + return; | |
385 | + } else if (!cisterna.capacidad) { | |
386 | + focaModalService.alert('Ingrese capacidad'); | |
387 | + return; | |
388 | + } else if (!cisterna.idUnidadMedida) { | |
389 | + focaModalService.alert('Ingrese unidad de medida'); | |
390 | + return; | |
391 | + } else if (cisterna.id === undefined) { | |
392 | + cisterna.id = 0; | |
393 | + } | |
394 | + | |
395 | + validaCodigo(cisterna); | |
396 | + }; | |
397 | + | |
398 | + if ($routeParams.idx !== -1) { | |
399 | + $scope.cisterna = [$routeParams.idx]; | |
400 | + focaAbmVehiculoService | |
401 | + .getCisternas($routeParams.idVehiculo) | |
402 | + .then(function (res) { | |
403 | + $scope.cisterna = res[$routeParams.idx]; | |
404 | + }); | |
405 | + } | |
406 | + | |
407 | + function validaCodigo(cisterna) { | |
408 | + focaAbmVehiculoService | |
409 | + .getCisternas($routeParams.idVehiculo) | |
410 | + .then(function (res) { | |
411 | + var cisternas = res; | |
412 | + var totalCargado = 0; | |
413 | + | |
414 | + for (var i = 0; i < cisternas.length; i++) { | |
415 | + //SI EL CODIGO YA EXISTE | |
416 | + if (cisternas[i].codigo === cisterna.codigo && | |
417 | + i !== $routeParams.idx && | |
418 | + cisternas[i].desactivado === false && | |
419 | + cisternas[i].id !== cisterna.id | |
420 | + ) { | |
421 | + focaModalService.alert('Código de cisterna existente'); | |
422 | + cisterna.editando = true; | |
423 | + return; | |
424 | + } | |
425 | + if (i !== $routeParams.idx && | |
426 | + !cisternas[i].desactivado) { | |
427 | + totalCargado += cisternas[i].capacidad; | |
428 | + } | |
429 | + } | |
430 | + $timeout(function () { | |
431 | + cisterna.editando = false; | |
432 | + $scope.crear = false; | |
433 | + }); | |
434 | + }); | |
435 | + } | |
320 | 436 | } |
321 | 437 | ]); |
src/js/controllerCisterna.js
... | ... | @@ -1,149 +0,0 @@ |
1 | -angular.module('focaAbmVehiculo') | |
2 | - .controller('focaAbmVehiculoCisternaController', [ | |
3 | - '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | |
4 | - 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', | |
5 | - function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | |
6 | - focaModalService, focaBotoneraLateralService, $timeout, $window) { | |
7 | - $scope.nuevo = ($routeParams.idx > -1) ? false : true; | |
8 | - $scope.editar = false; | |
9 | - $scope.now = new Date(); | |
10 | - $scope.cisterna = { | |
11 | - codigo: '', | |
12 | - capacidad: '', | |
13 | - unidadMedida: {} | |
14 | - }; | |
15 | - | |
16 | - $scope.focused = $scope.nuevo ? 1 : 2; | |
17 | - $scope.next = function(key) { | |
18 | - if (key === 13) $scope.focused++; | |
19 | - }; | |
20 | - $scope.capacidadVechiulo = 0; | |
21 | - $scope.transportista = ''; | |
22 | - | |
23 | - //SETEO BOTONERA LATERAL | |
24 | - $timeout(function() { | |
25 | - focaBotoneraLateralService.showSalir(false); | |
26 | - focaBotoneraLateralService.showPausar(true); | |
27 | - focaBotoneraLateralService.showCancelar(false); | |
28 | - focaBotoneraLateralService.showGuardar(true, $scope.guardar); | |
29 | - focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | |
30 | - }); | |
31 | - | |
32 | - if ($routeParams.idx !== -1) { | |
33 | - $scope.cisterna = [$routeParams.idx]; | |
34 | - focaAbmVehiculoService | |
35 | - .getCisternas($routeParams.idVehiculo) | |
36 | - .then(function(res) { | |
37 | - $scope.cisterna = res[$routeParams.idx]; | |
38 | - }); | |
39 | - } | |
40 | - | |
41 | - focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | |
42 | - var codigo = ('00000' + res.data.transportista.COD).slice(-5); | |
43 | - $scope.transportista = res.data.transportista.COD; | |
44 | - $scope.capacidadVechiulo = res.data.capacidad; | |
45 | - $scope.$broadcast('addCabecera', { | |
46 | - label: 'Transportista:', | |
47 | - valor: codigo + ' - ' + res.data.transportista.NOM | |
48 | - }); | |
49 | - $scope.$broadcast('addCabecera', { | |
50 | - label: 'Unidad:', | |
51 | - valor: res.data.codigo | |
52 | - }); | |
53 | - $scope.$broadcast('addCabecera', { | |
54 | - label: 'Capacidad total vehículo:', | |
55 | - valor: res.data.capacidad | |
56 | - }); | |
57 | - }); | |
58 | - | |
59 | - $scope.salir = function() { | |
60 | - | |
61 | - if (!$scope.formCisterna.$pristine) { | |
62 | - focaModalService.confirm( | |
63 | - '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | |
64 | - ).then(function(data) { | |
65 | - if (data) { | |
66 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + | |
67 | - $scope.transportista); | |
68 | - } | |
69 | - }); | |
70 | - } else { | |
71 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + | |
72 | - $scope.transportista); | |
73 | - } | |
74 | - }; | |
75 | - | |
76 | - $scope.guardar = function() { | |
77 | - | |
78 | - if ($scope.formCisterna.$pristine) { | |
79 | - $scope.salir(); | |
80 | - return; | |
81 | - } else if (!$scope.cisterna.codigo) { | |
82 | - focaModalService.alert('Ingrese codigo de cisterna'); | |
83 | - return; | |
84 | - } else if (!$scope.cisterna.capacidad) { | |
85 | - focaModalService.alert('Ingrese capacidad'); | |
86 | - return; | |
87 | - } else if (!$scope.cisterna.idUnidadMedida) { | |
88 | - focaModalService.alert('Ingrese unidad de medida'); | |
89 | - return; | |
90 | - } | |
91 | - | |
92 | - validaCodigo() | |
93 | - .then(function() { | |
94 | - $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | |
95 | - delete $scope.cisterna.vehiculo; | |
96 | - | |
97 | - focaAbmVehiculoService | |
98 | - .guardarCisterna($scope.cisterna, $routeParams.idx); | |
99 | - | |
100 | - $timeout(function() { | |
101 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + | |
102 | - '/' + $scope.transportista); | |
103 | - }, 0); | |
104 | - }, function(err) { | |
105 | - focaModalService.alert(err); | |
106 | - }); | |
107 | - | |
108 | - }; | |
109 | - | |
110 | - $scope.seleccionarUnidadMedida = function() { | |
111 | - var modalInstance = $uibModal.open( | |
112 | - { | |
113 | - ariaLabelledBy: 'Busqueda de Unidades de medida', | |
114 | - templateUrl: 'modal-unidad-medida.html', | |
115 | - controller: 'focaModalUnidadMedidaCtrl', | |
116 | - size: 'lg' | |
117 | - } | |
118 | - ); | |
119 | - modalInstance.result.then(function(unidaMedida) { | |
120 | - $scope.cisterna.idUnidadMedida = unidaMedida.ID; | |
121 | - $scope.cisterna.unidadMedida = unidaMedida; | |
122 | - }); | |
123 | - }; | |
124 | - | |
125 | - function validaCodigo() { | |
126 | - return new Promise(function(resolve, reject) { | |
127 | - focaAbmVehiculoService | |
128 | - .getCisternas($routeParams.idVehiculo) | |
129 | - .then(function(res) { | |
130 | - var cisternas = res; | |
131 | - var totalCargado = 0; | |
132 | - cisternas.forEach(function(cisterna, idx) { | |
133 | - //SI EL CODIGO YA EXISTE | |
134 | - if (cisterna.codigo === $scope.cisterna.codigo && | |
135 | - idx != $routeParams.idx && | |
136 | - !cisterna.desactivado) { | |
137 | - reject('Código de cisterna existente'); | |
138 | - } | |
139 | - if (idx !== $routeParams.idx && | |
140 | - !cisterna.desactivado) { | |
141 | - totalCargado += cisterna.capacidad; | |
142 | - } | |
143 | - }); | |
144 | - resolve(); | |
145 | - }); | |
146 | - }); | |
147 | - } | |
148 | - } | |
149 | - ]); |
src/js/service.js
... | ... | @@ -19,10 +19,6 @@ angular.module('focaAbmVehiculo') |
19 | 19 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); |
20 | 20 | }, |
21 | 21 | getCisternas: function(idVehiculo) { |
22 | - if (cisternas.length) { | |
23 | - cisternasPristine = true; | |
24 | - return Promise.resolve(angular.copy(cisternas)); | |
25 | - } else { | |
26 | 22 | cisternasPristine = true; |
27 | 23 | return new Promise(function(resolve) { |
28 | 24 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) |
... | ... | @@ -31,7 +27,6 @@ angular.module('focaAbmVehiculo') |
31 | 27 | resolve(res.data); |
32 | 28 | }); |
33 | 29 | }); |
34 | - } | |
35 | 30 | }, |
36 | 31 | guardarCisterna: function(cisterna, idx) { |
37 | 32 | if (idx !== '-1') { |
... | ... | @@ -47,9 +42,10 @@ angular.module('focaAbmVehiculo') |
47 | 42 | guardarCisternas: function(cisternas) { |
48 | 43 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); |
49 | 44 | }, |
50 | - deleteCisterna: function(idx) { | |
51 | - cisternas[idx].desactivado = true; | |
45 | + deleteCisterna: function(cisterna) { | |
46 | + cisterna.desactivado = true; | |
52 | 47 | cisternasPristine = false; |
48 | + return $http.delete(API_ENDPOINT.URL + '/cisterna/' + cisterna.id); | |
53 | 49 | }, |
54 | 50 | cleanCisternas: function() { |
55 | 51 | cisternas = []; |
src/views/foca-abm-cisterna-item.html
... | ... | @@ -1,63 +0,0 @@ |
1 | -<div class="row"> | |
2 | - <foca-cabecera-facturador | |
3 | - titulo="'Vehículo cisterna'" | |
4 | - fecha="now" | |
5 | - class="mb-0 col-lg-12" | |
6 | - ></foca-cabecera-facturador> | |
7 | -</div> | |
8 | -<div class="row"></div> | |
9 | -<form name="formCisterna"> | |
10 | - <div class="form-group row"> | |
11 | - <label class="offset-sm-1 col-sm-2 col-form-label">Código de cisterna</label> | |
12 | - <div class="col-sm-4"> | |
13 | - <input | |
14 | - class="form-control" | |
15 | - type="text" | |
16 | - ng-required="true" | |
17 | - ng-model="cisterna.codigo" | |
18 | - ng-keypress="next($event.keyCode)" | |
19 | - foca-focus="focused == 1" | |
20 | - ng-focus="focused = 1" | |
21 | - ng-disabled="!nuevo" | |
22 | - teclado-virtual | |
23 | - /> | |
24 | - </div> | |
25 | - </div> | |
26 | - <div class="form-group row"> | |
27 | - <label class="offset-sm-1 col-sm-2 col-form-label">Capacidad</label> | |
28 | - <div class="col-sm-4"> | |
29 | - <input | |
30 | - class="form-control" | |
31 | - type="text" | |
32 | - teclado-virtual | |
33 | - foca-tipo-input | |
34 | - ng-model="cisterna.capacidad" | |
35 | - ng-required="true" | |
36 | - ng-keypress="next($event.keyCode)" | |
37 | - foca-focus="focused == 2" | |
38 | - ng-focus="focused = 2" | |
39 | - /> | |
40 | - </div> | |
41 | - </div> | |
42 | - <div class="form-group row"> | |
43 | - <label class="offset-sm-1 col-sm-2 col-form-label">Unidad de medida</label> | |
44 | - <div class="col-sm-4 input-group"> | |
45 | - <input | |
46 | - ng-model="cisterna.unidadMedida.NOM" | |
47 | - class="form-control" | |
48 | - readonly | |
49 | - /> | |
50 | - <div class="input-group-append"> | |
51 | - <button | |
52 | - ladda="searchLoading" | |
53 | - class="btn btn-outline-secondary form-control" | |
54 | - type="button" | |
55 | - ng-click="seleccionarUnidadMedida()" | |
56 | - foca-focus="focused == 3" | |
57 | - > | |
58 | - <i class="fa fa-search" aria-hidden="true"></i> | |
59 | - </button> | |
60 | - </div> | |
61 | - </div> | |
62 | - </div> | |
63 | -</form> |
src/views/foca-abm-vehiculos-item.html
1 | 1 | <div class="row"> |
2 | 2 | <foca-cabecera-facturador |
3 | - titulo="'Vehículo'" | |
3 | + titulo="'Vehiculo / ' + tipo" | |
4 | 4 | fecha="now" |
5 | 5 | class="mb-0 col-lg-12" |
6 | 6 | ></foca-cabecera-facturador> |
... | ... | @@ -60,56 +60,176 @@ |
60 | 60 | <div class="input-group col-md-8 pl-0"> |
61 | 61 | <input |
62 | 62 | class="form-control" |
63 | - type="text" | |
63 | + foca-tipo-input | |
64 | + solo-positivos | |
64 | 65 | teclado-virtual |
65 | 66 | ng-model="vehiculo.capacidad" |
66 | 67 | ng-required="true" |
67 | 68 | foca-focus="focused == 4" |
68 | 69 | ng-focus="focused = 4" |
69 | - ng-keypress="guardar($event.keyCode)" | |
70 | + ng-disabled="!nuevo" | |
70 | 71 | /> |
71 | 72 | </div> |
72 | 73 | </div> |
73 | 74 | </div> |
74 | 75 | </form> |
75 | - <div ng-show="!nuevo"> | |
76 | + <div> | |
76 | 77 | <h5 class="pl-4 table-title">Cisternas</h5> |
77 | - <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> | |
78 | + <table class="table table-default table-hover table-sm table-abm table-striped mb-0" > | |
78 | 79 | <thead> |
79 | 80 | <tr> |
80 | - <th class="px-5">Código</th> | |
81 | - <th class="text-right px-5">Capacidad</th> | |
82 | - <th class="text-center px-4"> | |
81 | + <th class="text-center px-4">Código</th> | |
82 | + <th class="text-center">Capacidad</th> | |
83 | + <th class="text-center">Unidad de Medida</th> | |
84 | + <th class="text-center"> | |
83 | 85 | <button |
84 | 86 | class="btn btn-outline-debo boton-accion" |
85 | - title="Agregar" | |
86 | - ng-click="editar(-1)"> | |
87 | + title="Agregar Cisterna" | |
88 | + ng-click="crearCisterna()" | |
89 | + ng-disabled="crear"> | |
87 | 90 | <i class="fa fa-plus"></i> |
88 | 91 | </button> |
89 | 92 | </th> |
90 | - </tr> | |
93 | + </tr> | |
91 | 94 | </thead> |
92 | 95 | <tbody> |
93 | - <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" | |
94 | - ng-show="!cisterna.desactivado"> | |
95 | - <td ng-bind="cisterna.codigo" class="px-5"></td> | |
96 | - <td ng-bind="cisterna.capacidad + ' ' + cisterna.unidadMedida.NOM" class="text-right px-5"></td> | |
97 | - <td class="text-center px-4"> | |
96 | + <tr ng-show="creando"> | |
97 | + <td align="center"> | |
98 | + <input | |
99 | + class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | |
100 | + ng-model="cisterna.codigo" | |
101 | + ng-keypress="next($event.keyCode)" | |
102 | + foca-focus="focused == 1" | |
103 | + ng-focus="focused = 1" | |
104 | + ng-disabled="!nuevoCisterna" | |
105 | + teclado-virtual | |
106 | + > | |
107 | + </td> | |
108 | + <td align="center"> | |
109 | + <input | |
110 | + class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | |
111 | + teclado-virtual | |
112 | + foca-tipo-input | |
113 | + solo-positivos | |
114 | + ng-model="cisterna.capacidad" | |
115 | + ng-required="true" | |
116 | + ng-keypress="next($event.keyCode)" | |
117 | + foca-focus="focused == 2" | |
118 | + ng-focus="focused = 2" | |
119 | + > | |
120 | + </td> | |
121 | + <td align="center"> | |
122 | + <div class="input-group"> | |
123 | + <input | |
124 | + ng-model="cisterna.unidadMedida.NOM" | |
125 | + class="form-control" | |
126 | + readonly | |
127 | + /> | |
128 | + <div class="input-group-append"> | |
129 | + <button | |
130 | + ladda="searchLoading" | |
131 | + class="btn btn-outline-secondary form-control" | |
132 | + type="button" | |
133 | + ng-click="seleccionarUnidadMedida()" | |
134 | + foca-focus="focused == 3" | |
135 | + > | |
136 | + <i class="fa fa-search" aria-hidden="true"></i> | |
137 | + </button> | |
138 | + </div> | |
139 | + </div> | |
140 | + </td> | |
141 | + <td align="center"> | |
142 | + <button | |
143 | + class="btn btn-outline-dark boton-accion" | |
144 | + ng-click="agregarCisterna()" | |
145 | + > | |
146 | + <i class="fa fa-save"></i> | |
147 | + </button> | |
148 | + </td> | |
149 | + </tr> | |
150 | + | |
151 | + <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" ng-hide="cisterna.desactivado"> | |
152 | + <td ng-bind="cisterna.codigo" class="text-center" ng-hide="cisterna.editando"></td> | |
153 | + <td align="center" ng-show="cisterna.editando"> | |
154 | + <input | |
155 | + class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | |
156 | + ng-model="cisterna.codigo" | |
157 | + ng-keypress="next($event.keyCode)" | |
158 | + foca-focus="focused == 1" | |
159 | + ng-focus="focused = 1" | |
160 | + teclado-virtual | |
161 | + esc-key="volver(cisterna, key)" | |
162 | + > | |
163 | + </td> | |
164 | + <td ng-bind="cisterna.capacidad" class="text-center" ng-hide="cisterna.editando"></td> | |
165 | + <td align="center" ng-show="cisterna.editando" > | |
166 | + <input | |
167 | + class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | |
168 | + teclado-virtual | |
169 | + foca-tipo-input | |
170 | + solo-positivos | |
171 | + ng-model="cisterna.capacidad" | |
172 | + ng-required="true" | |
173 | + ng-keypress="next($event.keyCode)" | |
174 | + foca-focus="focused == 2" | |
175 | + ng-focus="focused = 2" | |
176 | + esc-key="volver(cisterna, key)" | |
177 | + > | |
178 | + </td> | |
179 | + <td ng-bind="cisterna.unidadMedida.NOM" class="text-center" ng-hide="cisterna.editando"></td> | |
180 | + <td align="center" ng-show="cisterna.editando"> | |
181 | + <div class="input-group"> | |
182 | + <input | |
183 | + ng-model="cisterna.unidadMedida.NOM" | |
184 | + class="form-control" | |
185 | + readonly | |
186 | + esc-key="volver(cisterna, key)" | |
187 | + /> | |
188 | + <div class="input-group-append"> | |
189 | + <button | |
190 | + ladda="searchLoading" | |
191 | + class="btn btn-outline-secondary form-control" | |
192 | + type="button" | |
193 | + ng-click="seleccionarUnidadMedida(cisterna)" | |
194 | + foca-focus="focused == 3" | |
195 | + > | |
196 | + <i class="fa fa-search" aria-hidden="true"></i> | |
197 | + </button> | |
198 | + </div> | |
199 | + </div> | |
200 | + </td> | |
201 | + <td class="text-center" ng-hide="cisterna.editando"> | |
98 | 202 | <button |
99 | 203 | class="btn btn-outline-dark boton-accion" |
100 | 204 | title="Editar" |
101 | - ng-click="editar(key)" | |
205 | + ng-click="editar(cisterna)" | |
102 | 206 | > |
103 | 207 | <i class="fa fa-pencil"></i> |
104 | 208 | </button> |
105 | 209 | <button |
106 | 210 | class="btn btn-outline-dark boton-accion" |
107 | 211 | title="Eliminar" |
108 | - ng-click="solicitarConfirmacionCisterna(cisterna, key)" | |
212 | + ng-click="solicitarConfirmacionTabla(cisterna, $index)" | |
109 | 213 | > |
110 | 214 | <i class="fa fa-trash"></i> |
111 | 215 | </button> |
112 | 216 | </td> |
217 | + <td align="center" ng-show="cisterna.editando" > | |
218 | + <button | |
219 | + class="btn btn-outline-dark boton-accion" | |
220 | + ng-click="agregarCisterna(cisterna)" | |
221 | + > | |
222 | + <i class="fa fa-save"></i> | |
223 | + </button> | |
224 | + <button | |
225 | + class="btn btn-outline-dark boton-accion" | |
226 | + ng-click="volver(cisterna, key)" | |
227 | + > | |
228 | + <i class="fa fa-undo" aria-hidden="true"></i> | |
229 | + </button> | |
230 | + </td> | |
231 | + </tr> | |
232 | + <tr ng-repeat="(key, cisterna) in cisternas" ng-show="false"> | |
113 | 233 | </tr> |
114 | 234 | </body> |
115 | 235 | </table> |
src/views/foca-abm-vehiculos-listado.html