angular.module('incidente', []) .controller('home', function($scope, $http) { $http.get('/resource/').success(function(data) { $scope.greeting = data; }) }) .controller( 'navigation', function($rootScope, $scope, $http, $location) { var authenticate = function(credentials, callback) { var headers = credentials ? { authorization : "Basic " + btoa(credentials.username + ":" + credentials.password) } : {}; $http.get('user', { headers : headers }).success(function(data) { if (data.name) { $rootScope.authenticated = true; } else { $rootScope.authenticated = false; } callback && callback(); }).error(function() { $rootScope.authenticated = false; callback && callback(); }); } authenticate(); $scope.credentials = {}; $scope.login = function() { authenticate($scope.credentials, function() { if ($rootScope.authenticated) { $location.path("/"); $scope.error = false; } else { $location.path("/login"); $scope.error = true; } }); }; }) .controller('IncidenteController', [ '$scope', '$http', function($scope, $http) { var urlbase = "http://localhost:8080/get/"; var onError = function(reason) { $scope.error = "No se pudo encontrar"; }; var onIncidenteComplete = function(response) { $scope.incidentes = response.data; }; $http.get(urlbase + "incidente/").then(onIncidenteComplete, onError); $scope.obtenerSoftware = function(incidente) { $scope.software = incidente.software; }; $scope.obtenerHardware = function(incidente) { $scope.hardware = incidente.hardware; }; $scope.obtenerSistema = function(incidente) { $scope.sistema = incidente.sistema; }; } ]) .controller( 'TecnicoController', [ '$scope', '$http', function($scope, $http) { var onError = function(reason) { $scope.error = "No se pudo encontrar"; }; var onTecnicoComplete = function(response) { $scope.tecnicos = response.data; }; $http.get("http://localhost:8080/get/tecnico/").then( onTecnicoComplete, onError); } ]) .controller('SistemaController', [ '$scope', '$http', function($scope, $http) { var urlbase = "http://localhost:8080/get/"; var onError = function(reason) { $scope.error = "No se pudo encontrar"; }; var onSistemaComplete = function(response) { $scope.sistemas = response.data; }; $http.get(urlbase + "sistema/").then(onSistemaComplete, onError); $scope.obtenerSoftware = function(sistema) { $scope.software = sistema.software; }; $scope.obtenerHardware = function(sistema) { $scope.hardware = sistema.hardware; }; $scope.obtenerIncidente = function(sistema) { $scope.incidente = sistema.incidente; }; } ]);