Still Tasks... Controller stuff

This commit is contained in:
Sagi Dayan 2015-08-02 22:34:05 +03:00
parent 87b19b2255
commit 233e1dbc69
2 changed files with 37 additions and 3 deletions

View file

@ -2,18 +2,44 @@ angular.module('SeHub')
.controller('tasksController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', .controller('tasksController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast',
'$mdDialog', 'apiService', '$rootScope', '$mdDialog', 'apiService', '$rootScope',
function($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService, $rootScope) { function($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService, $rootScope) {
$scope.lecturerTasks = []; var token = $cookies['com.sehub.www'];
$rootScope.seToken = $cookies['com.sehub.www'];
var token = $rootScope.seToken;
$scope.user = $scope.$parent.user; $scope.user = $scope.$parent.user;
apiService.getAllUserTasks(token).success(function(data) { apiService.getAllUserTasks(token).success(function(data) {
$scope.tasks = data; $scope.tasks = data;
console.log(data); console.log(data);
}).error(function(err) { }).error(function(err) {
console.log(err.message); console.log(err.message);
}); });
$scope.taskClicked = function(task, classId, isPersonal) {
var ownerId = null;
if (classId === $scope.user.id) {
///This Is The Lecturer
///Need to show the List
} 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];
}
apiService.isTaskSubmitted(token, task.id, ownerId).success(function(data){
if(data.submitted)
$location.path('/tasks/overview/'+task.id+'/'+ownerId+'/'+ownerId)
else
$location.path('/tasks/fill/'+task.id+'/'+ownerId)
})
}).error(function(err) {
console.error('Error: ', err);
})
}
}
}
} }
]); ]);

View file

@ -279,6 +279,14 @@ service.factory('apiService', ['$http', function($http) {
url: url url: url
}; };
return $http(req); return $http(req);
},
isTaskSubmitted: function(token, taskId, ownerId){
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/tasks/isTaskSubmitted/" + token + '/' + taskId + '/' + ownerId;
req = {
method: 'GET',
url: url
};
return $http(req);
} }
}; };
}]); }]);