2015-05-09 19:00:14 +00:00
|
|
|
angular.module('SeHub')
|
2015-06-24 21:10:08 +00:00
|
|
|
.controller('mainController',
|
|
|
|
['$scope', '$rootScope', 'dataService', 'apiService', '$cookies',
|
|
|
|
'$cookieStore', '$location', '$window',
|
2015-05-09 19:00:14 +00:00
|
|
|
|
2015-06-17 17:59:45 +00:00
|
|
|
function($scope, $rootScope, dataService, apiService, $cookies, $cookieStore, $location, $window) {
|
2015-06-17 21:04:36 +00:00
|
|
|
top.setIsEnterd = true;
|
2015-06-17 17:14:53 +00:00
|
|
|
var token = $cookies['com.sehub.www'];
|
2015-05-09 19:00:14 +00:00
|
|
|
|
2015-06-17 17:14:53 +00:00
|
|
|
$scope.loadingData = true;
|
|
|
|
$scope.isInRegisterMode = false;
|
|
|
|
|
2015-07-25 11:20:29 +00:00
|
|
|
apiService.getUserByToken(token).success(function(data, status) {
|
|
|
|
if (status == 204) {
|
2015-06-17 17:14:53 +00:00
|
|
|
console.error("No User Found!");
|
2015-07-25 11:20:29 +00:00
|
|
|
$cookieStore.remove('com.sehub.www');
|
2015-07-25 15:25:26 +00:00
|
|
|
window.location = 'http://se-hub.appstpot.com/';
|
2015-06-17 17:14:53 +00:00
|
|
|
}
|
2015-06-16 17:34:37 +00:00
|
|
|
$scope.loadingData = false;
|
2015-06-17 17:14:53 +00:00
|
|
|
$scope.user = data;
|
2015-06-24 21:10:08 +00:00
|
|
|
|
|
|
|
$scope.menuItems = [{
|
|
|
|
"title": "Dash Board",
|
|
|
|
"icon": "fa fa-tachometer",
|
|
|
|
"style": "selected",
|
|
|
|
"route": "/home"
|
2015-06-26 11:08:23 +00:00
|
|
|
}, {
|
2015-06-27 12:08:17 +00:00
|
|
|
"title": "Explore",
|
|
|
|
"icon": "fa fa-compass",
|
2015-06-24 21:10:08 +00:00
|
|
|
"style": "",
|
2015-06-26 11:08:23 +00:00
|
|
|
"route": "/campuses"
|
2015-06-24 21:10:08 +00:00
|
|
|
}, {
|
2015-06-27 11:20:21 +00:00
|
|
|
"title": "My Projects",
|
2015-06-24 21:10:08 +00:00
|
|
|
"icon": "fa fa-cube",
|
|
|
|
"style": "",
|
2015-06-27 11:20:21 +00:00
|
|
|
"route": "/myProjects"
|
2015-06-24 21:10:08 +00:00
|
|
|
}, {
|
|
|
|
"title": "Tasks",
|
|
|
|
"icon": "fa fa-clipboard",
|
|
|
|
"style": "",
|
|
|
|
"route": "/tasks"
|
|
|
|
}, {
|
|
|
|
"title": "Profile",
|
|
|
|
"icon": "fa fa-cogs",
|
|
|
|
"style": "",
|
|
|
|
"route": "/profile/" + $scope.user.id.toString()
|
|
|
|
}, {
|
|
|
|
"title": "Log Out",
|
|
|
|
"icon": "fa fa-power-off",
|
|
|
|
"style": "",
|
|
|
|
"route": "/logout"
|
|
|
|
}];
|
|
|
|
|
2015-06-17 17:59:45 +00:00
|
|
|
dataService.initService($scope); //Start Data Sync Service (For User)
|
2015-06-17 17:14:53 +00:00
|
|
|
console.log(data);
|
|
|
|
if ($scope.user.isFirstLogin) {
|
|
|
|
$scope.menuObj = {};
|
|
|
|
$scope.isInRegisterMode = true;
|
|
|
|
$scope.loadingData = false;
|
|
|
|
$location.path('/register')
|
|
|
|
} else {
|
|
|
|
$location.path('/home')
|
|
|
|
}
|
2015-06-16 11:15:59 +00:00
|
|
|
|
2015-07-25 11:20:29 +00:00
|
|
|
}).error(function(err){
|
|
|
|
console.error(err);
|
|
|
|
$cookieStore.remove('com.sehub.www');
|
|
|
|
window.location = DEBUG ? 'http://localhost:8080' : 'http://se-hub.appstpot.com/';
|
2015-06-17 17:59:45 +00:00
|
|
|
});
|
|
|
|
|
2015-05-09 19:00:14 +00:00
|
|
|
|
2015-06-16 17:34:37 +00:00
|
|
|
|
2015-06-17 17:14:53 +00:00
|
|
|
$scope.menuClicked = function(item) {
|
|
|
|
var route = ""
|
|
|
|
if (item.title == "Log Out") {
|
|
|
|
console.info('Logging Out!');
|
|
|
|
$cookieStore.remove('com.sehub.www');
|
|
|
|
$window.location.href = 'http://se-hub.appspot.com'; // Reference to 'welcome' page
|
2015-06-16 20:32:10 +00:00
|
|
|
}
|
2015-06-17 17:14:53 +00:00
|
|
|
for (var i = $scope.menuItems.length - 1; i >= 0; i--) {
|
|
|
|
if ($scope.menuItems[i].title === item.title) {
|
|
|
|
$scope.menuItems[i].style = "selected";
|
|
|
|
route = $scope.menuItems[i].route;
|
|
|
|
} else {
|
|
|
|
$scope.menuItems[i].style = "";
|
|
|
|
}
|
|
|
|
};
|
2015-06-17 21:04:36 +00:00
|
|
|
top.setIsEnterd = false;
|
2015-06-17 17:14:53 +00:00
|
|
|
$location.path(route);
|
|
|
|
}
|
2015-06-16 20:32:10 +00:00
|
|
|
|
|
|
|
|
2015-06-17 17:14:53 +00:00
|
|
|
}
|
|
|
|
]);
|