2015-06-27 12:10:03 +00:00
|
|
|
angular.module('SeHub')
|
2015-06-29 11:41:17 +00:00
|
|
|
.controller('myProjectsController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope)
|
2015-06-27 12:10:03 +00:00
|
|
|
{
|
|
|
|
$scope.isEditPressed = false;
|
2015-06-29 17:04:33 +00:00
|
|
|
$scope.loadingData = true;
|
2015-06-29 16:20:56 +00:00
|
|
|
$scope.myProjectsEmpty = true;
|
2015-06-29 11:41:17 +00:00
|
|
|
$scope.user = $scope.$parent.user;
|
2015-06-29 16:20:56 +00:00
|
|
|
var token = $cookies['com.sehub.www'];
|
|
|
|
console.log(token);
|
2015-06-27 12:10:03 +00:00
|
|
|
|
|
|
|
$scope.displayMyProjects = function()
|
|
|
|
{
|
|
|
|
apiService.getProjectsByUser(token).success(function(data)
|
|
|
|
{
|
2015-06-29 17:04:33 +00:00
|
|
|
$scope.loadingData = false;
|
2015-06-27 12:10:03 +00:00
|
|
|
$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");
|
2015-06-27 12:10:03 +00:00
|
|
|
}).error(function(err)
|
|
|
|
{
|
2015-06-29 16:20:56 +00:00
|
|
|
console.log("Error: " + err.message);
|
2015-06-27 12:10:03 +00:00
|
|
|
});
|
2015-06-29 16:20:56 +00:00
|
|
|
|
2015-06-27 12:10:03 +00:00
|
|
|
}
|
|
|
|
|
2015-06-29 16:20:56 +00:00
|
|
|
$scope.goToProject = function(projectId)
|
2015-06-27 12:10:03 +00:00
|
|
|
{
|
2015-06-29 16:20:56 +00:00
|
|
|
for (var i = 0; i < $scope.myProjects; i++)
|
|
|
|
{
|
|
|
|
if($scope.myProjects.id === projectId)
|
|
|
|
{
|
|
|
|
console.log("project ID: " + projectId)
|
|
|
|
$location.path('/project/' + projectId);
|
|
|
|
}
|
|
|
|
};
|
2015-06-27 12:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var init = function()
|
|
|
|
{
|
2015-06-29 11:41:17 +00:00
|
|
|
$scope.arrayHolder = [];
|
|
|
|
var tempArr = [];
|
|
|
|
var sizeOfSmallArrays = 3;
|
2015-06-29 17:04:33 +00:00
|
|
|
for (var i = 0 ; i < $scope.myProjects.length ; i++) {
|
2015-06-29 11:41:17 +00:00
|
|
|
if(i % sizeOfSmallArrays !== 0){
|
2015-06-29 17:04:33 +00:00
|
|
|
tempArr.push($scope.myProjects[i]);
|
2015-06-29 11:41:17 +00:00
|
|
|
}else{
|
|
|
|
if(i !== 0){
|
|
|
|
$scope.arrayHolder.push(tempArr);
|
|
|
|
tempArr = [];
|
2015-06-29 17:04:33 +00:00
|
|
|
tempArr.push($scope.myProjects[i]);
|
2015-06-29 11:41:17 +00:00
|
|
|
}else{
|
2015-06-29 17:04:33 +00:00
|
|
|
tempArr.push($scope.myProjects[i]);
|
2015-06-27 12:10:03 +00:00
|
|
|
}
|
2015-06-29 11:41:17 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
$scope.arrayHolder.push(tempArr);
|
2015-06-27 12:10:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$scope.editPressed = function()
|
|
|
|
{
|
|
|
|
$scope.isEditPressed = true;
|
|
|
|
console.log("EditPressed " + $scope.isEditPressed);
|
|
|
|
}
|
|
|
|
$scope.removeProject = function()
|
|
|
|
{
|
|
|
|
console.log("Project has been removed!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$scope.displayMyProjects(); // Will display all my projects
|
|
|
|
|
|
|
|
}]);
|