From 233e1dbc69fb52c8cdf33ece61f092d4d3caf350 Mon Sep 17 00:00:00 2001 From: Sagi Dayan Date: Sun, 2 Aug 2015 22:34:05 +0300 Subject: [PATCH] Still Tasks... Controller stuff --- templates/js/controllers/tasksController.js | 32 +++++++++++++++++++-- templates/js/services/apiService.js | 8 ++++++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/templates/js/controllers/tasksController.js b/templates/js/controllers/tasksController.js index ab5e4be..b176be4 100644 --- a/templates/js/controllers/tasksController.js +++ b/templates/js/controllers/tasksController.js @@ -2,18 +2,44 @@ angular.module('SeHub') .controller('tasksController', ['$scope', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function($scope, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService, $rootScope) { - $scope.lecturerTasks = []; - $rootScope.seToken = $cookies['com.sehub.www']; - var token = $rootScope.seToken; + var token = $cookies['com.sehub.www']; $scope.user = $scope.$parent.user; apiService.getAllUserTasks(token).success(function(data) { $scope.tasks = data; + console.log(data); }).error(function(err) { 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); + }) + } + } + } + + } ]); \ No newline at end of file diff --git a/templates/js/services/apiService.js b/templates/js/services/apiService.js index c82d25a..264cc5f 100644 --- a/templates/js/services/apiService.js +++ b/templates/js/services/apiService.js @@ -279,6 +279,14 @@ service.factory('apiService', ['$http', function($http) { url: url }; 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); } }; }]); \ No newline at end of file