diff --git a/models/Task.py b/models/Task.py index 5449fa2..6153fe9 100644 --- a/models/Task.py +++ b/models/Task.py @@ -7,7 +7,7 @@ from google.appengine.ext import db class Task(db.Model): title = db.StringProperty(required=True) courseId = db.IntegerProperty(required=True) - description = db.StringProperty(required=True,default=" ") + description = db.StringProperty(required=True,default=" ", multiline=True) dueDate = db.DateProperty(required=True) isPersonal = db.BooleanProperty(required=True, default=True) diff --git a/templates/js/controllers/newTasksController.js b/templates/js/controllers/newTasksController.js index be7922d..2de2c85 100644 --- a/templates/js/controllers/newTasksController.js +++ b/templates/js/controllers/newTasksController.js @@ -1,8 +1,72 @@ -angular.module('SeHub').controller('newTasksController', ['$scope', - function($scope) { +angular.module('SeHub').controller('newTasksController', ['$scope', 'apiService', '$cookies', '$location' , + function($scope, apiService, $cookies, $location) { $scope.newComp = {}; $scope.newComp.isMandatory = false; + var user = $scope.$parent.user; + var token = $cookies['com.sehub.www']; + $scope.submitting = false; + $scope.course = {} + $scope.loading = true; + apiService.getCoursesByUserID(token, user.id.toString()).success(function(data) { + $scope.courses = []; + for (var i = 0; i < data.length; i++) { + if (data[i].master_id == user.id) + $scope.courses.push(data[i]); + } + $scope.loading = false; + }).error(function(err) { + console.error('Error', err); + $scope.courses = []; + $scope.loading = false; + }); + + var compOrder = 0; + + + $scope.courseSelected = function() { + for (var i = 0; i < $scope.courses.length; i++) { + if ($scope.course.title === $scope.courses[i].courseName) { + $scope.course.id = $scope.courses[i].id; + $scope.task.courseId = $scope.course.id; + } + } + }; + + $scope.submit = function() { + if (validForm()) { + $scope.submitting = true; + var payload = $scope.task; + payload.dueDate = new Date(payload.date); + payload.dueDate = { + year: payload.dueDate.getFullYear(), + month: payload.dueDate.getMonth() + 1, + day: payload.dueDate.getDate() + + } + + apiService.createTask(token, payload).success(function(data){ + $location.path('/tasks'); + }).error(function(err){ + console.error(err); + }) + } else { + alert('Fill All Shit!'); + } + } + + function validForm() { + if (!$scope.course.title) + return false; + if (!$scope.task.title || $scope.task.title.trim() == '') + return false; + if (!$scope.task.description || $scope.task.description.trim() == '') + return false; + if (!$scope.task.date) + return false; + + return true; + } $scope.componentTypes = [{ @@ -28,6 +92,8 @@ angular.module('SeHub').controller('newTasksController', ['$scope', var comp = {}; var type = $scope.newComp.type; comp.type = type; + comp.order = compOrder; + compOrder ++; comp.isMandatory = $scope.newComp.isMandatory; comp.label = ""; var i = 0 @@ -36,7 +102,7 @@ angular.module('SeHub').controller('newTasksController', ['$scope', comp.label += $scope.newComp.label[i] + "|"; i++; } else - comp.label = $scope.newComp.label[i]; + comp.label = $scope.newComp.label[i]; console.log(comp); $scope.task.components.push(comp); @@ -46,6 +112,7 @@ angular.module('SeHub').controller('newTasksController', ['$scope', $scope.newComp.isMandatory = false; $scope.compDetails = []; $scope.isRadioButton = false; + } $scope.ComponentType = function(type) { @@ -86,28 +153,31 @@ angular.module('SeHub').controller('newTasksController', ['$scope', $scope.dueTimeFromNow = moment(d).fromNow(); } - $scope.initLinkComp = function(component){ + $scope.initLinkComp = function(component) { var arr = component.label.split("|"); for (var i = 0; i < arr.length - 1; i++) { - if(i == 0) + if (i == 0) component.title = arr[i]; else component.href = arr[i]; }; } - $scope.initRadioButtonsComp = function(component){ + $scope.initRadioButtonsComp = function(component) { var arr = component.label.split("|"); component.values = []; for (var i = 0; i < arr.length - 1; i++) { - if(i == 0) + if (i == 0) component.title = arr[i]; else - component.values.push({text: arr[i], id: i}); + component.values.push({ + text: arr[i], + id: i + }); }; } - $scope.RB = function(comp){ + $scope.RB = function(comp) { console.info(comp); } diff --git a/templates/js/services/apiService.js b/templates/js/services/apiService.js index ee40112..c20c90f 100644 --- a/templates/js/services/apiService.js +++ b/templates/js/services/apiService.js @@ -188,6 +188,15 @@ service.factory('apiService', ['$http', function($http) { url: url }; return $http(req); + }, + createTask: function(token, payload){ + var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/tasks/create/" + token; + req = { + method: 'POST', + data: payload, + url: url + }; + return $http(req); } }; }]); \ No newline at end of file diff --git a/templates/views/newTask.html b/templates/views/newTask.html index 0a7a855..4cb89bb 100644 --- a/templates/views/newTask.html +++ b/templates/views/newTask.html @@ -1,4 +1,8 @@ -
{{ dueTimeFromNow }}
-{{task.task.description}}
+{{task.description}}
{{(task.isPersonal) ? "Personal" : "Project"}} Task