2015-06-23 16:40:30 +00:00
|
|
|
angular.module('SeHub')
|
2015-06-27 11:52:49 +00:00
|
|
|
.controller('myClassesController', ['$scope', '$location', '$routeParams', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope',
|
|
|
|
function ($scope, $location, $routeParams, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope)
|
2015-06-23 16:40:30 +00:00
|
|
|
{
|
2015-06-30 12:56:53 +00:00
|
|
|
$scope.loadingData = true;
|
2015-06-23 16:40:30 +00:00
|
|
|
$scope.isStudent = false;
|
|
|
|
$scope.isCourse = false;
|
|
|
|
$scope.isNewCourse = false;
|
|
|
|
$scope.newClassName = false;
|
2015-06-24 11:01:08 +00:00
|
|
|
$scope.course = {};
|
|
|
|
var token = $cookies['com.sehub.www'];
|
2015-06-23 16:40:30 +00:00
|
|
|
$scope.user.finalDate = '';
|
2015-06-24 11:01:08 +00:00
|
|
|
$scope.user.startDate = '';
|
2015-06-23 16:40:30 +00:00
|
|
|
$scope.showMyClass = false;
|
2015-06-30 12:56:53 +00:00
|
|
|
$scope.coursesEmpty = true;
|
2015-06-29 09:57:07 +00:00
|
|
|
$scope.campusId;
|
2015-08-02 16:51:29 +00:00
|
|
|
$scope.isMemberInCourse = false;
|
2015-06-26 18:56:41 +00:00
|
|
|
var campusId = $routeParams.campusId;
|
2015-06-23 16:40:30 +00:00
|
|
|
|
2015-06-29 18:01:30 +00:00
|
|
|
$scope.goToClass = function(classId, className)
|
2015-06-26 18:56:41 +00:00
|
|
|
{
|
2015-06-29 18:01:30 +00:00
|
|
|
$location.path('/class/' + classId.toString() + '/' + className); // Will display all the projects in this course
|
2015-06-26 13:49:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-29 09:57:07 +00:00
|
|
|
$scope.chooseCampusClicked = function()
|
2015-06-23 16:40:30 +00:00
|
|
|
{
|
|
|
|
$scope.isCourse = true;
|
2015-06-26 18:56:41 +00:00
|
|
|
|
|
|
|
apiService.getAllCampuses(token).success(function(data)
|
|
|
|
{
|
|
|
|
$scope.campuses = data;
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
2015-08-02 16:51:29 +00:00
|
|
|
console.log(err.message);
|
2015-06-26 18:56:41 +00:00
|
|
|
});
|
2015-06-23 16:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.createCourseClicked = function()
|
|
|
|
{
|
2015-06-24 18:35:21 +00:00
|
|
|
$scope.isNewCourse = !$scope.isNewCourse;
|
2015-06-23 16:40:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.submitNewClassClicked = function()
|
|
|
|
{
|
2015-06-29 09:57:07 +00:00
|
|
|
var i;
|
2015-06-27 09:45:44 +00:00
|
|
|
if($scope.course.courseName != null && $scope.course.endDate != null && $scope.course.startDate != null)
|
2015-06-23 16:40:30 +00:00
|
|
|
{
|
2015-06-29 09:57:07 +00:00
|
|
|
for(i = 0; i < $scope.campuses.length; i++)
|
|
|
|
{
|
|
|
|
if($scope.course.campusName === $scope.campuses[i].title)
|
|
|
|
{
|
|
|
|
$scope.campusId = $scope.campuses[i].id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-24 11:01:08 +00:00
|
|
|
var jsonNewCourse =
|
|
|
|
{
|
|
|
|
'courseName': $scope.course.courseName,
|
2015-06-29 09:57:07 +00:00
|
|
|
'campusId': $scope.campusId,
|
2015-06-24 11:01:08 +00:00
|
|
|
'startDate': {
|
|
|
|
'year' : $scope.course.startDate.getFullYear(),
|
2015-06-27 09:45:44 +00:00
|
|
|
'day' : $scope.course.startDate.getDate(),
|
|
|
|
'month': $scope.course.startDate.getMonth() + 1
|
2015-06-24 11:01:08 +00:00
|
|
|
},
|
|
|
|
'endDate': {
|
|
|
|
'year' : $scope.course.endDate.getFullYear(),
|
2015-06-27 09:45:44 +00:00
|
|
|
'day' : $scope.course.endDate.getDate(),
|
|
|
|
'month': $scope.course.endDate.getMonth() + 1
|
2015-06-24 11:01:08 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
apiService.createCourse(token, jsonNewCourse).success(function(data)
|
|
|
|
{
|
2015-06-27 09:45:44 +00:00
|
|
|
$mdDialog.show($mdDialog.alert().title('Course Created').content('You have created course successfully.')
|
2015-06-24 18:35:21 +00:00
|
|
|
.ariaLabel('Email verification alert dialog').ok('Lets Start!').targetEvent())
|
|
|
|
.then(function() {
|
2015-06-29 18:01:30 +00:00
|
|
|
$location.path('/class/' + data.id + '/' + data.courseName); // Will display all the projects in this course
|
2015-06-24 18:35:21 +00:00
|
|
|
}); // Pop-up alert
|
2015-06-27 09:45:44 +00:00
|
|
|
}).error(function(err)
|
|
|
|
{
|
2015-07-02 19:15:50 +00:00
|
|
|
$mdDialog.show($mdDialog.alert().title('Error Creating Class').content(err)
|
|
|
|
.ariaLabel('Create Class alert dialog').ok('Try Again!').targetEvent()); // Pop-up alert
|
2015-06-27 09:45:44 +00:00
|
|
|
});
|
2015-06-23 16:40:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-27 09:45:44 +00:00
|
|
|
$mdDialog.show($mdDialog.alert().title('Error - Creating Course').content('Some fields are missing.')
|
2015-06-23 16:40:30 +00:00
|
|
|
.ariaLabel('Email verification alert dialog').ok('Try Again!').targetEvent());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-26 13:49:46 +00:00
|
|
|
var init = function()
|
|
|
|
{
|
2015-06-28 12:27:06 +00:00
|
|
|
$scope.holdArrays = [];
|
|
|
|
var tempArr = [];
|
|
|
|
var sizeOfSmallArrays = 3;
|
|
|
|
for (var i = 0 ; i < $scope.courses.length ; i++) {
|
|
|
|
if(i % sizeOfSmallArrays !== 0){
|
|
|
|
tempArr.push($scope.courses[i]);
|
|
|
|
}else{
|
|
|
|
if(i !== 0){
|
|
|
|
$scope.holdArrays.push(tempArr);
|
|
|
|
tempArr = [];
|
|
|
|
tempArr.push($scope.courses[i]);
|
|
|
|
}else{
|
|
|
|
tempArr.push($scope.courses[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.holdArrays.push(tempArr);
|
|
|
|
}
|
2015-06-27 11:20:21 +00:00
|
|
|
|
2015-06-28 12:27:06 +00:00
|
|
|
var displayCourses = function()
|
|
|
|
{
|
2015-06-29 10:06:13 +00:00
|
|
|
apiService.getAllCoursesByCampus(token, campusId).success(function(data) // Shows all classes from this campus
|
2015-06-28 12:27:06 +00:00
|
|
|
{
|
2015-06-30 12:56:53 +00:00
|
|
|
$scope.loadingData = false;
|
2015-06-28 12:27:06 +00:00
|
|
|
$scope.courses = data;
|
|
|
|
init(); // Executing the function to initialize course display
|
2015-06-30 12:56:53 +00:00
|
|
|
if($scope.courses && $scope.courses.length > 0)
|
2015-06-27 11:20:21 +00:00
|
|
|
{
|
2015-06-30 12:56:53 +00:00
|
|
|
$scope.coursesEmpty = false;
|
2015-06-28 12:27:06 +00:00
|
|
|
}
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
2015-08-02 16:51:29 +00:00
|
|
|
console.log(err.message);
|
2015-06-28 12:27:06 +00:00
|
|
|
});
|
2015-06-27 09:45:44 +00:00
|
|
|
}
|
2015-06-26 13:49:46 +00:00
|
|
|
|
2015-06-27 09:45:44 +00:00
|
|
|
if($scope.user.isLecturer)
|
|
|
|
{
|
|
|
|
$scope.isStudent = false;
|
2015-06-26 13:49:46 +00:00
|
|
|
}
|
2015-06-27 09:45:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$scope.isStudent = true;
|
|
|
|
}
|
|
|
|
displayCourses(); // Will display the courses that the user related to // TODO!!
|
2015-06-23 16:40:30 +00:00
|
|
|
}]);
|