se-hub/templates/js/controllers/myProjectsController.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

angular.module('SeHub')
.controller('myProjectsController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope)
{
2015-06-29 17:04:33 +00:00
$scope.loadingData = true;
2015-06-29 16:20:56 +00:00
$scope.myProjectsEmpty = true;
$scope.user = $scope.$parent.user;
2015-06-29 16:20:56 +00:00
var token = $cookies['com.sehub.www'];
console.log(token);
$scope.displayMyProjects = function()
{
apiService.getProjectsByUser(token).success(function(data)
{
2015-06-29 17:04:33 +00:00
$scope.loadingData = false;
$scope.myProjects = data;
2015-06-29 16:20:56 +00:00
if($scope.myProjects != null && $scope.myProjects.length > 0)
{
$scope.myProjectsEmpty = false;
}
2015-06-29 17:04:33 +00:00
init(); // Executing the function to initialize my projects display
console.log(data);
console.log("Success");
}).error(function(err)
{
2015-06-29 16:20:56 +00:00
console.log("Error: " + err.message);
});
}
2015-06-29 16:20:56 +00:00
$scope.goToProject = function(projectId)
{
2015-06-29 17:28:20 +00:00
$location.path('/project/' + projectId);
}
var init = function()
{
$scope.arrayHolder = [];
var tempArr = [];
var sizeOfSmallArrays = 3;
2015-06-29 17:04:33 +00:00
for (var i = 0 ; i < $scope.myProjects.length ; i++) {
if(i % sizeOfSmallArrays !== 0){
2015-06-29 17:04:33 +00:00
tempArr.push($scope.myProjects[i]);
}else{
if(i !== 0){
$scope.arrayHolder.push(tempArr);
tempArr = [];
2015-06-29 17:04:33 +00:00
tempArr.push($scope.myProjects[i]);
}else{
2015-06-29 17:04:33 +00:00
tempArr.push($scope.myProjects[i]);
}
}
};
$scope.arrayHolder.push(tempArr);
}
$scope.displayMyProjects(); // Will display all my projects
}]);