2015-06-24 18:35:55 +00:00
|
|
|
angular.module('SeHub')
|
2015-06-26 13:49:46 +00:00
|
|
|
.controller('campusesController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService, $rootScope)
|
|
|
|
{
|
|
|
|
$scope.threeSizedArray =[];
|
2015-06-27 09:45:44 +00:00
|
|
|
$scope.campusesEmpty = false;
|
2015-06-26 13:49:46 +00:00
|
|
|
var token = $cookies['com.sehub.www'];
|
2015-06-26 18:56:41 +00:00
|
|
|
|
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.campuses.length % 3) === 0)
|
2015-06-26 13:49:46 +00:00
|
|
|
{
|
2015-06-27 11:20:21 +00:00
|
|
|
newLength = ($scope.campuses.length / 3);
|
2015-06-26 13:49:46 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-06-27 11:20:21 +00:00
|
|
|
newLength = (Math.ceil($scope.campuses.length / 3)); // Rounds number up
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("length: " + newLength);
|
|
|
|
$scope.threeSizedArray.length = newLength;
|
|
|
|
|
|
|
|
for(j = 0; j < newLength; j++)
|
|
|
|
{
|
|
|
|
$scope.threeSizedArray[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.campuses[(3*i) + j] != null)
|
|
|
|
{
|
|
|
|
$scope.threeSizedArray[i][j] = $scope.campuses[(3*i) + j];
|
|
|
|
}
|
|
|
|
}
|
2015-06-26 13:49:46 +00:00
|
|
|
}
|
2015-06-26 18:56:41 +00:00
|
|
|
console.log($scope.threeSizedArray); // TODO REMOVE
|
2015-06-26 13:49:46 +00:00
|
|
|
}
|
|
|
|
|
2015-06-26 18:56:41 +00:00
|
|
|
$scope.goToCampus = function(campusId) // Will pass you to courses by specific campus
|
|
|
|
{
|
|
|
|
$location.path('/myClasses/' + campusId.toString());
|
|
|
|
}
|
2015-06-26 13:49:46 +00:00
|
|
|
|
2015-06-27 11:20:21 +00:00
|
|
|
$scope.displayCampuses = function()
|
|
|
|
{
|
|
|
|
apiService.getCampusesByUser(token).success(function(data) // Get all the campuses
|
|
|
|
{
|
|
|
|
$scope.campuses = data;
|
|
|
|
console.log("INSIDE " + $scope.campuses);
|
|
|
|
init(); // Executing the function to initialize campuses display
|
|
|
|
|
|
|
|
}).error(function()
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
});
|
|
|
|
if($scope.campuses != null)
|
|
|
|
{
|
|
|
|
$scope.campusesEmpty = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.displayCampuses(); // Displaying all campuses by user
|
|
|
|
|
2015-06-26 13:49:46 +00:00
|
|
|
|
2015-06-24 18:35:55 +00:00
|
|
|
|
2015-06-26 13:49:46 +00:00
|
|
|
}]);
|