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

95 lines
2.6 KiB
JavaScript
Raw Normal View History

2015-06-29 16:23:14 +00:00
angular.module('SeHub')
.controller('projectController', ['$scope', '$routeParams', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope',
function ($scope, $routeParams, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope)
{
2015-06-29 19:31:32 +00:00
var token = $cookies['com.sehub.www'];
var projectId = $routeParams.projectId;
$scope.isEditPressed = false;
$scope.user = $scope.$parent.user;
$scope.loadingData = true;
$scope.isMasterOrLecturer = false;
$scope.isMember = false;
2015-06-29 16:23:14 +00:00
2015-06-29 19:31:32 +00:00
// $scope.thisProject = {};
// $scope.thisProject.courseName = $routeParams.className;
2015-06-29 16:23:14 +00:00
$scope.joinProject = function()
{
apiService.joinProject(token, projectId).success(function(data)
{
$scope.isMember = true;
$scope.project = data;
$mdDialog.show($mdDialog.alert().title('Join Project').content('Joined successfully.')
.ariaLabel('Join project alert dialog').ok('Aight').targetEvent(ev));
}).error(function(err)
{
2015-08-01 15:18:21 +00:00
$mdDialog.show($mdDialog.alert().title('Join Project').content(err.message)
.ariaLabel('Join project alert dialog').ok('Try Again').targetEvent(ev));
});
}
$scope.editProject = function(ev)
2015-06-29 19:31:32 +00:00
{
$scope.isEditPressed = true;
}
$scope.removeProject = function(ev)
2015-06-29 19:31:32 +00:00
{
$mdDialog.show($mdDialog.confirm().title('Remove Project').content('Are you sure you want to remove the project ?')
.ariaLabel('Removing project alert dialog').ok('Yes').cancel('No').targetEvent(ev));
/*
.than(function()
{
$scope.alert = 'You decided to get rid of your debt.';
},
function()
{
$scope.alert = 'You decided to keep your debt.';
});
*/
// $location.path('/class/' + data.id + '/' + data.courseName); // Will display all the projects in this course
};
$scope.getProfileRoute = function(userName)
{
for(var i = 0; i < $scope.project.members.length; i++)
{
if(userName === $scope.project.members[i].name)
{
return '#/profile/' + $scope.project.members[i].id;
}
else
return '#';
}
}
2015-06-29 19:31:32 +00:00
$scope.getProjectInfo = function()
{
apiService.getProjectsById(token, projectId).success(function(data)
{
$scope.project = data;
for(var i = 0; i < data.members.length; i++)
{
if($scope.user.id === data.members[i].id)
{
$scope.isMember = true;
}
}
// if($scope.user === $scope.project.info.master_id)
// {
// $scope.isMasterOrLecturer = true;
// }
// if($scope.project && $scope.project.length > 0) // TODO - TEST?
// {
$scope.loadingData = false;
// }
2015-06-29 19:31:32 +00:00
}).error(function(err)
{
console.log("Error: " + err.message);
});
}
$scope.getProjectInfo(); // Get all this project data
2015-06-29 16:23:14 +00:00
}]);