'use strict'; var app = angular.module('App2', ['ngStorage', 'ngRoute', 'ngPagination', 'ngFileUpload', 'ngDialog', 'angucomplete-alt']); var app3 = angular.module('App3', ['ngStorage']); app.config(function ($routeProvider) { $routeProvider.when('/', { controller: 'MainCtrl', templateUrl: '/templates/home.html', resolve: { 'service1': 'regService', } }); $routeProvider.when('/view/:id', { controller: 'detController', templateUrl: '/templates/detalle.html', resolve:{ 'service1':'regService', } }); $routeProvider.when('/estadist', { controller: 'estadistController', templateUrl: '/templates/estadist.html', }); $routeProvider.otherwise({ redirectTo: '/' }); }); /* factory de catalogos*/ app.factory('userService', function ($rootScope, $http, $q, $log) { var deferred = $q.defer(); $http.get('rest/cat_users') .success(function (data, status, headers, config) { $rootScope.cat_users = data; deferred.resolve(); //console.log(data); }); return deferred.promise; }); app.factory('regService', function ($rootScope, $http, $q, $log) { var deferred = $q.defer(); $http.get('https://jsonplaceholder.typicode.com/comments') .success(function (data, status, headers, config) { $rootScope.cat_registros= data; deferred.resolve(); //console.log(data); }); return deferred.promise; }); /* factory de catalogos*/ /* controllers*/ app3.controller('gac', function ($scope, $window, $q, $http, $rootScope, $location, $sessionStorage, $timeout) { var auth2; $scope.user = {}; $window.appStart = function () { gapi.load('auth2', initSigninV2); }; var initSigninV2 = function () { auth2 = gapi.auth2.getAuthInstance(); auth2.isSignedIn.listen(signinChanged); auth2.currentUser.listen(userChanged); if (auth2.isSignedIn.get() == true) { auth2.signIn(); } }; var signinChanged = function (isSignedIn) { if (isSignedIn) { var googleUser = auth2.currentUser.get(); var authResponse = googleUser.getAuthResponse(); var profile = googleUser.getBasicProfile(); $scope.user.id = profile.getId(); $scope.user.fullName = profile.getName(); $scope.user.firstName = profile.getGivenName(); $scope.user.lastName = profile.getFamilyName(); $scope.user.photo = profile.getImageUrl(); $scope.user.email = profile.getEmail(); $scope.user.domain = googleUser.getHostedDomain(); $scope.user.timestamp = moment().format('x'); $scope.user.idToken = authResponse.id_token; $scope.user.expiresAt = authResponse.expires_at; $scope.$digest(); } else { $scope.user = {}; $scope.$digest(); } //console.log($scope.user) $rootScope.user = $scope.user; }; var userChanged = function (user) {}; //botton continuar// $scope.submitLogin = function () { var deferred = $q.defer(); $http.get('rest/cat_users') .success(function (data, status, headers, config) { var salida = []; angular.forEach(data, function (value, key) { if (value.email == $scope.user.email && value.activo == 1) salida.push(value); }) //console.log(salida) deferred.resolve(); if (salida.length > 0) { $scope.userData = { 'id_user': salida[0].id_usuario, 'name': $scope.user.firstName, 'email': $scope.user.email, 'perfil': salida[0].perfil, 'img': $scope.user.photo }; $sessionStorage.userLocal = $scope.userData; loginSuccess(); $timeout(function () { $window.location.href = ('index.html') }, 1500); } else { loginError(); $scope.solicAccesAlert = true; } }); return deferred.promise; } //botton continuar// }); app.controller('MasterController', function ($scope, $location, $rootScope, $window, $sessionStorage, ngDialog) { $scope.userActivo = $sessionStorage.userLocal; //console.log($scope.userActivo); if ($scope.userActivo == undefined) { console.log("no se ha definido el usuario") $window.location.href = ('/') } //MARCAR LOS MENUS COMO ACTIVOS// $scope.isActive = function (destination) { return destination === $location.path(); } //MARCAR LOS MENUS COMO ACTIVOS// $scope.clickToOpen2 = function (report) { //console.log(report) ngDialog.open({ template: 'templates/ayuda.html', plain: false, closeByDocument: false, className: 'ngdialog-theme-default', width: '50%', height: 500 }); }; //NOTIFICACION PARA ACTUALIZAR LOS FONDOS// if ($scope.userActivo.perfil == 'ADMIN' || $scope.userActivo.perfil=='GOD') { var date = new Date(); var diaActual = date.getDate(); var primerDia = new Date(date.getFullYear(), date.getMonth(), 1); var ultimoDia = new Date(date.getFullYear(), date.getMonth() + 1, 0); /* console.log("La fecha de hoy es: " + diaActual) console.log("El primer día es: " + primerDia.getDate()); console.log("El ultimo día es: " + ultimoDia.getDate()); */ if (diaActual == ultimoDia) { //console.log("ES EL ULTIMO DIA") } else { //console.log("aun hay tiempo") } } //NOTIFICACION PARA ACTUALIZAR LOS FONDOS// }); app.controller('MainCtrl', function ($scope, $rootScope, $log, $http, $routeParams, $location, $route, $q, $window, $timeout) { $rootScope.overlayLoad = false; $scope.sortType = '-id_facultamiento'; // set the default sort type $scope.sortReverse = false; $scope.regList = $rootScope.cat_registros; /* var facults = $rootScope.facults; var salida = []; if ($scope.userActivo.perfil == 'ADMIN' || $scope.userActivo.perfil == 'GOD' || $scope.userActivo.perfil == 'CONSULTA') { $scope.facultList = facults; } else if ($scope.userActivo.perfil == 'FUNCIONARIO') { angular.forEach(facults, function (value, key) { if (value.id_solicitante == $scope.userActivo.id_user || value.id_func_vb == $scope.userActivo.id_user) salida.push(value); }) $scope.facultList = salida; } else if ($scope.userActivo.perfil == 'SOLICITANTE') { angular.forEach(facults, function (value, key) { if (value.id_solicitante == $scope.userActivo.id_user) salida.push(value); }) $scope.facultList = salida; }*/ //IR AL DETALLE DEL FAE// $scope.detRegist = function(id){ $location.path('/view/'+id); } //IR AL DETALLE DEL FAE// }); app.controller('detController', function($routeParams, $rootScope, $scope, $log, $http, $location, ngDialog, $timeout, $window){ for (var i = 0; i < $rootScope.cat_registros.length; i++) { if ($rootScope.cat_registros[i].id == $routeParams.id) { $scope.selectReg = angular.copy($rootScope.cat_registros[i]); } } //console.log($scope.selectReg) }) app.controller('estadistController', function($scope,$rootScope){ $scope.nombre = '' $scope.$watch("nombre",function(newValue,oldValue){ if(newValue === oldValue){ return; } console.log("el nuevo nombre es: " + newValue) }) }) /* controllers*/