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
| 1 | { | 1 | { |
| 2 | "name": "foca-abm-vehiculo", | 2 | "name": "foca-abm-vehiculo", |
| 3 | "version": "0.0.1", | 3 | "version": "0.0.1", |
| 4 | "description": "Abm de vehiculo", | 4 | "description": "Abm de vehiculo", |
| 5 | "main": "index.html", | 5 | "main": "index.html", |
| 6 | "scripts": { | 6 | "scripts": { |
| 7 | "test": "test.html", | 7 | "test": "test.html", |
| 8 | "compile": "gulp uglify", | 8 | "compile": "gulp uglify", |
| 9 | "gulp-pre-commit": "gulp pre-commit", | 9 | "gulp-pre-commit": "gulp pre-commit", |
| 10 | "postinstall": "npm run compile && gulp clean-post-install", | 10 | "postinstall": "npm run compile && gulp clean-post-install", |
| 11 | "install-dev": "npm install -D angular bootstrap ui-bootstrap4 font-awesome jquery gulp gulp-connect jasmine-core pre-commit gulp-angular-templatecache gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify-es gulp-uglify gulp-clean jshint pump git+http://git.focasoftware.com/npm/foca-modal.git" | 11 | "install-dev": "npm install -D angular bootstrap ui-bootstrap4 font-awesome jquery gulp gulp-connect jasmine-core pre-commit gulp-angular-templatecache gulp-htmlmin gulp-jshint gulp-rename gulp-replace gulp-uglify-es gulp-uglify gulp-clean jshint pump git+http://git.focasoftware.com/npm/foca-modal.git" |
| 12 | }, | 12 | }, |
| 13 | "pre-commit": [ | 13 | "pre-commit": [ |
| 14 | "gulp-pre-commit" | 14 | "gulp-pre-commit" |
| 15 | ], | 15 | ], |
| 16 | "repository": { | 16 | "repository": { |
| 17 | "type": "git", | 17 | "type": "git", |
| 18 | "url": "http://git.focasoftware.com/npm/foca-abm-vehiculo.git" | 18 | "url": "http://git.focasoftware.com/npm/foca-abm-vehiculo.git" |
| 19 | }, | 19 | }, |
| 20 | "author": "Foca Software", | 20 | "author": "Foca Software", |
| 21 | "license": "ISC", | 21 | "license": "ISC", |
| 22 | "peerDependencies": { | 22 | "peerDependencies": { |
| 23 | "angular": "^1.7.x", | 23 | "angular": "^1.7.x", |
| 24 | "angular-route": "^1.7.x", | 24 | "angular-route": "^1.7.x", |
| 25 | "bootstrap": "^4.1.x", | 25 | "bootstrap": "^4.1.x", |
| 26 | "jquery": "^3.3.x", | 26 | "jquery": "^3.3.x", |
| 27 | "font-awesome": "^4.7.x", | 27 | "font-awesome": "^4.7.x", |
| 28 | "gulp": "^3.9.x", | 28 | "gulp": "^3.9.x", |
| 29 | "gulp-concat": "2.6.x", | 29 | "gulp-concat": "2.6.x", |
| 30 | "gulp-jshint": "^2.1.x", | 30 | "gulp-jshint": "^2.1.x", |
| 31 | "gulp-rename": "^1.4.x", | 31 | "gulp-rename": "^1.4.x", |
| 32 | "gulp-replace": "^1.0.x", | 32 | "gulp-replace": "^1.0.x", |
| 33 | "gulp-uglify-es": "^1.0.x", | 33 | "gulp-uglify-es": "^1.0.x", |
| 34 | "jshint": "^2.9.x", | 34 | "jshint": "^2.9.x", |
| 35 | "pump": "^3.0.x" | 35 | "pump": "^3.0.x" |
| 36 | }, | 36 | }, |
| 37 | "devDependencies": { | 37 | "devDependencies": { |
| 38 | "angular": "^1.7.5", | 38 | "angular": "^1.7.5", |
| 39 | "angular-mocks": "^1.7.7", | 39 | "angular-mocks": "^1.7.8", |
| 40 | "angular-route": "^1.7.7", | 40 | "angular-route": "^1.7.7", |
| 41 | "bootstrap": "^4.1.3", | 41 | "bootstrap": "^4.1.3", |
| 42 | "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", | 42 | "foca-modal": "git+http://git.focasoftware.com/npm/foca-modal.git", |
| 43 | "font-awesome": "^4.7.0", | 43 | "font-awesome": "^4.7.0", |
| 44 | "gulp": "^3.9.1", | 44 | "gulp": "^3.9.1", |
| 45 | "gulp-angular-templatecache": "^2.2.5", | 45 | "gulp-angular-templatecache": "^2.2.5", |
| 46 | "gulp-clean": "^0.4.0", | 46 | "gulp-clean": "^0.4.0", |
| 47 | "gulp-connect": "^5.6.1", | 47 | "gulp-connect": "^5.6.1", |
| 48 | "gulp-footer": "^2.0.2", | 48 | "gulp-footer": "^2.0.2", |
| 49 | "gulp-header": "^2.0.7", | 49 | "gulp-header": "^2.0.7", |
| 50 | "gulp-htmlmin": "^5.0.1", | 50 | "gulp-htmlmin": "^5.0.1", |
| 51 | "gulp-jshint": "^2.1.0", | 51 | "gulp-jshint": "^2.1.0", |
| 52 | "gulp-rename": "^1.4.0", | 52 | "gulp-rename": "^1.4.0", |
| 53 | "gulp-replace": "^1.0.0", | 53 | "gulp-replace": "^1.0.0", |
| 54 | "gulp-uglify": "^3.0.1", | 54 | "gulp-uglify": "^3.0.1", |
| 55 | "gulp-uglify-es": "^1.0.4", | 55 | "gulp-uglify-es": "^1.0.4", |
| 56 | "jasmine": "^3.3.1", | 56 | "jasmine": "^3.3.1", |
| 57 | "jasmine-core": "^3.3.0", | 57 | "jasmine-core": "^3.3.0", |
| 58 | "jquery": "^3.3.1", | 58 | "jquery": "^3.3.1", |
| 59 | "jshint": "^2.9.6", | 59 | "jshint": "^2.9.6", |
| 60 | "pre-commit": "^1.2.2", | 60 | "pre-commit": "^1.2.2", |
| 61 | "pump": "^3.0.0", | 61 | "pump": "^3.0.0", |
| 62 | "ui-bootstrap4": "^3.0.5" | 62 | "ui-bootstrap4": "^3.0.5" |
| 63 | } | 63 | } |
| 64 | } | 64 | } |
| 65 | 65 |
spec/controllerSpec.js
| 1 | describe('Controladores abm vehículo', function() { | 1 | describe('Controladores abm vehículo', function() { |
| 2 | 2 | ||
| 3 | var $controller; | 3 | var $controller; |
| 4 | 4 | ||
| 5 | beforeEach(function() { | 5 | beforeEach(function() { |
| 6 | module('focaAbmVehiculo'); | 6 | module('focaAbmVehiculo'); |
| 7 | inject(function(_$controller_) { | 7 | inject(function(_$controller_) { |
| 8 | $controller = _$controller_; | 8 | $controller = _$controller_; |
| 9 | }); | 9 | }); |
| 10 | }); | 10 | }); |
| 11 | 11 | ||
| 12 | describe('Controlador focaAbmVehiculosController', function() { | 12 | describe('Controlador focaAbmVehiculosController', function() { |
| 13 | 13 | ||
| 14 | it('Existe el controller focaAbmVehiculosController', function() { | 14 | it('Existe el controller focaAbmVehiculosController', function() { |
| 15 | //arrange | 15 | //arrange |
| 16 | var controller = $controller('focaAbmVehiculosController', { | 16 | var controller = $controller('focaAbmVehiculosController', { |
| 17 | $scope: {}, | 17 | $scope: {}, |
| 18 | focaAbmVehiculoService: { | 18 | focaAbmVehiculoService: { |
| 19 | cleanCisternas: function() { return;}, | 19 | cleanCisternas: function() { return;}, |
| 20 | transportistaSeleccionado: {} | 20 | transportistaSeleccionado: {} |
| 21 | }, | 21 | }, |
| 22 | $location: {}, | 22 | $location: {}, |
| 23 | focaModalService: {}, | 23 | focaModalService: {}, |
| 24 | $uibModal: {}, | 24 | $uibModal: {}, |
| 25 | focaBotoneraLateralService: { | 25 | focaBotoneraLateralService: { |
| 26 | showSalir: function() { return; }, | 26 | showSalir: function() { return; }, |
| 27 | showPausar: function() { return; }, | 27 | showPausar: function() { return; }, |
| 28 | showCancelar: function() { return; }, | 28 | showCancelar: function() { return; }, |
| 29 | showGuardar: function() { return; }, | 29 | showGuardar: function() { return; }, |
| 30 | addCustomButton: function() { return; } | 30 | addCustomButton: function() { return; } |
| 31 | }, | 31 | }, |
| 32 | $localStorage: {}, | ||
| 32 | $timeout: {} | 33 | $timeout: {} |
| 33 | }); | 34 | }); |
| 34 | 35 | ||
| 35 | //assert | 36 | //assert |
| 36 | expect(typeof controller).toEqual('object'); | 37 | expect(typeof controller).toEqual('object'); |
| 37 | }); | 38 | }); |
| 38 | 39 | ||
| 39 | it('Crea fecha nueva', function() { | 40 | it('Crea fecha nueva', function() { |
| 40 | //arrange | 41 | //arrange |
| 41 | var scope = {}; | 42 | var scope = { |
| 43 | $watch: function() {} | ||
| 44 | }; | ||
| 42 | var controller = $controller('focaAbmVehiculosController', { | 45 | var controller = $controller('focaAbmVehiculosController', { |
| 43 | $scope: scope, | 46 | $scope: scope, |
| 44 | focaAbmVehiculoService: { | 47 | focaAbmVehiculoService: { |
| 45 | cleanCisternas: function() { return;}, | 48 | cleanCisternas: function() { return;}, |
| 46 | transportistaSeleccionado: {} | 49 | transportistaSeleccionado: {} |
| 47 | }, | 50 | }, |
| 48 | $location: {}, | 51 | $location: {}, |
| 49 | focaModalService: {}, | 52 | focaModalService: {}, |
| 50 | $uibModal: {}, | 53 | $uibModal: {}, |
| 51 | focaBotoneraLateralService: { | 54 | focaBotoneraLateralService: { |
| 52 | showSalir: function() { return; }, | 55 | showSalir: function() { return; }, |
| 53 | showPausar: function() { return; }, | 56 | showPausar: function() { return; }, |
| 54 | showCancelar: function() { return; }, | 57 | showCancelar: function() { return; }, |
| 55 | showGuardar: function() { return; }, | 58 | showGuardar: function() { return; }, |
| 56 | addCustomButton: function() { return; } | 59 | addCustomButton: function() { return; } |
| 57 | }, | 60 | }, |
| 61 | $localStorage: {}, | ||
| 58 | $timeout: {} | 62 | $timeout: {} |
| 59 | }); | 63 | }); |
| 60 | 64 | ||
| 61 | //act | 65 | //act |
| 62 | var date = scope.now; | 66 | var date = scope.now; |
| 63 | 67 | ||
| 64 | //assert | 68 | //assert |
| 65 | expect(angular.isDate(date)).toBe(true); | 69 | expect(angular.isDate(date)).toBe(true); |
| 66 | }); | 70 | }); |
| 67 | 71 | ||
| 68 | it('$scope setea botonera lateral', function() { | 72 | it('$scope setea botonera lateral', function() { |
| 69 | //arrange | 73 | //arrange |
| 70 | var scope = {}; | 74 | var scope = { |
| 75 | $watch: function() {} | ||
| 76 | }; | ||
| 71 | var controller = $controller('focaAbmVehiculosController', { | 77 | var controller = $controller('focaAbmVehiculosController', { |
| 72 | $scope: scope, | 78 | $scope: scope, |
| 73 | focaAbmVehiculoService: { | 79 | focaAbmVehiculoService: { |
| 74 | cleanCisternas: function() { return;}, | 80 | cleanCisternas: function() { return;}, |
| 75 | transportistaSeleccionado: {} | 81 | transportistaSeleccionado: {} |
| 76 | }, | 82 | }, |
| 77 | $location: {}, | 83 | $location: {}, |
| 78 | focaModalService: {}, | 84 | focaModalService: {}, |
| 79 | $uibModal: {}, | 85 | $uibModal: {}, |
| 80 | focaBotoneraLateralService: { | 86 | focaBotoneraLateralService: { |
| 81 | showSalir: function() { return; }, | 87 | showSalir: function() { return; }, |
| 82 | showPausar: function() { return; }, | 88 | showPausar: function() { return; }, |
| 83 | showCancelar: function() { return; }, | 89 | showCancelar: function() { return; }, |
| 84 | showGuardar: function() { return; }, | 90 | showGuardar: function() { return; }, |
| 85 | addCustomButton: function() { return; } | 91 | addCustomButton: function() { return; } |
| 86 | }, | 92 | }, |
| 87 | $timeout: {} | 93 | $timeout: {}, |
| 94 | $localStorage: {} | ||
| 88 | }); | 95 | }); |
| 89 | 96 | ||
| 90 | //act | 97 | //act |
| 91 | var botonera = scope.botonera; | 98 | var botonera = scope.botonera; |
| 92 | 99 | ||
| 93 | //assert | 100 | //assert |
| 94 | expect(angular.isArray(botonera)).toBe(true); | 101 | expect(angular.isArray(botonera)).toBe(true); |
| 95 | }); | 102 | }); |
| 96 | 103 | ||
| 97 | it('$scope.editar lleva a la ruta correcta', function() { | 104 | it('$scope.editar lleva a la ruta correcta', function() { |
| 98 | inject(function($location) { | 105 | inject(function($location) { |
| 99 | //arrange | 106 | //arrange |
| 100 | var scope = {}; | 107 | var scope = { |
| 108 | $watch: function() {} | ||
| 109 | }; | ||
| 101 | var controller = $controller('focaAbmVehiculosController', { | 110 | var controller = $controller('focaAbmVehiculosController', { |
| 102 | $scope: scope, | 111 | $scope: scope, |
| 103 | focaAbmVehiculoService: { | 112 | focaAbmVehiculoService: { |
| 104 | cleanCisternas: function() { return;}, | 113 | cleanCisternas: function() { return;}, |
| 105 | transportistaSeleccionado: {} | 114 | transportistaSeleccionado: {} |
| 106 | }, | 115 | }, |
| 107 | $location: $location, | 116 | $location: $location, |
| 108 | focaModalService: {}, | 117 | focaModalService: {}, |
| 109 | $uibModal: {}, | 118 | $uibModal: {}, |
| 110 | focaBotoneraLateralService: { | 119 | focaBotoneraLateralService: { |
| 111 | showSalir: function() { return; }, | 120 | showSalir: function() { return; }, |
| 112 | showPausar: function() { return; }, | 121 | showPausar: function() { return; }, |
| 113 | showCancelar: function() { return; }, | 122 | showCancelar: function() { return; }, |
| 114 | showGuardar: function() { return; }, | 123 | showGuardar: function() { return; }, |
| 115 | addCustomButton: function() { return; } | 124 | addCustomButton: function() { return; } |
| 116 | }, | 125 | }, |
| 117 | $timeout: {} | 126 | $timeout: {}, |
| 127 | $localStorage: {} | ||
| 118 | }); | 128 | }); |
| 119 | 129 | ||
| 120 | //act | 130 | //act |
| 121 | scope.editar(1); | 131 | scope.editar(1); |
| 122 | var esperado = '/vehiculo/' + 1 + '/' + scope.idTransportista; | 132 | var esperado = '/vehiculo/' + 1 + '/' + scope.idTransportista; |
| 123 | 133 | ||
| 124 | //assert | 134 | //assert |
| 125 | expect($location.url()).toEqual(esperado); | 135 | expect($location.url()).toEqual(esperado); |
| 126 | }); | 136 | }); |
| 127 | }); | 137 | }); |
| 128 | 138 | ||
| 129 | it('Solicita confirmacion', function() { | 139 | it('Solicita confirmacion', function() { |
| 130 | //arrange | 140 | //arrange |
| 131 | var scope = {}; | 141 | var scope = { |
| 142 | $watch: function() {} | ||
| 143 | }; | ||
| 132 | var focaModalService = { | 144 | var focaModalService = { |
| 133 | confirm: function() {} | 145 | confirm: function() {} |
| 134 | }; | 146 | }; |
| 135 | var controller = $controller('focaAbmVehiculosController', { | 147 | var controller = $controller('focaAbmVehiculosController', { |
| 136 | $scope: scope, | 148 | $scope: scope, |
| 137 | focaAbmVehiculoService: { | 149 | focaAbmVehiculoService: { |
| 138 | cleanCisternas: function() { return;}, | 150 | cleanCisternas: function() { return;}, |
| 139 | transportistaSeleccionado: {} | 151 | transportistaSeleccionado: {} |
| 140 | }, | 152 | }, |
| 141 | $location: {}, | 153 | $location: {}, |
| 142 | focaModalService: focaModalService, | 154 | focaModalService: focaModalService, |
| 143 | $uibModal: {}, | 155 | $uibModal: {}, |
| 144 | focaBotoneraLateralService: { | 156 | focaBotoneraLateralService: { |
| 145 | showSalir: function() { return; }, | 157 | showSalir: function() { return; }, |
| 146 | showPausar: function() { return; }, | 158 | showPausar: function() { return; }, |
| 147 | showCancelar: function() { return; }, | 159 | showCancelar: function() { return; }, |
| 148 | showGuardar: function() { return; }, | 160 | showGuardar: function() { return; }, |
| 149 | addCustomButton: function() { return; } | 161 | addCustomButton: function() { return; } |
| 150 | }, | 162 | }, |
| 151 | $timeout: {} | 163 | $timeout: {}, |
| 164 | $localStorage: {} | ||
| 152 | }); | 165 | }); |
| 153 | 166 | ||
| 154 | //act | 167 | //act |
| 155 | spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); | 168 | spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); |
| 156 | scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); | 169 | scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); |
| 157 | 170 | ||
| 158 | //assert | 171 | //assert |
| 159 | expect(focaModalService.confirm).toHaveBeenCalled(); | 172 | expect(focaModalService.confirm).toHaveBeenCalled(); |
| 160 | }); | 173 | }); |
| 161 | 174 | ||
| 162 | it('Elimina vehículo al confirmar', function(done) { | 175 | it('Elimina vehículo al confirmar', function(done) { |
| 163 | 176 | ||
| 164 | //arrange | 177 | //arrange |
| 165 | var scope = { | 178 | var scope = { |
| 166 | vehiculos: [] | 179 | vehiculos: [] |
| 167 | }; | 180 | }; |
| 168 | var focaModalService = { | 181 | var focaModalService = { |
| 169 | confirm: function() { return; } | 182 | confirm: function() { return; } |
| 170 | }; | 183 | }; |
| 171 | var focaAbmVehiculoService = { | 184 | var focaAbmVehiculoService = { |
| 172 | cleanCisternas: function() { return;}, | 185 | cleanCisternas: function() { return;}, |
| 173 | transportistaSeleccionado: {}, | 186 | transportistaSeleccionado: {}, |
| 174 | deleteVehiculo: function() { return; } | 187 | deleteVehiculo: function() { return; } |
| 175 | }; | 188 | }; |
| 176 | var controller = $controller('focaAbmVehiculosController', { | 189 | var controller = $controller('focaAbmVehiculosController', { |
| 177 | $scope: scope, | 190 | $scope: scope, |
| 178 | focaAbmVehiculoService: focaAbmVehiculoService, | 191 | focaAbmVehiculoService: focaAbmVehiculoService, |
| 179 | $location: {}, | 192 | $location: {}, |
| 180 | focaModalService: focaModalService, | 193 | focaModalService: focaModalService, |
| 181 | $uibModal: {}, | 194 | $uibModal: {}, |
| 182 | focaBotoneraLateralService: { | 195 | focaBotoneraLateralService: { |
| 183 | showSalir: function() { return; }, | 196 | showSalir: function() { return; }, |
| 184 | showPausar: function() { return; }, | 197 | showPausar: function() { return; }, |
| 185 | showCancelar: function() { return; }, | 198 | showCancelar: function() { return; }, |
| 186 | showGuardar: function() { return; }, | 199 | showGuardar: function() { return; }, |
| 187 | addCustomButton: function() { return; } | 200 | addCustomButton: function() { return; } |
| 188 | }, | 201 | }, |
| 189 | $timeout: {} | 202 | $timeout: {}, |
| 203 | $localStorage: {} | ||
| 190 | }); | 204 | }); |
| 191 | var promesa = Promise.resolve(true); | 205 | var promesa = Promise.resolve(true); |
| 192 | 206 | ||
| 193 | //act | 207 | //act |
| 194 | spyOn(focaModalService, 'confirm').and.returnValue(promesa); | 208 | spyOn(focaModalService, 'confirm').and.returnValue(promesa); |
| 195 | spyOn(focaAbmVehiculoService, 'deleteVehiculo'); | 209 | spyOn(focaAbmVehiculoService, 'deleteVehiculo'); |
| 196 | scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); | 210 | scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); |
| 197 | 211 | ||
| 198 | //assert | 212 | //assert |
| 199 | promesa.then( | 213 | promesa.then( |
| 200 | function() { | 214 | function() { |
| 201 | expect(focaAbmVehiculoService.deleteVehiculo).toHaveBeenCalled(); | 215 | expect(focaAbmVehiculoService.deleteVehiculo).toHaveBeenCalled(); |
| 202 | done(); | 216 | done(); |
| 203 | } | 217 | } |
| 204 | ); | 218 | ); |
| 205 | }); | 219 | }); |
| 206 | 220 | ||
| 207 | it('Se selecciona transportista', function() { | 221 | it('Se selecciona transportista', function() { |
| 208 | //arrange | 222 | //arrange |
| 209 | var scope = {}; | 223 | var scope = { |
| 224 | $watch: function() {} | ||
| 225 | }; | ||
| 210 | var focaModalService = { | 226 | var focaModalService = { |
| 211 | modal: function() {} | 227 | modal: function() {} |
| 212 | }; | 228 | }; |
| 213 | var controller = $controller('focaAbmVehiculosController', { | 229 | var controller = $controller('focaAbmVehiculosController', { |
| 214 | $scope: scope, | 230 | $scope: scope, |
| 215 | focaAbmVehiculoService: { | 231 | focaAbmVehiculoService: { |
| 216 | cleanCisternas: function() { return;}, | 232 | cleanCisternas: function() { return;}, |
| 217 | transportistaSeleccionado: {} | 233 | transportistaSeleccionado: {} |
| 218 | }, | 234 | }, |
| 219 | $location: {}, | 235 | $location: {}, |
| 220 | focaModalService: focaModalService, | 236 | focaModalService: focaModalService, |
| 221 | $uibModal: {}, | 237 | $uibModal: {}, |
| 222 | focaBotoneraLateralService: { | 238 | focaBotoneraLateralService: { |
| 223 | showSalir: function() { return; }, | 239 | showSalir: function() { return; }, |
| 224 | showPausar: function() { return; }, | 240 | showPausar: function() { return; }, |
| 225 | showCancelar: function() { return; }, | 241 | showCancelar: function() { return; }, |
| 226 | showGuardar: function() { return; }, | 242 | showGuardar: function() { return; }, |
| 227 | addCustomButton: function() { return; } | 243 | addCustomButton: function() { return; } |
| 228 | }, | 244 | }, |
| 229 | $timeout: {} | 245 | $timeout: {}, |
| 246 | $localStorage: {} | ||
| 230 | }); | 247 | }); |
| 231 | 248 | ||
| 232 | //act | 249 | //act |
| 233 | spyOn(focaModalService, 'modal').and.returnValue({then: function() {}}); | 250 | spyOn(focaModalService, 'modal').and.returnValue({then: function() {}}); |
| 234 | scope.seleccionarTransportista(); | 251 | scope.seleccionarTransportista(); |
| 235 | 252 | ||
| 236 | //assert | 253 | //assert |
| 237 | expect(focaModalService.modal).toHaveBeenCalled(); | 254 | expect(focaModalService.modal).toHaveBeenCalled(); |
| 238 | }); | 255 | }); |
| 239 | 256 | ||
| 240 | it('Se setea el transportista seleccionado al service', function(done) { | 257 | it('Se setea el transportista seleccionado al service', function(done) { |
| 241 | inject(function($timeout) { | 258 | inject(function($timeout) { |
| 242 | 259 | ||
| 243 | //arrange | 260 | //arrange |
| 244 | var scope = {}; | 261 | var scope = { |
| 262 | $watch: function() {} | ||
| 263 | }; | ||
| 245 | var focaModalService = { | 264 | var focaModalService = { |
| 246 | modal: function() { return; } | 265 | modal: function() { return; } |
| 247 | }; | 266 | }; |
| 248 | var focaAbmVehiculoService = { | 267 | var focaAbmVehiculoService = { |
| 249 | cleanCisternas: function() { return;}, | 268 | cleanCisternas: function() { return;}, |
| 250 | transportistaSeleccionado: {}, | 269 | transportistaSeleccionado: {}, |
| 251 | deleteVehiculo: function() { return; }, | 270 | deleteVehiculo: function() { return; }, |
| 252 | getVehiculosPorTransportista: function() { | 271 | getVehiculosPorTransportista: function() { |
| 253 | return { | 272 | return { |
| 254 | then: function() { return; } | 273 | then: function() { return; } |
| 255 | }; | 274 | }; |
| 256 | } | 275 | } |
| 257 | }; | 276 | }; |
| 258 | var controller = $controller('focaAbmVehiculosController', { | 277 | var controller = $controller('focaAbmVehiculosController', { |
| 259 | $scope: scope, | 278 | $scope: scope, |
| 260 | focaAbmVehiculoService: focaAbmVehiculoService, | 279 | focaAbmVehiculoService: focaAbmVehiculoService, |
| 261 | $location: {}, | 280 | $location: {}, |
| 262 | focaModalService: focaModalService, | 281 | focaModalService: focaModalService, |
| 263 | $uibModal: {}, | 282 | $uibModal: {}, |
| 264 | focaBotoneraLateralService: { | 283 | focaBotoneraLateralService: { |
| 265 | showSalir: function() { return; }, | 284 | showSalir: function() { return; }, |
| 266 | showPausar: function() { return; }, | 285 | showPausar: function() { return; }, |
| 267 | showCancelar: function() { return; }, | 286 | showCancelar: function() { return; }, |
| 268 | showGuardar: function() { return; }, | 287 | showGuardar: function() { return; }, |
| 269 | addCustomButton: function() { return; } | 288 | addCustomButton: function() { return; } |
| 270 | }, | 289 | }, |
| 290 | $localStorage: {}, | ||
| 271 | $timeout: $timeout | 291 | $timeout: $timeout |
| 272 | }); | 292 | }); |
| 273 | var promesa = Promise.resolve({COD: '', NOM: ''}); | 293 | var promesa = Promise.resolve({COD: '', NOM: ''}); |
| 274 | 294 | ||
| 275 | //act | 295 | //act |
| 276 | spyOn(focaModalService, 'modal').and.returnValue(promesa); | 296 | spyOn(focaModalService, 'modal').and.returnValue(promesa); |
| 277 | scope.seleccionarTransportista(); | 297 | scope.seleccionarTransportista(); |
| 278 | 298 | ||
| 279 | //assert | 299 | //assert |
| 280 | promesa.then( | 300 | promesa.then( |
| 281 | function() { | 301 | function() { |
| 282 | expect(focaAbmVehiculoService.transportistaSeleccionado) | 302 | expect(focaAbmVehiculoService.transportistaSeleccionado) |
| 283 | .toEqual(jasmine.objectContaining({ | 303 | .toEqual(jasmine.objectContaining({ |
| 284 | COD: '', NOM: '' | 304 | COD: '', NOM: '' |
| 285 | })); | 305 | })); |
| 286 | done(); | 306 | done(); |
| 287 | } | 307 | } |
| 288 | ); | 308 | ); |
| 289 | }); | 309 | }); |
| 290 | }); | 310 | }); |
| 291 | }); | 311 | }); |
| 292 | 312 | ||
| 293 | describe('Controlador focaAbmVehiculoController', function() { | 313 | describe('Controlador focaAbmVehiculoController', function() { |
| 294 | 314 | ||
| 295 | var $timeout; | 315 | var $timeout; |
| 296 | beforeEach(inject(function(_$timeout_) { | 316 | beforeEach(inject(function(_$timeout_) { |
| 297 | $timeout = _$timeout_; | 317 | $timeout = _$timeout_; |
| 298 | })); | 318 | })); |
| 299 | 319 | ||
| 300 | it('Existe el controller focaAbmVehiculoController', function() { | 320 | it('Existe el controller focaAbmVehiculoController', function() { |
| 301 | 321 | ||
| 302 | //arrange | 322 | //arrange |
| 303 | var controller = $controller('focaAbmVehiculoController', { | 323 | var controller = $controller('focaAbmVehiculoController', { |
| 304 | $scope: {}, | 324 | $scope: { |
| 325 | $watch: function() {} | ||
| 326 | }, | ||
| 305 | focaAbmVehiculoService: { | 327 | focaAbmVehiculoService: { |
| 306 | getVehiculo: function() { | 328 | getVehiculo: function() { |
| 307 | return { | 329 | return { |
| 308 | then: function() { return; } | 330 | then: function() { return; } |
| 309 | }; | 331 | }; |
| 310 | } | 332 | } |
| 311 | }, | 333 | }, |
| 312 | $routeParams: {}, | 334 | $routeParams: {}, |
| 313 | $location: {}, | 335 | $location: {}, |
| 314 | $uibModal: {}, | 336 | $uibModal: {}, |
| 315 | focaModalService: {}, | 337 | focaModalService: {}, |
| 316 | $timeout: $timeout, | 338 | $timeout: $timeout, |
| 317 | focaBotoneraLateralService: { | 339 | focaBotoneraLateralService: { |
| 318 | showSalir: function() { return; }, | 340 | showSalir: function() { return; }, |
| 319 | showPausar: function() { return; }, | 341 | showPausar: function() { return; }, |
| 320 | showCancelar: function() { return; }, | 342 | showCancelar: function() { return; }, |
| 321 | showGuardar: function() { return; }, | 343 | showGuardar: function() { return; }, |
| 322 | addCustomButton: function() { return; } | 344 | addCustomButton: function() { return; } |
| 323 | }, | 345 | }, |
| 346 | $localStorage: {}, | ||
| 324 | $window: {} | 347 | $window: {} |
| 325 | }); | 348 | }); |
| 326 | 349 | ||
| 327 | //assert | 350 | //assert |
| 328 | expect(typeof controller).toEqual('object'); | 351 | expect(typeof controller).toEqual('object'); |
| 329 | 352 | ||
| 330 | }); | 353 | }); |
| 331 | 354 | ||
| 332 | it('Se busca el transportista cuando es nuevo', function() { | 355 | it('Se busca el transportista cuando es nuevo', function() { |
| 333 | 356 | ||
| 334 | //arrange | 357 | //arrange |
| 335 | var scope = {}; | 358 | var scope = { |
| 359 | $watch: function() {} | ||
| 360 | }; | ||
| 336 | var focaAbmVehiculoService = { | 361 | var focaAbmVehiculoService = { |
| 337 | getVehiculo: function() { | 362 | getVehiculo: function() { |
| 338 | return { | 363 | return { |
| 339 | then: function() { return; } | 364 | then: function() { return; } |
| 340 | }; | 365 | }; |
| 341 | }, | 366 | }, |
| 342 | getTransportistaPorId: function() { return; } | 367 | getTransportistaPorId: function() { return; } |
| 343 | }; | 368 | }; |
| 344 | 369 | ||
| 345 | spyOn(focaAbmVehiculoService, 'getTransportistaPorId') | 370 | spyOn(focaAbmVehiculoService, 'getTransportistaPorId') |
| 346 | .and.returnValue({then: function() { return; }}); | 371 | .and.returnValue({then: function() { return; }}); |
| 347 | 372 | ||
| 348 | //act | 373 | //act |
| 349 | var controller = $controller('focaAbmVehiculoController', { | 374 | var controller = $controller('focaAbmVehiculoController', { |
| 350 | $scope: scope, | 375 | $scope: scope, |
| 351 | focaAbmVehiculoService: focaAbmVehiculoService, | 376 | focaAbmVehiculoService: focaAbmVehiculoService, |
| 352 | $routeParams: { | 377 | $routeParams: { |
| 353 | idVehiculo: '0' | 378 | idVehiculo: '0' |
| 354 | }, | 379 | }, |
| 355 | $location: {}, | 380 | $location: {}, |
| 356 | $uibModal: {}, | 381 | $uibModal: {}, |
| 357 | focaModalService: {}, | 382 | focaModalService: {}, |
| 358 | $timeout: $timeout, | 383 | $timeout: $timeout, |
| 359 | focaBotoneraLateralService: { | 384 | focaBotoneraLateralService: { |
| 360 | showSalir: function() { return; }, | 385 | showSalir: function() { return; }, |
| 361 | showPausar: function() { return; }, | 386 | showPausar: function() { return; }, |
| 362 | showCancelar: function() { return; }, | 387 | showCancelar: function() { return; }, |
| 363 | showGuardar: function() { return; }, | 388 | showGuardar: function() { return; }, |
| 364 | addCustomButton: function() { return; } | 389 | addCustomButton: function() { return; } |
| 365 | }, | 390 | }, |
| 391 | $localStorage: {}, | ||
| 366 | $window: {} | 392 | $window: {} |
| 367 | }); | 393 | }); |
| 368 | 394 | ||
| 369 | //assert | 395 | //assert |
| 370 | expect(focaAbmVehiculoService.getTransportistaPorId).toHaveBeenCalled(); | 396 | expect(focaAbmVehiculoService.getTransportistaPorId).toHaveBeenCalled(); |
| 371 | }); | 397 | }); |
| 372 | 398 | ||
| 373 | it('No se busca el transportista cuando es nuevo', function() { | 399 | it('No se busca el transportista cuando es nuevo', function() { |
| 374 | 400 | ||
| 375 | //arrange | 401 | //arrange |
| 376 | var scope = {}; | 402 | var scope = { |
| 403 | $watch: function() {} | ||
| 404 | }; | ||
| 377 | var focaAbmVehiculoService = { | 405 | var focaAbmVehiculoService = { |
| 378 | getVehiculo: function() { | 406 | getVehiculo: function() { |
| 379 | return { | 407 | return { |
| 380 | then: function() { return; } | 408 | then: function() { return; } |
| 381 | }; | 409 | }; |
| 382 | }, | 410 | }, |
| 383 | getTransportistaPorId: function() { return; } | 411 | getTransportistaPorId: function() { return; } |
| 384 | }; | 412 | }; |
| 385 | 413 | ||
| 386 | spyOn(focaAbmVehiculoService, 'getTransportistaPorId') | 414 | spyOn(focaAbmVehiculoService, 'getTransportistaPorId') |
| 387 | .and.returnValue({then: function() { return; }}); | 415 | .and.returnValue({then: function() { return; }}); |
| 388 | 416 | ||
| 389 | //act | 417 | //act |
| 390 | var controller = $controller('focaAbmVehiculoController', { | 418 | var controller = $controller('focaAbmVehiculoController', { |
| 391 | $scope: scope, | 419 | $scope: scope, |
| 392 | focaAbmVehiculoService: focaAbmVehiculoService, | 420 | focaAbmVehiculoService: focaAbmVehiculoService, |
| 393 | $routeParams: {}, | 421 | $routeParams: {}, |
| 394 | $location: {}, | 422 | $location: {}, |
| 395 | $uibModal: {}, | 423 | $uibModal: {}, |
| 396 | focaModalService: {}, | 424 | focaModalService: {}, |
| 397 | $timeout: $timeout, | 425 | $timeout: $timeout, |
| 398 | focaBotoneraLateralService: { | 426 | focaBotoneraLateralService: { |
| 399 | showSalir: function() { return; }, | 427 | showSalir: function() { return; }, |
| 400 | showPausar: function() { return; }, | 428 | showPausar: function() { return; }, |
| 401 | showCancelar: function() { return; }, | 429 | showCancelar: function() { return; }, |
| 402 | showGuardar: function() { return; }, | 430 | showGuardar: function() { return; }, |
| 403 | addCustomButton: function() { return; } | 431 | addCustomButton: function() { return; } |
| 404 | }, | 432 | }, |
| 433 | $localStorage: {}, | ||
| 405 | $window: {} | 434 | $window: {} |
| 406 | }); | 435 | }); |
| 407 | 436 | ||
| 408 | //assert | 437 | //assert |
| 409 | expect(focaAbmVehiculoService.getTransportistaPorId).not.toHaveBeenCalled(); | 438 | expect(focaAbmVehiculoService.getTransportistaPorId).not.toHaveBeenCalled(); |
| 410 | }); | 439 | }); |
| 411 | 440 | ||
| 412 | it('Cancelar lleva a la ruta /vehiculo', function() { | 441 | it('Cancelar lleva a la ruta /vehiculo', function() { |
| 413 | 442 | ||
| 414 | inject(function($location) { | 443 | inject(function($location) { |
| 415 | //arrange | 444 | //arrange |
| 416 | var scope = {}; | 445 | var scope = { |
| 446 | $watch: function() {}, | ||
| 447 | cancelar: function() {}, | ||
| 448 | formVehiculo: { | ||
| 449 | $pristine: true | ||
| 450 | } | ||
| 451 | }; | ||
| 417 | var controller = $controller('focaAbmVehiculoController', { | 452 | var controller = $controller('focaAbmVehiculoController', { |
| 418 | $scope: scope, | 453 | $scope: scope, |
| 419 | focaAbmVehiculoService: { | 454 | focaAbmVehiculoService: { |
| 420 | getVehiculo: function() { | 455 | getVehiculo: function() { |
| 421 | return { | 456 | return { |
| 422 | then: function() { return; } | 457 | then: function() { return; } |
| 423 | }; | 458 | }; |
| 424 | } | 459 | } |
| 425 | }, | 460 | }, |
| 426 | $routeParams: {}, | 461 | $routeParams: {}, |
| 427 | $location: $location, | 462 | $location: $location, |
| 428 | $uibModal: {}, | 463 | $uibModal: {}, |
| 429 | focaModalService: {}, | 464 | focaModalService: {}, |
| 430 | $timeout: $timeout, | 465 | $timeout: $timeout, |
| 431 | focaBotoneraLateralService: { | 466 | focaBotoneraLateralService: { |
| 432 | showSalir: function() { return; }, | 467 | showSalir: function() { return; }, |
| 433 | showPausar: function() { return; }, | 468 | showPausar: function() { return; }, |
| 434 | showCancelar: function() { return; }, | 469 | showCancelar: function() { return; }, |
| 435 | showGuardar: function() { return; }, | 470 | showGuardar: function() { return; }, |
| 436 | addCustomButton: function() { return; } | 471 | addCustomButton: function() { return; } |
| 437 | }, | 472 | }, |
| 438 | $window: {} | 473 | $localStorage: {}, |
| 474 | $window: {}, | ||
| 475 | |||
| 439 | }); | 476 | }); |
| 440 | 477 | ||
| 441 | //act | 478 | //act |
| 442 | scope.cancelar(); | 479 | scope.salir(); |
| 443 | 480 | ||
| 444 | //assert | 481 | //assert |
| 445 | expect($location.url()).toEqual('/vehiculo'); | 482 | expect($location.url()).toEqual('/vehiculo'); |
| 446 | }); | 483 | }); |
| 447 | }); | 484 | }); |
| 448 | 485 | ||
| 449 | it('Editar lleva a la ruta correcta cuando recibe variable key', function() { | 486 | it('Editar lleva a la ruta correcta cuando recibe variable key', function() { |
| 450 | 487 | ||
| 451 | inject(function($location) { | 488 | inject(function($location) { |
| 452 | //arrange | 489 | //arrange |
| 453 | var scope = {}; | 490 | var scope = { |
| 491 | $watch: function() {} | ||
| 492 | }; | ||
| 454 | var controller = $controller('focaAbmVehiculoController', { | 493 | var controller = $controller('focaAbmVehiculoController', { |
| 455 | $scope: scope, | 494 | $scope: scope, |
| 456 | focaAbmVehiculoService: { | 495 | focaAbmVehiculoService: { |
| 457 | getVehiculo: function() { | 496 | getVehiculo: function() { |
| 458 | return { | 497 | return { |
| 459 | then: function() { return; } | 498 | then: function() { return; } |
| 460 | }; | 499 | }; |
| 461 | } | 500 | } |
| 462 | }, | 501 | }, |
| 463 | $routeParams: { | 502 | $routeParams: { |
| 464 | idVehiculo: 1 | 503 | idVehiculo: 1 |
| 465 | }, | 504 | }, |
| 466 | $location: $location, | 505 | $location: $location, |
| 467 | $uibModal: {}, | 506 | $uibModal: {}, |
| 468 | focaModalService: {}, | 507 | focaModalService: {}, |
| 469 | $timeout: $timeout, | 508 | $timeout: $timeout, |
| 470 | focaBotoneraLateralService: { | 509 | focaBotoneraLateralService: { |
| 471 | showSalir: function() { return; }, | 510 | showSalir: function() { return; }, |
| 472 | showPausar: function() { return; }, | 511 | showPausar: function() { return; }, |
| 473 | showCancelar: function() { return; }, | 512 | showCancelar: function() { return; }, |
| 474 | showGuardar: function() { return; }, | 513 | showGuardar: function() { return; }, |
| 475 | addCustomButton: function() { return; } | 514 | addCustomButton: function() { return; } |
| 476 | }, | 515 | }, |
| 516 | $localStorage: {}, | ||
| 477 | $window: {} | 517 | $window: {} |
| 478 | }); | 518 | }); |
| 479 | 519 | ||
| 480 | //act | 520 | //act |
| 481 | scope.editar('testing'); | 521 | scope.editar('testing'); |
| 482 | var esperado = '/vehiculo/1/cisterna/testing'; | 522 | var esperado = '/vehiculo/1/cisterna/testing'; |
| 483 | 523 | ||
| 484 | //assert | 524 | //assert |
| 485 | expect($location.url()).toEqual(esperado); | 525 | expect($location.url()).toEqual(esperado); |
| 486 | }); | 526 | }); |
| 487 | }); | 527 | }); |
| 488 | 528 | ||
| 489 | it('Editar lleva a la ruta correcta cuando no recibe variable key', function() { | 529 | it('Editar lleva a la ruta correcta cuando no recibe variable key', function() { |
| 490 | 530 | ||
| 491 | inject(function($location) { | 531 | inject(function($location) { |
| 492 | //arrange | 532 | //arrange |
| 493 | var scope = {}; | 533 | var scope = { |
| 534 | $watch: function() {} | ||
| 535 | }; | ||
| 494 | var controller = $controller('focaAbmVehiculoController', { | 536 | var controller = $controller('focaAbmVehiculoController', { |
| 495 | $scope: scope, | 537 | $scope: scope, |
| 496 | focaAbmVehiculoService: { | 538 | focaAbmVehiculoService: { |
| 497 | getVehiculo: function() { | 539 | getVehiculo: function() { |
| 498 | return { | 540 | return { |
| 499 | then: function() { return; } | 541 | then: function() { return; } |
| 500 | }; | 542 | }; |
| 501 | } | 543 | } |
| 502 | }, | 544 | }, |
| 503 | $routeParams: { | 545 | $routeParams: { |
| 504 | idVehiculo: 1 | 546 | idVehiculo: 1 |
| 505 | }, | 547 | }, |
| 506 | $location: $location, | 548 | $location: $location, |
| 507 | $uibModal: {}, | 549 | $uibModal: {}, |
| 508 | focaModalService: {}, | 550 | focaModalService: {}, |
| 509 | $timeout: $timeout, | 551 | $timeout: $timeout, |
| 510 | focaBotoneraLateralService: { | 552 | focaBotoneraLateralService: { |
| 511 | showSalir: function() { return; }, | 553 | showSalir: function() { return; }, |
| 512 | showPausar: function() { return; }, | 554 | showPausar: function() { return; }, |
| 513 | showCancelar: function() { return; }, | 555 | showCancelar: function() { return; }, |
| 514 | showGuardar: function() { return; }, | 556 | showGuardar: function() { return; }, |
| 515 | addCustomButton: function() { return; } | 557 | addCustomButton: function() { return; } |
| 516 | }, | 558 | }, |
| 559 | $localStorage: {}, | ||
| 517 | $window: {} | 560 | $window: {} |
| 518 | }); | 561 | }); |
| 519 | 562 | ||
| 520 | //act | 563 | //act |
| 521 | scope.editar(); | 564 | scope.editar(); |
| 522 | var esperado = '/vehiculo/1/cisterna/0/'; | 565 | var esperado = '/vehiculo/1/cisterna/0/'; |
| 523 | 566 | ||
| 524 | //assert | 567 | //assert |
| 525 | expect($location.url()).toEqual(esperado); | 568 | expect($location.url()).toEqual(esperado); |
| 526 | }); | 569 | }); |
| 527 | }); | 570 | }); |
| 528 | 571 | ||
| 529 | it('$scope.solicitarConfirmacionCisterna ejecuta modal de confirmación', function() { | 572 | it('$scope.solicitarConfirmacionCisterna ejecuta modal de confirmación', function() { |
| 530 | 573 | ||
| 531 | //arrange | 574 | //arrange |
| 532 | var focaModalService = { | 575 | var focaModalService = { |
| 533 | confirm: function() {} | 576 | confirm: function() {} |
| 534 | }; | 577 | }; |
| 535 | var scope = {}; | 578 | var scope = { |
| 579 | $watch: function() {} | ||
| 580 | }; | ||
| 536 | var controller = $controller('focaAbmVehiculoController', { | 581 | var controller = $controller('focaAbmVehiculoController', { |
| 537 | $scope: scope, | 582 | $scope: scope, |
| 538 | focaAbmVehiculoService: { | 583 | focaAbmVehiculoService: { |
| 539 | getVehiculo: function() { | 584 | getVehiculo: function() { |
| 540 | return { | 585 | return { |
| 541 | then: function() { return; } | 586 | then: function() { return; } |
| 542 | }; | 587 | }; |
| 543 | } | 588 | } |
| 544 | }, | 589 | }, |
| 545 | $routeParams: { | 590 | $routeParams: { |
| 546 | idVehiculo: 1 | 591 | idVehiculo: 1 |
| 547 | }, | 592 | }, |
| 548 | $location: {}, | 593 | $location: {}, |
| 549 | $uibModal: {}, | 594 | $uibModal: {}, |
| 550 | focaModalService: focaModalService, | 595 | focaModalService: focaModalService, |
| 551 | $timeout: $timeout, | 596 | $timeout: $timeout, |
| 552 | focaBotoneraLateralService: { | 597 | focaBotoneraLateralService: { |
| 553 | showSalir: function() { return; }, | 598 | showSalir: function() { return; }, |
| 554 | showPausar: function() { return; }, | 599 | showPausar: function() { return; }, |
| 555 | showCancelar: function() { return; }, | 600 | showCancelar: function() { return; }, |
| 556 | showGuardar: function() { return; }, | 601 | showGuardar: function() { return; }, |
| 557 | addCustomButton: function() { return; } | 602 | addCustomButton: function() { return; } |
| 558 | }, | 603 | }, |
| 604 | $localStorage: {}, | ||
| 559 | $window: {} | 605 | $window: {} |
| 560 | }); | 606 | }); |
| 561 | 607 | ||
| 562 | //act | 608 | //act |
| 563 | spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); | 609 | spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); |
| 564 | scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); | 610 | scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); |
| 565 | 611 | ||
| 566 | //assert | 612 | //assert |
| 567 | expect(focaModalService.confirm).toHaveBeenCalled(); | 613 | expect(focaModalService.confirm).toHaveBeenCalled(); |
| 568 | }); | 614 | }); |
| 569 | 615 | ||
| 570 | it('Elimina y obtiene cisternas al dar confirmar', function(done) { | 616 | it('Elimina y obtiene cisternas al dar confirmar', function(done) { |
| 571 | 617 | ||
| 572 | //arrange | 618 | //arrange |
| 573 | var scope = {}; | 619 | var scope = { |
| 620 | $watch: function() {} | ||
| 621 | }; | ||
| 574 | var focaModalService = { | 622 | var focaModalService = { |
| 575 | confirm: function() {} | 623 | confirm: function() {} |
| 576 | }; | 624 | }; |
| 577 | var focaAbmVehiculoService = { | 625 | var focaAbmVehiculoService = { |
| 578 | getVehiculo: function() { | 626 | getVehiculo: function() { |
| 579 | return { | 627 | return { |
| 580 | then: function() { return; } | 628 | then: function() { return; } |
| 581 | }; | 629 | }; |
| 582 | }, | 630 | }, |
| 583 | getCisternas: function() { return; }, | 631 | getCisternas: function() { return; }, |
| 584 | deleteCisterna: function() { return; } | 632 | deleteCisterna: function() { return; } |
| 585 | }; | 633 | }; |
| 586 | var controller = $controller('focaAbmVehiculoController', { | 634 | var controller = $controller('focaAbmVehiculoController', { |
| 587 | $scope: scope, | 635 | $scope: scope, |
| 588 | focaAbmVehiculoService: focaAbmVehiculoService, | 636 | focaAbmVehiculoService: focaAbmVehiculoService, |
| 589 | $routeParams: {}, | 637 | $routeParams: {}, |
| 590 | $location: {}, | 638 | $location: {}, |
| 591 | $uibModal: {}, | 639 | $uibModal: {}, |
| 592 | focaModalService: focaModalService, | 640 | focaModalService: focaModalService, |
| 593 | $timeout: $timeout, | 641 | $timeout: $timeout, |
| 594 | focaBotoneraLateralService: { | 642 | focaBotoneraLateralService: { |
| 595 | showSalir: function() { return; }, | 643 | showSalir: function() { return; }, |
| 596 | showPausar: function() { return; }, | 644 | showPausar: function() { return; }, |
| 597 | showCancelar: function() { return; }, | 645 | showCancelar: function() { return; }, |
| 598 | showGuardar: function() { return; }, | 646 | showGuardar: function() { return; }, |
| 599 | addCustomButton: function() { return; } | 647 | addCustomButton: function() { return; } |
| 600 | }, | 648 | }, |
| 649 | $localStorage: {}, | ||
| 601 | $window: {} | 650 | $window: {} |
| 602 | }); | 651 | }); |
| 603 | var promesa = Promise.resolve(true); | 652 | var promesa = Promise.resolve(true); |
| 604 | 653 | ||
| 605 | //act | 654 | //act |
| 606 | spyOn(focaModalService, 'confirm').and.returnValue(promesa); | 655 | spyOn(focaModalService, 'confirm').and.returnValue(promesa); |
| 607 | spyOn(focaAbmVehiculoService, 'deleteCisterna'); | 656 | spyOn(focaAbmVehiculoService, 'deleteCisterna'); |
| 608 | spyOn(focaAbmVehiculoService, 'getCisternas').and.returnValue({ then: function() {} }); | 657 | spyOn(focaAbmVehiculoService, 'getCisternas').and.returnValue({ then: function() {} }); |
| 609 | scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); | 658 | scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); |
| 610 | 659 | ||
| 611 | //assert | 660 | //assert |
| 612 | promesa.then( | 661 | promesa.then( |
| 613 | function() { | 662 | function() { |
| 614 | expect(focaAbmVehiculoService.deleteCisterna).toHaveBeenCalled(); | 663 | expect(focaAbmVehiculoService.deleteCisterna).toHaveBeenCalled(); |
| 615 | expect(focaAbmVehiculoService.getCisternas).toHaveBeenCalled(); | 664 | expect(focaAbmVehiculoService.getCisternas).toHaveBeenCalled(); |
| 616 | done(); | 665 | done(); |
| 617 | } | 666 | } |
| 618 | ); | 667 | ); |
| 619 | }); | 668 | }); |
| 620 | }); | 669 | }); |
| 621 | }); | 670 | }); |
| 622 | 671 |
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', '$localStorage', | 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', |
| 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, |
| 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { | 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { |
| 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 | function elegirTransportista(transportista) { | 68 | function elegirTransportista(transportista) { |
| 69 | var codigo = ('00000' + transportista.COD).slice(-5); | 69 | var codigo = ('00000' + transportista.COD).slice(-5); |
| 70 | $scope.idTransportista = transportista.COD; | 70 | $scope.idTransportista = transportista.COD; |
| 71 | $scope.filtros = transportista.NOM.trim(); | 71 | $scope.filtros = transportista.NOM.trim(); |
| 72 | $timeout(function() { | 72 | $timeout(function() { |
| 73 | $scope.$broadcast('addCabecera', { | 73 | $scope.$broadcast('addCabecera', { |
| 74 | label: 'Transportista:', | 74 | label: 'Transportista:', |
| 75 | valor: codigo + ' - ' + transportista.NOM | 75 | valor: codigo + ' - ' + transportista.NOM |
| 76 | }); | 76 | }); |
| 77 | }); | 77 | }); |
| 78 | buscar(transportista.COD); | 78 | buscar(transportista.COD); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | function buscar(idTransportista) { | 81 | function buscar(idTransportista) { |
| 82 | focaAbmVehiculoService | 82 | focaAbmVehiculoService |
| 83 | .getVehiculosPorTransportista(idTransportista) | 83 | .getVehiculosPorTransportista(idTransportista) |
| 84 | .then(function(datos) { | 84 | .then(function(datos) { |
| 85 | $scope.vehiculos = datos.data; | 85 | $scope.vehiculos = datos.data; |
| 86 | }); | 86 | }); |
| 87 | } | 87 | } |
| 88 | function salir() { | 88 | function salir() { |
| 89 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 89 | focaAbmVehiculoService.transportistaSeleccionado = {}; |
| 90 | $location.path('/'); | 90 | $location.path('/'); |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | ]) | 93 | ]) |
| 94 | .controller('focaAbmVehiculoController', [ | 94 | .controller('focaAbmVehiculoController', [ |
| 95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', | 96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', |
| 97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 98 | focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | 98 | focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { |
| 99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
| 100 | $scope.now = new Date(); | 100 | $scope.now = new Date(); |
| 101 | $scope.focused = 1; | 101 | $scope.focused = 1; |
| 102 | $scope.transportistaStamp = ''; | 102 | $scope.transportistaStamp = ''; |
| 103 | $scope.cisternas = []; | 103 | $scope.cisternas = []; |
| 104 | 104 | ||
| 105 | $timeout(function() { | 105 | $timeout(function() { |
| 106 | focaBotoneraLateralService.showSalir(false); | 106 | focaBotoneraLateralService.showSalir(false); |
| 107 | focaBotoneraLateralService.showPausar(true); | 107 | focaBotoneraLateralService.showPausar(true); |
| 108 | focaBotoneraLateralService.showCancelar(false); | 108 | focaBotoneraLateralService.showCancelar(false); |
| 109 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 109 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 110 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 110 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); |
| 111 | }); | 111 | }); |
| 112 | 112 | ||
| 113 | $timeout(function() {getLSVehiculo();}); | 113 | $timeout(function() {getLSVehiculo();}); |
| 114 | 114 | ||
| 115 | if ($scope.nuevo) { | 115 | if ($scope.nuevo) { |
| 116 | focaAbmVehiculoService | 116 | focaAbmVehiculoService |
| 117 | .getTransportistaPorId($routeParams.idTransportista) | 117 | .getTransportistaPorId($routeParams.idTransportista) |
| 118 | .then(function(res) { | 118 | .then(function(res) { |
| 119 | var codigo = ('00000' + res.data.COD).slice(-5); | 119 | var codigo = ('00000' + res.data.COD).slice(-5); |
| 120 | $scope.vehiculo.idTransportista = res.data.COD; | 120 | $scope.vehiculo.idTransportista = res.data.COD; |
| 121 | $scope.vehiculo.transportista = res.data; | 121 | $scope.vehiculo.transportista = res.data; |
| 122 | $scope.$broadcast('addCabecera', { | 122 | $scope.$broadcast('addCabecera', { |
| 123 | label: 'Transportista:', | 123 | label: 'Transportista:', |
| 124 | valor: codigo + ' - ' + res.data.NOM | 124 | valor: codigo + ' - ' + res.data.NOM |
| 125 | }); | 125 | }); |
| 126 | }); | 126 | }); |
| 127 | } | 127 | } |
| 128 | $scope.vehiculo = {}; | 128 | $scope.vehiculo = {}; |
| 129 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 129 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 130 | if (res.data) { | 130 | if (res.data) { |
| 131 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 131 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); |
| 132 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 132 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; |
| 133 | 133 | ||
| 134 | $scope.vehiculo = res.data; | 134 | $scope.vehiculo = res.data; |
| 135 | $scope.$broadcast('addCabecera', { | 135 | $scope.$broadcast('addCabecera', { |
| 136 | label: 'Transportista:', | 136 | label: 'Transportista:', |
| 137 | valor: $scope.transportistaStamp | 137 | valor: $scope.transportistaStamp |
| 138 | }); | 138 | }); |
| 139 | $scope.$broadcast('addCabecera', { | 139 | $scope.$broadcast('addCabecera', { |
| 140 | label: 'Unidad:', | 140 | label: 'Unidad:', |
| 141 | valor: res.data.codigo | 141 | valor: res.data.codigo |
| 142 | }); | 142 | }); |
| 143 | focaAbmVehiculoService | 143 | focaAbmVehiculoService |
| 144 | .getCisternas($routeParams.idVehiculo) | 144 | .getCisternas($routeParams.idVehiculo) |
| 145 | .then(function(res) { | 145 | .then(function(res) { |
| 146 | $scope.cisternas = res; | 146 | $scope.cisternas = res; |
| 147 | $scope.$apply(); | 147 | $scope.$apply(); |
| 148 | }); | 148 | }); |
| 149 | } | 149 | } |
| 150 | }); | 150 | }); |
| 151 | 151 | ||
| 152 | $scope.next = function(key) { | 152 | $scope.next = function(key) { |
| 153 | if (key === 13) $scope.focused++; | 153 | if (key === 13) $scope.focused++; |
| 154 | }; | 154 | }; |
| 155 | 155 | ||
| 156 | function salir() { | 156 | $scope.salir = function() { |
| 157 | if (!$scope.formVehiculo.$pristine) { | 157 | if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { |
| 158 | focaModalService.confirm( | 158 | focaModalService.confirm( |
| 159 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 159 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 160 | ).then(function(data) { | 160 | ).then(function(data) { |
| 161 | if (data) { | 161 | if (data) { |
| 162 | $location.path('/vehiculo'); | 162 | $location.path('/vehiculo'); |
| 163 | } | 163 | } |
| 164 | }); | 164 | }); |
| 165 | } else { | 165 | } else { |
| 166 | $location.path('/vehiculo'); | 166 | $location.path('/vehiculo'); |
| 167 | } | 167 | } |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | $scope.editar = function(key) { | 170 | $scope.editar = function(key) { |
| 171 | if (key) { | 171 | if (key) { |
| 172 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 172 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
| 173 | '/cisterna/' + key); | 173 | '/cisterna/' + key); |
| 174 | } else { | 174 | } else { |
| 175 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 175 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); |
| 176 | } | 176 | } |
| 177 | }; | 177 | }; |
| 178 | $scope.guardar = function(key) { | 178 | $scope.guardar = function(key) { |
| 179 | 179 | ||
| 180 | key = (typeof key === 'undefined') ? 13 : key; | 180 | key = (typeof key === 'undefined') ? 13 : key; |
| 181 | 181 | ||
| 182 | if (key === 13) { | 182 | if (key === 13) { |
| 183 | 183 | ||
| 184 | if ($scope.formVehiculo.$pristine) { | 184 | if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { |
| 185 | $scope.cancelar(); | 185 | $scope.salir(); |
| 186 | return; | 186 | return; |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | if (!$scope.vehiculo.codigo) { | 189 | if (!$scope.vehiculo.codigo) { |
| 190 | focaModalService.alert('Ingrese unidad'); | 190 | focaModalService.alert('Ingrese unidad'); |
| 191 | return; | 191 | return; |
| 192 | } else if (!$scope.vehiculo.tractor) { | 192 | } else if (!$scope.vehiculo.tractor) { |
| 193 | focaModalService.alert('Ingrese dominio tractor'); | 193 | focaModalService.alert('Ingrese dominio tractor'); |
| 194 | return; | 194 | return; |
| 195 | } else if (!$scope.vehiculo.semi) { | 195 | } else if (!$scope.vehiculo.semi) { |
| 196 | focaModalService.alert('Ingrese dominio semi'); | 196 | focaModalService.alert('Ingrese dominio semi'); |
| 197 | return; | 197 | return; |
| 198 | } else if (!$scope.vehiculo.capacidad) { | 198 | } else if (!$scope.vehiculo.capacidad) { |
| 199 | focaModalService.alert('Ingrese capacidad total'); | 199 | focaModalService.alert('Ingrese capacidad total'); |
| 200 | return; | 200 | return; |
| 201 | } | 201 | } |
| 202 | //Valida si existe numero de unidad | 202 | //Valida si existe numero de unidad |
| 203 | if (!validaTotalCargas() && !$scope.nuevo) { | 203 | if (!validaTotalCargas() && !$scope.nuevo) { |
| 204 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 204 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
| 205 | ' debe ser igual a la capacidad total del vehículo'); | 205 | ' debe ser igual a la capacidad total del vehículo'); |
| 206 | return; | 206 | return; |
| 207 | } | 207 | } |
| 208 | validaCodigoUnidad().then(function() { | 208 | validaCodigoUnidad().then(function() { |
| 209 | delete $scope.vehiculo.transportista; | 209 | delete $scope.vehiculo.transportista; |
| 210 | delete $scope.vehiculo.cisternas; | 210 | delete $scope.vehiculo.cisternas; |
| 211 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 211 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) |
| 212 | .then(function(res) { | 212 | .then(function(res) { |
| 213 | if ($scope.nuevo) { | 213 | if ($scope.nuevo) { |
| 214 | $location.path('/vehiculo/' + res.data.id + | 214 | $location.path('/vehiculo/' + res.data.id + |
| 215 | '/' + res.data.idTransportista); | 215 | '/' + res.data.idTransportista); |
| 216 | } else { | 216 | } else { |
| 217 | guardarCisternas().then(function() { | 217 | guardarCisternas().then(function() { |
| 218 | $location.path('/vehiculo'); | 218 | $location.path('/vehiculo'); |
| 219 | }); | 219 | }); |
| 220 | } | 220 | } |
| 221 | }); | 221 | }); |
| 222 | }, function() { | 222 | }, function() { |
| 223 | focaModalService.alert('Código de unidad existente'); | 223 | focaModalService.alert('Código de unidad existente'); |
| 224 | }); | 224 | }); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | }; | 227 | }; |
| 228 | 228 | ||
| 229 | $scope.$watch('vehiculo', function(newValue) { | 229 | $scope.$watch('vehiculo', function(newValue) { |
| 230 | focaBotoneraLateralService.setPausarData({ | 230 | focaBotoneraLateralService.setPausarData({ |
| 231 | label:'vehiculo', | 231 | label:'vehiculo', |
| 232 | val: { | 232 | val: { |
| 233 | codigo: newValue.codigo, | 233 | codigo: newValue.codigo, |
| 234 | tractor: newValue.tractor, | 234 | tractor: newValue.tractor, |
| 235 | semi: newValue.semi, | 235 | semi: newValue.semi, |
| 236 | capacidad: newValue.capacidad, | 236 | capacidad: newValue.capacidad, |
| 237 | idVehiculo: newValue.idVehiculo, | 237 | idVehiculo: newValue.idVehiculo, |
| 238 | idTransportista: newValue.idTransportista | 238 | idTransportista: newValue.idTransportista |
| 239 | } | 239 | } |
| 240 | }); | 240 | }); |
| 241 | }, true); | 241 | }, true); |
| 242 | 242 | ||
| 243 | function getLSVehiculo() { | 243 | function getLSVehiculo() { |
| 244 | var vehiculo = JSON.parse($localStorage.vehiculo|| null); | 244 | var vehiculo = JSON.parse($localStorage.vehiculo|| null); |
| 245 | if (vehiculo) { | 245 | if (vehiculo) { |
| 246 | setearVehiculo(vehiculo); | 246 | setearVehiculo(vehiculo); |
| 247 | delete $localStorage.vehiculo; | 247 | delete $localStorage.vehiculo; |
| 248 | } | 248 | } |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | function setearVehiculo(vehiculo) { | 251 | function setearVehiculo(vehiculo) { |
| 252 | $scope.vehiculo = vehiculo; | 252 | $scope.vehiculo = vehiculo; |
| 253 | $scope.$broadcast('addCabecera', { | 253 | $scope.$broadcast('addCabecera', { |
| 254 | label: 'Vehiculo:', | 254 | label: 'Vehiculo:', |
| 255 | valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | 255 | valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' |
| 256 | }); | 256 | }); |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 259 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { |
| 260 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 260 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + |
| 261 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 261 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( |
| 262 | function(data) { | 262 | function(data) { |
| 263 | if (data) { | 263 | if (data) { |
| 264 | focaAbmVehiculoService.deleteCisterna(idx); | 264 | focaAbmVehiculoService.deleteCisterna(idx); |
| 265 | focaAbmVehiculoService | 265 | focaAbmVehiculoService |
| 266 | .getCisternas($routeParams.idVehiculo) | 266 | .getCisternas($routeParams.idVehiculo) |
| 267 | .then(function(res) { | 267 | .then(function(res) { |
| 268 | $scope.cisternas = res; | 268 | $scope.cisternas = res; |
| 269 | }); | 269 | }); |
| 270 | } | 270 | } |
| 271 | } | 271 | } |
| 272 | ); | 272 | ); |
| 273 | }; | 273 | }; |
| 274 | 274 | ||
| 275 | function validaCodigoUnidad() { | 275 | function validaCodigoUnidad() { |
| 276 | return new Promise(function(resolve, reject) { | 276 | return new Promise(function(resolve, reject) { |
| 277 | focaAbmVehiculoService | 277 | focaAbmVehiculoService |
| 278 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 278 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) |
| 279 | .then(function(res) { | 279 | .then(function(res) { |
| 280 | //Valida si existe numero de unidad | 280 | //Valida si existe numero de unidad |
| 281 | var existe = res.data.filter(function(vehiculo) { | 281 | var existe = res.data.filter(function(vehiculo) { |
| 282 | return vehiculo.codigo === $scope.vehiculo.codigo && | 282 | return vehiculo.codigo === $scope.vehiculo.codigo && |
| 283 | vehiculo.id !== $scope.vehiculo.id; | 283 | vehiculo.id !== $scope.vehiculo.id; |
| 284 | }); | 284 | }); |
| 285 | 285 | ||
| 286 | if (existe.length) { | 286 | if (existe.length) { |
| 287 | reject(existe); | 287 | reject(existe); |
| 288 | } else { | 288 | } else { |
| 289 | resolve(); | 289 | resolve(); |
| 290 | } | 290 | } |
| 291 | }); | 291 | }); |
| 292 | }); | 292 | }); |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | function validaTotalCargas() { | 295 | function validaTotalCargas() { |
| 296 | var total = 0; | 296 | var total = 0; |
| 297 | $scope.cisternas.forEach(function(cisterna) { | 297 | $scope.cisternas.forEach(function(cisterna) { |
| 298 | if (!cisterna.desactivado) { | 298 | if (!cisterna.desactivado) { |
| 299 | total += parseInt(cisterna.capacidad); | 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 | function guardarCisternas() { | 305 | function guardarCisternas() { |
| 306 | var cisternas = $scope.cisternas.map(function(cisterna) { | 306 | var cisternas = $scope.cisternas.map(function(cisterna) { |
| 307 | return { | 307 | return { |
| 308 | id: cisterna.id, | 308 | id: cisterna.id, |
| 309 | capacidad: parseFloat(cisterna.capacidad), | 309 | capacidad: parseFloat(cisterna.capacidad), |
| 310 | codigo: cisterna.codigo, | 310 | codigo: cisterna.codigo, |
| 311 | idUnidadMedida: cisterna.idUnidadMedida, | 311 | idUnidadMedida: cisterna.idUnidadMedida, |
| 312 | idVehiculo: $routeParams.idVehiculo, | 312 | idVehiculo: $routeParams.idVehiculo, |
| 313 | desactivado: cisterna.desactivado | 313 | desactivado: cisterna.desactivado |
| 314 | }; | 314 | }; |
| 315 | }); | 315 | }); |
| 316 | 316 | ||
| 317 | return focaAbmVehiculoService.guardarCisternas(cisternas); | 317 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
| 318 | } | 318 | } |
| 319 | |||
| 319 | } | 320 | } |
| 320 | ]); | 321 | ]); |
| 321 | 322 |
src/js/controllerCisterna.js
| 1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') |
| 2 | .controller('focaAbmVehiculoCisternaController', [ | 2 | .controller('focaAbmVehiculoCisternaController', [ |
| 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter', | 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', |
| 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 6 | focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { | 6 | focaModalService, focaBotoneraLateralService, $timeout, $window) { |
| 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; | 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; |
| 8 | $scope.editar = false; | 8 | $scope.editar = false; |
| 9 | $scope.now = new Date(); | 9 | $scope.now = new Date(); |
| 10 | $scope.cisterna = { | 10 | $scope.cisterna = { |
| 11 | codigo: '', | 11 | codigo: '', |
| 12 | capacidad: '', | 12 | capacidad: '', |
| 13 | unidadMedida: {} | 13 | unidadMedida: {} |
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| 16 | $scope.focused = $scope.nuevo ? 1 : 2; | 16 | $scope.focused = $scope.nuevo ? 1 : 2; |
| 17 | $scope.next = function(key) { | 17 | $scope.next = function(key) { |
| 18 | if (key === 13) $scope.focused++; | 18 | if (key === 13) $scope.focused++; |
| 19 | }; | 19 | }; |
| 20 | $scope.capacidadVechiulo = 0; | 20 | $scope.capacidadVechiulo = 0; |
| 21 | $scope.transportista = ''; | 21 | $scope.transportista = ''; |
| 22 | 22 | ||
| 23 | //SETEO BOTONERA LATERAL | 23 | //SETEO BOTONERA LATERAL |
| 24 | $timeout(function() { | 24 | $timeout(function() { |
| 25 | focaBotoneraLateralService.showSalir(false); | 25 | focaBotoneraLateralService.showSalir(false); |
| 26 | focaBotoneraLateralService.showPausar(true); | 26 | focaBotoneraLateralService.showPausar(true); |
| 27 | focaBotoneraLateralService.showCancelar(false); | 27 | focaBotoneraLateralService.showCancelar(false); |
| 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 29 | focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); | 29 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); |
| 30 | }); | 30 | }); |
| 31 | 31 | ||
| 32 | if ($routeParams.idx !== -1) { | 32 | if ($routeParams.idx !== -1) { |
| 33 | $scope.cisterna = [$routeParams.idx]; | 33 | $scope.cisterna = [$routeParams.idx]; |
| 34 | focaAbmVehiculoService | 34 | focaAbmVehiculoService |
| 35 | .getCisternas($routeParams.idVehiculo) | 35 | .getCisternas($routeParams.idVehiculo) |
| 36 | .then(function(res) { | 36 | .then(function(res) { |
| 37 | $scope.cisterna = res[$routeParams.idx]; | 37 | $scope.cisterna = res[$routeParams.idx]; |
| 38 | }); | 38 | }); |
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 41 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 42 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 42 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); |
| 43 | $scope.transportista = res.data.transportista.COD; | 43 | $scope.transportista = res.data.transportista.COD; |
| 44 | $scope.capacidadVechiulo = res.data.capacidad; | 44 | $scope.capacidadVechiulo = res.data.capacidad; |
| 45 | $scope.$broadcast('addCabecera', { | 45 | $scope.$broadcast('addCabecera', { |
| 46 | label: 'Transportista:', | 46 | label: 'Transportista:', |
| 47 | valor: codigo + ' - ' + res.data.transportista.NOM | 47 | valor: codigo + ' - ' + res.data.transportista.NOM |
| 48 | }); | 48 | }); |
| 49 | $scope.$broadcast('addCabecera', { | 49 | $scope.$broadcast('addCabecera', { |
| 50 | label: 'Unidad:', | 50 | label: 'Unidad:', |
| 51 | valor: res.data.codigo | 51 | valor: res.data.codigo |
| 52 | }); | 52 | }); |
| 53 | $scope.$broadcast('addCabecera', { | 53 | $scope.$broadcast('addCabecera', { |
| 54 | label: 'Capacidad total vehículo:', | 54 | label: 'Capacidad total vehículo:', |
| 55 | valor: res.data.capacidad | 55 | valor: res.data.capacidad |
| 56 | }); | 56 | }); |
| 57 | }); | 57 | }); |
| 58 | 58 | ||
| 59 | $scope.cancelar = function() { | 59 | $scope.salir = function() { |
| 60 | 60 | ||
| 61 | if (!$scope.formCisterna.$pristine) { | 61 | if (!$scope.formCisterna.$pristine) { |
| 62 | focaModalService.confirm( | 62 | focaModalService.confirm( |
| 63 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 63 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 64 | ).then(function(data) { | 64 | ).then(function(data) { |
| 65 | if (data) { | 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 | $scope.guardar = function() { | 76 | $scope.guardar = function() { |
| 73 | 77 | ||
| 74 | if ($scope.formCisterna.$pristine) { | 78 | if ($scope.formCisterna.$pristine) { |
| 75 | $scope.cancelar(); | 79 | $scope.salir(); |
| 76 | return; | 80 | return; |
| 77 | } | 81 | } else if (!$scope.cisterna.codigo) { |
| 78 | |||
| 79 | if (!$scope.cisterna.codigo) { | ||
| 80 | focaModalService.alert('Ingrese codigo de cisterna'); | 82 | focaModalService.alert('Ingrese codigo de cisterna'); |
| 81 | return; | 83 | return; |
| 82 | } else if (!$scope.cisterna.capacidad) { | 84 | } else if (!$scope.cisterna.capacidad) { |
| 83 | focaModalService.alert('Ingrese capacidad'); | 85 | focaModalService.alert('Ingrese capacidad'); |
| 84 | return; | 86 | return; |
| 85 | } else if (!$scope.cisterna.idUnidadMedida) { | 87 | } else if (!$scope.cisterna.idUnidadMedida) { |
| 86 | focaModalService.alert('Ingrese unidad de medida'); | 88 | focaModalService.alert('Ingrese unidad de medida'); |
| 87 | return; | 89 | return; |
| 88 | } | 90 | } |
| 89 | 91 | ||
| 90 | validaCodigo() | 92 | validaCodigo() |
| 91 | .then(function() { | 93 | .then(function() { |
| 92 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 94 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); |
| 93 | delete $scope.cisterna.vehiculo; | 95 | delete $scope.cisterna.vehiculo; |
| 94 | 96 | ||
| 95 | focaAbmVehiculoService | 97 | focaAbmVehiculoService |
| 96 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 98 | .guardarCisterna($scope.cisterna, $routeParams.idx); |
| 97 | 99 | ||
| 98 | $timeout(function() { | 100 | $timeout(function() { |
| 99 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 101 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
| 100 | '/' + $scope.transportista); | 102 | '/' + $scope.transportista); |
| 101 | }, 0); | 103 | }, 0); |
| 102 | }, function(err) { | 104 | }, function(err) { |
| 103 | focaModalService.alert(err); | 105 | focaModalService.alert(err); |
| 104 | }); | 106 | }); |
| 105 | 107 | ||
| 106 | }; | 108 | }; |
| 107 | 109 | ||
| 108 | $scope.seleccionarUnidadMedida = function() { | 110 | $scope.seleccionarUnidadMedida = function() { |
| 109 | var modalInstance = $uibModal.open( | 111 | var modalInstance = $uibModal.open( |
| 110 | { | 112 | { |
| 111 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 113 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
| 112 | templateUrl: 'modal-unidad-medida.html', | 114 | templateUrl: 'modal-unidad-medida.html', |
| 113 | controller: 'focaModalUnidadMedidaCtrl', | 115 | controller: 'focaModalUnidadMedidaCtrl', |
| 114 | size: 'lg' | 116 | size: 'lg' |
| 115 | } | 117 | } |
| 116 | ); | 118 | ); |
| 117 | modalInstance.result.then(function(unidaMedida) { | 119 | modalInstance.result.then(function(unidaMedida) { |
| 118 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 120 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
| 119 | $scope.cisterna.unidadMedida = unidaMedida; | 121 | $scope.cisterna.unidadMedida = unidaMedida; |
| 120 | }); | 122 | }); |
| 121 | }; | 123 | }; |
| 122 | 124 | ||
| 123 | function validaCodigo() { | 125 | function validaCodigo() { |
| 124 | return new Promise(function(resolve, reject) { | 126 | return new Promise(function(resolve, reject) { |
| 125 | focaAbmVehiculoService | 127 | focaAbmVehiculoService |
| 126 | .getCisternas($routeParams.idVehiculo) | 128 | .getCisternas($routeParams.idVehiculo) |
| 127 | .then(function(res) { | 129 | .then(function(res) { |
| 128 | var cisternas = res; | 130 | var cisternas = res; |
| 129 | var totalCargado = 0; | 131 | var totalCargado = 0; |
| 130 | cisternas.forEach(function(cisterna, idx) { | 132 | cisternas.forEach(function(cisterna, idx) { |
| 131 | //SI EL CODIGO YA EXISTE | 133 | //SI EL CODIGO YA EXISTE |
| 132 | if (cisterna.codigo === $scope.cisterna.codigo && | 134 | if (cisterna.codigo === $scope.cisterna.codigo && |
| 133 | idx !== $routeParams.idx && | 135 | idx != $routeParams.idx && |
| 134 | !cisterna.desactivado) { | 136 | !cisterna.desactivado) { |
| 135 | reject('Código de cisterna existente'); | 137 | reject('Código de cisterna existente'); |
| 136 | } | 138 | } |
| 137 | if (idx !== $routeParams.idx && | 139 | if (idx !== $routeParams.idx && |
| 138 | !cisterna.desactivado) { | 140 | !cisterna.desactivado) { |
| 139 | totalCargado += cisterna.capacidad; | 141 | totalCargado += cisterna.capacidad; |
| 140 | } | 142 | } |
| 141 | }); | 143 | }); |
| 142 | resolve(); | 144 | resolve(); |
| 143 | }); | 145 | }); |
| 144 | }); | 146 | }); |
| 145 | } | 147 | } |
| 146 | } | 148 | } |
src/js/service.js
| 1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') |
| 2 | .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | 2 | .factory('focaAbmVehiculoService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { |
| 3 | var cisternas = []; | 3 | var cisternas = []; |
| 4 | var cisternasPristine = true; | ||
| 4 | return { | 5 | return { |
| 5 | getVehiculos: function() { | 6 | getVehiculos: function() { |
| 6 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); | 7 | return $http.get(API_ENDPOINT.URL + '/vehiculo'); |
| 7 | }, | 8 | }, |
| 8 | getVehiculo: function(id) { | 9 | getVehiculo: function(id) { |
| 9 | return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); | 10 | return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); |
| 10 | }, | 11 | }, |
| 11 | getTransportistas: function() { | 12 | getTransportistas: function() { |
| 12 | return $http.get(API_ENDPOINT.URL + '/transportista'); | 13 | return $http.get(API_ENDPOINT.URL + '/transportista'); |
| 13 | }, | 14 | }, |
| 14 | guardarVehiculo: function(vehiculo) { | 15 | guardarVehiculo: function(vehiculo) { |
| 15 | return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); | 16 | return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); |
| 16 | }, | 17 | }, |
| 17 | deleteVehiculo: function(id) { | 18 | deleteVehiculo: function(id) { |
| 18 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); | 19 | return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); |
| 19 | }, | 20 | }, |
| 20 | getCisternas: function(idVehiculo) { | 21 | getCisternas: function(idVehiculo) { |
| 21 | if(cisternas.length) { | 22 | if (cisternas.length) { |
| 23 | cisternasPristine = true; | ||
| 22 | return Promise.resolve(angular.copy(cisternas)); | 24 | return Promise.resolve(angular.copy(cisternas)); |
| 23 | }else { | 25 | } else { |
| 26 | cisternasPristine = true; | ||
| 24 | return new Promise(function(resolve) { | 27 | return new Promise(function(resolve) { |
| 25 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) | 28 | $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) |
| 26 | .then(function(res) { | 29 | .then(function(res) { |
| 27 | cisternas = res.data; | 30 | cisternas = res.data; |
| 28 | resolve(res.data); | 31 | resolve(res.data); |
| 29 | }); | 32 | }); |
| 30 | }); | 33 | }); |
| 31 | } | 34 | } |
| 32 | }, | 35 | }, |
| 33 | guardarCisterna: function(cisterna, idx) { | 36 | guardarCisterna: function(cisterna, idx) { |
| 34 | if(idx !== '-1') { | 37 | if (idx !== '-1') { |
| 35 | //update | 38 | //update |
| 36 | cisternas[idx] = cisterna; | 39 | cisternas[idx] = cisterna; |
| 37 | }else { | 40 | cisternasPristine = false; |
| 41 | } else { | ||
| 38 | //insert | 42 | //insert |
| 39 | cisternas.push(cisterna); | 43 | cisternas.push(cisterna); |
| 44 | cisternasPristine = false; | ||
| 40 | } | 45 | } |
| 41 | }, | 46 | }, |
| 42 | guardarCisternas: function(cisternas) { | 47 | guardarCisternas: function(cisternas) { |
| 43 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); | 48 | return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); |
| 44 | }, | 49 | }, |
| 45 | deleteCisterna: function(idx) { | 50 | deleteCisterna: function(idx) { |
| 46 | cisternas[idx].desactivado = true; | 51 | cisternas[idx].desactivado = true; |
| 52 | cisternasPristine = false; | ||
| 47 | }, | 53 | }, |
| 48 | cleanCisternas: function() { | 54 | cleanCisternas: function() { |
| 49 | cisternas = []; | 55 | cisternas = []; |
| 50 | }, | 56 | }, |
| 51 | getVehiculosPorTransportista: function(id) { | 57 | getVehiculosPorTransportista: function(id) { |
| 52 | return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); | 58 | return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); |
| 53 | }, | 59 | }, |
| 54 | getTransportistaPorId: function(id) { | 60 | getTransportistaPorId: function(id) { |
| 55 | return $http.get(API_ENDPOINT.URL + '/transportista/' + id); | 61 | return $http.get(API_ENDPOINT.URL + '/transportista/' + id); |
| 56 | }, | 62 | }, |
| 57 | transportistaSeleccionado: {} | 63 | transportistaSeleccionado: {} |
| 58 | }; | 64 | }; |
| 59 | }]); | 65 | }]); |
| 60 | 66 |