2015-06-16 11:15:59 +00:00
|
|
|
angular.module('SeHub')
|
|
|
|
.controller('homeController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope)
|
|
|
|
{
|
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-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 = {};
|
|
|
|
// $scope.course = ""; // should be "" ? // {} ??
|
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
|
|
|
var imagePath = $scope.user.avatar_url;
|
2015-06-23 16:04:41 +00:00
|
|
|
|
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
|
|
|
console.log("Lecturer Mode!");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-20 11:58:30 +00:00
|
|
|
$scope.isStudent = true;
|
2015-06-20 11:21:32 +00:00
|
|
|
console.log("Student Mode!");
|
|
|
|
}
|
|
|
|
|
|
|
|
$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");
|
|
|
|
console.log(err);
|
|
|
|
});
|
2015-06-27 09:45:44 +00:00
|
|
|
|
2015-06-22 10:06:56 +00:00
|
|
|
console.log($scope.msg.msgToAdd);
|
|
|
|
$scope.messages.push({"text": $scope.msg.msgToAdd});
|
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-07-01 04:05:13 +00:00
|
|
|
$scope.displayTasks = function()
|
|
|
|
{
|
|
|
|
// apiService.getAllFutureTasks(token, courseId).success(function(data) // need to check courseId
|
|
|
|
// {
|
|
|
|
|
|
|
|
// }).error(function(err)
|
|
|
|
// {
|
|
|
|
|
|
|
|
// });
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-07-02 18:24:01 +00:00
|
|
|
$scope.displayMessages = function()
|
2015-07-01 04:05:13 +00:00
|
|
|
{
|
2015-07-02 18:24:01 +00:00
|
|
|
// apiService.getMessagesByGroupId(token, $scope.courseObj.id).success(function(data)
|
2015-07-01 04:05:13 +00:00
|
|
|
// {
|
2015-07-02 18:24:01 +00:00
|
|
|
// $scope.messages = data;
|
|
|
|
// console.log($scope.messages);
|
2015-07-01 04:05:13 +00:00
|
|
|
// }).error(function(err)
|
|
|
|
// {
|
2015-07-02 18:24:01 +00:00
|
|
|
// console.log(err);
|
|
|
|
// });
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$scope.getCampuses = function()
|
|
|
|
{
|
|
|
|
apiService.getCampusesByUser(token).success(function(data)
|
|
|
|
{
|
|
|
|
$scope.campuses = data;
|
|
|
|
$scope.getCourses(); // Get all the courses info
|
|
|
|
if($scope.messages)
|
|
|
|
{
|
|
|
|
$scope.displayMessages(); // // Display all messages in message feed and the latest one
|
|
|
|
}
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
|
|
|
console.log("Error: " + err);
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$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)
|
|
|
|
{
|
|
|
|
console.log("Error: " + err);
|
|
|
|
});
|
|
|
|
}
|
2015-07-01 04:05:13 +00:00
|
|
|
}
|
|
|
|
|
2015-06-20 11:21:32 +00:00
|
|
|
$scope.clearAllClicked = function() // Clear Screen from text
|
|
|
|
{
|
2015-06-22 10:06:56 +00:00
|
|
|
$scope.messages = [];
|
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
|
|
|
}
|
|
|
|
|
2015-07-02 18:24:01 +00:00
|
|
|
// $scope.chooseCourseClicked = function()
|
|
|
|
// {
|
|
|
|
// console.log("Click ");
|
|
|
|
// console.log($scope.choosenCourse);
|
|
|
|
// if($scope.choosenCourse)
|
|
|
|
// {
|
|
|
|
// console.log("here");
|
|
|
|
// $scope.courseObj = null;
|
|
|
|
// for(var i = 0; i < $scope.courses.length; i++)
|
|
|
|
// {
|
|
|
|
// if($scope.courses[i].courseName === $scope.choosenCourse)
|
|
|
|
// {
|
|
|
|
// $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-07-02 18:24:01 +00:00
|
|
|
|
|
|
|
// $scope.displayTasks(); // Display all tasks in task feed and the latest one
|
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
|
|
|
}]);
|