Create Task works.

This commit is contained in:
Sagi Dayan 2015-08-02 13:44:15 +03:00
parent 448a9e66f7
commit 5c4ca0eea1
4 changed files with 104 additions and 16 deletions

View file

@ -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)

View file

@ -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
@ -46,6 +112,7 @@ angular.module('SeHub').controller('newTasksController', ['$scope',
$scope.newComp.isMandatory = false;
$scope.compDetails = [];
$scope.isRadioButton = false;
}
$scope.ComponentType = function(type) {
@ -103,7 +170,10 @@ angular.module('SeHub').controller('newTasksController', ['$scope',
if (i == 0)
component.title = arr[i];
else
component.values.push({text: arr[i], id: i});
component.values.push({
text: arr[i],
id: i
});
};
}

View file

@ -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);
}
};
}]);

View file

@ -1,4 +1,8 @@
<div layout-padding>
<div ng-if='loading' layout-padding>
<md-progress-circular md-mode="indeterminate"></md-progress-circular>
</div>
<div layout-padding ng-if='!loading'>
<div layout="row">
<div flex="40" layout-padding>
<md-card layout-padding>
@ -6,16 +10,21 @@
<i class="fa fa-info-circle"></i> Task Info:
</h2>
<div layout="column">
<div>
<md-select placeholder="Pick A Course" ng-model="course.title" required ng-change='courseSelected()'>
<md-option ng-repeat="c in courses" value="{{c.courseName}}">{{c.courseName}}</md-option>
</md-select>
</div>
<div>
<md-input-container>
<label>Title</label>
<input ng-model="task.task.title" required>
<input ng-model="task.title" required>
</md-input-container>
</div>
<div>
<md-input-container>
<label>Description</label>
<textarea ng-model="task.task.description" required></textarea>
<textarea ng-model="task.description" required></textarea>
</md-input-container>
</div>
<div>
@ -32,7 +41,7 @@
<div layout="row">
<div flex="60"></div>
<div>
<md-button class="md-raised md-primary"><i class="fa fa-paper-plane"></i> Submit</md-button>
<md-button class="md-raised md-primary" ng-click='submit()' ng-disabled="submitting"><i class="fa fa-paper-plane"></i> Submit</md-button>
</div>
</div>
</div>
@ -84,10 +93,10 @@
</h2>
<md-card layout-padding>
<h3><i class="fa fa-clipboard"></i> {{task.task.title}}</h3>
<h3><i class="fa fa-clipboard"></i> {{task.title}}</h3>
<h4>Due At: {{ task.date }}</h4>
<p>{{ dueTimeFromNow }}</p>
<p style="white-space: pre-wrap;">{{task.task.description}}</p>
<p style="white-space: pre-wrap;">{{task.description}}</p>
<p>{{(task.isPersonal) ? "Personal" : "Project"}} Task</p>
<md-divider ng-if="!$last"></md-divider>