2015-07-23 21:57:14 +00:00
|
|
|
angular.module('SeHub')
|
|
|
|
.controller('taskController', ['$scope', '$rootScope', 'dataService', 'apiService',
|
2015-07-25 15:25:45 +00:00
|
|
|
'$cookies', '$location', '$routeParams', '$mdDialog',
|
|
|
|
|
|
|
|
function($scope, $rootScope, dataService, apiService, $cookies, $location, $routeParams, $mdDialog) {
|
2015-07-23 21:57:14 +00:00
|
|
|
|
|
|
|
var taskId = $routeParams.taskId;
|
|
|
|
var submitterId = $routeParams.submitterId;
|
2015-08-02 11:55:39 +00:00
|
|
|
var token = $cookies['com.sehub.www'];
|
|
|
|
var groupId = $routeParams.gId;
|
2015-08-02 16:53:35 +00:00
|
|
|
var user = $scope.$parent.user;
|
2015-08-02 13:57:46 +00:00
|
|
|
$scope.loading = true;
|
2015-08-02 16:53:35 +00:00
|
|
|
$scope.isMaster = false;
|
2015-07-23 21:57:14 +00:00
|
|
|
|
2015-08-02 13:57:46 +00:00
|
|
|
apiService.getTaskById(token, taskId, groupId).success(function(data) {
|
2015-08-02 16:53:35 +00:00
|
|
|
if(!data.grade.grade)
|
|
|
|
data.grade.grade = 0;
|
2015-08-02 11:55:39 +00:00
|
|
|
$scope.task = data;
|
|
|
|
$scope.dateInit($scope.task.dueDate);
|
2015-08-02 16:53:35 +00:00
|
|
|
apiService.getCourseById(token, data.courseId).success(function(data) {
|
|
|
|
$scope.isMaster = (user.id === data.master_id);
|
|
|
|
});
|
|
|
|
if (!data.isPersonal) {
|
|
|
|
apiService.getProjectsById(token, groupId).sucsess(function(data) {
|
|
|
|
$scope.group = data;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
apiService.getUserById(token, groupId).success(function(data) {
|
|
|
|
$scope.group = data;
|
|
|
|
});
|
|
|
|
}
|
2015-08-02 13:57:46 +00:00
|
|
|
$scope.loading = false;
|
|
|
|
}).error(function(err) {
|
|
|
|
$location.path('/tasks');
|
2015-08-02 11:55:39 +00:00
|
|
|
})
|
2015-07-23 21:57:14 +00:00
|
|
|
|
|
|
|
if (submitterId) { //In This Case we Only Want to show The Content of the Submitter
|
|
|
|
$scope.readOnly = true;
|
2015-08-02 11:55:39 +00:00
|
|
|
|
2015-07-23 21:57:14 +00:00
|
|
|
} else { //In This Case We Need An Empty Task To Be Able To Fill It
|
|
|
|
$scope.readOnly = false;
|
|
|
|
}
|
|
|
|
|
2015-07-25 15:25:45 +00:00
|
|
|
$scope.dateInit = function(date) {
|
2015-07-23 21:57:14 +00:00
|
|
|
d = moment(new Date(date.year, date.month - 1, date.day));
|
|
|
|
$scope.task.date = d.format("d MMMM YYYY");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$scope.dueTime = function() {
|
|
|
|
if (!$scope.task.date || $scope.task.date === '')
|
|
|
|
$scope.dueTimeFromNow = "";
|
|
|
|
var d = new Date($scope.task.date);
|
|
|
|
$scope.dueTimeFromNow = moment(d).fromNow();
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.initLinkComp = function(component) {
|
|
|
|
var arr = component.label.split("|");
|
|
|
|
for (var i = 0; i < arr.length - 1; i++) {
|
|
|
|
if (i == 0)
|
|
|
|
component.title = arr[i];
|
|
|
|
else
|
|
|
|
component.href = arr[i];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.initRadioButtonsComp = function(component) {
|
|
|
|
var arr = component.label.split("|");
|
|
|
|
component.values = [];
|
|
|
|
for (var i = 0; i < arr.length - 1; i++) {
|
|
|
|
if (i == 0)
|
|
|
|
component.title = arr[i];
|
|
|
|
else
|
|
|
|
component.values.push({
|
|
|
|
text: arr[i],
|
|
|
|
id: i
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2015-07-25 15:25:45 +00:00
|
|
|
function validateComponents() {
|
|
|
|
for (var i = 0; i < $scope.task.components.length; i++) {
|
|
|
|
if ($scope.task.components[i].isMandatory && (!$scope.task.components[i].value || $scope.task.components[i].value == ''))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
$scope.submitTask = function(event) { //Dialog will pop-up if not all mandatory fields are filled
|
|
|
|
if (validateComponents()) {
|
2015-08-02 13:57:46 +00:00
|
|
|
apiService.submitTask(token, taskId, groupId, $scope.task.components).success(function(data) {
|
|
|
|
$mdDialog.show(
|
|
|
|
$mdDialog.alert()
|
|
|
|
.title('Submitted!')
|
|
|
|
.content('Your Task Was Successfully Submitted!')
|
|
|
|
.ariaLabel('ddd')
|
|
|
|
.ok('GoTo My Submitted Task')
|
2015-08-02 15:15:51 +00:00
|
|
|
.targetEvent(event)
|
|
|
|
|
2015-08-02 16:53:35 +00:00
|
|
|
).then(function() {
|
|
|
|
$location.path('/tasks/overview/' + taskId + '/' + groupId + '/' + groupId);
|
2015-08-02 15:15:51 +00:00
|
|
|
});
|
2015-08-02 16:53:35 +00:00
|
|
|
|
2015-08-02 13:57:46 +00:00
|
|
|
})
|
|
|
|
|
2015-08-02 16:53:35 +00:00
|
|
|
} else {
|
|
|
|
|
|
|
|
$mdDialog.show(
|
|
|
|
$mdDialog.alert()
|
|
|
|
.title('Hey There...')
|
|
|
|
.content('You Must Fill All Mandatory Fields In Order To Submit The Task')
|
|
|
|
.ariaLabel('Not All Mandatory Are Filled')
|
|
|
|
.ok('Got it!')
|
|
|
|
.targetEvent(event)
|
|
|
|
);
|
2015-07-25 15:25:45 +00:00
|
|
|
}
|
|
|
|
|
2015-08-02 16:53:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$scope.submitGrade = function(event){
|
2015-08-02 17:09:00 +00:00
|
|
|
apiService.submitGrade(token, taskId, groupId, $scope.task.grade.grade).success(function(data){
|
2015-08-02 16:53:35 +00:00
|
|
|
$mdDialog.show(
|
|
|
|
$mdDialog.alert()
|
|
|
|
.title('Thanks For Grading')
|
|
|
|
.content('The Grade was successfully posted. you can change the grade later if you want')
|
|
|
|
.ariaLabel('Not All Mandatory Are Filled')
|
|
|
|
.ok('Go Back To Tasks')
|
|
|
|
.targetEvent(event)
|
|
|
|
).then(function(){
|
|
|
|
$location.path('/tasks');
|
|
|
|
});
|
|
|
|
}).error(function(err){
|
|
|
|
$mdDialog.show(
|
|
|
|
$mdDialog.alert()
|
|
|
|
.title('Something Happened')
|
|
|
|
.content('something went wrong... Try Again Later')
|
|
|
|
.ariaLabel('Not All Mandatory Are Filled')
|
|
|
|
.ok('No Problem!')
|
|
|
|
.targetEvent(event)
|
|
|
|
);
|
|
|
|
})
|
2015-07-25 15:25:45 +00:00
|
|
|
}
|
|
|
|
|
2015-07-23 21:57:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
$scope.dueTime = function() {
|
2015-07-25 15:25:45 +00:00
|
|
|
if (!$scope.task.date || $scope.task.date === '')
|
|
|
|
$scope.dueTimeFromNow = "";
|
|
|
|
var d = new Date($scope.task.date);
|
|
|
|
$scope.descriptionInit = function(desc) {
|
|
|
|
desc.replace('\n', '<br>');
|
|
|
|
}
|
|
|
|
$scope.descriptionInit($scope.task.description);
|
|
|
|
$scope.dueTimeFromNow = moment(d).fromNow();
|
2015-07-23 21:57:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
]); //End Controller
|