Commit c6f26bc623ec0c8d0423d245c045d7e275cb9eda
Exists in
master
Merge branch 'master' into 'master'
fuera cisternaCarga See merge request !16
Showing
2 changed files
Show diff stats
gulpfile.js
| 1 | const templateCache = require('gulp-angular-templatecache'); | 1 | const templateCache = require('gulp-angular-templatecache'); |
| 2 | const concat = require('gulp-concat'); | 2 | const concat = require('gulp-concat'); |
| 3 | const htmlmin = require('gulp-htmlmin'); | 3 | const htmlmin = require('gulp-htmlmin'); |
| 4 | const rename = require('gulp-rename'); | 4 | const rename = require('gulp-rename'); |
| 5 | const uglify = require('gulp-uglify-es').default; | 5 | const uglify = require('gulp-uglify-es').default; |
| 6 | const gulp = require('gulp'); | 6 | const gulp = require('gulp'); |
| 7 | const pump = require('pump'); | 7 | const pump = require('pump'); |
| 8 | const jshint = require('gulp-jshint'); | 8 | const jshint = require('gulp-jshint'); |
| 9 | const replace = require('gulp-replace'); | 9 | const replace = require('gulp-replace'); |
| 10 | const connect = require('gulp-connect'); | 10 | const connect = require('gulp-connect'); |
| 11 | const clean = require('gulp-clean'); | 11 | const clean = require('gulp-clean'); |
| 12 | 12 | ||
| 13 | var paths = { | 13 | var paths = { |
| 14 | srcJS: 'src/js/*.js', | 14 | srcJS: 'src/js/*.js', |
| 15 | srcViews: 'src/views/*.html', | 15 | srcViews: 'src/views/*.html', |
| 16 | tmp: 'tmp', | 16 | tmp: 'tmp', |
| 17 | dist: 'dist/' | 17 | dist: 'dist/' |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | gulp.task('templates', function() { | 20 | gulp.task('templates', function() { |
| 21 | return pump( | 21 | return pump( |
| 22 | [ | 22 | [ |
| 23 | gulp.src(paths.srcViews), | 23 | gulp.src(paths.srcViews), |
| 24 | replace('views/', ''), | 24 | replace('views/', ''), |
| 25 | htmlmin(), | 25 | htmlmin(), |
| 26 | templateCache('views.js', { | 26 | templateCache('views.js', { |
| 27 | module: 'focaAbmVehiculo', | 27 | module: 'focaAbmVehiculo', |
| 28 | root: '' | 28 | root: '' |
| 29 | }), | 29 | }), |
| 30 | gulp.dest(paths.tmp) | 30 | gulp.dest(paths.tmp) |
| 31 | ] | 31 | ] |
| 32 | ); | 32 | ); |
| 33 | }); | 33 | }); |
| 34 | 34 | ||
| 35 | gulp.task('uglify', ['templates'], function() { | 35 | gulp.task('uglify', ['templates'], function() { |
| 36 | return pump( | 36 | return pump( |
| 37 | [ | 37 | [ |
| 38 | gulp.src([ | 38 | gulp.src([ |
| 39 | paths.srcJS, | 39 | paths.srcJS, |
| 40 | 'tmp/views.js' | 40 | 'tmp/views.js' |
| 41 | ]), | 41 | ]), |
| 42 | concat('foca-abm-vehiculo.js'), | 42 | concat('foca-abm-vehiculo.js'), |
| 43 | replace("['ngRoute', 'focaModal', 'ui.bootstrap']", '[]'), | 43 | replace("['ngRoute', 'focaModal', 'ui.bootstrap', 'focaBotoneraLateral']", '[]'), |
| 44 | replace("src/views/", ''), | 44 | replace("src/views/", ''), |
| 45 | gulp.dest(paths.tmp), | 45 | gulp.dest(paths.tmp), |
| 46 | rename('foca-abm-vehiculo.min.js'), | 46 | rename('foca-abm-vehiculo.min.js'), |
| 47 | uglify(), | 47 | uglify(), |
| 48 | gulp.dest(paths.dist) | 48 | gulp.dest(paths.dist) |
| 49 | ] | 49 | ] |
| 50 | ); | 50 | ); |
| 51 | }); | 51 | }); |
| 52 | 52 | ||
| 53 | gulp.task('clean', function() { | 53 | gulp.task('clean', function() { |
| 54 | return gulp.src(['tmp', 'dist'], {read: false}) | 54 | return gulp.src(['tmp', 'dist'], {read: false}) |
| 55 | .pipe(clean()); | 55 | .pipe(clean()); |
| 56 | }); | 56 | }); |
| 57 | 57 | ||
| 58 | gulp.task('pre-commit', function() { | 58 | gulp.task('pre-commit', function() { |
| 59 | pump( | 59 | pump( |
| 60 | [ | 60 | [ |
| 61 | gulp.src(paths.srcJS), | 61 | gulp.src(paths.srcJS), |
| 62 | jshint('.jshintrc'), | 62 | jshint('.jshintrc'), |
| 63 | jshint.reporter('default'), | 63 | jshint.reporter('default'), |
| 64 | jshint.reporter('fail') | 64 | jshint.reporter('fail') |
| 65 | ] | 65 | ] |
| 66 | ); | 66 | ); |
| 67 | 67 | ||
| 68 | gulp.start('uglify'); | 68 | gulp.start('uglify'); |
| 69 | }); | 69 | }); |
| 70 | 70 | ||
| 71 | gulp.task('clean-post-install', function() { | 71 | gulp.task('clean-post-install', function() { |
| 72 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', | 72 | return gulp.src(['src', 'tmp', '.jshintrc','readme.md', '.gitignore', 'gulpfile.js', |
| 73 | 'index.html'], {read: false}) | 73 | 'index.html'], {read: false}) |
| 74 | .pipe(clean()); | 74 | .pipe(clean()); |
| 75 | }); | 75 | }); |
| 76 | 76 | ||
| 77 | gulp.task('compile', ['templates', 'uglify']); | 77 | gulp.task('compile', ['templates', 'uglify']); |
| 78 | 78 | ||
| 79 | gulp.task('watch', function() { | 79 | gulp.task('watch', function() { |
| 80 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); | 80 | gulp.watch([paths.srcJS, paths.srcViews], ['uglify']); |
| 81 | }); | 81 | }); |
| 82 | 82 | ||
| 83 | gulp.task('webserver', function() { | 83 | gulp.task('webserver', function() { |
| 84 | pump [ | 84 | pump [ |
| 85 | connect.server({port: 3000}) | 85 | connect.server({port: 3000}) |
| 86 | ] | 86 | ] |
| 87 | }); | 87 | }); |
| 88 | 88 | ||
| 89 | gulp.task('default', ['webserver']); | 89 | gulp.task('default', ['webserver']); |
| 90 | 90 |
src/js/controllerCisterna.js
| 1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') |
| 2 | .controller('focaAbmVehiculoCisternaController', [ | 2 | .controller('focaAbmVehiculoCisternaController', [ |
| 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', | 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', |
| 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 6 | focaModalService, focaBotoneraLateralService, $timeout, $window) { | 6 | focaModalService, focaBotoneraLateralService, $timeout, $window) { |
| 7 | $scope.editar = false; | 7 | $scope.editar = false; |
| 8 | $scope.now = new Date(); | 8 | $scope.now = new Date(); |
| 9 | $scope.cisterna = { | 9 | $scope.cisterna = {}; |
| 10 | cisternaCarga: { | ||
| 11 | articulo: {} | ||
| 12 | } | ||
| 13 | }; | ||
| 14 | 10 | ||
| 15 | $scope.focused = 1; | 11 | $scope.focused = 1; |
| 16 | $scope.next = function(key) { | 12 | $scope.next = function(key) { |
| 17 | if (key === 13) $scope.focused++; | 13 | if (key === 13) $scope.focused++; |
| 18 | }; | 14 | }; |
| 19 | $scope.capacidadVechiulo = 0; | 15 | $scope.capacidadVechiulo = 0; |
| 20 | $scope.transportista = ''; | 16 | $scope.transportista = ''; |
| 21 | 17 | ||
| 22 | //SETEO BOTONERA LATERAL | 18 | //SETEO BOTONERA LATERAL |
| 23 | $timeout(function() { | 19 | $timeout(function() { |
| 24 | focaBotoneraLateralService.showSalir(false); | 20 | focaBotoneraLateralService.showSalir(false); |
| 25 | focaBotoneraLateralService.showPausar(false); | 21 | focaBotoneraLateralService.showPausar(false); |
| 26 | focaBotoneraLateralService.showCancelar(true); | 22 | focaBotoneraLateralService.showCancelar(true); |
| 27 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 23 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 28 | }); | 24 | }); |
| 29 | 25 | ||
| 30 | 26 | ||
| 31 | if($routeParams.idTemp != undefined) { | 27 | if($routeParams.idTemp != undefined) { |
| 32 | $scope.cisterna = focaAbmVehiculoService.getCisternasLocal()[$routeParams.idTemp]; | 28 | $scope.cisterna = focaAbmVehiculoService.getCisternasLocal()[$routeParams.idTemp]; |
| 33 | }else { | 29 | }else { |
| 34 | focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) { | 30 | focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) { |
| 35 | if(res.data) $scope.cisterna = res.data; | 31 | if(res.data) $scope.cisterna = res.data; |
| 36 | }); | 32 | }); |
| 37 | } | 33 | } |
| 38 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 34 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 39 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 35 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); |
| 40 | $scope.transportista = res.data.transportista.COD; | 36 | $scope.transportista = res.data.transportista.COD; |
| 41 | $scope.capacidadVechiulo = res.data.capacidad; | 37 | $scope.capacidadVechiulo = res.data.capacidad; |
| 42 | $scope.$broadcast('addCabecera', { | 38 | $scope.$broadcast('addCabecera', { |
| 43 | label: 'Transportista:', | 39 | label: 'Transportista:', |
| 44 | valor: codigo + ' - ' + res.data.transportista.NOM | 40 | valor: codigo + ' - ' + res.data.transportista.NOM |
| 45 | }); | 41 | }); |
| 46 | $scope.$broadcast('addCabecera', { | 42 | $scope.$broadcast('addCabecera', { |
| 47 | label: 'Unidad:', | 43 | label: 'Unidad:', |
| 48 | valor: res.data.codigo | 44 | valor: res.data.codigo |
| 49 | }); | 45 | }); |
| 50 | $scope.$broadcast('addCabecera', { | 46 | $scope.$broadcast('addCabecera', { |
| 51 | label: 'Capacidad total vehículo:', | 47 | label: 'Capacidad total vehículo:', |
| 52 | valor: res.data.capacidad | 48 | valor: res.data.capacidad |
| 53 | }); | 49 | }); |
| 54 | }); | 50 | }); |
| 55 | $scope.cancelar = function() { | 51 | $scope.cancelar = function() { |
| 56 | $location.path('/vehiculo/' + $routeParams.idVehiculo); | 52 | $location.path('/vehiculo/' + $routeParams.idVehiculo); |
| 57 | }; | 53 | }; |
| 58 | $scope.guardar = function() { | 54 | $scope.guardar = function() { |
| 59 | if(!$scope.cisterna.unidadMedida) { | 55 | if(!$scope.cisterna.unidadMedida) { |
| 60 | focaModalService.alert('Ingrese unidad de medida'); | 56 | focaModalService.alert('Ingrese unidad de medida'); |
| 61 | return; | 57 | return; |
| 62 | } | 58 | } |
| 63 | validaCodigoCapacidad().then(function() { | 59 | validaCodigoCapacidad().then(function() { |
| 64 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 60 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); |
| 65 | delete $scope.cisterna.vehiculo; | 61 | delete $scope.cisterna.vehiculo; |
| 66 | delete $scope.cisterna.cisternaCarga.articulo; | ||
| 67 | 62 | ||
| 68 | if($routeParams.idTemp != undefined) { | 63 | if($routeParams.idTemp != undefined) { |
| 69 | //SI SE EDITA UNA CISTERNA LOCALMENTE | 64 | //SI SE EDITA UNA CISTERNA LOCALMENTE |
| 70 | focaAbmVehiculoService | 65 | focaAbmVehiculoService |
| 71 | .guardarCisternaLocal($scope.cisterna, $routeParams.idTemp); | 66 | .guardarCisternaLocal($scope.cisterna, $routeParams.idTemp); |
| 72 | }else if($scope.cisterna.id) { | 67 | }else if($scope.cisterna.id) { |
| 73 | //SI SE EDITA UNA CISTERNA PREVIAMENTE GUARDADA | 68 | //SI SE EDITA UNA CISTERNA PREVIAMENTE GUARDADA |
| 74 | focaAbmVehiculoService.deleteCisterna($scope.cisterna.id); | 69 | focaAbmVehiculoService.deleteCisterna($scope.cisterna.id); |
| 75 | focaAbmVehiculoService.guardarCisternaLocal($scope.cisterna); | 70 | focaAbmVehiculoService.guardarCisternaLocal($scope.cisterna); |
| 76 | }else { | 71 | }else { |
| 77 | //SI SE EDITA CREA UNA NUEVA CISTERNA | 72 | //SI SE EDITA CREA UNA NUEVA CISTERNA |
| 78 | focaAbmVehiculoService.guardarCisternaLocal($scope.cisterna); | 73 | focaAbmVehiculoService.guardarCisternaLocal($scope.cisterna); |
| 79 | } | 74 | } |
| 80 | $window.location.assign('/#!/vehiculo/' + $routeParams.idVehiculo + | 75 | $window.location.assign('/#!/vehiculo/' + $routeParams.idVehiculo + |
| 81 | '/' + $scope.transportista); | 76 | '/' + $scope.transportista); |
| 82 | }, function(err) { | 77 | }, function(err) { |
| 83 | focaModalService.alert(err); | 78 | focaModalService.alert(err); |
| 84 | }); | 79 | }); |
| 85 | 80 | ||
| 86 | }; | 81 | }; |
| 87 | 82 | ||
| 88 | $scope.seleccionarUnidadMedida = function() { | 83 | $scope.seleccionarUnidadMedida = function() { |
| 89 | var modalInstance = $uibModal.open( | 84 | var modalInstance = $uibModal.open( |
| 90 | { | 85 | { |
| 91 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 86 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
| 92 | templateUrl: 'modal-unidad-medida.html', | 87 | templateUrl: 'modal-unidad-medida.html', |
| 93 | controller: 'focaModalUnidadMedidaCtrl', | 88 | controller: 'focaModalUnidadMedidaCtrl', |
| 94 | size: 'lg' | 89 | size: 'lg' |
| 95 | } | 90 | } |
| 96 | ); | 91 | ); |
| 97 | modalInstance.result.then(function(unidaMedida) { | 92 | modalInstance.result.then(function(unidaMedida) { |
| 98 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 93 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
| 99 | $scope.cisterna.unidadMedida = unidaMedida; | 94 | $scope.cisterna.unidadMedida = unidaMedida; |
| 100 | }); | 95 | }); |
| 101 | }; | 96 | }; |
| 102 | 97 | ||
| 103 | function validaCodigoCapacidad() { | 98 | function validaCodigoCapacidad() { |
| 104 | return new Promise(function(resolve, reject) { | 99 | return new Promise(function(resolve, reject) { |
| 105 | focaAbmVehiculoService | 100 | focaAbmVehiculoService |
| 106 | .getCisternadoPorVehiculo($routeParams.idVehiculo) | 101 | .getCisternadoPorVehiculo($routeParams.idVehiculo) |
| 107 | .then(function(res) { | 102 | .then(function(res) { |
| 108 | var cisternas = focaAbmVehiculoService.getCisternasLocal().concat(res.data); | 103 | var cisternas = focaAbmVehiculoService.getCisternasLocal().concat(res.data); |
| 109 | var totalCargado = 0; | 104 | var totalCargado = 0; |
| 110 | 105 | ||
| 111 | cisternas.forEach(function(cisterna) { | 106 | cisternas.forEach(function(cisterna) { |
| 112 | //SI EL CODIGO YA EXISTE | 107 | //SI EL CODIGO YA EXISTE |
| 113 | if(cisterna.codigo === $scope.cisterna.codigo && | 108 | if(cisterna.codigo === $scope.cisterna.codigo && |
| 114 | (cisterna.id !== $scope.cisterna.id || | 109 | (cisterna.id !== $scope.cisterna.id || |
| 115 | cisterna.idTemp !== $scope.cisterna.idTemp)) { | 110 | cisterna.idTemp !== $scope.cisterna.idTemp)) { |
| 116 | reject('Código de cisterna existente'); | 111 | reject('Código de cisterna existente'); |
| 117 | } | 112 | } |
| 118 | if(cisterna.id !== $scope.cisterna.id) { | 113 | if(cisterna.id !== $scope.cisterna.id) { |
| 119 | totalCargado += cisterna.capacidad; | 114 | totalCargado += cisterna.capacidad; |
| 120 | } | 115 | } |
| 121 | }); | 116 | }); |
| 122 | 117 | ||
| 123 | //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO | 118 | //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO |
| 124 | totalCargado = totalCargado + parseInt($scope.cisterna.capacidad); | 119 | totalCargado = totalCargado + parseInt($scope.cisterna.capacidad); |
| 125 | if(totalCargado > $scope.capacidadVechiulo) { | 120 | if(totalCargado > $scope.capacidadVechiulo) { |
| 126 | reject('La capacidad total de las cisternas' + | 121 | reject('La capacidad total de las cisternas' + |
| 127 | ' no debe ser mayor a la del vehiculo'); | 122 | ' no debe ser mayor a la del vehiculo'); |
| 128 | }else { | 123 | }else { |
| 129 | resolve(); | 124 | resolve(); |
| 130 | } | 125 | } |
| 131 | }); | 126 | }); |
| 132 | }); | 127 | }); |
| 133 | } | 128 | } |
| 134 | } | 129 | } |
| 135 | ]); | 130 | ]); |
| 136 | 131 |