2015-06-16 11:15:59 +00:00
|
|
|
angular.module('SeHub')
|
2015-08-02 09:55:43 +00:00
|
|
|
.controller('homeController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope',
|
|
|
|
function ($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope)
|
2015-06-16 11:15:59 +00:00
|
|
|
{
|
2015-06-20 11:58:30 +00:00
|
|
|
$scope.isStudent = false;
|
2015-06-20 11:21:32 +00:00
|
|
|
$scope.addMsg = false;
|
|
|
|
$scope.msgToPost = "";
|
|
|
|
$scope.oldText = "";
|
2015-06-22 10:06:56 +00:00
|
|
|
$scope.messages = [];
|
2015-08-02 09:55:43 +00:00
|
|
|
$scope.userMessages = [];
|
2015-08-02 10:45:42 +00:00
|
|
|
$scope.userTasks = [];
|
2015-07-02 18:24:01 +00:00
|
|
|
$scope.messagesDisplay = [];
|
|
|
|
$scope.courses = [];
|
|
|
|
$scope.campuses = [];
|
2015-06-23 16:04:41 +00:00
|
|
|
$scope.msg = {};
|
2015-07-02 18:24:01 +00:00
|
|
|
$scope.courseObj = {};
|
2015-08-02 09:55:43 +00:00
|
|
|
$scope.user = $scope.$parent.user;
|
2015-06-23 16:04:41 +00:00
|
|
|
$rootScope.seToken = $cookies['com.sehub.www'];
|
|
|
|
var token = $rootScope.seToken;
|
|
|
|
|
2015-06-20 11:21:32 +00:00
|
|
|
if($scope.user.isLecturer)
|
|
|
|
{
|
2015-06-20 11:58:30 +00:00
|
|
|
$scope.isStudent = false;
|
2015-06-20 11:21:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-20 11:58:30 +00:00
|
|
|
$scope.isStudent = true;
|
2015-06-20 11:21:32 +00:00
|
|
|
}
|
|
|
|
|
2015-08-02 09:55:43 +00:00
|
|
|
$scope.displayMessages = function()
|
|
|
|
{
|
|
|
|
apiService.getAllUserMessages(token).success(function(data)
|
|
|
|
{
|
|
|
|
$scope.userMessages = data;
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
2015-08-02 14:51:08 +00:00
|
|
|
console.log(err.message);
|
2015-08-02 09:55:43 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-06-20 11:21:32 +00:00
|
|
|
$scope.addMessageClicked = function()
|
|
|
|
{
|
|
|
|
$scope.addMsg = true; // Reveal the "POST" Button
|
|
|
|
}
|
2015-06-22 10:06:56 +00:00
|
|
|
$scope.postMessageClicked = function() // Posting the message itself
|
2015-06-20 11:21:32 +00:00
|
|
|
{
|
2015-07-02 18:24:01 +00:00
|
|
|
console.log($scope.courseObj);
|
|
|
|
if($scope.msg.msgToAdd != null && $scope.courseObj.courseName)
|
2015-06-20 11:21:32 +00:00
|
|
|
{
|
2015-07-02 18:24:01 +00:00
|
|
|
console.log("NOW");
|
|
|
|
|
2015-06-27 09:45:44 +00:00
|
|
|
jsonNewMsg = {
|
2015-07-02 18:24:01 +00:00
|
|
|
'groupId': $scope.courseObj.id, // TODO Should be ===> $scope.courseObj.id
|
2015-06-27 09:45:44 +00:00
|
|
|
'message': $scope.msg.msgToAdd
|
|
|
|
};
|
|
|
|
|
2015-07-02 18:24:01 +00:00
|
|
|
apiService.createMessage(token, jsonNewMsg).success(function(data)
|
|
|
|
{
|
|
|
|
console.log("create Msg!");
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
|
|
|
console.log("Error Below");
|
2015-08-02 10:45:42 +00:00
|
|
|
console.log(err.message);
|
2015-07-02 18:24:01 +00:00
|
|
|
});
|
2015-06-27 09:45:44 +00:00
|
|
|
|
2015-08-02 10:45:42 +00:00
|
|
|
$scope.userMessages.push({"text": $scope.msg.msgToAdd});
|
2015-08-02 09:55:43 +00:00
|
|
|
$location.path('/home/');
|
2015-06-20 11:21:32 +00:00
|
|
|
}
|
2015-07-02 18:24:01 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$mdDialog.show($mdDialog.alert().title('Error Creating Message').content('Message content or Course is missing')
|
|
|
|
.ariaLabel('Send Message alert dialog').ok('Try Again!').targetEvent()); // Pop-up alert
|
|
|
|
}
|
2015-06-22 10:06:56 +00:00
|
|
|
$scope.msg.msgToAdd = null;
|
2015-06-20 11:21:32 +00:00
|
|
|
}
|
2015-06-16 11:15:59 +00:00
|
|
|
|
2015-08-02 12:39:39 +00:00
|
|
|
$scope.gotoTask = function(task)
|
|
|
|
{
|
|
|
|
console.log(task);
|
|
|
|
if(task.isPersonal)
|
|
|
|
{
|
|
|
|
$location.path('/tasks/fill/' + task.id + '/' + $scope.user.id);
|
|
|
|
}
|
|
|
|
else // it's a project task
|
|
|
|
{
|
|
|
|
apiService.getProjectsByCourse(token, task.courseId).success(function(data)
|
|
|
|
{
|
2015-08-02 14:51:08 +00:00
|
|
|
// console.log($scope.user);
|
2015-08-02 12:39:39 +00:00
|
|
|
for(var i = 0; i < $scope.user.projects_id_list.length; i++)
|
|
|
|
for(var j = 0; j < data.length; j++)
|
|
|
|
{
|
2015-08-02 14:51:08 +00:00
|
|
|
if($scope.user.projects_id_list[i] === data[j].id.toString())
|
2015-08-02 12:39:39 +00:00
|
|
|
{
|
|
|
|
$location.path('/tasks/fill/' + task.id + '/' + data[j].id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
|
|
|
console.log(err.message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-01 04:05:13 +00:00
|
|
|
$scope.displayTasks = function()
|
|
|
|
{
|
2015-08-02 10:45:42 +00:00
|
|
|
apiService.getAllFutureTasks(token).success(function(data) // Get all Tasks // TODO change to closest TASK
|
2015-08-02 09:55:43 +00:00
|
|
|
{
|
2015-08-02 10:45:42 +00:00
|
|
|
$scope.userTasks = data;
|
2015-08-02 09:55:43 +00:00
|
|
|
}).error(function(err)
|
|
|
|
{
|
2015-08-02 10:45:42 +00:00
|
|
|
console.log(err.message);
|
2015-08-02 09:55:43 +00:00
|
|
|
});
|
2015-08-02 12:39:39 +00:00
|
|
|
}
|
2015-07-01 04:05:13 +00:00
|
|
|
|
2015-08-02 12:39:39 +00:00
|
|
|
$scope.getProjects = function(courseId)
|
|
|
|
{
|
|
|
|
apiService.getProjectsByCourse(token, courseId).success(function(data)
|
|
|
|
{
|
|
|
|
return data;
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
|
|
|
console.log(err.message);
|
|
|
|
});
|
2015-08-02 09:55:43 +00:00
|
|
|
}
|
2015-07-02 18:24:01 +00:00
|
|
|
|
|
|
|
$scope.getCampuses = function()
|
|
|
|
{
|
|
|
|
apiService.getCampusesByUser(token).success(function(data)
|
|
|
|
{
|
|
|
|
$scope.campuses = data;
|
|
|
|
$scope.getCourses(); // Get all the courses info
|
2015-08-02 12:39:39 +00:00
|
|
|
if($scope.userMessages)
|
2015-07-02 18:24:01 +00:00
|
|
|
{
|
2015-08-02 09:55:43 +00:00
|
|
|
//$scope.displayMessages(); // // Display all messages in message feed and the latest one
|
2015-07-02 18:24:01 +00:00
|
|
|
}
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
2015-08-02 10:45:42 +00:00
|
|
|
console.log(err.message);
|
2015-07-02 18:24:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.getCourses = function()
|
|
|
|
{
|
|
|
|
for(var i = 0; i < $scope.campuses.length; i++)
|
|
|
|
{
|
|
|
|
apiService.getAllCoursesByCampus(token, $scope.campuses[i].id).success(function(data) // Shows all classes from this campus
|
|
|
|
{
|
|
|
|
$scope.loadingData = false;
|
|
|
|
$scope.courses = data;
|
|
|
|
// console.log($scope.courses);
|
|
|
|
if($scope.courses && $scope.courses.length > 0)
|
|
|
|
{
|
|
|
|
$scope.coursesEmpty = false;
|
|
|
|
}
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
2015-08-02 09:55:43 +00:00
|
|
|
console.log("Error: " + err.message);
|
2015-07-02 18:24:01 +00:00
|
|
|
});
|
|
|
|
}
|
2015-07-01 04:05:13 +00:00
|
|
|
}
|
|
|
|
|
2015-06-20 11:21:32 +00:00
|
|
|
$scope.clearAllClicked = function() // Clear Screen from text
|
|
|
|
{
|
2015-08-02 09:55:43 +00:00
|
|
|
$scope.userMessages = [];
|
2015-06-20 11:21:32 +00:00
|
|
|
}
|
2015-06-17 21:04:36 +00:00
|
|
|
|
2015-06-22 10:06:56 +00:00
|
|
|
$scope.chooseCourseClicked = function()
|
|
|
|
{
|
2015-07-02 18:24:01 +00:00
|
|
|
// console.log($scope.courseObj);
|
|
|
|
if($scope.courseObj)
|
|
|
|
{
|
|
|
|
for(var i = 0; i < $scope.courses.length; i++)
|
|
|
|
{
|
|
|
|
if($scope.courses[i].courseName === $scope.courseObj.name)
|
|
|
|
{
|
|
|
|
$scope.courseObj = $scope.courses[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
console.log($scope.courseObj);
|
2015-06-22 10:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.chooseProjectClicked = function()
|
|
|
|
{
|
|
|
|
console.log("choose project Clicked!!");
|
|
|
|
}
|
2015-07-02 18:24:01 +00:00
|
|
|
|
|
|
|
$scope.getCampuses(); // Get all the campuses info
|
2015-06-22 10:06:56 +00:00
|
|
|
|
2015-06-20 11:21:32 +00:00
|
|
|
// animation
|
2015-08-02 12:39:39 +00:00
|
|
|
if($scope.userMessages)
|
|
|
|
{
|
|
|
|
$scope.displayMessages(); // // Display all messages in message feed and the latest one
|
|
|
|
}
|
|
|
|
// $scope.displayMessages();
|
2015-08-02 09:55:43 +00:00
|
|
|
$scope.displayTasks(); // Display all tasks in task feed and the latest one
|
2015-08-02 12:39:39 +00:00
|
|
|
// $scope.getProjects(); // Get all projects info
|
2015-06-20 11:21:32 +00:00
|
|
|
$scope.isEnterd = top.setIsEnterd;
|
2015-07-02 18:24:01 +00:00
|
|
|
|
2015-06-16 11:15:59 +00:00
|
|
|
}]);
|