Commit 4fcf250fd974c12c5dc84c35bb2e847dff5c3a31
Exists in
master
and in
1 other branch
Merge branch 'master' into 'develop'
Master See merge request !39
Showing
5 changed files
Show diff stats
package.json
spec/controllerSpec.js
| ... | ... | @@ -29,6 +29,7 @@ describe('Controladores abm vehículo', function() { |
| 29 | 29 | showGuardar: function() { return; }, |
| 30 | 30 | addCustomButton: function() { return; } |
| 31 | 31 | }, |
| 32 | + $localStorage: {}, | |
| 32 | 33 | $timeout: {} |
| 33 | 34 | }); |
| 34 | 35 | |
| ... | ... | @@ -38,7 +39,9 @@ describe('Controladores abm vehículo', function() { |
| 38 | 39 | |
| 39 | 40 | it('Crea fecha nueva', function() { |
| 40 | 41 | //arrange |
| 41 | - var scope = {}; | |
| 42 | + var scope = { | |
| 43 | + $watch: function() {} | |
| 44 | + }; | |
| 42 | 45 | var controller = $controller('focaAbmVehiculosController', { |
| 43 | 46 | $scope: scope, |
| 44 | 47 | focaAbmVehiculoService: { |
| ... | ... | @@ -55,6 +58,7 @@ describe('Controladores abm vehículo', function() { |
| 55 | 58 | showGuardar: function() { return; }, |
| 56 | 59 | addCustomButton: function() { return; } |
| 57 | 60 | }, |
| 61 | + $localStorage: {}, | |
| 58 | 62 | $timeout: {} |
| 59 | 63 | }); |
| 60 | 64 | |
| ... | ... | @@ -67,7 +71,9 @@ describe('Controladores abm vehículo', function() { |
| 67 | 71 | |
| 68 | 72 | it('$scope setea botonera lateral', function() { |
| 69 | 73 | //arrange |
| 70 | - var scope = {}; | |
| 74 | + var scope = { | |
| 75 | + $watch: function() {} | |
| 76 | + }; | |
| 71 | 77 | var controller = $controller('focaAbmVehiculosController', { |
| 72 | 78 | $scope: scope, |
| 73 | 79 | focaAbmVehiculoService: { |
| ... | ... | @@ -84,7 +90,8 @@ describe('Controladores abm vehículo', function() { |
| 84 | 90 | showGuardar: function() { return; }, |
| 85 | 91 | addCustomButton: function() { return; } |
| 86 | 92 | }, |
| 87 | - $timeout: {} | |
| 93 | + $timeout: {}, | |
| 94 | + $localStorage: {} | |
| 88 | 95 | }); |
| 89 | 96 | |
| 90 | 97 | //act |
| ... | ... | @@ -97,7 +104,9 @@ describe('Controladores abm vehículo', function() { |
| 97 | 104 | it('$scope.editar lleva a la ruta correcta', function() { |
| 98 | 105 | inject(function($location) { |
| 99 | 106 | //arrange |
| 100 | - var scope = {}; | |
| 107 | + var scope = { | |
| 108 | + $watch: function() {} | |
| 109 | + }; | |
| 101 | 110 | var controller = $controller('focaAbmVehiculosController', { |
| 102 | 111 | $scope: scope, |
| 103 | 112 | focaAbmVehiculoService: { |
| ... | ... | @@ -114,7 +123,8 @@ describe('Controladores abm vehículo', function() { |
| 114 | 123 | showGuardar: function() { return; }, |
| 115 | 124 | addCustomButton: function() { return; } |
| 116 | 125 | }, |
| 117 | - $timeout: {} | |
| 126 | + $timeout: {}, | |
| 127 | + $localStorage: {} | |
| 118 | 128 | }); |
| 119 | 129 | |
| 120 | 130 | //act |
| ... | ... | @@ -128,7 +138,9 @@ describe('Controladores abm vehículo', function() { |
| 128 | 138 | |
| 129 | 139 | it('Solicita confirmacion', function() { |
| 130 | 140 | //arrange |
| 131 | - var scope = {}; | |
| 141 | + var scope = { | |
| 142 | + $watch: function() {} | |
| 143 | + }; | |
| 132 | 144 | var focaModalService = { |
| 133 | 145 | confirm: function() {} |
| 134 | 146 | }; |
| ... | ... | @@ -148,7 +160,8 @@ describe('Controladores abm vehículo', function() { |
| 148 | 160 | showGuardar: function() { return; }, |
| 149 | 161 | addCustomButton: function() { return; } |
| 150 | 162 | }, |
| 151 | - $timeout: {} | |
| 163 | + $timeout: {}, | |
| 164 | + $localStorage: {} | |
| 152 | 165 | }); |
| 153 | 166 | |
| 154 | 167 | //act |
| ... | ... | @@ -186,7 +199,8 @@ describe('Controladores abm vehículo', function() { |
| 186 | 199 | showGuardar: function() { return; }, |
| 187 | 200 | addCustomButton: function() { return; } |
| 188 | 201 | }, |
| 189 | - $timeout: {} | |
| 202 | + $timeout: {}, | |
| 203 | + $localStorage: {} | |
| 190 | 204 | }); |
| 191 | 205 | var promesa = Promise.resolve(true); |
| 192 | 206 | |
| ... | ... | @@ -206,7 +220,9 @@ describe('Controladores abm vehículo', function() { |
| 206 | 220 | |
| 207 | 221 | it('Se selecciona transportista', function() { |
| 208 | 222 | //arrange |
| 209 | - var scope = {}; | |
| 223 | + var scope = { | |
| 224 | + $watch: function() {} | |
| 225 | + }; | |
| 210 | 226 | var focaModalService = { |
| 211 | 227 | modal: function() {} |
| 212 | 228 | }; |
| ... | ... | @@ -226,7 +242,8 @@ describe('Controladores abm vehículo', function() { |
| 226 | 242 | showGuardar: function() { return; }, |
| 227 | 243 | addCustomButton: function() { return; } |
| 228 | 244 | }, |
| 229 | - $timeout: {} | |
| 245 | + $timeout: {}, | |
| 246 | + $localStorage: {} | |
| 230 | 247 | }); |
| 231 | 248 | |
| 232 | 249 | //act |
| ... | ... | @@ -241,7 +258,9 @@ describe('Controladores abm vehículo', function() { |
| 241 | 258 | inject(function($timeout) { |
| 242 | 259 | |
| 243 | 260 | //arrange |
| 244 | - var scope = {}; | |
| 261 | + var scope = { | |
| 262 | + $watch: function() {} | |
| 263 | + }; | |
| 245 | 264 | var focaModalService = { |
| 246 | 265 | modal: function() { return; } |
| 247 | 266 | }; |
| ... | ... | @@ -268,6 +287,7 @@ describe('Controladores abm vehículo', function() { |
| 268 | 287 | showGuardar: function() { return; }, |
| 269 | 288 | addCustomButton: function() { return; } |
| 270 | 289 | }, |
| 290 | + $localStorage: {}, | |
| 271 | 291 | $timeout: $timeout |
| 272 | 292 | }); |
| 273 | 293 | var promesa = Promise.resolve({COD: '', NOM: ''}); |
| ... | ... | @@ -301,7 +321,9 @@ describe('Controladores abm vehículo', function() { |
| 301 | 321 | |
| 302 | 322 | //arrange |
| 303 | 323 | var controller = $controller('focaAbmVehiculoController', { |
| 304 | - $scope: {}, | |
| 324 | + $scope: { | |
| 325 | + $watch: function() {} | |
| 326 | + }, | |
| 305 | 327 | focaAbmVehiculoService: { |
| 306 | 328 | getVehiculo: function() { |
| 307 | 329 | return { |
| ... | ... | @@ -321,6 +343,7 @@ describe('Controladores abm vehículo', function() { |
| 321 | 343 | showGuardar: function() { return; }, |
| 322 | 344 | addCustomButton: function() { return; } |
| 323 | 345 | }, |
| 346 | + $localStorage: {}, | |
| 324 | 347 | $window: {} |
| 325 | 348 | }); |
| 326 | 349 | |
| ... | ... | @@ -332,7 +355,9 @@ describe('Controladores abm vehículo', function() { |
| 332 | 355 | it('Se busca el transportista cuando es nuevo', function() { |
| 333 | 356 | |
| 334 | 357 | //arrange |
| 335 | - var scope = {}; | |
| 358 | + var scope = { | |
| 359 | + $watch: function() {} | |
| 360 | + }; | |
| 336 | 361 | var focaAbmVehiculoService = { |
| 337 | 362 | getVehiculo: function() { |
| 338 | 363 | return { |
| ... | ... | @@ -363,6 +388,7 @@ describe('Controladores abm vehículo', function() { |
| 363 | 388 | showGuardar: function() { return; }, |
| 364 | 389 | addCustomButton: function() { return; } |
| 365 | 390 | }, |
| 391 | + $localStorage: {}, | |
| 366 | 392 | $window: {} |
| 367 | 393 | }); |
| 368 | 394 | |
| ... | ... | @@ -373,7 +399,9 @@ describe('Controladores abm vehículo', function() { |
| 373 | 399 | it('No se busca el transportista cuando es nuevo', function() { |
| 374 | 400 | |
| 375 | 401 | //arrange |
| 376 | - var scope = {}; | |
| 402 | + var scope = { | |
| 403 | + $watch: function() {} | |
| 404 | + }; | |
| 377 | 405 | var focaAbmVehiculoService = { |
| 378 | 406 | getVehiculo: function() { |
| 379 | 407 | return { |
| ... | ... | @@ -402,6 +430,7 @@ describe('Controladores abm vehículo', function() { |
| 402 | 430 | showGuardar: function() { return; }, |
| 403 | 431 | addCustomButton: function() { return; } |
| 404 | 432 | }, |
| 433 | + $localStorage: {}, | |
| 405 | 434 | $window: {} |
| 406 | 435 | }); |
| 407 | 436 | |
| ... | ... | @@ -413,7 +442,13 @@ describe('Controladores abm vehículo', function() { |
| 413 | 442 | |
| 414 | 443 | inject(function($location) { |
| 415 | 444 | //arrange |
| 416 | - var scope = {}; | |
| 445 | + var scope = { | |
| 446 | + $watch: function() {}, | |
| 447 | + cancelar: function() {}, | |
| 448 | + formVehiculo: { | |
| 449 | + $pristine: true | |
| 450 | + } | |
| 451 | + }; | |
| 417 | 452 | var controller = $controller('focaAbmVehiculoController', { |
| 418 | 453 | $scope: scope, |
| 419 | 454 | focaAbmVehiculoService: { |
| ... | ... | @@ -435,11 +470,13 @@ describe('Controladores abm vehículo', function() { |
| 435 | 470 | showGuardar: function() { return; }, |
| 436 | 471 | addCustomButton: function() { return; } |
| 437 | 472 | }, |
| 438 | - $window: {} | |
| 473 | + $localStorage: {}, | |
| 474 | + $window: {}, | |
| 475 | + | |
| 439 | 476 | }); |
| 440 | 477 | |
| 441 | 478 | //act |
| 442 | - scope.cancelar(); | |
| 479 | + scope.salir(); | |
| 443 | 480 | |
| 444 | 481 | //assert |
| 445 | 482 | expect($location.url()).toEqual('/vehiculo'); |
| ... | ... | @@ -450,7 +487,9 @@ describe('Controladores abm vehículo', function() { |
| 450 | 487 | |
| 451 | 488 | inject(function($location) { |
| 452 | 489 | //arrange |
| 453 | - var scope = {}; | |
| 490 | + var scope = { | |
| 491 | + $watch: function() {} | |
| 492 | + }; | |
| 454 | 493 | var controller = $controller('focaAbmVehiculoController', { |
| 455 | 494 | $scope: scope, |
| 456 | 495 | focaAbmVehiculoService: { |
| ... | ... | @@ -474,6 +513,7 @@ describe('Controladores abm vehículo', function() { |
| 474 | 513 | showGuardar: function() { return; }, |
| 475 | 514 | addCustomButton: function() { return; } |
| 476 | 515 | }, |
| 516 | + $localStorage: {}, | |
| 477 | 517 | $window: {} |
| 478 | 518 | }); |
| 479 | 519 | |
| ... | ... | @@ -490,7 +530,9 @@ describe('Controladores abm vehículo', function() { |
| 490 | 530 | |
| 491 | 531 | inject(function($location) { |
| 492 | 532 | //arrange |
| 493 | - var scope = {}; | |
| 533 | + var scope = { | |
| 534 | + $watch: function() {} | |
| 535 | + }; | |
| 494 | 536 | var controller = $controller('focaAbmVehiculoController', { |
| 495 | 537 | $scope: scope, |
| 496 | 538 | focaAbmVehiculoService: { |
| ... | ... | @@ -514,6 +556,7 @@ describe('Controladores abm vehículo', function() { |
| 514 | 556 | showGuardar: function() { return; }, |
| 515 | 557 | addCustomButton: function() { return; } |
| 516 | 558 | }, |
| 559 | + $localStorage: {}, | |
| 517 | 560 | $window: {} |
| 518 | 561 | }); |
| 519 | 562 | |
| ... | ... | @@ -532,7 +575,9 @@ describe('Controladores abm vehículo', function() { |
| 532 | 575 | var focaModalService = { |
| 533 | 576 | confirm: function() {} |
| 534 | 577 | }; |
| 535 | - var scope = {}; | |
| 578 | + var scope = { | |
| 579 | + $watch: function() {} | |
| 580 | + }; | |
| 536 | 581 | var controller = $controller('focaAbmVehiculoController', { |
| 537 | 582 | $scope: scope, |
| 538 | 583 | focaAbmVehiculoService: { |
| ... | ... | @@ -556,6 +601,7 @@ describe('Controladores abm vehículo', function() { |
| 556 | 601 | showGuardar: function() { return; }, |
| 557 | 602 | addCustomButton: function() { return; } |
| 558 | 603 | }, |
| 604 | + $localStorage: {}, | |
| 559 | 605 | $window: {} |
| 560 | 606 | }); |
| 561 | 607 | |
| ... | ... | @@ -570,7 +616,9 @@ describe('Controladores abm vehículo', function() { |
| 570 | 616 | it('Elimina y obtiene cisternas al dar confirmar', function(done) { |
| 571 | 617 | |
| 572 | 618 | //arrange |
| 573 | - var scope = {}; | |
| 619 | + var scope = { | |
| 620 | + $watch: function() {} | |
| 621 | + }; | |
| 574 | 622 | var focaModalService = { |
| 575 | 623 | confirm: function() {} |
| 576 | 624 | }; |
| ... | ... | @@ -598,6 +646,7 @@ describe('Controladores abm vehículo', function() { |
| 598 | 646 | showGuardar: function() { return; }, |
| 599 | 647 | addCustomButton: function() { return; } |
| 600 | 648 | }, |
| 649 | + $localStorage: {}, | |
| 601 | 650 | $window: {} |
| 602 | 651 | }); |
| 603 | 652 | var promesa = Promise.resolve(true); |
src/js/controller.js
| ... | ... | @@ -107,7 +107,7 @@ angular.module('focaAbmVehiculo') |
| 107 | 107 | focaBotoneraLateralService.showPausar(true); |
| 108 | 108 | focaBotoneraLateralService.showCancelar(false); |
| 109 | 109 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 110 | - focaBotoneraLateralService.addCustomButton('Salir', salir); | |
| 110 | + focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | |
| 111 | 111 | }); |
| 112 | 112 | |
| 113 | 113 | $timeout(function() {getLSVehiculo();}); |
| ... | ... | @@ -153,8 +153,8 @@ angular.module('focaAbmVehiculo') |
| 153 | 153 | if (key === 13) $scope.focused++; |
| 154 | 154 | }; |
| 155 | 155 | |
| 156 | - function salir() { | |
| 157 | - if (!$scope.formVehiculo.$pristine) { | |
| 156 | + $scope.salir = function() { | |
| 157 | + if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | |
| 158 | 158 | focaModalService.confirm( |
| 159 | 159 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 160 | 160 | ).then(function(data) { |
| ... | ... | @@ -181,8 +181,8 @@ angular.module('focaAbmVehiculo') |
| 181 | 181 | |
| 182 | 182 | if (key === 13) { |
| 183 | 183 | |
| 184 | - if ($scope.formVehiculo.$pristine) { | |
| 185 | - $scope.cancelar(); | |
| 184 | + if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | |
| 185 | + $scope.salir(); | |
| 186 | 186 | return; |
| 187 | 187 | } |
| 188 | 188 | |
| ... | ... | @@ -299,7 +299,7 @@ angular.module('focaAbmVehiculo') |
| 299 | 299 | total += parseInt(cisterna.capacidad); |
| 300 | 300 | } |
| 301 | 301 | }); |
| 302 | - return $scope.vehiculo.capacidad === total; | |
| 302 | + return $scope.vehiculo.capacidad == total; | |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | function guardarCisternas() { |
| ... | ... | @@ -316,5 +316,6 @@ angular.module('focaAbmVehiculo') |
| 316 | 316 | |
| 317 | 317 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
| 318 | 318 | } |
| 319 | + | |
| 319 | 320 | } |
| 320 | 321 | ]); |
src/js/controllerCisterna.js
| 1 | 1 | angular.module('focaAbmVehiculo') |
| 2 | 2 | .controller('focaAbmVehiculoCisternaController', [ |
| 3 | 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 4 | - 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter', | |
| 4 | + 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', | |
| 5 | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 6 | - focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { | |
| 6 | + focaModalService, focaBotoneraLateralService, $timeout, $window) { | |
| 7 | 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; |
| 8 | 8 | $scope.editar = false; |
| 9 | 9 | $scope.now = new Date(); |
| ... | ... | @@ -26,7 +26,7 @@ angular.module('focaAbmVehiculo') |
| 26 | 26 | focaBotoneraLateralService.showPausar(true); |
| 27 | 27 | focaBotoneraLateralService.showCancelar(false); |
| 28 | 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 29 | - focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); | |
| 29 | + focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | |
| 30 | 30 | }); |
| 31 | 31 | |
| 32 | 32 | if ($routeParams.idx !== -1) { |
| ... | ... | @@ -56,27 +56,29 @@ angular.module('focaAbmVehiculo') |
| 56 | 56 | }); |
| 57 | 57 | }); |
| 58 | 58 | |
| 59 | - $scope.cancelar = function() { | |
| 59 | + $scope.salir = function() { | |
| 60 | 60 | |
| 61 | 61 | if (!$scope.formCisterna.$pristine) { |
| 62 | 62 | focaModalService.confirm( |
| 63 | 63 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 64 | 64 | ).then(function(data) { |
| 65 | 65 | if (data) { |
| 66 | - $location.path('/vehiculo'); | |
| 66 | + $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + | |
| 67 | + $scope.transportista); | |
| 67 | 68 | } |
| 68 | 69 | }); |
| 70 | + } else { | |
| 71 | + $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' + | |
| 72 | + $scope.transportista); | |
| 69 | 73 | } |
| 70 | 74 | }; |
| 71 | 75 | |
| 72 | 76 | $scope.guardar = function() { |
| 73 | 77 | |
| 74 | 78 | if ($scope.formCisterna.$pristine) { |
| 75 | - $scope.cancelar(); | |
| 79 | + $scope.salir(); | |
| 76 | 80 | return; |
| 77 | - } | |
| 78 | - | |
| 79 | - if (!$scope.cisterna.codigo) { | |
| 81 | + } else if (!$scope.cisterna.codigo) { | |
| 80 | 82 | focaModalService.alert('Ingrese codigo de cisterna'); |
| 81 | 83 | return; |
| 82 | 84 | } else if (!$scope.cisterna.capacidad) { |
| ... | ... | @@ -130,7 +132,7 @@ angular.module('focaAbmVehiculo') |
| 130 | 132 | cisternas.forEach(function(cisterna, idx) { |
| 131 | 133 | //SI EL CODIGO YA EXISTE |
| 132 | 134 | if (cisterna.codigo === $scope.cisterna.codigo && |
| 133 | - idx !== $routeParams.idx && | |
| 135 | + idx != $routeParams.idx && | |
| 134 | 136 | !cisterna.desactivado) { |
| 135 | 137 | reject('Código de cisterna existente'); |
| 136 | 138 | } |
src/js/service.js
| 1 | 1 | angular.module('focaAbmVehiculo') |
| 2 | 2 | .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { |
| 3 | 3 | var cisternas = []; |
| 4 | + var cisternasPristine = true; | |
| 4 | 5 | return { |
| 5 | 6 | getVehiculos: function() { |
| 6 | 7 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); |
| ... | ... | @@ -18,9 +19,11 @@ angular.module('focaAbmVehiculo') |
| 18 | 19 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); |
| 19 | 20 | }, |
| 20 | 21 | getCisternas: function(idVehiculo) { |
| 21 | - if(cisternas.length) { | |
| 22 | + if (cisternas.length) { | |
| 23 | + cisternasPristine = true; | |
| 22 | 24 | return Promise.resolve(angular.copy(cisternas)); |
| 23 | - }else { | |
| 25 | + } else { | |
| 26 | + cisternasPristine = true; | |
| 24 | 27 | return new Promise(function(resolve) { |
| 25 | 28 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) |
| 26 | 29 | .then(function(res) { |
| ... | ... | @@ -31,12 +34,14 @@ angular.module('focaAbmVehiculo') |
| 31 | 34 | } |
| 32 | 35 | }, |
| 33 | 36 | guardarCisterna: function(cisterna, idx) { |
| 34 | - if(idx !== '-1') { | |
| 37 | + if (idx !== '-1') { | |
| 35 | 38 | //update |
| 36 | 39 | cisternas[idx] = cisterna; |
| 37 | - }else { | |
| 40 | + cisternasPristine = false; | |
| 41 | + } else { | |
| 38 | 42 | //insert |
| 39 | 43 | cisternas.push(cisterna); |
| 44 | + cisternasPristine = false; | |
| 40 | 45 | } |
| 41 | 46 | }, |
| 42 | 47 | guardarCisternas: function(cisternas) { |
| ... | ... | @@ -44,6 +49,7 @@ angular.module('focaAbmVehiculo') |
| 44 | 49 | }, |
| 45 | 50 | deleteCisterna: function(idx) { |
| 46 | 51 | cisternas[idx].desactivado = true; |
| 52 | + cisternasPristine = false; | |
| 47 | 53 | }, |
| 48 | 54 | cleanCisternas: function() { |
| 49 | 55 | cisternas = []; |