From 8a7c70286e0840fa36cb139989d7779b20067488 Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 22 Apr 2019 10:57:35 -0300 Subject: [PATCH] changes mobile --- src/js/controller.js | 66 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 49 insertions(+), 17 deletions(-) diff --git a/src/js/controller.js b/src/js/controller.js index 0c44aac..60a1943 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -8,6 +8,8 @@ angular.module('focaHojaRuta') 'hojaRutaService', 'focaLoginService', 'focaModalService', + '$rootScope', + '$localStorage', function( $scope, $location, @@ -15,11 +17,26 @@ angular.module('focaHojaRuta') $uibModal, hojaRutaService, focaLoginService, - focaModalService + focaModalService, + $rootScope, + $localStorage ) { + var loginData = focaLoginService.getLoginData(); + config(); + + function config() { + + $scope.cabecera = []; + $scope.showCabecera = true; + $scope.now = new Date(); + $scope.puntoVenta = '0000'; + $scope.comprobante = '00000000'; + } + hojaRutaService.getHojaRuta(loginData.chofer).then(function(res) { + if (res.data) { var hojaRuta = res.data; $scope.hojaRuta = hojaRuta; @@ -32,14 +49,22 @@ angular.module('focaHojaRuta') focaModalService.alert('Sin hoja de ruta asignada'); $location.path('/'); } + + watch(); + + if (!$scope.esatadoRed) { + getLSHojaRuta(); + } + }); - $scope.cabecera = []; - $scope.showCabecera = true; + function watch() { + + $scope.$watch('hojaRuta', function(nuevoValor) { + $localStorage.hojaRuta = JSON.stringify(nuevoValor); + }, true); + } - $scope.now = new Date(); - $scope.puntoVenta = '0000'; - $scope.comprobante = '00000000'; $scope.verDetalle = function(remito) { var modalInstance = $uibModal.open( { @@ -54,10 +79,8 @@ angular.module('focaHojaRuta') size: 'lg' } ); - modalInstance.result.then(function(detalle) { - console.log(detalle); - //función a ejecutar cuando se carga la cisterna - //eliminar console log en produccion cuando sea necesario + modalInstance.result.then(function() { + //funcion se ejecuta cuando se carga pantalla }); }; @@ -69,13 +92,6 @@ angular.module('focaHojaRuta') $scope.cabecera.push({label: label, valor: valor}); } } - //TODO Descomentar cuando se use - // function removeCabecera(label) { - // var propiedad = $filter('filter')($scope.cabecera, {label: label}, true); - // if(propiedad.length === 1) { - // $scope.cabecera.splice($scope.cabecera.indexOf(propiedad[0]), 1); - // } - // } $scope.rellenar = function(relleno, longitud) { relleno = '' + relleno; @@ -85,6 +101,7 @@ angular.module('focaHojaRuta') return relleno; }; + $scope.salir = function() { $location.path('/'); }; @@ -128,5 +145,20 @@ angular.module('focaHojaRuta') ); modalInstance.result.then(terminar); }; + + $rootScope.$on('estadoRed', function(event, value) { + $scope.esatadoRed = value; + }); + + function getLSHojaRuta() { + + var hojaRuta = JSON.parse($localStorage.hojaRuta || null); + + if (hojaRuta) { + $scope.hojaRuta = hojaRuta; + delete $localStorage.hojaRuta; + } + } + } ]); -- 1.9.1