2015-06-23 16:40:30 +00:00
|
|
|
angular.module('SeHub')
|
2015-08-02 18:46:42 +00:00
|
|
|
.controller('tasksController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast',
|
|
|
|
'$mdDialog', 'apiService', '$rootScope',
|
|
|
|
function($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService, $rootScope) {
|
2015-08-02 19:34:05 +00:00
|
|
|
var token = $cookies['com.sehub.www'];
|
2015-06-23 16:40:30 +00:00
|
|
|
|
2015-08-02 19:18:17 +00:00
|
|
|
$scope.user = $scope.$parent.user;
|
|
|
|
apiService.getAllUserTasks(token).success(function(data) {
|
|
|
|
$scope.tasks = data;
|
|
|
|
}).error(function(err) {
|
2015-08-02 20:53:20 +00:00
|
|
|
console.error(err.message);
|
2015-08-02 19:18:17 +00:00
|
|
|
});
|
2015-06-23 16:40:30 +00:00
|
|
|
|
|
|
|
|
2015-08-02 20:53:20 +00:00
|
|
|
$scope.taskClicked = function(task, classId, isPersonal, masterId, ev) {
|
2015-08-02 19:34:05 +00:00
|
|
|
var ownerId = null;
|
2015-08-02 20:53:20 +00:00
|
|
|
if (masterId === $scope.user.id) {
|
2015-08-02 19:34:05 +00:00
|
|
|
///This Is The Lecturer
|
|
|
|
///Need to show the List
|
2015-08-02 20:53:20 +00:00
|
|
|
$mdDialog.show({
|
|
|
|
controller: DialogController,
|
2015-08-02 21:22:10 +00:00
|
|
|
templateUrl: 'templates/views/UserStateList.html?v=1122231',
|
2015-08-02 20:53:20 +00:00
|
|
|
parent: $scope,
|
|
|
|
targetEvent: ev,
|
|
|
|
locals: {
|
2015-08-02 23:18:32 +00:00
|
|
|
data: {
|
|
|
|
task: task,
|
|
|
|
token: token,
|
|
|
|
isPersonal: isPersonal
|
|
|
|
}
|
2015-08-02 20:53:20 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(function(answer) {
|
|
|
|
$scope.alert = 'You said the information was "' + answer + '".';
|
|
|
|
}, function() {
|
|
|
|
$scope.alert = 'You cancelled the dialog.';
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2015-08-02 19:34:05 +00:00
|
|
|
} else {
|
|
|
|
if (!isPersonal) {
|
|
|
|
apiService.getProjectsByCourse(token, task.courseId).success(function(data) {
|
|
|
|
for (var i = 0; i < data.length; i++) {
|
|
|
|
for (var j = 0; j < $scope.user.projects_id_list.length; j++)
|
|
|
|
if (data[i].id.toString() === $scope.user.projects_id_list[j])
|
|
|
|
ownerId = $scope.user.projects_id_list[j];
|
|
|
|
}
|
2015-08-02 20:53:20 +00:00
|
|
|
apiService.isTaskSubmitted(token, task.id, ownerId).success(function(data) {
|
2015-08-02 23:18:32 +00:00
|
|
|
if (data.submitted) {
|
|
|
|
if (ownerId)
|
|
|
|
$location.path('/tasks/overview/' + task.id + '/' + ownerId + '/' + ownerId);
|
|
|
|
else {
|
|
|
|
$mdDialog.show(
|
|
|
|
$mdDialog.alert()
|
|
|
|
.title('You Have No Project in this class')
|
|
|
|
.content('To Be Able To Fill A Project Task you need to be assigned to a project')
|
|
|
|
.ariaLabel('ddd')
|
|
|
|
.ok('Ok, ill join/create a project')
|
|
|
|
.targetEvent(event)
|
|
|
|
|
|
|
|
).then(function() {
|
|
|
|
$location.path('/campuses');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ownerId)
|
|
|
|
$location.path('/tasks/fill/' + task.id + '/' + ownerId);
|
|
|
|
else {
|
|
|
|
$mdDialog.show(
|
|
|
|
$mdDialog.alert()
|
|
|
|
.title('You Have No Project in this class')
|
|
|
|
.content('To Be Able To Fill A Project Task you need to be assigned to a project')
|
|
|
|
.ariaLabel('ddd')
|
|
|
|
.ok('Ok, ill join/create a project')
|
|
|
|
.targetEvent(event)
|
|
|
|
|
|
|
|
).then(function() {
|
|
|
|
$location.path('/campuses');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}).error(function(err) {
|
|
|
|
console.error(err);
|
|
|
|
});
|
2015-08-02 19:34:05 +00:00
|
|
|
}).error(function(err) {
|
|
|
|
console.error('Error: ', err);
|
2015-08-02 23:18:32 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
apiService.isTaskSubmitted(token, task.id, $scope.user.id).success(function(data) {
|
|
|
|
if (data.submitted) {
|
|
|
|
$location.path('/tasks/overview/' + task.id + '/' + $scope.user.id + '/' + $scope.user.id);
|
|
|
|
} else {
|
|
|
|
$location.path('/tasks/fill/' + task.id + '/' + $scope.user.id);
|
|
|
|
}
|
|
|
|
}).error(function(err) {
|
|
|
|
console.error(err);
|
2015-08-02 19:34:05 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-02 23:18:32 +00:00
|
|
|
$scope.createNewTask = function() {
|
2015-08-02 22:01:34 +00:00
|
|
|
$location.path('/tasks/new');
|
|
|
|
}
|
|
|
|
|
2015-08-02 19:34:05 +00:00
|
|
|
|
2015-08-02 20:53:20 +00:00
|
|
|
function DialogController($scope, $mdDialog, data, apiService) {
|
|
|
|
$scope.task = data.task;
|
|
|
|
$scope.isPersonal = data.isPersonal;
|
|
|
|
var token = data.token;
|
|
|
|
$scope.loading = true;
|
|
|
|
|
2015-08-02 23:18:32 +00:00
|
|
|
apiService.getUsersStateByTask(token, $scope.task.id).success(function(data) {
|
2015-08-02 20:53:20 +00:00
|
|
|
$scope.classList = data;
|
|
|
|
$scope.loading = false;
|
2015-08-02 23:18:32 +00:00
|
|
|
}).error(function(err) {
|
2015-08-02 20:53:20 +00:00
|
|
|
console.error(err);
|
|
|
|
$scope.hide();
|
|
|
|
})
|
|
|
|
|
2015-08-02 23:18:32 +00:00
|
|
|
$scope.goToTask = function(obj) {
|
2015-08-02 21:22:10 +00:00
|
|
|
$mdDialog.hide();
|
|
|
|
$location.path('/tasks/overview/' + $scope.task.id + '/' + obj.id + '/' + obj.id);
|
|
|
|
}
|
|
|
|
|
2015-08-02 20:53:20 +00:00
|
|
|
|
|
|
|
$scope.hide = function() {
|
|
|
|
$mdDialog.hide();
|
|
|
|
};
|
|
|
|
$scope.cancel = function() {
|
|
|
|
$mdDialog.cancel();
|
|
|
|
};
|
|
|
|
$scope.answer = function(answer) {
|
|
|
|
$mdDialog.hide(answer);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-08-02 18:46:42 +00:00
|
|
|
}
|
|
|
|
]);
|