Commit 98d3e2b2fdd469366860dc38e3452941d0f43c47

Authored by Eric Fernandez

Merge branch 'develop' into 'master'

Develop

See merge request !48
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.8",
39 "angular-mocks": "^1.7.8", 39 "angular-mocks": "^1.7.8",
40 "angular-route": "^1.7.7", 40 "angular-route": "^1.7.8",
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.7",
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.4.0",
57 "jasmine-core": "^3.3.0", 57 "jasmine-core": "^3.4.0",
58 "jquery": "^3.3.1", 58 "jquery": "^3.4.1",
59 "jshint": "^2.9.6", 59 "jshint": "^2.10.2",
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 $localStorage: {},
33 $timeout: {} 33 $timeout: {}
34 }); 34 });
35 35
36 //assert 36 //assert
37 expect(typeof controller).toEqual('object'); 37 expect(typeof controller).toEqual('object');
38 }); 38 });
39 39
40 it('Crea fecha nueva', function() { 40 it('Crea fecha nueva', function() {
41 //arrange 41 //arrange
42 var scope = { 42 var scope = {
43 $watch: function() {} 43 $watch: function() {}
44 }; 44 };
45 var controller = $controller('focaAbmVehiculosController', { 45 var controller = $controller('focaAbmVehiculosController', {
46 $scope: scope, 46 $scope: scope,
47 focaAbmVehiculoService: { 47 focaAbmVehiculoService: {
48 cleanCisternas: function() { return;}, 48 cleanCisternas: function() { return;},
49 transportistaSeleccionado: {} 49 transportistaSeleccionado: {}
50 }, 50 },
51 $location: {}, 51 $location: {},
52 focaModalService: {}, 52 focaModalService: {},
53 $uibModal: {}, 53 $uibModal: {},
54 focaBotoneraLateralService: { 54 focaBotoneraLateralService: {
55 showSalir: function() { return; }, 55 showSalir: function() { return; },
56 showPausar: function() { return; }, 56 showPausar: function() { return; },
57 showCancelar: function() { return; }, 57 showCancelar: function() { return; },
58 showGuardar: function() { return; }, 58 showGuardar: function() { return; },
59 addCustomButton: function() { return; } 59 addCustomButton: function() { return; }
60 }, 60 },
61 $localStorage: {}, 61 $localStorage: {},
62 $timeout: {} 62 $timeout: {}
63 }); 63 });
64 64
65 //act 65 //act
66 var date = scope.now; 66 var date = scope.now;
67 67
68 //assert 68 //assert
69 expect(angular.isDate(date)).toBe(true); 69 expect(angular.isDate(date)).toBe(true);
70 }); 70 });
71 71
72 it('$scope setea botonera lateral', function() { 72 it('$scope setea botonera lateral', function() {
73 //arrange 73 //arrange
74 var scope = { 74 var scope = {
75 $watch: function() {} 75 $watch: function() {}
76 }; 76 };
77 var controller = $controller('focaAbmVehiculosController', { 77 var controller = $controller('focaAbmVehiculosController', {
78 $scope: scope, 78 $scope: scope,
79 focaAbmVehiculoService: { 79 focaAbmVehiculoService: {
80 cleanCisternas: function() { return;}, 80 cleanCisternas: function() { return;},
81 transportistaSeleccionado: {} 81 transportistaSeleccionado: {}
82 }, 82 },
83 $location: {}, 83 $location: {},
84 focaModalService: {}, 84 focaModalService: {},
85 $uibModal: {}, 85 $uibModal: {},
86 focaBotoneraLateralService: { 86 focaBotoneraLateralService: {
87 showSalir: function() { return; }, 87 showSalir: function() { return; },
88 showPausar: function() { return; }, 88 showPausar: function() { return; },
89 showCancelar: function() { return; }, 89 showCancelar: function() { return; },
90 showGuardar: function() { return; }, 90 showGuardar: function() { return; },
91 addCustomButton: function() { return; } 91 addCustomButton: function() { return; }
92 }, 92 },
93 $timeout: {}, 93 $timeout: {},
94 $localStorage: {} 94 $localStorage: {}
95 }); 95 });
96 96
97 //act 97 //act
98 var botonera = scope.botonera; 98 var botonera = scope.botonera;
99 99
100 //assert 100 //assert
101 expect(angular.isArray(botonera)).toBe(true); 101 expect(angular.isArray(botonera)).toBe(true);
102 }); 102 });
103 103
104 it('$scope.editar lleva a la ruta correcta', function() { 104 it('$scope.editar lleva a la ruta correcta', function() {
105 inject(function($location) { 105 inject(function($location) {
106 //arrange 106 //arrange
107 var scope = { 107 var scope = {
108 $watch: function() {} 108 $watch: function() {}
109 }; 109 };
110 var controller = $controller('focaAbmVehiculosController', { 110 var controller = $controller('focaAbmVehiculosController', {
111 $scope: scope, 111 $scope: scope,
112 focaAbmVehiculoService: { 112 focaAbmVehiculoService: {
113 cleanCisternas: function() { return;}, 113 cleanCisternas: function() { return;},
114 transportistaSeleccionado: {} 114 transportistaSeleccionado: {}
115 }, 115 },
116 $location: $location, 116 $location: $location,
117 focaModalService: {}, 117 focaModalService: {},
118 $uibModal: {}, 118 $uibModal: {},
119 focaBotoneraLateralService: { 119 focaBotoneraLateralService: {
120 showSalir: function() { return; }, 120 showSalir: function() { return; },
121 showPausar: function() { return; }, 121 showPausar: function() { return; },
122 showCancelar: function() { return; }, 122 showCancelar: function() { return; },
123 showGuardar: function() { return; }, 123 showGuardar: function() { return; },
124 addCustomButton: function() { return; } 124 addCustomButton: function() { return; }
125 }, 125 },
126 $timeout: {}, 126 $timeout: {},
127 $localStorage: {} 127 $localStorage: {}
128 }); 128 });
129 129
130 //act 130 //act
131 scope.editar(1); 131 scope.editar(1);
132 var esperado = '/vehiculo/' + 1 + '/' + scope.idTransportista; 132 var esperado = '/vehiculo/' + 1 + '/' + scope.idTransportista;
133 133
134 //assert 134 //assert
135 expect($location.url()).toEqual(esperado); 135 expect($location.url()).toEqual(esperado);
136 }); 136 });
137 }); 137 });
138 138
139 it('Solicita confirmacion', function() { 139 it('Solicita confirmacion', function() {
140 //arrange 140 //arrange
141 var scope = { 141 var scope = {
142 $watch: function() {} 142 $watch: function() {}
143 }; 143 };
144 var focaModalService = { 144 var focaModalService = {
145 confirm: function() {} 145 confirm: function() {}
146 }; 146 };
147 var controller = $controller('focaAbmVehiculosController', { 147 var controller = $controller('focaAbmVehiculosController', {
148 $scope: scope, 148 $scope: scope,
149 focaAbmVehiculoService: { 149 focaAbmVehiculoService: {
150 cleanCisternas: function() { return;}, 150 cleanCisternas: function() { return;},
151 transportistaSeleccionado: {} 151 transportistaSeleccionado: {}
152 }, 152 },
153 $location: {}, 153 $location: {},
154 focaModalService: focaModalService, 154 focaModalService: focaModalService,
155 $uibModal: {}, 155 $uibModal: {},
156 focaBotoneraLateralService: { 156 focaBotoneraLateralService: {
157 showSalir: function() { return; }, 157 showSalir: function() { return; },
158 showPausar: function() { return; }, 158 showPausar: function() { return; },
159 showCancelar: function() { return; }, 159 showCancelar: function() { return; },
160 showGuardar: function() { return; }, 160 showGuardar: function() { return; },
161 addCustomButton: function() { return; } 161 addCustomButton: function() { return; }
162 }, 162 },
163 $timeout: {}, 163 $timeout: {},
164 $localStorage: {} 164 $localStorage: {}
165 }); 165 });
166 166
167 //act 167 //act
168 spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); 168 spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}});
169 scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); 169 scope.solicitarConfirmacion({id: 1, tractor: 'abc'});
170 170
171 //assert 171 //assert
172 expect(focaModalService.confirm).toHaveBeenCalled(); 172 expect(focaModalService.confirm).toHaveBeenCalled();
173 }); 173 });
174 174
175 it('Elimina vehículo al confirmar', function(done) { 175 it('Elimina vehículo al confirmar', function(done) {
176 176
177 //arrange 177 //arrange
178 var scope = { 178 var scope = {
179 vehiculos: [] 179 vehiculos: []
180 }; 180 };
181 var focaModalService = { 181 var focaModalService = {
182 confirm: function() { return; } 182 confirm: function() { return; }
183 }; 183 };
184 var focaAbmVehiculoService = { 184 var focaAbmVehiculoService = {
185 cleanCisternas: function() { return;}, 185 cleanCisternas: function() { return;},
186 transportistaSeleccionado: {}, 186 transportistaSeleccionado: {},
187 deleteVehiculo: function() { return; } 187 deleteVehiculo: function() { return; }
188 }; 188 };
189 var controller = $controller('focaAbmVehiculosController', { 189 var controller = $controller('focaAbmVehiculosController', {
190 $scope: scope, 190 $scope: scope,
191 focaAbmVehiculoService: focaAbmVehiculoService, 191 focaAbmVehiculoService: focaAbmVehiculoService,
192 $location: {}, 192 $location: {},
193 focaModalService: focaModalService, 193 focaModalService: focaModalService,
194 $uibModal: {}, 194 $uibModal: {},
195 focaBotoneraLateralService: { 195 focaBotoneraLateralService: {
196 showSalir: function() { return; }, 196 showSalir: function() { return; },
197 showPausar: function() { return; }, 197 showPausar: function() { return; },
198 showCancelar: function() { return; }, 198 showCancelar: function() { return; },
199 showGuardar: function() { return; }, 199 showGuardar: function() { return; },
200 addCustomButton: function() { return; } 200 addCustomButton: function() { return; }
201 }, 201 },
202 $timeout: {}, 202 $timeout: {},
203 $localStorage: {} 203 $localStorage: {}
204 }); 204 });
205 var promesa = Promise.resolve(true); 205 var promesa = Promise.resolve(true);
206 206
207 //act 207 //act
208 spyOn(focaModalService, 'confirm').and.returnValue(promesa); 208 spyOn(focaModalService, 'confirm').and.returnValue(promesa);
209 spyOn(focaAbmVehiculoService, 'deleteVehiculo'); 209 spyOn(focaAbmVehiculoService, 'deleteVehiculo');
210 scope.solicitarConfirmacion({id: 1, tractor: 'abc'}); 210 scope.solicitarConfirmacion({id: 1, tractor: 'abc'});
211 211
212 //assert 212 //assert
213 promesa.then( 213 promesa.then(
214 function() { 214 function() {
215 expect(focaAbmVehiculoService.deleteVehiculo).toHaveBeenCalled(); 215 expect(focaAbmVehiculoService.deleteVehiculo).toHaveBeenCalled();
216 done(); 216 done();
217 } 217 }
218 ); 218 );
219 }); 219 });
220 220
221 it('Se selecciona transportista', function() { 221 it('Se selecciona transportista', function() {
222 //arrange 222 //arrange
223 var scope = { 223 var scope = {
224 $watch: function() {} 224 $watch: function() {}
225 }; 225 };
226 var focaModalService = { 226 var focaModalService = {
227 modal: function() {} 227 modal: function() {}
228 }; 228 };
229 var controller = $controller('focaAbmVehiculosController', { 229 var controller = $controller('focaAbmVehiculosController', {
230 $scope: scope, 230 $scope: scope,
231 focaAbmVehiculoService: { 231 focaAbmVehiculoService: {
232 cleanCisternas: function() { return;}, 232 cleanCisternas: function() { return;},
233 transportistaSeleccionado: {} 233 transportistaSeleccionado: {}
234 }, 234 },
235 $location: {}, 235 $location: {},
236 focaModalService: focaModalService, 236 focaModalService: focaModalService,
237 $uibModal: {}, 237 $uibModal: {},
238 focaBotoneraLateralService: { 238 focaBotoneraLateralService: {
239 showSalir: function() { return; }, 239 showSalir: function() { return; },
240 showPausar: function() { return; }, 240 showPausar: function() { return; },
241 showCancelar: function() { return; }, 241 showCancelar: function() { return; },
242 showGuardar: function() { return; }, 242 showGuardar: function() { return; },
243 addCustomButton: function() { return; } 243 addCustomButton: function() { return; }
244 }, 244 },
245 $timeout: {}, 245 $timeout: {},
246 $localStorage: {} 246 $localStorage: {}
247 }); 247 });
248 248
249 //act 249 //act
250 spyOn(focaModalService, 'modal').and.returnValue({then: function() {}}); 250 spyOn(focaModalService, 'modal').and.returnValue({then: function() {}});
251 scope.seleccionarTransportista(); 251 scope.seleccionarTransportista();
252 252
253 //assert 253 //assert
254 expect(focaModalService.modal).toHaveBeenCalled(); 254 expect(focaModalService.modal).toHaveBeenCalled();
255 }); 255 });
256 256
257 it('Se setea el transportista seleccionado al service', function(done) { 257 it('Se setea el transportista seleccionado al service', function(done) {
258 inject(function($timeout) { 258 inject(function($timeout) {
259 259
260 //arrange 260 //arrange
261 var scope = { 261 var scope = {
262 $watch: function() {} 262 $watch: function() {}
263 }; 263 };
264 var focaModalService = { 264 var focaModalService = {
265 modal: function() { return; } 265 modal: function() { return; }
266 }; 266 };
267 var focaAbmVehiculoService = { 267 var focaAbmVehiculoService = {
268 cleanCisternas: function() { return;}, 268 cleanCisternas: function() { return;},
269 transportistaSeleccionado: {}, 269 transportistaSeleccionado: {},
270 deleteVehiculo: function() { return; }, 270 deleteVehiculo: function() { return; },
271 getVehiculosPorTransportista: function() { 271 getVehiculosPorTransportista: function() {
272 return { 272 return {
273 then: function() { return; } 273 then: function() { return; }
274 }; 274 };
275 } 275 }
276 }; 276 };
277 var controller = $controller('focaAbmVehiculosController', { 277 var controller = $controller('focaAbmVehiculosController', {
278 $scope: scope, 278 $scope: scope,
279 focaAbmVehiculoService: focaAbmVehiculoService, 279 focaAbmVehiculoService: focaAbmVehiculoService,
280 $location: {}, 280 $location: {},
281 focaModalService: focaModalService, 281 focaModalService: focaModalService,
282 $uibModal: {}, 282 $uibModal: {},
283 focaBotoneraLateralService: { 283 focaBotoneraLateralService: {
284 showSalir: function() { return; }, 284 showSalir: function() { return; },
285 showPausar: function() { return; }, 285 showPausar: function() { return; },
286 showCancelar: function() { return; }, 286 showCancelar: function() { return; },
287 showGuardar: function() { return; }, 287 showGuardar: function() { return; },
288 addCustomButton: function() { return; } 288 addCustomButton: function() { return; }
289 }, 289 },
290 $localStorage: {}, 290 $localStorage: {},
291 $timeout: $timeout 291 $timeout: $timeout
292 }); 292 });
293 var promesa = Promise.resolve({COD: '', NOM: ''}); 293 var promesa = Promise.resolve({COD: '', NOM: ''});
294 294
295 //act 295 //act
296 spyOn(focaModalService, 'modal').and.returnValue(promesa); 296 spyOn(focaModalService, 'modal').and.returnValue(promesa);
297 scope.seleccionarTransportista(); 297 scope.seleccionarTransportista();
298 298
299 //assert 299 //assert
300 promesa.then( 300 promesa.then(
301 function() { 301 function() {
302 expect(focaAbmVehiculoService.transportistaSeleccionado) 302 expect(focaAbmVehiculoService.transportistaSeleccionado)
303 .toEqual(jasmine.objectContaining({ 303 .toEqual(jasmine.objectContaining({
304 COD: '', NOM: '' 304 COD: '', NOM: ''
305 })); 305 }));
306 done(); 306 done();
307 } 307 }
308 ); 308 );
309 }); 309 });
310 }); 310 });
311 }); 311 });
312 312
313 describe('Controlador focaAbmVehiculoController', function() { 313 describe('Controlador focaAbmVehiculoController', function() {
314 314
315 var $timeout; 315 var $timeout;
316 beforeEach(inject(function(_$timeout_) { 316 beforeEach(inject(function(_$timeout_) {
317 $timeout = _$timeout_; 317 $timeout = _$timeout_;
318 })); 318 }));
319 319
320 it('Existe el controller focaAbmVehiculoController', function() { 320 it('Existe el controller focaAbmVehiculoController', function() {
321 321
322 //arrange 322 //arrange
323 var controller = $controller('focaAbmVehiculoController', { 323 var controller = $controller('focaAbmVehiculoController', {
324 $scope: { 324 $scope: {
325 $watch: function() {} 325 $watch: function() {}
326 }, 326 },
327 focaAbmVehiculoService: { 327 focaAbmVehiculoService: {
328 getCisternas: function() {
329 return {
330 then: function() { return; }
331 };
332 },
328 getVehiculo: function() { 333 getVehiculo: function() {
329 return { 334 return {
330 then: function() { return; } 335 then: function() { return; }
331 }; 336 };
332 } 337 }
333 }, 338 },
334 $routeParams: {}, 339 $routeParams: {},
335 $location: {}, 340 $location: {},
336 $uibModal: {}, 341 $uibModal: {},
337 focaModalService: {}, 342 focaModalService: {},
338 $timeout: $timeout, 343 $timeout: $timeout,
339 focaBotoneraLateralService: { 344 focaBotoneraLateralService: {
340 showSalir: function() { return; }, 345 showSalir: function() { return; },
341 showPausar: function() { return; }, 346 showPausar: function() { return; },
342 showCancelar: function() { return; }, 347 showCancelar: function() { return; },
343 showGuardar: function() { return; }, 348 showGuardar: function() { return; },
344 addCustomButton: function() { return; } 349 addCustomButton: function() { return; }
345 }, 350 },
346 $localStorage: {}, 351 $localStorage: {},
347 $window: {} 352 $window: {}
348 }); 353 });
349 354
350 //assert 355 //assert
351 expect(typeof controller).toEqual('object'); 356 expect(typeof controller).toEqual('object');
352 357
353 }); 358 });
354 359
355 it('Se busca el transportista cuando es nuevo', function() { 360 it('Se busca el transportista cuando es nuevo', function() {
356 361
357 //arrange 362 //arrange
358 var scope = { 363 var scope = {
359 $watch: function() {} 364 $watch: function() {}
360 }; 365 };
361 var focaAbmVehiculoService = { 366 var focaAbmVehiculoService = {
367
368 getCisternas: function() {
369 return {
370 then: function() { return; }
371 };
372 },
362 getVehiculo: function() { 373 getVehiculo: function() {
363 return { 374 return {
364 then: function() { return; } 375 then: function() { return; }
365 }; 376 };
366 }, 377 },
367 getTransportistaPorId: function() { return; } 378 getTransportistaPorId: function() { return; }
368 }; 379 };
369 380
370 spyOn(focaAbmVehiculoService, 'getTransportistaPorId') 381 spyOn(focaAbmVehiculoService, 'getTransportistaPorId')
371 .and.returnValue({then: function() { return; }}); 382 .and.returnValue({then: function() { return; }});
372 383
373 //act 384 //act
374 var controller = $controller('focaAbmVehiculoController', { 385 var controller = $controller('focaAbmVehiculoController', {
375 $scope: scope, 386 $scope: scope,
376 focaAbmVehiculoService: focaAbmVehiculoService, 387 focaAbmVehiculoService: focaAbmVehiculoService,
377 $routeParams: { 388 $routeParams: {
378 idVehiculo: '0' 389 idVehiculo: '0'
379 }, 390 },
380 $location: {}, 391 $location: {},
381 $uibModal: {}, 392 $uibModal: {},
382 focaModalService: {}, 393 focaModalService: {},
383 $timeout: $timeout, 394 $timeout: $timeout,
384 focaBotoneraLateralService: { 395 focaBotoneraLateralService: {
385 showSalir: function() { return; }, 396 showSalir: function() { return; },
386 showPausar: function() { return; }, 397 showPausar: function() { return; },
387 showCancelar: function() { return; }, 398 showCancelar: function() { return; },
388 showGuardar: function() { return; }, 399 showGuardar: function() { return; },
389 addCustomButton: function() { return; } 400 addCustomButton: function() { return; }
390 }, 401 },
391 $localStorage: {}, 402 $localStorage: {},
392 $window: {} 403 $window: {}
393 }); 404 });
394 405
395 //assert 406 //assert
396 expect(focaAbmVehiculoService.getTransportistaPorId).toHaveBeenCalled(); 407 expect(focaAbmVehiculoService.getTransportistaPorId).toHaveBeenCalled();
397 }); 408 });
398 409
399 it('No se busca el transportista cuando es nuevo', function() { 410 it('No se busca el transportista cuando es nuevo', function() {
400 411
401 //arrange 412 //arrange
402 var scope = { 413 var scope = {
403 $watch: function() {} 414 $watch: function() {}
404 }; 415 };
405 var focaAbmVehiculoService = { 416 var focaAbmVehiculoService = {
417
418 getCisternas: function() {
419 return {
420 then: function() { return; }
421 };
422 },
423
406 getVehiculo: function() { 424 getVehiculo: function() {
407 return { 425 return {
408 then: function() { return; } 426 then: function() { return; }
409 }; 427 };
410 }, 428 },
411 getTransportistaPorId: function() { return; } 429 getTransportistaPorId: function() { return; }
412 }; 430 };
413 431
414 spyOn(focaAbmVehiculoService, 'getTransportistaPorId') 432 spyOn(focaAbmVehiculoService, 'getTransportistaPorId')
415 .and.returnValue({then: function() { return; }}); 433 .and.returnValue({then: function() { return; }});
416 434
417 //act 435 //act
418 var controller = $controller('focaAbmVehiculoController', { 436 var controller = $controller('focaAbmVehiculoController', {
419 $scope: scope, 437 $scope: scope,
420 focaAbmVehiculoService: focaAbmVehiculoService, 438 focaAbmVehiculoService: focaAbmVehiculoService,
421 $routeParams: {}, 439 $routeParams: {},
422 $location: {}, 440 $location: {},
423 $uibModal: {}, 441 $uibModal: {},
424 focaModalService: {}, 442 focaModalService: {},
425 $timeout: $timeout, 443 $timeout: $timeout,
426 focaBotoneraLateralService: { 444 focaBotoneraLateralService: {
427 showSalir: function() { return; }, 445 showSalir: function() { return; },
428 showPausar: function() { return; }, 446 showPausar: function() { return; },
429 showCancelar: function() { return; }, 447 showCancelar: function() { return; },
430 showGuardar: function() { return; }, 448 showGuardar: function() { return; },
431 addCustomButton: function() { return; } 449 addCustomButton: function() { return; }
432 }, 450 },
433 $localStorage: {}, 451 $localStorage: {},
434 $window: {} 452 $window: {}
435 }); 453 });
436 454
437 //assert 455 //assert
438 expect(focaAbmVehiculoService.getTransportistaPorId).not.toHaveBeenCalled(); 456 expect(focaAbmVehiculoService.getTransportistaPorId).not.toHaveBeenCalled();
439 }); 457 });
440 458
441 it('Cancelar lleva a la ruta /vehiculo', function() { 459 it('Cancelar lleva a la ruta /vehiculo', function() {
442 460
443 inject(function($location) { 461 inject(function($location) {
444 //arrange 462 //arrange
445 var scope = { 463 var scope = {
446 $watch: function() {}, 464 $watch: function() {},
447 cancelar: function() {}, 465 cancelar: function() {},
448 formVehiculo: { 466 formVehiculo: {
449 $pristine: true 467 $pristine: true
450 } 468 }
451 }; 469 };
452 var controller = $controller('focaAbmVehiculoController', { 470 var controller = $controller('focaAbmVehiculoController', {
453 $scope: scope, 471 $scope: scope,
454 focaAbmVehiculoService: { 472 focaAbmVehiculoService: {
473 getCisternas: function() {
474 return {
475 then: function() { return; }
476 };
477 },
455 getVehiculo: function() { 478 getVehiculo: function() {
456 return { 479 return {
457 then: function() { return; } 480 then: function() { return; }
458 }; 481 };
459 } 482 }
460 }, 483 },
461 $routeParams: {}, 484 $routeParams: {},
462 $location: $location, 485 $location: $location,
463 $uibModal: {}, 486 $uibModal: {},
464 focaModalService: {}, 487 focaModalService: {},
465 $timeout: $timeout, 488 $timeout: $timeout,
466 focaBotoneraLateralService: { 489 focaBotoneraLateralService: {
467 showSalir: function() { return; }, 490 showSalir: function() { return; },
468 showPausar: function() { return; }, 491 showPausar: function() { return; },
469 showCancelar: function() { return; }, 492 showCancelar: function() { return; },
470 showGuardar: function() { return; }, 493 showGuardar: function() { return; },
471 addCustomButton: function() { return; } 494 addCustomButton: function() { return; }
472 }, 495 },
473 $localStorage: {}, 496 $localStorage: {},
474 $window: {}, 497 $window: {},
475 498
476 }); 499 });
477 500
478 //act 501 //act
479 scope.salir(); 502 scope.salir();
480 503
481 //assert 504 //assert
482 expect($location.url()).toEqual('/vehiculo'); 505 expect($location.url()).toEqual('/vehiculo');
483 }); 506 });
484 }); 507 });
485 508
486 it('Editar lleva a la ruta correcta cuando recibe variable key', function() { 509 it('Editar lleva a la ruta correcta cuando recibe variable key', function() {
487 510
488 inject(function($location) { 511 inject(function($location) {
489 //arrange 512 //arrange
490 var scope = { 513 var scope = {
491 $watch: function() {} 514 $watch: function() {}
492 }; 515 };
493 var controller = $controller('focaAbmVehiculoController', { 516 var controller = $controller('focaAbmVehiculoController', {
494 $scope: scope, 517 $scope: scope,
495 focaAbmVehiculoService: { 518 focaAbmVehiculoService: {
519 getCisternas: function() {
520 return {
521 then: function() { return; }
522 };
523 },
496 getVehiculo: function() { 524 getVehiculo: function() {
497 return { 525 return {
498 then: function() { return; } 526 then: function() { return; }
499 }; 527 };
500 } 528 }
501 }, 529 },
502 $routeParams: { 530 $routeParams: {
503 idVehiculo: 1 531 idVehiculo: 1
504 }, 532 },
505 $location: $location, 533 $location: $location,
506 $uibModal: {}, 534 $uibModal: {},
507 focaModalService: {}, 535 focaModalService: {},
508 $timeout: $timeout, 536 $timeout: $timeout,
509 focaBotoneraLateralService: { 537 focaBotoneraLateralService: {
510 showSalir: function() { return; }, 538 showSalir: function() { return; },
511 showPausar: function() { return; }, 539 showPausar: function() { return; },
512 showCancelar: function() { return; }, 540 showCancelar: function() { return; },
513 showGuardar: function() { return; }, 541 showGuardar: function() { return; },
514 addCustomButton: function() { return; } 542 addCustomButton: function() { return; }
515 }, 543 },
516 $localStorage: {}, 544 $localStorage: {},
517 $window: {} 545 $window: {}
518 }); 546 });
519 547
520 //act 548 //act
521 scope.editar('testing'); 549 scope.editar('testing');
522 var esperado = '/vehiculo/1/cisterna/testing'; 550 var esperado = '/vehiculo/1/cisterna/testing';
523 551
524 //assert 552 //assert
525 expect($location.url()).toEqual(esperado); 553 expect($location.url()).toEqual(esperado);
526 }); 554 });
527 }); 555 });
528 556
529 it('Editar lleva a la ruta correcta cuando no recibe variable key', function() { 557 it('Editar lleva a la ruta correcta cuando no recibe variable key', function() {
530 558
531 inject(function($location) { 559 inject(function($location) {
532 //arrange 560 //arrange
533 var scope = { 561 var scope = {
534 $watch: function() {} 562 $watch: function() {}
535 }; 563 };
536 var controller = $controller('focaAbmVehiculoController', { 564 var controller = $controller('focaAbmVehiculoController', {
537 $scope: scope, 565 $scope: scope,
538 focaAbmVehiculoService: { 566 focaAbmVehiculoService: {
567 getCisternas: function() {
568 return {
569 then: function() { return; }
570 };
571 },
539 getVehiculo: function() { 572 getVehiculo: function() {
540 return { 573 return {
541 then: function() { return; } 574 then: function() { return; }
542 }; 575 };
543 } 576 }
544 }, 577 },
545 $routeParams: { 578 $routeParams: {
546 idVehiculo: 1 579 idVehiculo: 1
547 }, 580 },
548 $location: $location, 581 $location: $location,
549 $uibModal: {}, 582 $uibModal: {},
550 focaModalService: {}, 583 focaModalService: {},
551 $timeout: $timeout, 584 $timeout: $timeout,
552 focaBotoneraLateralService: { 585 focaBotoneraLateralService: {
553 showSalir: function() { return; }, 586 showSalir: function() { return; },
554 showPausar: function() { return; }, 587 showPausar: function() { return; },
555 showCancelar: function() { return; }, 588 showCancelar: function() { return; },
556 showGuardar: function() { return; }, 589 showGuardar: function() { return; },
557 addCustomButton: function() { return; } 590 addCustomButton: function() { return; }
558 }, 591 },
559 $localStorage: {}, 592 $localStorage: {},
560 $window: {} 593 $window: {}
561 }); 594 });
562 595
563 //act 596 //act
564 scope.editar(); 597 scope.editar();
565 var esperado = '/vehiculo/1/cisterna/0/'; 598 var esperado = '/vehiculo/1/cisterna/0/';
566 599
567 //assert 600 //assert
568 expect($location.url()).toEqual(esperado); 601 expect($location.url()).toEqual(esperado);
569 }); 602 });
570 }); 603 });
571 604
572 it('$scope.solicitarConfirmacionCisterna ejecuta modal de confirmación', function() { 605 it('$scope.solicitarConfirmacionCisterna ejecuta modal de confirmación', function() {
573 606
574 //arrange 607 //arrange
575 var focaModalService = { 608 var focaModalService = {
576 confirm: function() {} 609 confirm: function() {}
577 }; 610 };
578 var scope = { 611 var scope = {
579 $watch: function() {} 612 $watch: function() {}
580 }; 613 };
581 var controller = $controller('focaAbmVehiculoController', { 614 var controller = $controller('focaAbmVehiculoController', {
582 $scope: scope, 615 $scope: scope,
583 focaAbmVehiculoService: { 616 focaAbmVehiculoService: {
617 getCisternas: function() {
618 return {
619 then: function() { return; }
620 };
621 },
584 getVehiculo: function() { 622 getVehiculo: function() {
585 return { 623 return {
586 then: function() { return; } 624 then: function() { return; }
587 }; 625 };
588 } 626 }
589 }, 627 },
590 $routeParams: { 628 $routeParams: {
591 idVehiculo: 1 629 idVehiculo: 1
592 }, 630 },
593 $location: {}, 631 $location: {},
594 $uibModal: {}, 632 $uibModal: {},
595 focaModalService: focaModalService, 633 focaModalService: focaModalService,
596 $timeout: $timeout, 634 $timeout: $timeout,
597 focaBotoneraLateralService: { 635 focaBotoneraLateralService: {
598 showSalir: function() { return; }, 636 showSalir: function() { return; },
599 showPausar: function() { return; }, 637 showPausar: function() { return; },
600 showCancelar: function() { return; }, 638 showCancelar: function() { return; },
601 showGuardar: function() { return; }, 639 showGuardar: function() { return; },
602 addCustomButton: function() { return; } 640 addCustomButton: function() { return; }
603 }, 641 },
604 $localStorage: {}, 642 $localStorage: {},
605 $window: {} 643 $window: {},
606 }); 644 });
607 645
608 //act 646 //act
609 spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}}); 647 spyOn(focaModalService, 'confirm').and.returnValue({then: function() {}});
610 scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); 648 scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'});
611 649
612 //assert 650 //assert
613 expect(focaModalService.confirm).toHaveBeenCalled(); 651 expect(focaModalService.confirm).toHaveBeenCalled();
614 }); 652 });
615 653
616 it('Elimina y obtiene cisternas al dar confirmar', function(done) { 654 it('Elimina y obtiene cisternas al dar confirmar', function(done) {
617 655
618 //arrange 656 //arrange
619 var scope = { 657 var scope = {
620 $watch: function() {} 658 $watch: function() {}
621 }; 659 };
622 var focaModalService = { 660 var focaModalService = {
623 confirm: function() {} 661 confirm: function() {}
624 }; 662 };
625 var focaAbmVehiculoService = { 663 var focaAbmVehiculoService = {
626 getVehiculo: function() { 664 getVehiculo: function() {
627 return { 665 return {
628 then: function() { return; } 666 then: function() { return; }
629 }; 667 };
630 }, 668 },
631 getCisternas: function() { return; }, 669 getCisternas: function() {
670 return {
671 then: function() { return; }
672 };
673 },
632 deleteCisterna: function() { return; } 674 deleteCisterna: function() { return; }
633 }; 675 };
634 var controller = $controller('focaAbmVehiculoController', { 676 var controller = $controller('focaAbmVehiculoController', {
635 $scope: scope, 677 $scope: scope,
636 focaAbmVehiculoService: focaAbmVehiculoService, 678 focaAbmVehiculoService: focaAbmVehiculoService,
637 $routeParams: {}, 679 $routeParams: {},
638 $location: {}, 680 $location: {},
639 $uibModal: {}, 681 $uibModal: {},
640 focaModalService: focaModalService, 682 focaModalService: focaModalService,
641 $timeout: $timeout, 683 $timeout: $timeout,
642 focaBotoneraLateralService: { 684 focaBotoneraLateralService: {
643 showSalir: function() { return; }, 685 showSalir: function() { return; },
644 showPausar: function() { return; }, 686 showPausar: function() { return; },
645 showCancelar: function() { return; }, 687 showCancelar: function() { return; },
646 showGuardar: function() { return; }, 688 showGuardar: function() { return; },
647 addCustomButton: function() { return; } 689 addCustomButton: function() { return; }
648 }, 690 },
649 $localStorage: {}, 691 $localStorage: {},
650 $window: {} 692 $window: {}
651 }); 693 });
652 var promesa = Promise.resolve(true); 694 var promesa = Promise.resolve(true);
653 695
654 //act 696 //act
655 spyOn(focaModalService, 'confirm').and.returnValue(promesa); 697 spyOn(focaModalService, 'confirm').and.returnValue(promesa);
656 spyOn(focaAbmVehiculoService, 'deleteCisterna'); 698 spyOn(focaAbmVehiculoService, 'deleteCisterna');
657 spyOn(focaAbmVehiculoService, 'getCisternas').and.returnValue({ then: function() {} }); 699 spyOn(focaAbmVehiculoService, 'getCisternas').and.returnValue({ then: function() {} });
658 scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'}); 700 scope.solicitarConfirmacionCisterna({id: 1, codigo: 'abc'});
659 701
660 //assert 702 //assert
661 promesa.then( 703 promesa.then(
662 function() { 704 function() {
663 expect(focaAbmVehiculoService.deleteCisterna).toHaveBeenCalled(); 705 expect(focaAbmVehiculoService.deleteCisterna).toHaveBeenCalled();
664 expect(focaAbmVehiculoService.getCisternas).toHaveBeenCalled(); 706 expect(focaAbmVehiculoService.getCisternas).toHaveBeenCalled();
665 done(); 707 done();
666 } 708 }
667 ); 709 );
668 }); 710 });
669 }); 711 });
670 }); 712 });
671 713
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.tipo = '';
9 $scope.botonera = [{ 10 $scope.botonera = [{
10 label: 'Transportista', 11 label: 'Transportista',
11 image: 'cliente.png' 12 image: 'cliente.png'
12 }]; 13 }];
13 14
14 focaAbmVehiculoService.cleanCisternas(); 15 focaAbmVehiculoService.cleanCisternas();
15 16
16 //SETEO BOTONERA LATERAL 17 //SETEO BOTONERA LATERAL
17 focaBotoneraLateralService.showSalir(false); 18 focaBotoneraLateralService.showSalir(false);
18 focaBotoneraLateralService.showPausar(false); 19 focaBotoneraLateralService.showPausar(false);
19 focaBotoneraLateralService.showCancelar(false); 20 focaBotoneraLateralService.showCancelar(false);
20 focaBotoneraLateralService.showGuardar(false); 21 focaBotoneraLateralService.showGuardar(false);
21 focaBotoneraLateralService.addCustomButton('Salir', salir); 22 focaBotoneraLateralService.addCustomButton('Salir', salir);
22 23
23 if (focaAbmVehiculoService.transportistaSeleccionado.COD) { 24 if (focaAbmVehiculoService.transportistaSeleccionado.COD) {
24 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); 25 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado);
25 } 26 }
26 $scope.editar = function(id) { 27 $scope.editar = function (id) {
27 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); 28 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista);
28 }; 29 };
29 $scope.solicitarConfirmacion = function(vehiculo) { 30
31 $scope.solicitarConfirmacion = function (vehiculo) {
30 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + 32 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
31 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( 33 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
32 function(data) { 34 function (data) {
33 if (data) { 35 if (data) {
34 focaAbmVehiculoService.deleteVehiculo(vehiculo.id); 36 focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
35 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); 37 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
36 } 38 }
37 } 39 }
38 ); 40 );
39 }; 41 };
40 $scope.seleccionarTransportista = function() { 42 $scope.seleccionarTransportista = function () {
41 var parametrosModal = { 43 var parametrosModal = {
42 titulo: 'Búsqueda de Transportista', 44 titulo: 'Búsqueda de Transportista',
43 query: '/transportista', 45 query: '/transportista',
44 columnas: [ 46 columnas: [
45 { 47 {
46 nombre: 'Código', 48 nombre: 'Código',
47 propiedad: 'COD' 49 propiedad: 'COD'
48 }, 50 },
49 { 51 {
50 nombre: 'Nombre', 52 nombre: 'Nombre',
51 propiedad: 'NOM' 53 propiedad: 'NOM'
52 }, 54 },
53 { 55 {
54 nombre: 'CUIT', 56 nombre: 'CUIT',
55 propiedad: 'CUIT' 57 propiedad: 'CUIT'
56 } 58 }
57 ] 59 ]
58 }; 60 };
59 focaModalService.modal(parametrosModal).then( 61 focaModalService.modal(parametrosModal).then(
60 function(transportista) { 62 function (transportista) {
61 elegirTransportista(transportista); 63 elegirTransportista(transportista);
62 focaAbmVehiculoService.transportistaSeleccionado = transportista; 64 focaAbmVehiculoService.transportistaSeleccionado = transportista;
63 }, function() { 65 }, function () {
64 66
65 } 67 }
66 ); 68 );
67 }; 69 };
68 function elegirTransportista(transportista) { 70 function elegirTransportista(transportista) {
69 var codigo = ('00000' + transportista.COD).slice(-5); 71 var codigo = ('00000' + transportista.COD).slice(-5);
70 $scope.idTransportista = transportista.COD; 72 $scope.idTransportista = transportista.COD;
71 $scope.filtros = transportista.NOM.trim(); 73 $scope.filtros = transportista.NOM.trim();
72 $timeout(function() { 74 $timeout(function () {
73 $scope.$broadcast('addCabecera', { 75 $scope.$broadcast('addCabecera', {
74 label: 'Transportista:', 76 label: 'Transportista:',
75 valor: codigo + ' - ' + transportista.NOM 77 valor: codigo + ' - ' + transportista.NOM
76 }); 78 });
77 }); 79 });
78 buscar(transportista.COD); 80 buscar(transportista.COD);
79 } 81 }
80 82
81 function buscar(idTransportista) { 83 function buscar(idTransportista) {
82 focaAbmVehiculoService 84 focaAbmVehiculoService
83 .getVehiculosPorTransportista(idTransportista) 85 .getVehiculosPorTransportista(idTransportista)
84 .then(function(datos) { 86 .then(function (datos) {
85 $scope.vehiculos = datos.data; 87 $scope.vehiculos = datos.data;
86 }); 88 });
87 } 89 }
88 function salir() { 90 function salir() {
89 focaAbmVehiculoService.transportistaSeleccionado = {}; 91 focaAbmVehiculoService.transportistaSeleccionado = {};
90 $location.path('/'); 92 $location.path('/');
91 } 93 }
92 } 94 }
93 ]) 95 ])
94 .controller('focaAbmVehiculoController', [ 96 .controller('focaAbmVehiculoController', [
95 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 97 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
96 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', 98 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter',
97 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 99 function ($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
98 focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { 100 focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) {
99 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; 101 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false;
102 $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true;
100 $scope.now = new Date(); 103 $scope.now = new Date();
101 $scope.focused = 1; 104 $scope.focused = 1;
105 $scope.tipo = '';
106 $scope.creando = false;
107 $scope.crear = false;
102 $scope.transportistaStamp = ''; 108 $scope.transportistaStamp = '';
103 $scope.cisternas = []; 109 $scope.cisternas = [];
104 110
105 $timeout(function() { 111 $timeout(function () {
106 focaBotoneraLateralService.showSalir(false); 112 focaBotoneraLateralService.showSalir(false);
107 focaBotoneraLateralService.showPausar(true); 113 focaBotoneraLateralService.showPausar(true);
108 focaBotoneraLateralService.showCancelar(false); 114 focaBotoneraLateralService.showCancelar(false);
109 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 115 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
110 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); 116 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
111 }); 117 });
112
113 $timeout(function() {getLSVehiculo();});
114 118
115 if ($scope.nuevo) { 119 if ($scope.nuevo) {
120 $scope.tipo = 'Crear Vehiculo';
116 focaAbmVehiculoService 121 focaAbmVehiculoService
117 .getTransportistaPorId($routeParams.idTransportista) 122 .getTransportistaPorId($routeParams.idTransportista)
118 .then(function(res) { 123 .then(function (res) {
119 var codigo = ('00000' + res.data.COD).slice(-5); 124 var codigo = ('00000' + res.data[0].COD).slice(-5);
120 $scope.vehiculo.idTransportista = res.data.COD; 125 $scope.vehiculo.idTransportista = res.data[0].COD;
121 $scope.vehiculo.transportista = res.data; 126 $scope.vehiculo.transportista = res.data;
122 $scope.$broadcast('addCabecera', { 127 $scope.$broadcast('addCabecera', {
123 label: 'Transportista:', 128 label: 'Transportista:',
124 valor: codigo + ' - ' + res.data.NOM 129 valor: codigo + ' - ' + res.data[0].ALI
130 });
131 $scope.$broadcast('addCabecera', {
132 label: 'Unidad:',
133 valor: 'NUEVO'
125 }); 134 });
126 }); 135 });
136 } else {
137 $scope.tipo = 'Editar Vehiculo';
127 } 138 }
128 $scope.vehiculo = {}; 139 $scope.vehiculo = {};
129 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 140
141 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function (res) {
130 if (res.data) { 142 if (res.data) {
131 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); 143 var vehiculoSeteado = getLSVehiculo();
132 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; 144 if (vehiculoSeteado === false) {
145 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5);
146 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM;
147
148 $scope.vehiculo = res.data;
149 $scope.$broadcast('addCabecera', {
150 label: 'Transportista:',
151 valor: $scope.transportistaStamp
152 });
153 $scope.$broadcast('addCabecera', {
154 label: 'Unidad:',
155 valor: res.data.codigo
156 });
157 }
133 158
134 $scope.vehiculo = res.data;
135 $scope.$broadcast('addCabecera', {
136 label: 'Transportista:',
137 valor: $scope.transportistaStamp
138 });
139 $scope.$broadcast('addCabecera', {
140 label: 'Unidad:',
141 valor: res.data.codigo
142 });
143 focaAbmVehiculoService 159 focaAbmVehiculoService
144 .getCisternas($routeParams.idVehiculo) 160 .getCisternas($routeParams.idVehiculo)
145 .then(function(res) { 161 .then(function (res) {
146 $scope.cisternas = res; 162 $scope.cisternas = res;
147 $scope.$apply(); 163 $scope.$apply();
148 }); 164 });
149 } 165 }
150 }); 166 });
151 167
152 $scope.next = function(key) { 168 $scope.next = function (key) {
153 if (key === 13) $scope.focused++; 169 if (key === 13) $scope.focused++;
154 }; 170 };
155 171
156 $scope.salir = function() { 172 $scope.salir = function () {
157 if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { 173 if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) {
158 focaModalService.confirm( 174 focaModalService.confirm(
159 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 175 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
160 ).then(function(data) { 176 ).then(function (data) {
161 if (data) { 177 if (data) {
162 $location.path('/vehiculo'); 178 $location.path('/vehiculo');
163 } 179 }
164 }); 180 });
165 } else { 181 } else {
166 $location.path('/vehiculo'); 182 $location.path('/vehiculo');
167 } 183 }
168 } 184 };
169 185
170 $scope.editar = function(key) { 186 $scope.editar = function (cisterna) {
171 if (key) { 187 $scope.cisternas.forEach(function (cisterna) {
172 $location.path('/vehiculo/' + $routeParams.idVehiculo + 188 cisterna.editando = false;
173 '/cisterna/' + key); 189 $scope.crear = true;
174 } else { 190 });
175 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); 191 cisterna.editando = true;
192 $scope.inicial = angular.copy(cisterna);
193 };
194
195 $scope.volver = function (cisterna, key) {
196 if (cisterna.id === undefined || !$scope.crear) {
197 $scope.cisternas.shift(cisterna);
198 $scope.crear = false;
199 return;
176 } 200 }
201 if (cisterna.id !== undefined) {
202 $scope.cisternas[key] = $scope.inicial;
203 $scope.cisternas[key].editando = false;
204 }
205 $scope.crear = false;
206 };
207
208 $scope.crearCisterna = function () {
209 var cisterna = {
210 codigo: '',
211 capacidad: '',
212 idUnidadMedida: 0,
213 unidadMedida: {},
214 editando: true,
215 };
216 $scope.cisternas.unshift(cisterna);
217 $scope.crear = true;
218 };
219
220 $scope.seleccionarUnidadMedida = function (cisterna) {
221 var modalInstance = $uibModal.open(
222 {
223 ariaLabelledBy: 'Busqueda de Unidades de medida',
224 templateUrl: 'modal-unidad-medida.html',
225 controller: 'focaModalUnidadMedidaCtrl',
226 size: 'lg'
227 }
228 );
229 modalInstance.result.then(function (unidaMedida) {
230 cisterna.idUnidadMedida = unidaMedida.ID;
231 cisterna.unidadMedida = unidaMedida;
232 });
177 }; 233 };
178 $scope.guardar = function(key) {
179 234
180 key = (typeof key === 'undefined') ? 13 : key; 235 $scope.guardar = function (key) {
236 key = (typeof key === 'undefined') ? 13 : key;
181 237
182 if (key === 13) { 238 if (key === 13) {
183 239
184 if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { 240 if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) {
185 $scope.salir(); 241 $scope.salir();
186 return; 242 return;
187 } 243 }
244 $scope.cisternas.forEach(function (cisterna) {
245 if (cisterna.id === 0) cisterna.id = undefined;
246 });
188 247
189 if (!$scope.vehiculo.codigo) { 248 if (!$scope.vehiculo.codigo) {
190 focaModalService.alert('Ingrese unidad'); 249 focaModalService.alert('Ingrese unidad');
191 return; 250 return;
192 } else if (!$scope.vehiculo.tractor) { 251 } else if (!$scope.vehiculo.tractor) {
193 focaModalService.alert('Ingrese dominio tractor'); 252 focaModalService.alert('Ingrese dominio tractor');
194 return; 253 return;
195 } else if (!$scope.vehiculo.semi) { 254 } else if (!$scope.vehiculo.semi) {
196 focaModalService.alert('Ingrese dominio semi'); 255 focaModalService.alert('Ingrese dominio semi');
197 return; 256 return;
198 } else if (!$scope.vehiculo.capacidad) { 257 } else if (!$scope.vehiculo.capacidad) {
199 focaModalService.alert('Ingrese capacidad total'); 258 focaModalService.alert('Ingrese capacidad total');
200 return; 259 return;
201 } 260 }
202 //Valida si existe numero de unidad 261 //Valida si existe numero de unidad
203 if (!validaTotalCargas() && !$scope.nuevo) { 262 if (!validaTotalCargas() && !$scope.nuevo) {
204 focaModalService.alert('La suma de las capacidades de las cisternas' + 263 focaModalService.alert('La suma de las capacidades de las cisternas' +
205 ' debe ser igual a la capacidad total del vehículo'); 264 ' debe ser igual a la capacidad total del vehículo');
206 return; 265 return;
207 } 266 }
208 validaCodigoUnidad().then(function() { 267
209 delete $scope.vehiculo.transportista; 268 if ($scope.nuevo) {
210 delete $scope.vehiculo.cisternas; 269 validaCodigoUnidad().then(function () {
211 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) 270 delete $scope.vehiculo.transportista;
212 .then(function(res) { 271 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo)
213 if ($scope.nuevo) { 272 .then(function (res) {
214 $location.path('/vehiculo/' + res.data.id + 273 $routeParams.idVehiculo = res.data.id;
215 '/' + res.data.idTransportista); 274 guardarCisternas($scope.cisternas).then(function () {
216 } else { 275 angular.element('#guardar').addClass('guardado');
217 guardarCisternas().then(function() { 276 $timeout(function () {$location.path('/vehiculo');},300);
218 $location.path('/vehiculo');
219 }); 277 });
220 } 278 });
221 }); 279 }, function () {
222 }, function() { 280 focaModalService.alert('Código de unidad existente');
223 focaModalService.alert('Código de unidad existente'); 281 });
224 }); 282 } else {
283 guardarCisternas($scope.cisternas).then(function () {
284 angular.element('#guardar').addClass('guardado');
285 $timeout(function () {$location.path('/vehiculo');},500);
286 });
287 }
225 } 288 }
226
227 }; 289 };
228 290 //Agregar propiedades de cisterna
229 $scope.$watch('vehiculo', function(newValue) { 291 $scope.$watch('vehiculo', function (newValue) {
230 focaBotoneraLateralService.setPausarData({ 292 focaBotoneraLateralService.setPausarData({
231 label:'vehiculo', 293 label: 'vehiculo',
232 val: { 294 val: {
233 codigo: newValue.codigo, 295 codigo: newValue.codigo,
234 tractor: newValue.tractor, 296 tractor: newValue.tractor,
235 semi: newValue.semi, 297 semi: newValue.semi,
236 capacidad: newValue.capacidad, 298 capacidad: newValue.capacidad,
237 idVehiculo: newValue.idVehiculo, 299 idVehiculo: newValue.idVehiculo,
238 idTransportista: newValue.idTransportista 300 idTransportista: newValue.idTransportista
239 } 301 }
240 }); 302 });
241 }, true); 303 }, true);
242 304
243 function getLSVehiculo() { 305 function getLSVehiculo() {
244 var vehiculo = JSON.parse($localStorage.vehiculo|| null); 306 var vehiculo = JSON.parse($localStorage.vehiculo || null);
245 if (vehiculo) { 307 if (vehiculo) {
246 setearVehiculo(vehiculo); 308 setearVehiculo(vehiculo);
247 delete $localStorage.vehiculo; 309 delete $localStorage.vehiculo;
310 return true;
248 } 311 }
312 return false;
249 } 313 }
250 314
251 function setearVehiculo(vehiculo) { 315 function setearVehiculo(vehiculo) {
252 $scope.vehiculo = vehiculo; 316 $scope.vehiculo = vehiculo;
253 $scope.$broadcast('addCabecera', { 317 $scope.$broadcast('addCabecera', {
254 label: 'Vehiculo:', 318 label: 'Vehiculo:',
255 valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' 319 valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - '
256 }); 320 });
257 } 321 }
258 322
259 $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { 323 $scope.solicitarConfirmacionTabla = function (cisterna) {
260 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + 324 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?')
261 cisterna.id + ' ' + cisterna.codigo + ' ?').then( 325 .then(function (data) {
262 function(data) { 326 if (data) {
263 if (data) { 327 cisterna.desactivado = true;
264 focaAbmVehiculoService.deleteCisterna(idx);
265 focaAbmVehiculoService
266 .getCisternas($routeParams.idVehiculo)
267 .then(function(res) {
268 $scope.cisternas = res;
269 });
270 }
271 } 328 }
272 ); 329 });
330 return;
273 }; 331 };
274 332
275 function validaCodigoUnidad() { 333 function validaCodigoUnidad() {
276 return new Promise(function(resolve, reject) { 334 return new Promise(function (resolve, reject) {
277 focaAbmVehiculoService 335 focaAbmVehiculoService
278 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) 336 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista))
279 .then(function(res) { 337 .then(function (res) {
280 //Valida si existe numero de unidad 338 //Valida si existe numero de unidad
281 var existe = res.data.filter(function(vehiculo) { 339 var existe = res.data.filter(function (vehiculo) {
282 return vehiculo.codigo === $scope.vehiculo.codigo && 340 return vehiculo.codigo === $scope.vehiculo.codigo &&
283 vehiculo.id !== $scope.vehiculo.id; 341 vehiculo.id !== $scope.vehiculo.id;
284 }); 342 });
285 343
286 if (existe.length) { 344 if (existe.length) {
287 reject(existe); 345 reject(existe);
288 } else { 346 } else {
289 resolve(); 347 resolve();
290 } 348 }
291 }); 349 });
292 }); 350 });
293 } 351 }
294 352
295 function validaTotalCargas() { 353 function validaTotalCargas() {
296 var total = 0; 354 var total = 0;
297 $scope.cisternas.forEach(function(cisterna) { 355 $scope.cisternas.forEach(function (cisterna) {
298 if (!cisterna.desactivado) { 356 if (!cisterna.desactivado) {
299 total += parseInt(cisterna.capacidad); 357 total += parseInt(cisterna.capacidad);
300 } 358 }
301 }); 359 });
302 return $scope.vehiculo.capacidad == total; 360 return $scope.vehiculo.capacidad >= total;
303 } 361 }
304
305 function guardarCisternas() { 362 function guardarCisternas() {
306 var cisternas = $scope.cisternas.map(function(cisterna) { 363
364 var cisternas = $scope.cisternas.map(function (cisterna) {
307 return { 365 return {
308 id: cisterna.id, 366 id: cisterna.id,
309 capacidad: parseFloat(cisterna.capacidad), 367 capacidad: parseFloat(cisterna.capacidad),
310 codigo: cisterna.codigo, 368 codigo: cisterna.codigo,
311 idUnidadMedida: cisterna.idUnidadMedida, 369 idUnidadMedida: cisterna.idUnidadMedida,
312 idVehiculo: $routeParams.idVehiculo, 370 idVehiculo: $routeParams.idVehiculo,
313 desactivado: cisterna.desactivado 371 desactivado: cisterna.desactivado
314 }; 372 };
315 }); 373 });
316 374
317 return focaAbmVehiculoService.guardarCisternas(cisternas); 375 return focaAbmVehiculoService.guardarCisternas(cisternas);
318 } 376 }
319 377
378 $scope.agregarCisterna = function (cisterna) {
379 if (!cisterna) {
380 focaModalService.alert('Ingrese valores');
381 return;
382 } else if (!cisterna.codigo) {
383 focaModalService.alert('Ingrese codigo de cisterna');
384 return;
385 } else if (!cisterna.capacidad) {
386 focaModalService.alert('Ingrese capacidad');
387 return;
388 } else if (!cisterna.idUnidadMedida) {
389 focaModalService.alert('Ingrese unidad de medida');
390 return;
391 } else if (cisterna.id === undefined) {
392 cisterna.id = 0;
393 }
394
395 validaCodigo(cisterna);
396 };
397
398 if ($routeParams.idx !== -1) {
399 $scope.cisterna = [$routeParams.idx];
400 focaAbmVehiculoService
401 .getCisternas($routeParams.idVehiculo)
402 .then(function (res) {
403 $scope.cisterna = res[$routeParams.idx];
404 });
405 }
406
407 function validaCodigo(cisterna) {
408 focaAbmVehiculoService
409 .getCisternas($routeParams.idVehiculo)
410 .then(function (res) {
411 var cisternas = res;
412 var totalCargado = 0;
413
414 for (var i = 0; i < cisternas.length; i++) {
415 //SI EL CODIGO YA EXISTE
416 if (cisternas[i].codigo === cisterna.codigo &&
src/js/controllerCisterna.js
1 angular.module('focaAbmVehiculo') File was deleted
2 .controller('focaAbmVehiculoCisternaController', [
3 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window',
5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
6 focaModalService, focaBotoneraLateralService, $timeout, $window) {
7 $scope.nuevo = ($routeParams.idx > -1) ? false : true;
8 $scope.editar = false;
9 $scope.now = new Date();
10 $scope.cisterna = {
11 codigo: '',
12 capacidad: '',
13 unidadMedida: {}
14 };
15
16 $scope.focused = $scope.nuevo ? 1 : 2;
17 $scope.next = function(key) {
18 if (key === 13) $scope.focused++;
19 };
20 $scope.capacidadVechiulo = 0;
21 $scope.transportista = '';
22
23 //SETEO BOTONERA LATERAL
24 $timeout(function() {
25 focaBotoneraLateralService.showSalir(false);
26 focaBotoneraLateralService.showPausar(true);
27 focaBotoneraLateralService.showCancelar(false);
28 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
29 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
30 });
31
32 if ($routeParams.idx !== -1) {
33 $scope.cisterna = [$routeParams.idx];
34 focaAbmVehiculoService
35 .getCisternas($routeParams.idVehiculo)
36 .then(function(res) {
37 $scope.cisterna = res[$routeParams.idx];
38 });
39 }
40
41 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
42 var codigo = ('00000' + res.data.transportista.COD).slice(-5);
43 $scope.transportista = res.data.transportista.COD;
44 $scope.capacidadVechiulo = res.data.capacidad;
45 $scope.$broadcast('addCabecera', {
46 label: 'Transportista:',
47 valor: codigo + ' - ' + res.data.transportista.NOM
48 });
49 $scope.$broadcast('addCabecera', {
50 label: 'Unidad:',
51 valor: res.data.codigo
52 });
53 $scope.$broadcast('addCabecera', {
54 label: 'Capacidad total vehículo:',
55 valor: res.data.capacidad
56 });
57 });
58
59 $scope.salir = function() {
60
61 if (!$scope.formCisterna.$pristine) {
62 focaModalService.confirm(
63 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
64 ).then(function(data) {
65 if (data) {
66 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' +
67 $scope.transportista);
68 }
69 });
70 } else {
71 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/' +
72 $scope.transportista);
73 }
74 };
75
76 $scope.guardar = function() {
77
78 if ($scope.formCisterna.$pristine) {
79 $scope.salir();
80 return;
81 } else if (!$scope.cisterna.codigo) {
82 focaModalService.alert('Ingrese codigo de cisterna');
83 return;
84 } else if (!$scope.cisterna.capacidad) {
85 focaModalService.alert('Ingrese capacidad');
86 return;
87 } else if (!$scope.cisterna.idUnidadMedida) {
88 focaModalService.alert('Ingrese unidad de medida');
89 return;
90 }
91
92 validaCodigo()
93 .then(function() {
94 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo);
95 delete $scope.cisterna.vehiculo;
96
97 focaAbmVehiculoService
98 .guardarCisterna($scope.cisterna, $routeParams.idx);
99
100 $timeout(function() {
101 $location.path('/vehiculo/' + $routeParams.idVehiculo +
102 '/' + $scope.transportista);
103 }, 0);
104 }, function(err) {
105 focaModalService.alert(err);
106 });
107
108 };
109
110 $scope.seleccionarUnidadMedida = function() {
111 var modalInstance = $uibModal.open(
112 {
113 ariaLabelledBy: 'Busqueda de Unidades de medida',
114 templateUrl: 'modal-unidad-medida.html',
115 controller: 'focaModalUnidadMedidaCtrl',
116 size: 'lg'
117 }
118 );
119 modalInstance.result.then(function(unidaMedida) {
120 $scope.cisterna.idUnidadMedida = unidaMedida.ID;
121 $scope.cisterna.unidadMedida = unidaMedida;
122 });
123 };
124
125 function validaCodigo() {
126 return new Promise(function(resolve, reject) {
127 focaAbmVehiculoService
128 .getCisternas($routeParams.idVehiculo)
129 .then(function(res) {
130 var cisternas = res;
131 var totalCargado = 0;
132 cisternas.forEach(function(cisterna, idx) {
133 //SI EL CODIGO YA EXISTE
134 if (cisterna.codigo === $scope.cisterna.codigo &&
135 idx != $routeParams.idx &&
136 !cisterna.desactivado) {
137 reject('Código de cisterna existente');
138 }
139 if (idx !== $routeParams.idx &&
140 !cisterna.desactivado) {
141 totalCargado += cisterna.capacidad;
142 }
143 });
144 resolve();
145 });
146 });
147 }
148 }
149 ]);
150 1 angular.module('focaAbmVehiculo')
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 var cisternasPristine = true;
5 return { 5 return {
6 getVehiculos: function() { 6 getVehiculos: function() {
7 return $http.get(API_ENDPOINT.URL + '/vehiculo'); 7 return $http.get(API_ENDPOINT.URL + '/vehiculo');
8 }, 8 },
9 getVehiculo: function(id) { 9 getVehiculo: function(id) {
10 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); 10 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id);
11 }, 11 },
12 getTransportistas: function() { 12 getTransportistas: function() {
13 return $http.get(API_ENDPOINT.URL + '/transportista'); 13 return $http.get(API_ENDPOINT.URL + '/transportista');
14 }, 14 },
15 guardarVehiculo: function(vehiculo) { 15 guardarVehiculo: function(vehiculo) {
16 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); 16 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo});
17 }, 17 },
18 deleteVehiculo: function(id) { 18 deleteVehiculo: function(id) {
19 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); 19 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id);
20 }, 20 },
21 getCisternas: function(idVehiculo) { 21 getCisternas: function(idVehiculo) {
22 if (cisternas.length) {
23 cisternasPristine = true;
24 return Promise.resolve(angular.copy(cisternas));
25 } else {
26 cisternasPristine = true; 22 cisternasPristine = true;
27 return new Promise(function(resolve) { 23 return new Promise(function(resolve) {
28 $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo) 24 $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo)
29 .then(function(res) { 25 .then(function(res) {
30 cisternas = res.data; 26 cisternas = res.data;
31 resolve(res.data); 27 resolve(res.data);
32 }); 28 });
33 }); 29 });
34 }
35 }, 30 },
36 guardarCisterna: function(cisterna, idx) { 31 guardarCisterna: function(cisterna, idx) {
37 if (idx !== '-1') { 32 if (idx !== '-1') {
38 //update 33 //update
39 cisternas[idx] = cisterna; 34 cisternas[idx] = cisterna;
40 cisternasPristine = false; 35 cisternasPristine = false;
41 } else { 36 } else {
42 //insert 37 //insert
43 cisternas.push(cisterna); 38 cisternas.push(cisterna);
44 cisternasPristine = false; 39 cisternasPristine = false;
45 } 40 }
46 }, 41 },
47 guardarCisternas: function(cisternas) { 42 guardarCisternas: function(cisternas) {
48 return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas}); 43 return $http.post(API_ENDPOINT.URL + '/cisterna', {cisternas: cisternas});
49 }, 44 },
50 deleteCisterna: function(idx) { 45 deleteCisterna: function(cisterna) {
51 cisternas[idx].desactivado = true; 46 cisterna.desactivado = true;
52 cisternasPristine = false; 47 cisternasPristine = false;
48 return $http.delete(API_ENDPOINT.URL + '/cisterna/' + cisterna.id);
53 }, 49 },
54 cleanCisternas: function() { 50 cleanCisternas: function() {
55 cisternas = []; 51 cisternas = [];
56 }, 52 },
57 getVehiculosPorTransportista: function(id) { 53 getVehiculosPorTransportista: function(id) {
58 return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); 54 return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id);
59 }, 55 },
60 getTransportistaPorId: function(id) { 56 getTransportistaPorId: function(id) {
61 return $http.get(API_ENDPOINT.URL + '/transportista/' + id); 57 return $http.get(API_ENDPOINT.URL + '/transportista/' + id);
62 }, 58 },
63 transportistaSeleccionado: {} 59 transportistaSeleccionado: {}
64 }; 60 };
65 }]); 61 }]);
src/views/foca-abm-cisterna-item.html
1 <div class="row"> File was deleted
2 <foca-cabecera-facturador
3 titulo="'Vehículo cisterna'"
4 fecha="now"
5 class="mb-0 col-lg-12"
6 ></foca-cabecera-facturador>
7 </div>
8 <div class="row"></div>
9 <form name="formCisterna">
10 <div class="form-group row">
11 <label class="offset-sm-1 col-sm-2 col-form-label">Código de cisterna</label>
12 <div class="col-sm-4">
13 <input
14 class="form-control"
15 type="text"
16 ng-required="true"
17 ng-model="cisterna.codigo"
18 ng-keypress="next($event.keyCode)"
19 foca-focus="focused == 1"
20 ng-focus="focused = 1"
21 ng-disabled="!nuevo"
22 teclado-virtual
23 />
24 </div>
25 </div>
26 <div class="form-group row">
27 <label class="offset-sm-1 col-sm-2 col-form-label">Capacidad</label>
28 <div class="col-sm-4">
29 <input
30 class="form-control"
31 type="text"
32 teclado-virtual
33 foca-tipo-input
34 ng-model="cisterna.capacidad"
35 ng-required="true"
36 ng-keypress="next($event.keyCode)"
37 foca-focus="focused == 2"
38 ng-focus="focused = 2"
39 />
40 </div>
41 </div>
42 <div class="form-group row">
43 <label class="offset-sm-1 col-sm-2 col-form-label">Unidad de medida</label>
44 <div class="col-sm-4 input-group">
45 <input
46 ng-model="cisterna.unidadMedida.NOM"
47 class="form-control"
48 readonly
49 />
50 <div class="input-group-append">
51 <button
52 ladda="searchLoading"
53 class="btn btn-outline-secondary form-control"
54 type="button"
55 ng-click="seleccionarUnidadMedida()"
56 foca-focus="focused == 3"
57 >
58 <i class="fa fa-search" aria-hidden="true"></i>
59 </button>
60 </div>
61 </div>
62 </div>
63 </form>
64 1 <div class="row">
src/views/foca-abm-vehiculos-item.html
1 <div class="row"> 1 <div class="row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Vehículo'" 3 titulo="'Vehiculo / ' + tipo"
4 fecha="now" 4 fecha="now"
5 class="mb-0 col-lg-12" 5 class="mb-0 col-lg-12"
6 ></foca-cabecera-facturador> 6 ></foca-cabecera-facturador>
7 </div> 7 </div>
8 <div class="row"> 8 <div class="row">
9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> 9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded">
10 <form name="formVehiculo" class="px-3"> 10 <form name="formVehiculo" class="px-3">
11 <input type="hidden" name="id" ng-model="sector.id" /> 11 <input type="hidden" name="id" ng-model="sector.id" />
12 <div class="row mt-3"> 12 <div class="row mt-3">
13 <div class="form-group d-flex mb-2 col-md-6"> 13 <div class="form-group d-flex mb-2 col-md-6">
14 <label class="col-form-label col-md-4">Unidad</label> 14 <label class="col-form-label col-md-4">Unidad</label>
15 <div class="input-group col-md-8 pl-0"> 15 <div class="input-group col-md-8 pl-0">
16 <input 16 <input
17 class="form-control" 17 class="form-control"
18 type="text" 18 type="text"
19 teclado-virtual 19 teclado-virtual
20 ng-model="vehiculo.codigo" 20 ng-model="vehiculo.codigo"
21 foca-focus="focused == 1" 21 foca-focus="focused == 1"
22 ng-focus="focused = 1" 22 ng-focus="focused = 1"
23 ng-keypress="next($event.keyCode)" 23 ng-keypress="next($event.keyCode)"
24 ng-disabled="!nuevo" 24 ng-disabled="!nuevo"
25 /> 25 />
26 </div> 26 </div>
27 </div> 27 </div>
28 <div class="form-group d-flex mb-2 col-md-6"> 28 <div class="form-group d-flex mb-2 col-md-6">
29 <label class="col-form-label col-md-4">Dominio tractor</label> 29 <label class="col-form-label col-md-4">Dominio tractor</label>
30 <div class="input-group col-md-8 pl-0"> 30 <div class="input-group col-md-8 pl-0">
31 <input 31 <input
32 class="form-control" 32 class="form-control"
33 type="text" 33 type="text"
34 teclado-virtual 34 teclado-virtual
35 ng-model="vehiculo.tractor" 35 ng-model="vehiculo.tractor"
36 ng-required="true" 36 ng-required="true"
37 foca-focus="focused == 2" 37 foca-focus="focused == 2"
38 ng-focus="focused = 2" 38 ng-focus="focused = 2"
39 ng-keypress="next($event.keyCode)" 39 ng-keypress="next($event.keyCode)"
40 /> 40 />
41 </div> 41 </div>
42 </div> 42 </div>
43 <div class="form-group d-flex mb-2 col-md-6"> 43 <div class="form-group d-flex mb-2 col-md-6">
44 <label class="col-form-label col-md-4">Dominio semi</label> 44 <label class="col-form-label col-md-4">Dominio semi</label>
45 <div class="input-group col-md-8 pl-0"> 45 <div class="input-group col-md-8 pl-0">
46 <input 46 <input
47 class="form-control" 47 class="form-control"
48 type="text" 48 type="text"
49 teclado-virtual 49 teclado-virtual
50 ng-model="vehiculo.semi" 50 ng-model="vehiculo.semi"
51 ng-required="true" 51 ng-required="true"
52 foca-focus="focused == 3" 52 foca-focus="focused == 3"
53 ng-focus="focused = 3" 53 ng-focus="focused = 3"
54 ng-keypress="next($event.keyCode)" 54 ng-keypress="next($event.keyCode)"
55 /> 55 />
56 </div> 56 </div>
57 </div> 57 </div>
58 <div class="form-group d-flex mb-2 col-md-6"> 58 <div class="form-group d-flex mb-2 col-md-6">
59 <label class="col-form-label col-md-4">Capacidad total</label> 59 <label class="col-form-label col-md-4">Capacidad total</label>
60 <div class="input-group col-md-8 pl-0"> 60 <div class="input-group col-md-8 pl-0">
61 <input 61 <input
62 class="form-control" 62 class="form-control"
63 type="text" 63 foca-tipo-input
64 solo-positivos
64 teclado-virtual 65 teclado-virtual
65 ng-model="vehiculo.capacidad" 66 ng-model="vehiculo.capacidad"
66 ng-required="true" 67 ng-required="true"
67 foca-focus="focused == 4" 68 foca-focus="focused == 4"
68 ng-focus="focused = 4" 69 ng-focus="focused = 4"
69 ng-keypress="guardar($event.keyCode)" 70 ng-disabled="!nuevo"
70 /> 71 />
71 </div> 72 </div>
72 </div> 73 </div>
73 </div> 74 </div>
74 </form> 75 </form>
75 <div ng-show="!nuevo"> 76 <div>
76 <h5 class="pl-4 table-title">Cisternas</h5> 77 <h5 class="pl-4 table-title">Cisternas</h5>
77 <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> 78 <table class="table table-default table-hover table-sm table-abm table-striped mb-0" >
78 <thead> 79 <thead>
79 <tr> 80 <tr>
80 <th class="px-5">Código</th> 81 <th class="text-center px-4">Código</th>
81 <th class="text-right px-5">Capacidad</th> 82 <th class="text-center">Capacidad</th>
82 <th class="text-center px-4"> 83 <th class="text-center">Unidad de Medida</th>
84 <th class="text-center">
83 <button 85 <button
84 class="btn btn-outline-debo boton-accion" 86 class="btn btn-outline-debo boton-accion"
85 title="Agregar" 87 title="Agregar Cisterna"
86 ng-click="editar(-1)"> 88 ng-click="crearCisterna()"
89 ng-disabled="crear">
87 <i class="fa fa-plus"></i> 90 <i class="fa fa-plus"></i>
88 </button> 91 </button>
89 </th> 92 </th>
90 </tr> 93 </tr>
91 </thead> 94 </thead>
92 <tbody> 95 <tbody>
93 <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" 96 <tr ng-show="creando">
94 ng-show="!cisterna.desactivado"> 97 <td align="center">
95 <td ng-bind="cisterna.codigo" class="px-5"></td> 98 <input
96 <td ng-bind="cisterna.capacidad + ' ' + cisterna.unidadMedida.NOM" class="text-right px-5"></td> 99 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
97 <td class="text-center px-4"> 100 ng-model="cisterna.codigo"
101 ng-keypress="next($event.keyCode)"
102 foca-focus="focused == 1"
103 ng-focus="focused = 1"
104 ng-disabled="!nuevoCisterna"
105 teclado-virtual
106 >
107 </td>
108 <td align="center">
109 <input
110 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
111 teclado-virtual
112 foca-tipo-input
113 solo-positivos
114 ng-model="cisterna.capacidad"
115 ng-required="true"
116 ng-keypress="next($event.keyCode)"
117 foca-focus="focused == 2"
118 ng-focus="focused = 2"
119 >
120 </td>
121 <td align="center">
122 <div class="input-group">
123 <input
124 ng-model="cisterna.unidadMedida.NOM"
125 class="form-control"
126 readonly
127 />
128 <div class="input-group-append">
129 <button
130 ladda="searchLoading"
131 class="btn btn-outline-secondary form-control"
132 type="button"
133 ng-click="seleccionarUnidadMedida()"
134 foca-focus="focused == 3"
135 >
136 <i class="fa fa-search" aria-hidden="true"></i>
137 </button>
138 </div>
139 </div>
140 </td>
141 <td align="center">
142 <button
143 class="btn btn-outline-dark boton-accion"
144 ng-click="agregarCisterna()"
145 >
146 <i class="fa fa-save"></i>
147 </button>
148 </td>
149 </tr>
150
151 <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" ng-hide="cisterna.desactivado">
152 <td ng-bind="cisterna.codigo" class="text-center" ng-hide="cisterna.editando"></td>
153 <td align="center" ng-show="cisterna.editando">
154 <input
155 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
156 ng-model="cisterna.codigo"
157 ng-keypress="next($event.keyCode)"
158 foca-focus="focused == 1"
159 ng-focus="focused = 1"
160 teclado-virtual
161 esc-key="volver(cisterna, key)"
162 >
163 </td>
164 <td ng-bind="cisterna.capacidad" class="text-center" ng-hide="cisterna.editando"></td>
165 <td align="center" ng-show="cisterna.editando" >
166 <input
167 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
168 teclado-virtual
169 foca-tipo-input
170 solo-positivos
171 ng-model="cisterna.capacidad"
172 ng-required="true"
173 ng-keypress="next($event.keyCode)"
174 foca-focus="focused == 2"
175 ng-focus="focused = 2"
176 esc-key="volver(cisterna, key)"
177 >
178 </td>
179 <td ng-bind="cisterna.unidadMedida.NOM" class="text-center" ng-hide="cisterna.editando"></td>
180 <td align="center" ng-show="cisterna.editando">
181 <div class="input-group">
182 <input
183 ng-model="cisterna.unidadMedida.NOM"
184 class="form-control"
185 readonly
186 esc-key="volver(cisterna, key)"
187 />
188 <div class="input-group-append">
189 <button
190 ladda="searchLoading"
191 class="btn btn-outline-secondary form-control"
192 type="button"
193 ng-click="seleccionarUnidadMedida(cisterna)"
194 foca-focus="focused == 3"
195 >
196 <i class="fa fa-search" aria-hidden="true"></i>
197 </button>
198 </div>
199 </div>
200 </td>
201 <td class="text-center" ng-hide="cisterna.editando">
98 <button 202 <button
99 class="btn btn-outline-dark boton-accion" 203 class="btn btn-outline-dark boton-accion"
100 title="Editar" 204 title="Editar"
101 ng-click="editar(key)" 205 ng-click="editar(cisterna)"
102 > 206 >
103 <i class="fa fa-pencil"></i> 207 <i class="fa fa-pencil"></i>
104 </button> 208 </button>
105 <button 209 <button
106 class="btn btn-outline-dark boton-accion" 210 class="btn btn-outline-dark boton-accion"
107 title="Eliminar" 211 title="Eliminar"
108 ng-click="solicitarConfirmacionCisterna(cisterna, key)" 212 ng-click="solicitarConfirmacionTabla(cisterna, $index)"
109 > 213 >
110 <i class="fa fa-trash"></i> 214 <i class="fa fa-trash"></i>
111 </button> 215 </button>
112 </td> 216 </td>
217 <td align="center" ng-show="cisterna.editando" >
218 <button
219 class="btn btn-outline-dark boton-accion"
220 ng-click="agregarCisterna(cisterna)"
221 >
222 <i class="fa fa-save"></i>
223 </button>
224 <button
225 class="btn btn-outline-dark boton-accion"
226 ng-click="volver(cisterna, key)"
227 >
228 <i class="fa fa-undo" aria-hidden="true"></i>
229 </button>
230 </td>
231 </tr>
232 <tr ng-repeat="(key, cisterna) in cisternas" ng-show="false">
113 </tr> 233 </tr>
114 </body> 234 </body>
115 </table> 235 </table>
116 </div> 236 </div>
117 </div> 237 </div>
118 </div> 238 </div>
119 239
src/views/foca-abm-vehiculos-listado.html
1 <div class="row"> 1 <div class="row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Vehículos'" 3 titulo="'Vehículos'"
4 fecha="now" 4 fecha="now"
5 class="mb-0 col-lg-12" 5 class="mb-0 col-lg-12"
6 ></foca-cabecera-facturador> 6 ></foca-cabecera-facturador>
7 </div> 7 </div>
8 <div class="row"> 8 <div class="row">
9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> 9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded">
10 <div class="row px-5 py-2 botonera-secundaria"> 10 <div class="row px-5 py-2 botonera-secundaria">
11 <div class="col-12"> 11 <div class="col-12">
12 <foca-botonera-facturador botones="botonera" max="6" class="row"></foca-botonera-facturador> 12 <foca-botonera-facturador botones="botonera" max="6" class="row"></foca-botonera-facturador>
13 </div> 13 </div>
14 </div> 14 </div>
15 <!-- <div class="col-6 form-group"> 15 <!-- <div class="col-6 form-group">
16 <input seleccionarTransportista() 16 <input seleccionarTransportista()
17 type="text" 17 type="text"
18 teclado-virtual 18 teclado-virtual
19 class="form-control form-control-sm" 19 class="form-control form-control-sm"
20 placeholder="Búsqueda" 20 placeholder="Búsqueda"
21 ng-model="filtros" 21 ng-model="filtros"
22 /> 22 />
23 </div> --> 23 </div> -->
24 <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> 24 <table class="table table-default table-hover table-sm table-abm table-striped mb-0">
25 <thead> 25 <thead>
26 <tr> 26 <tr>
27 <th class="text-center">Unidad</th> 27 <th class="text-center">Unidad</th>
28 <th>Dominio Tractor</th> 28 <th>Dominio Tractor</th>
29 <th>Dominio Semi</th> 29 <th>Dominio Semi</th>
30 <th class="text-right">Capacidad</th> 30 <th class="text-right">Capacidad</th>
31 <th class="text-center"> 31 <th class="text-center">
32 <button 32 <button
33 ng-disabled="!idTransportista" 33 ng-disabled="!idTransportista"
34 class="btn btn-outline-debo boton-accion" 34 class="btn btn-outline-debo boton-accion"
35 title="Agregar" 35 title="Agregar Vehículo"
36 ng-click="editar(0)" 36 ng-click="editar(0)"
37 ><i class="fa fa-plus"></i> 37 ><i class="fa fa-plus"></i>
38 </button> 38 </button>
39 </th> 39 </th>
40 </tr> 40 </tr>
41 </thead> 41 </thead>
42 <tbody> 42 <tbody>
43 <tr ng-repeat="vehiculo in vehiculos | filter:filtros"> 43 <tr ng-repeat="vehiculo in vehiculos | filter:filtros">
44 <td ng-bind="vehiculo.codigo" class="text-center"></td> 44 <td ng-bind="vehiculo.codigo" class="text-center"></td>
45 <td ng-bind="vehiculo.tractor"></td> 45 <td ng-bind="vehiculo.tractor"></td>
46 <td ng-bind="vehiculo.semi"></td> 46 <td ng-bind="vehiculo.semi"></td>
47 <td ng-bind="vehiculo.capacidad" class="text-right"></td> 47 <td ng-bind="vehiculo.capacidad" class="text-right"></td>
48 <td class="text-center"> 48 <td class="text-center">
49 <button 49 <button
50 class="btn btn-outline-dark boton-accion" 50 class="btn btn-outline-dark boton-accion"
51 title="Editar" 51 title="Editar"
52 ng-click="editar(vehiculo.id)" 52 ng-click="editar(vehiculo.id)"
53 > 53 >
54 <i class="fa fa-pencil"></i> 54 <i class="fa fa-pencil"></i>
55 </button> 55 </button>
56 <button 56 <button
57 class="btn btn-outline-dark boton-accion" 57 class="btn btn-outline-dark boton-accion"
58 title="Eliminar" 58 title="Eliminar"
59 ng-click="solicitarConfirmacion(vehiculo)" 59 ng-click="solicitarConfirmacion(vehiculo)"
60 > 60 >
61 <i class="fa fa-trash"></i> 61 <i class="fa fa-trash"></i>
62 </button> 62 </button>
63 </td> 63 </td>
64 </tr> 64 </tr>
65 </body> 65 </body>
66 </table> 66 </table>
67 </div> 67 </div>
68 </div> 68 </div>
69 69