var urlapi = "http://192.168.1.41:3000/api/"; var urlapi = "http://localhost:3000/api/"; angular.module('workApp', ['chart.js']) .controller('workController', function( $scope, $interval, $http ) { $scope.users={}; $scope.projects={}; $scope.currentInclude='login.html'; var refreshTime=20000; $scope.getLoggedUser = function(){ //get logged user $http.get(urlapi + 'users/byusername/' + $scope.user.username) .success(function(data, status, headers,config){ console.log(data); $scope.user=data; }) .error(function(data, status, headers,config){ console.log("server not responding, data error"); toastr.error("server not responding"); $scope.$broadcast('scroll.refreshComplete');//refresher stop }) .then(function(result){ users = result.data; }); }; /* DASHBOARD initialization */ $scope.dashboardInit = function(){ if(localStorage.getItem('owt_token')){// adding token to the headers $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('owt_token'); $http.defaults.headers.post['Content-Type'] = 'application/json'; $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('owt_token'); } if(localStorage.getItem("owt_user")){ $scope.user=JSON.parse(localStorage.getItem("owt_user")); }else{ $scope.currentInclude="login.html"; } $scope.getLoggedUser(); //getting users $http.get(urlapi + 'users') .success(function(data, status, headers,config){ if(data.success==false){ localStorage.removeItem("owt_token"); localStorage.removeItem("owt_user"); $scope.currentInclude="login.html"; console.log("token ended"); }else{ console.log(data); $scope.users=data; } }) .error(function(data, status, headers,config){ console.log("server not responding, data error"); toastr.error("server not responding"); $scope.$broadcast('scroll.refreshComplete');//refresher stop }) .then(function(result){ users = result.data; }); //getting projects $http.get(urlapi + 'projects') .success(function(data, status, headers,config){ if(data.success==false){ localStorage.removeItem("owt_token"); localStorage.removeItem("owt_user"); $scope.currentInclude="login.html"; console.log("token ended"); }else{ for(var i=0; i