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
|
|
|
{
|
|
|
|
$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-27 09:45:44 +00:00
|
|
|
$scope.coursesEmpty = false;
|
2015-06-26 18:56:41 +00:00
|
|
|
var campusId = $routeParams.campusId;
|
2015-06-23 16:40:30 +00:00
|
|
|
|
2015-06-27 09:45:44 +00:00
|
|
|
var displayCourses = function()
|
2015-06-23 16:40:30 +00:00
|
|
|
{
|
2015-06-27 09:45:44 +00:00
|
|
|
apiService.getCoursesByUser(token, campusId).success(function(data) // Get all the courses for display
|
|
|
|
{
|
|
|
|
$scope.courses = data;
|
|
|
|
console.log("success " + $scope.courses);
|
|
|
|
init(); // Executing the function to initialize course display
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
|
|
|
console.log("error: " + err);
|
|
|
|
});
|
2015-06-27 11:20:21 +00:00
|
|
|
if($scope.courses = null)
|
|
|
|
{
|
|
|
|
$scope.coursesEmpty = true;
|
|
|
|
}
|
2015-06-23 16:40:30 +00:00
|
|
|
}
|
|
|
|
|
2015-06-26 18:56:41 +00:00
|
|
|
$scope.goToClass = function(classId)
|
|
|
|
{
|
|
|
|
console.log("Done! " + $scope.courses);
|
|
|
|
$location.path('/projects/' + classId.toString()); // Will display all the projects in this course
|
2015-06-26 13:49:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-23 16:40:30 +00:00
|
|
|
$scope.chooseCourseClicked = function()
|
|
|
|
{
|
|
|
|
$scope.isCourse = true;
|
|
|
|
console.log("choose course Clicked!!");
|
2015-06-26 18:56:41 +00:00
|
|
|
|
|
|
|
apiService.getAllCampuses(token).success(function(data)
|
|
|
|
{
|
|
|
|
$scope.campuses = data;
|
|
|
|
console.log("Campuses: " + $scope.campuses.toString());
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
|
|
|
console.log("Error: " + err);
|
|
|
|
});
|
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-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-24 11:01:08 +00:00
|
|
|
var jsonNewCourse =
|
|
|
|
{
|
|
|
|
'courseName': $scope.course.courseName,
|
|
|
|
'campusName': $scope.course.campusName,
|
|
|
|
'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
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-06-27 09:45:44 +00:00
|
|
|
console.log("Json here: " + $scope.chosenCampus);
|
2015-06-24 11:01:08 +00:00
|
|
|
console.log(jsonNewCourse);
|
|
|
|
|
|
|
|
apiService.createCourse(token, jsonNewCourse).success(function(data)
|
|
|
|
{
|
|
|
|
console.log("createCourse API done");
|
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-27 11:52:49 +00:00
|
|
|
$location.path('/newCourse'); // TODO TODO TODO
|
2015-06-24 18:35:21 +00:00
|
|
|
}); // Pop-up alert
|
2015-06-27 09:45:44 +00:00
|
|
|
}).error(function(err)
|
|
|
|
{
|
|
|
|
console.log(err);
|
|
|
|
});
|
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()
|
|
|
|
{
|
|
|
|
var i, j, counter = 0;
|
|
|
|
var newLength = 0;
|
2015-06-27 11:20:21 +00:00
|
|
|
|
|
|
|
if(($scope.courses.length % 3) === 0)
|
2015-06-26 13:49:46 +00:00
|
|
|
{
|
2015-06-27 11:20:21 +00:00
|
|
|
newLength = ($scope.courses.length / 3);
|
2015-06-26 13:49:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-27 11:20:21 +00:00
|
|
|
newLength = (Math.ceil($scope.courses.length / 3)); // Rounds number up
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("length: " + newLength);
|
|
|
|
$scope.holdArrays.length = newLength;
|
|
|
|
|
|
|
|
for(j = 0; j < newLength; j++)
|
|
|
|
{
|
|
|
|
$scope.holdArrays[j] = [3]; // Creating array in size of 3 in each array cell
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < newLength; i++)
|
|
|
|
{
|
|
|
|
for(j = 0; j < newLength; j++)
|
|
|
|
{
|
|
|
|
if($scope.courses[(3*i) + j] != null)
|
|
|
|
{
|
|
|
|
$scope.holdArrays[i][j] = $scope.courses[(3*i) + j];
|
|
|
|
}
|
|
|
|
}
|
2015-06-26 13:49:46 +00:00
|
|
|
}
|
2015-06-27 11:20:21 +00:00
|
|
|
console.log($scope.holdArrays);
|
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;
|
|
|
|
console.log("Lecturer Mode!");
|
2015-06-26 13:49:46 +00:00
|
|
|
}
|
2015-06-27 09:45:44 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
$scope.isStudent = true;
|
|
|
|
console.log("Student Mode!");
|
|
|
|
}
|
|
|
|
|
|
|
|
displayCourses(); // Will display the courses that the user related to // TODO!!
|
2015-06-26 13:49:46 +00:00
|
|
|
|
2015-06-23 16:40:30 +00:00
|
|
|
|
|
|
|
|
|
|
|
}]);
|