Merge branch 'master' of https://github.com/sagidayan/SE-Hub into UI

This commit is contained in:
Matan Bar Yosef 2015-08-02 15:39:52 +03:00
commit ec3dc29024
5 changed files with 158 additions and 52 deletions

View file

@ -143,7 +143,79 @@ def create_task(token):
status=200, status=200,
mimetype="application/json") mimetype="application/json")
@task_routes.route('/api/tasks/submitTask/<string:token>/<string:taskId>/<string:ownerId>', methods=['POST'])
@auto.doc()
def submitTask(token, taskId, ownerId):
"""
<span class="card-title">This call will create a new Task in the DB</span>
<br>
<b>Route Parameters</b><br>
- seToken: 'seToken'
<br>
<br>
<b>Payload</b><br>
- JSON Object, Example: <br>
{<br>
"title":"task1",<br>
"courseId":1234567890,<br>
"description":"pls fddfsdfdsk",<br>
"dueDate":{"year":2010,<br>
"month":2,<br>
"day":4<br>
},
"isPersonal":true,<br>
"components":[<br>
{<br>
"type" : "should be type1",<br>
"label" : "should be label1",<br>
"isMandatory" : true,<br>
"order" : 1<br>
},<br>
{<br>
"type" : "should be type2",<br>
"label" : "should be label2",<br>
"isMandatory" : true,<br>
"order" : 2<br>
},<br>
{<br>
"type" : "should be type3",<br>
"label" : "should be label3",<br>
"isMandatory" : false,<br>
"order" : 3<br>
}<br>
]<br>
}
<br>
<br>
<b>Response</b>
<br>
201 - Created
<br>
400 - Bad Request
<br>
403 - Invalid token or not a lecturer
"""
if not request.data:
return bad_request("no payload")
payload = json.loads(request.data)
user = get_user_by_token(token)
task = Task.get_by_id(int(taskId))
#create components
for c in payload['components']:
try:
component = TaskComponent(taskId=task.key().id(), userId=(int(ownerId)), type=c['type'], label=c['label'], isMandatory=c['isMandatory'], order=c['order'])
except Exception as e:
print e
return bad_request("Bad component")
db.put(component)
db.save
return Response(response=task.to_JSON(),
status=200,
mimetype="application/json")
#---------------------------------------------------------- #----------------------------------------------------------
# PUT # PUT
#---------------------------------------------------------- #----------------------------------------------------------
@ -267,7 +339,7 @@ def getAllFutureCampusTasks(token, courseId):
for t in query.run(): for t in query.run():
taskDic =dict(json.loads(t.to_JSON())) taskDic =dict(json.loads(t.to_JSON()))
#add a key 'forSortDate' for sorting dates #add a key 'forSortDate' for sorting dates
taskTime = datetime.datetime(taskDic['dueDate']['year'], taskDic['dueDate']['month'], taskDic['dueDate']['day']) taskTime = datetime.date(taskDic['dueDate']['year'], taskDic['dueDate']['month'], taskDic['dueDate']['day'])
if taskTime >= datetime.date.today(): if taskTime >= datetime.date.today():
taskDic['forSortDate'] = taskTime taskDic['forSortDate'] = taskTime
arr.append(taskDic) arr.append(taskDic)
@ -558,15 +630,16 @@ def getAllUserTasks(token):
@task_routes.route('/api/tasks/getUserTaskById/<string:token>/<string:taskId>', methods=["GET"]) @task_routes.route('/api/tasks/getTaskById/<string:token>/<string:taskId>/<string:ownerId>', methods=["GET"])
@auto.doc() @auto.doc()
def getUserTaskById(token, taskId): def getTaskById(token, taskId, ownerId):
""" """
<span class="card-title">>This Call will return an array of all components for a given task</span> <span class="card-title">>This Call will return an array of all components for a given task</span>
<br> <br>
<b>Route Parameters</b><br> <b>Route Parameters</b><br>
- SeToken: token<br> - SeToken: token<br>
- taskId: 1234567890 - taskId: 1234567890
- ownerId: 123456789
<br> <br>
<br> <br>
<b>Payload</b><br> <b>Payload</b><br>
@ -606,33 +679,45 @@ def getUserTaskById(token, taskId):
if task is None: if task is None:
return bad_request("Bad Task id") return bad_request("Bad Task id")
task = json.loads(task.to_JSON())
task['components'] = []
task['grade'] = {}
taskCompQuery = TaskComponent.all() taskCompQuery = TaskComponent.all()
taskCompQuery.filter("taskId = ", task.key().id()) taskCompQuery.filter("taskId = ", taskId)
if task.isPersonal: taskCompQuery.filter("userId = ", ownerId)
taskCompQuery.filter("userId = ", user.key().id()) # if task.isPersonal:
else: # taskCompQuery.filter("userId = ", user.key().id())
taskCompQuery.filter("userId = ", user.key().id())#TODO: fix to project # else:
# taskCompQuery.filter("userId = ", user.key().id())#TODO: fix to project
#check if never created a personalized task and if so, create it #check if never created a personalized task and if so, create it
if taskCompQuery.count() == 0: if taskCompQuery.count() == 0:
taskCompQuery = TaskComponent.all().filter("taskId = ", task.key().id()).filter("userId = ", -1) print "here"
taskCompQuery = TaskComponent.all().filter("taskId =", int(taskId)).filter("userId =", -1)
print "query count is: ", taskCompQuery.count()
for tc in taskCompQuery.run(): for tc in taskCompQuery.run():
tcNew = TaskComponent(taskId=tc.taskId, userId=user.key().id(), type=tc.type, label=tc.label, isMandatory=tc.isMandatory, order=tc.order) task['components'].append(dict(json.loads(tc.to_JSON())))
db.put(tcNew)
grade = TaskGrade(grade=0, taskId=task.key().id(), userId=user.key().id()) # for tc in taskCompQuery.run():
db.put(grade) # tcNew = TaskComponent(taskId=tc.taskId, userId=user.key().id(), type=tc.type, label=tc.label, isMandatory=tc.isMandatory, order=tc.order)
# db.put(tcNew)
# grade = TaskGrade(grade=0, taskId=task.key().id(), userId=user.key().id())
# db.put(grade)
grade = TaskGrade.all().filter("taskId = ", taskId).filter("userId = ", ownerId)
gradeFound = False
for g in grade.run():
task['grade'] = g
gradeFound = True
if not gradeFound:
task['grade'] = {'taskId': taskId, 'userId': ownerId, 'grade': None}
return Response(response=json.dumps(task),
status=200,
mimetype="application/json")
db.save
return no_content()

View file

@ -48,11 +48,11 @@ app.config(['$routeProvider', '$locationProvider',
templateUrl: 'templates/views/newTask.html', templateUrl: 'templates/views/newTask.html',
controller: 'newTasksController' controller: 'newTasksController'
}) })
.when('/tasks/overview/:taskId/:submitterId', { .when('/tasks/overview/:taskId/:submitterId/:gId', {
templateUrl: 'templates/views/task.html', templateUrl: 'templates/views/task.html',
controller: 'taskController' controller: 'taskController'
}) })
.when('/tasks/fill/:taskId', { .when('/tasks/fill/:taskId/:gId', {
templateUrl: 'templates/views/task.html', templateUrl: 'templates/views/task.html',
controller: 'taskController' controller: 'taskController'
}) })

View file

@ -51,7 +51,7 @@ angular.module('SeHub').controller('newTasksController', ['$scope', 'apiService'
console.error(err); console.error(err);
}) })
} else { } else {
alert('Fill All Shit!'); alert('Please Fill All Task info & At least one component');
} }
} }
@ -64,6 +64,8 @@ angular.module('SeHub').controller('newTasksController', ['$scope', 'apiService'
return false; return false;
if (!$scope.task.date) if (!$scope.task.date)
return false; return false;
if ($scope.task.components.length < 1)
return false;
return true; return true;
} }

View file

@ -6,12 +6,22 @@ angular.module('SeHub')
var taskId = $routeParams.taskId; var taskId = $routeParams.taskId;
var submitterId = $routeParams.submitterId; var submitterId = $routeParams.submitterId;
var token = $cookies['com.sehub.www'];
var groupId = $routeParams.gId;
apiService.getTaskById(token, taskId, groupId).success(function(data){
$scope.task = data;
$scope.dateInit($scope.task.dueDate);
}).error(function(err){
console.error('Error: ', err);
})
if (submitterId) { //In This Case we Only Want to show The Content of the Submitter if (submitterId) { //In This Case we Only Want to show The Content of the Submitter
$scope.readOnly = true; $scope.readOnly = true;
} else { //In This Case We Need An Empty Task To Be Able To Fill It } else { //In This Case We Need An Empty Task To Be Able To Fill It
$scope.readOnly = false; $scope.readOnly = false;
apiService.getTaskById(token, taskId, groupId);
} }
$scope.dateInit = function(date) { $scope.dateInit = function(date) {
@ -81,35 +91,35 @@ angular.module('SeHub')
= Mock Data = = Mock Data =
=================================*/ =================================*/
$scope.task = { // $scope.task = {
"title": "task1", // "title": "task1",
"courseId": 1234567890, // "courseId": 1234567890,
"description": "one line\nsecondline\nthirdline", // "description": "one line\nsecondline\nthirdline",
"dueDate": { // "dueDate": {
"year": 2010, // "year": 2010,
"month": 2, // "month": 2,
"day": 4 // "day": 4
}, // },
"isPersonal": true, // "isPersonal": true,
"components": [{ // "components": [{
"type": "radiobuttons", // "type": "radiobuttons",
"label": "pick One|this|orthis|MaybeThis", // "label": "pick One|this|orthis|MaybeThis",
"isMandatory": true, // "isMandatory": true,
"order": 1 // "order": 1
}, { // }, {
"type": "checkbox", // "type": "checkbox",
"label": "tick Me", // "label": "tick Me",
"isMandatory": true, // "isMandatory": true,
"order": 2 // "order": 2
}, { // }, {
"type": "textarea", // "type": "textarea",
"label": "fill shit", // "label": "fill shit",
"isMandatory": false, // "isMandatory": false,
"order": 3 // "order": 3
}] // }]
}; // };
$scope.dateInit($scope.task.dueDate);
$scope.dueTime = function() { $scope.dueTime = function() {
if (!$scope.task.date || $scope.task.date === '') if (!$scope.task.date || $scope.task.date === '')

View file

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