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;
|
2015-08-02 22:01:25 +00:00
|
|
|
$scope.displayingMessages = true;
|
2015-08-02 14:51:08 +00:00
|
|
|
$scope.isMaster = false;
|
2015-08-01 14:51:13 +00:00
|
|
|
$scope.isMember = false;
|
2015-08-02 16:51:29 +00:00
|
|
|
$scope.project = [];
|
|
|
|
$scope.isInProject = false;
|
2015-08-02 19:06:35 +00:00
|
|
|
$scope.projectMessages = [];
|
2015-08-02 20:52:41 +00:00
|
|
|
$scope.msg = {};
|
2015-08-02 22:01:25 +00:00
|
|
|
$scope.isMaster = false;
|
2015-08-03 19:26:57 +00:00
|
|
|
$scope.isLecturer = $scope.user.isLecturer;
|
2015-08-02 16:51:29 +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
|
|
|
|
2015-08-02 22:01:25 +00:00
|
|
|
|
|
|
|
console.log($scope.user.id)
|
|
|
|
// console.log($scope.projectid)
|
2015-08-02 19:06:35 +00:00
|
|
|
|
2015-08-03 20:51:52 +00:00
|
|
|
$scope.getDate = function(msg){
|
|
|
|
return msg.date.day.toString() + "-" + msg.date.month.toString() +"-"+ msg.date.year.toString() + " " + msg.date.hour.toString() +":"+msg.date.minute.toString();
|
|
|
|
}
|
|
|
|
|
2015-08-02 19:06:35 +00:00
|
|
|
$scope.displayProjectMessages = function()
|
|
|
|
{
|
|
|
|
apiService.getAllUserMessages(token).success(function(data)
|
|
|
|
{
|
2015-08-02 22:01:25 +00:00
|
|
|
$scope.displayingMessages = false;
|
2015-08-02 22:40:14 +00:00
|
|
|
// for(var i = 0; i < data.length; i ++)
|
|
|
|
// if(!data.isPersonal)
|
|
|
|
$scope.projectMessages = data;
|
2015-08-02 19:06:35 +00:00
|
|
|
}).error(function(err)
|
|
|
|
{
|
2015-08-02 22:01:25 +00:00
|
|
|
console.log(err.message);
|
2015-08-02 19:06:35 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.goToProfile = function(memberId)
|
|
|
|
{
|
2015-08-02 22:01:25 +00:00
|
|
|
$location.path('/profile/' + memberId);
|
2015-08-02 19:06:35 +00:00
|
|
|
}
|
2015-08-02 14:51:08 +00:00
|
|
|
$scope.removeUserFromProject = function()
|
|
|
|
{
|
2015-08-02 22:01:25 +00:00
|
|
|
apiService.removeUserFromProject(token, $scope.user.id, projectId).success(function(data)
|
2015-08-02 14:51:08 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
|
|
|
console.log(err.message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.joinProject = function(ev)
|
2015-08-01 14:51:13 +00:00
|
|
|
{
|
|
|
|
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));
|
2015-08-01 14:51:13 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-06-30 12:56:53 +00:00
|
|
|
$scope.editProject = function(ev)
|
2015-06-29 19:31:32 +00:00
|
|
|
{
|
2015-08-02 14:51:08 +00:00
|
|
|
$scope.isEditPressed = !$scope.isEditPressed;
|
2015-06-29 19:31:32 +00:00
|
|
|
}
|
2015-06-30 12:56:53 +00:00
|
|
|
|
|
|
|
$scope.removeProject = function(ev)
|
2015-06-29 19:31:32 +00:00
|
|
|
{
|
2015-08-02 22:01:25 +00:00
|
|
|
if($scope.user.id === $scope.project.master_id)
|
|
|
|
$scope.isMaster = true;
|
|
|
|
|
2015-08-02 14:51:08 +00:00
|
|
|
var confirm = $mdDialog.confirm().title('Remove Project').content('Would you like to delete this project?').ariaLabel('removeProj')
|
|
|
|
.ok('Please do it!').cancel('No').targetEvent(ev);
|
|
|
|
$mdDialog.show(confirm).then(function()
|
|
|
|
{ // Yes - Remove the project
|
|
|
|
console.log("Removed");
|
2015-08-02 09:55:43 +00:00
|
|
|
|
2015-08-02 14:51:08 +00:00
|
|
|
apiService.removeProject(token, projectId).success(function(data)
|
|
|
|
{
|
|
|
|
$mdDialog.show($mdDialog.alert().title('Project Removal').content('Project removed successfully.')
|
|
|
|
.ariaLabel('project remove alert dialog').ok('Ok').targetEvent(ev));
|
2015-08-02 16:51:29 +00:00
|
|
|
$location.path('/myProjects');
|
2015-08-02 14:51:08 +00:00
|
|
|
}).error(function(err)
|
|
|
|
{
|
2015-08-02 22:01:25 +00:00
|
|
|
$mdDialog.show($mdDialog.alert().title('Project Removal').content('Project removal failed - reason ' + err.message)
|
2015-08-02 14:51:08 +00:00
|
|
|
.ariaLabel('project remove alert dialog').ok('Try Again').targetEvent(ev));
|
|
|
|
});
|
2015-08-02 09:55:43 +00:00
|
|
|
},
|
2015-08-02 14:51:08 +00:00
|
|
|
function()
|
|
|
|
{ // No - Dont remove
|
2015-08-02 09:55:43 +00:00
|
|
|
});
|
2015-06-30 12:56:53 +00:00
|
|
|
// $location.path('/class/' + data.id + '/' + data.courseName); // Will display all the projects in this course
|
|
|
|
};
|
|
|
|
|
2015-08-02 20:52:41 +00:00
|
|
|
$scope.addMessageClicked = function()
|
|
|
|
{
|
|
|
|
$scope.addMsg = !$scope.addMsg; // Reveal the "POST" Button
|
|
|
|
}
|
|
|
|
$scope.postMessageClicked = function() // Posting the message itself
|
|
|
|
{
|
|
|
|
if($scope.msg.msgToAdd != null)
|
|
|
|
{
|
|
|
|
// console.log(msg.msgToAdd);
|
|
|
|
jsonNewMsg = {
|
|
|
|
'groupId': parseInt(projectId), // TODO Should be ===> $scope.courseObj.id
|
|
|
|
'message': $scope.msg.msgToAdd,
|
|
|
|
'isProject': true
|
|
|
|
};
|
|
|
|
|
|
|
|
apiService.createMessage(token, jsonNewMsg).success(function(data)
|
|
|
|
{
|
|
|
|
$scope.projectMessages.push(data);
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
|
|
|
console.log(err.message);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$mdDialog.show($mdDialog.alert().title('Error Creating Message').content('Message content or Course is missing')
|
|
|
|
.ariaLabel('Send Message alert dialog').ok('Try Again!').targetEvent()); // Pop-up alert
|
|
|
|
}
|
|
|
|
$scope.msg.msgToAdd = null;
|
|
|
|
}
|
|
|
|
|
2015-06-30 23:35:23 +00:00
|
|
|
$scope.getProfileRoute = function(userName)
|
2015-06-30 16:47:22 +00:00
|
|
|
{
|
|
|
|
for(var i = 0; i < $scope.project.members.length; i++)
|
|
|
|
{
|
2015-06-30 23:35:23 +00:00
|
|
|
if(userName === $scope.project.members[i].name)
|
2015-06-30 16:47:22 +00:00
|
|
|
{
|
|
|
|
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;
|
2015-08-02 22:01:25 +00:00
|
|
|
if($scope.user.id === $scope.project.master_id)
|
|
|
|
$scope.isMaster = true;
|
2015-08-01 14:51:13 +00:00
|
|
|
for(var i = 0; i < data.members.length; i++)
|
|
|
|
{
|
|
|
|
if($scope.user.id === data.members[i].id)
|
|
|
|
{
|
|
|
|
$scope.isMember = true;
|
|
|
|
}
|
|
|
|
}
|
2015-08-02 16:51:29 +00:00
|
|
|
|
|
|
|
apiService.getProjectsByCourse(token, $scope.project.courseId).success(function(data)
|
|
|
|
{
|
|
|
|
if($scope.user.projects_id_list)
|
|
|
|
for(var i = 0; i < $scope.project.length; i++)
|
|
|
|
if($scope.user.projects_id_list[i].id === data[i].id.toString())
|
|
|
|
$scope.isInProject = true;
|
|
|
|
|
|
|
|
}).error(function(err)
|
|
|
|
{
|
|
|
|
console.log(err.message);
|
|
|
|
});
|
|
|
|
|
2015-06-30 12:56:53 +00:00
|
|
|
// 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)
|
|
|
|
{
|
2015-08-02 16:51:29 +00:00
|
|
|
console.log(err.message);
|
2015-06-29 19:31:32 +00:00
|
|
|
});
|
|
|
|
}
|
2015-08-02 19:06:35 +00:00
|
|
|
$scope.displayProjectMessages(); // Display all messages in project
|
2015-08-02 20:52:41 +00:00
|
|
|
$scope.getProjectInfo(); // Get all this project data
|
|
|
|
|
2015-06-29 16:23:14 +00:00
|
|
|
}]);
|