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

74 lines
1.8 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)
{
$scope.isEditPressed = false;
2015-06-29 16:20:56 +00:00
$scope.loadingDate = true;
$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 16:20:56 +00:00
$scope.loadingDate = false;
$scope.myProjects = data;
2015-06-29 16:20:56 +00:00
if($scope.myProjects != null && $scope.myProjects.length > 0)
{
$scope.myProjectsEmpty = false;
}
}).error(function(err)
{
2015-06-29 16:20:56 +00:00
console.log("Error: " + err.message);
});
2015-06-29 16:20:56 +00:00
}
2015-06-29 16:20:56 +00:00
$scope.goToProject = function(projectId)
{
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);
}
};
}
var init = function()
{
$scope.arrayHolder = [];
var tempArr = [];
var sizeOfSmallArrays = 3;
for (var i = 0 ; i < $scope.projects.length ; i++) {
if(i % sizeOfSmallArrays !== 0){
tempArr.push($scope.projects[i]);
}else{
if(i !== 0){
$scope.arrayHolder.push(tempArr);
tempArr = [];
tempArr.push($scope.projects[i]);
}else{
tempArr.push($scope.projects[i]);
}
}
};
$scope.arrayHolder.push(tempArr);
}
$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
}]);