Commit 7d2ea6cb17b3410d1e9d53e1dbecc0bfcc2f58f7

Authored by Eric Fernandez
1 parent 915a5e6d50
Exists in master and in 1 other branch develop

fix guardar, rutas nuevas

src/js/controller.js
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .controller('focaAbmVehiculosController', [ 2 .controller('focaAbmVehiculosController', [
3 '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', '$uibModal', 3 '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', '$uibModal',
4 function($scope, focaAbmVehiculoService, $location, focaModalService, $uibModal) { 4 function($scope, focaAbmVehiculoService, $location, focaModalService, $uibModal) {
5 $scope.buscar = function(idTransportista) { 5 $scope.buscar = function(idTransportista) {
6 focaAbmVehiculoService 6 focaAbmVehiculoService
7 .getVehiculosPorTransportista(idTransportista) 7 .getVehiculosPorTransportista(idTransportista)
8 .then(function(datos) { 8 .then(function(datos) {
9 $scope.vehiculos = datos.data; 9 $scope.vehiculos = datos.data;
10 }); 10 });
11 }; 11 };
12 $scope.editar = function(id) { 12 $scope.editar = function(id) {
13 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); 13 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista);
14 }; 14 };
15 $scope.solicitarConfirmacion = function(vehiculo) { 15 $scope.solicitarConfirmacion = function(vehiculo) {
16 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + 16 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
17 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( 17 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
18 function(data) { 18 function(data) {
19 if(data) { 19 if(data) {
20 focaAbmVehiculoService.deleteVehiculo(vehiculo.id); 20 focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
21 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); 21 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
22 } 22 }
23 } 23 }
24 ); 24 );
25 }; 25 };
26 $scope.seleccionarTransportista = function() { 26 $scope.seleccionarTransportista = function() {
27 var modalInstance = $uibModal.open( 27 var modalInstance = $uibModal.open(
28 { 28 {
29 ariaLabelledBy: 'Busqueda de Transportista', 29 ariaLabelledBy: 'Busqueda de Transportista',
30 templateUrl: 'modal-proveedor.html', 30 templateUrl: 'modal-proveedor.html',
31 controller: 'focaModalProveedorCtrl', 31 controller: 'focaModalProveedorCtrl',
32 size: 'lg', 32 size: 'lg',
33 resolve: { 33 resolve: {
34 transportista: function() { 34 transportista: function() {
35 return true; 35 return true;
36 } 36 }
37 } 37 }
38 } 38 }
39 ); 39 );
40 modalInstance.result.then( 40 modalInstance.result.then(
41 function(transprotista) { 41 function(transprotista) {
42 $scope.idTransportista = transprotista.COD; 42 $scope.idTransportista = transprotista.COD;
43 $scope.filtros = transprotista.NOM.trim(); 43 $scope.filtros = transprotista.NOM.trim();
44 $scope.buscar(transprotista.COD); 44 $scope.buscar(transprotista.COD);
45 }, function() { 45 }, function() {
46 46
47 } 47 }
48 ); 48 );
49 }; 49 };
50 } 50 }
51 ]) 51 ])
52 .controller('focaAbmVehiculoController', [ 52 .controller('focaAbmVehiculoController', [
53 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 53 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
54 'focaModalService', 54 'focaModalService',
55 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 55 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
56 focaModalService) { 56 focaModalService) {
57 $scope.nuevo = $routeParams.idVehiculo == 0 ? true : false; 57 $scope.nuevo = $routeParams.idVehiculo == 0 ? true : false;
58 if($scope.nuevo) { 58 if($scope.nuevo) {
59 focaAbmVehiculoService 59 focaAbmVehiculoService
60 .getTransportistaPorId($routeParams.idTransportista) 60 .getTransportistaPorId($routeParams.idTransportista)
61 .then(function(res) { 61 .then(function(res) {
62 $scope.vehiculo.idTransportista = res.data.COD;
62 $scope.vehiculo.transportista = res.data; 63 $scope.vehiculo.transportista = res.data;
63 }) 64 })
64 } 65 }
65 $scope.vehiculo = {}; 66 $scope.vehiculo = {};
66 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { 67 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) {
67 if(res.data) $scope.vehiculo = res.data; 68 if(res.data) $scope.vehiculo = res.data;
68 }); 69 });
69 focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo) 70 focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo)
70 .then(function(res) { 71 .then(function(res) {
71 $scope.cisternas = res.data; 72 $scope.cisternas = res.data;
72 }); 73 });
73 $scope.cancelar = function() { 74 $scope.cancelar = function() {
74 $location.path('/vehiculo'); 75 $location.path('/vehiculo');
75 }; 76 };
76 $scope.editar = function(id) { 77 $scope.editar = function(id) {
77 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/' + id); 78 $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/' + id);
78 }; 79 };
79 $scope.guardar = function() { 80 $scope.guardar = function() {
80 if(!$scope.vehiculo.transportista) { 81 if(!$scope.vehiculo.transportista) {
81 focaModalService.alert('Elija Transportista'); 82 focaModalService.alert('Elija Transportista');
82 return; 83 return;
83 } 84 }
84 delete $scope.vehiculo.transportista; 85 delete $scope.vehiculo.transportista;
85 focaAbmVehiculoService.guerdarVehiculo($scope.vehiculo).then(function(res) { 86 focaAbmVehiculoService.guerdarVehiculo($scope.vehiculo).then(function(res) {
86 $location.path('/vehiculo/' + res.data.id); 87 console.log(res.data);
88 $location.path('/vehiculo/' + res.data.id + '/' + res.data.idTransportista);
87 }); 89 });
88 }; 90 };
89 $scope.solicitarConfirmacionCisterna = function(cisterna) { 91 $scope.solicitarConfirmacionCisterna = function(cisterna) {
90 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + 92 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
91 cisterna.id + ' ' + cisterna.codigo + ' ?').then( 93 cisterna.id + ' ' + cisterna.codigo + ' ?').then(
92 function(data) { 94 function(data) {
93 if(data) { 95 if(data) {
94 focaAbmVehiculoService.deleteCisterna(cisterna.id); 96 focaAbmVehiculoService.deleteCisterna(cisterna.id);
95 $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1); 97 $scope.cisternas.splice($scope.cisternas.indexOf(cisterna), 1);
96 } 98 }
97 } 99 }
98 ); 100 );
99 }; 101 };
100 $scope.seleccionarTransportista = function() { 102 $scope.seleccionarTransportista = function() {
101 var modalInstance = $uibModal.open( 103 var modalInstance = $uibModal.open(
102 { 104 {
103 ariaLabelledBy: 'Busqueda de Transportista', 105 ariaLabelledBy: 'Busqueda de Transportista',
104 templateUrl: 'modal-proveedor.html', 106 templateUrl: 'modal-proveedor.html',
105 controller: 'focaModalProveedorCtrl', 107 controller: 'focaModalProveedorCtrl',
106 size: 'lg', 108 size: 'lg',
107 resolve: { 109 resolve: {
108 transportista: function() { 110 transportista: function() {
109 return true; 111 return true;
110 } 112 }
111 } 113 }
112 } 114 }
113 ); 115 );
114 modalInstance.result.then( 116 modalInstance.result.then(
115 function(transprotista) { 117 function(transprotista) {
116 $scope.vehiculo.idTransportista = transprotista.COD; 118 $scope.vehiculo.idTransportista = transprotista.COD;
117 $scope.vehiculo.transportista = transprotista; 119 $scope.vehiculo.transportista = transprotista;
118 }, function() { 120 }, function() {
119 121
120 } 122 }
121 ); 123 );
122 }; 124 };
123 } 125 }
124 ]); 126 ]);
125 127
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .config([ 2 .config([
3 '$routeProvider', 3 '$routeProvider',
4 function($routeProvider) { 4 function($routeProvider) {
5 $routeProvider.when('/vehiculo', { 5 $routeProvider.when('/vehiculo', {
6 controller: 'focaAbmVehiculosController', 6 controller: 'focaAbmVehiculosController',
7 templateUrl: 'src/views/foca-abm-vehiculos-listado.html' 7 templateUrl: 'src/views/foca-abm-vehiculos-listado.html'
8 }); 8 });
9 } 9 }
10 ]) 10 ])
11 .config([ 11 .config([
12 '$routeProvider', 12 '$routeProvider',
13 function($routeProvider) { 13 function($routeProvider) {
14 $routeProvider.when('/vehiculo/:idVehiculo/:idTransportista', { 14 $routeProvider.when('/vehiculo/:idVehiculo/:idTransportista', {
15 controller: 'focaAbmVehiculoController', 15 controller: 'focaAbmVehiculoController',
16 templateUrl: 'src/views/foca-abm-vehiculos-item.html' 16 templateUrl: 'src/views/foca-abm-vehiculos-item.html'
17 }); 17 });
18 } 18 }
19 ]) 19 ])
20 .config([ 20 .config([
21 '$routeProvider', 21 '$routeProvider',
22 function($routeProvider) { 22 function($routeProvider) {
23 $routeProvider.when('/vehiculo/:idVehiculo', {
24 controller: 'focaAbmVehiculoController',
25 templateUrl: 'src/views/foca-abm-vehiculos-item.html'
26 });
27 }
28 ])
29 .config([
30 '$routeProvider',
31 function($routeProvider) {
23 $routeProvider.when('/vehiculo/:idVehiculo/cisterna/:id', { 32 $routeProvider.when('/vehiculo/:idVehiculo/cisterna/:id', {
24 controller: 'focaAbmVehiculoCisternaController', 33 controller: 'focaAbmVehiculoCisternaController',
25 templateUrl: 'src/views/foca-abm-cisterna-item.html' 34 templateUrl: 'src/views/foca-abm-cisterna-item.html'
26 }); 35 });
27 } 36 }
28 ]); 37 ]);
29 38
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 return { 3 return {
4 getVehiculos: function() { 4 getVehiculos: function() {
5 return $http.get(API_ENDPOINT.URL + '/vehiculo'); 5 return $http.get(API_ENDPOINT.URL + '/vehiculo');
6 }, 6 },
7 getVehiculo: function(id) { 7 getVehiculo: function(id) {
8 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id); 8 return $http.get(API_ENDPOINT.URL + '/vehiculo/' + id);
9 }, 9 },
10 getTransportistas: function() { 10 getTransportistas: function() {
11 return $http.get(API_ENDPOINT.URL + '/transportista'); 11 return $http.get(API_ENDPOINT.URL + '/transportista');
12 }, 12 },
13 guerdarVehiculo: function(vehiculo) { 13 guerdarVehiculo: function(vehiculo) {
14 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo}); 14 return $http.post(API_ENDPOINT.URL + '/vehiculo', {vehiculo: vehiculo});
15 }, 15 },
16 deleteVehiculo: function(id) { 16 deleteVehiculo: function(id) {
17 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id); 17 return $http.delete(API_ENDPOINT.URL + '/vehiculo/' + id);
18 }, 18 },
19 getCisternadoPorVehiculo: function(idVehiculo) { 19 getCisternadoPorVehiculo: function(idVehiculo) {
20 return $http.get(API_ENDPOINT.URL + '/cisterna/listar/vehiculo/' + idVehiculo); 20 return $http.get(API_ENDPOINT.URL + '/cisterna/listar/' + idVehiculo);
21 }, 21 },
22 getCisterna: function(id) { 22 getCisterna: function(id) {
23 return $http.get(API_ENDPOINT.URL + '/cisterna/' + id); 23 return $http.get(API_ENDPOINT.URL + '/cisterna/' + id);
24 }, 24 },
25 guardarCisterna: function(cisterna) { 25 guardarCisterna: function(cisterna) {
26 return $http.post(API_ENDPOINT.URL + '/cisterna/guardar', {cisterna: cisterna}); 26 return $http.post(API_ENDPOINT.URL + '/cisterna/guardar', {cisterna: cisterna});
27 }, 27 },
28 deleteCisterna: function(id) { 28 deleteCisterna: function(id) {
29 return $http.delete(API_ENDPOINT.URL + '/cisterna/borrar/' + id); 29 return $http.delete(API_ENDPOINT.URL + '/cisterna/borrar/' + id);
30 }, 30 },
31 getVehiculosPorTransportista: function(id) { 31 getVehiculosPorTransportista: function(id) {
32 return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id); 32 return $http.get(API_ENDPOINT.URL + '/vehiculo/transportista/' + id);
33 }, 33 },
34 getTransportistaPorId: function(id) { 34 getTransportistaPorId: function(id) {
35 return $http.get(API_ENDPOINT.URL + '/transportista/' + id); 35 return $http.get(API_ENDPOINT.URL + '/transportista/' + id);
36 } 36 }
37 }; 37 };
38 }]); 38 }]);
39 39