Create Task works.
This commit is contained in:
parent
448a9e66f7
commit
5c4ca0eea1
4 changed files with 104 additions and 16 deletions
|
@ -7,7 +7,7 @@ from google.appengine.ext import db
|
||||||
class Task(db.Model):
|
class Task(db.Model):
|
||||||
title = db.StringProperty(required=True)
|
title = db.StringProperty(required=True)
|
||||||
courseId = db.IntegerProperty(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)
|
dueDate = db.DateProperty(required=True)
|
||||||
isPersonal = db.BooleanProperty(required=True, default=True)
|
isPersonal = db.BooleanProperty(required=True, default=True)
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,72 @@
|
||||||
angular.module('SeHub').controller('newTasksController', ['$scope',
|
angular.module('SeHub').controller('newTasksController', ['$scope', 'apiService', '$cookies', '$location' ,
|
||||||
function($scope) {
|
function($scope, apiService, $cookies, $location) {
|
||||||
|
|
||||||
$scope.newComp = {};
|
$scope.newComp = {};
|
||||||
$scope.newComp.isMandatory = false;
|
$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 = [{
|
$scope.componentTypes = [{
|
||||||
|
@ -28,6 +92,8 @@ angular.module('SeHub').controller('newTasksController', ['$scope',
|
||||||
var comp = {};
|
var comp = {};
|
||||||
var type = $scope.newComp.type;
|
var type = $scope.newComp.type;
|
||||||
comp.type = type;
|
comp.type = type;
|
||||||
|
comp.order = compOrder;
|
||||||
|
compOrder ++;
|
||||||
comp.isMandatory = $scope.newComp.isMandatory;
|
comp.isMandatory = $scope.newComp.isMandatory;
|
||||||
comp.label = "";
|
comp.label = "";
|
||||||
var i = 0
|
var i = 0
|
||||||
|
@ -36,7 +102,7 @@ angular.module('SeHub').controller('newTasksController', ['$scope',
|
||||||
comp.label += $scope.newComp.label[i] + "|";
|
comp.label += $scope.newComp.label[i] + "|";
|
||||||
i++;
|
i++;
|
||||||
} else
|
} else
|
||||||
comp.label = $scope.newComp.label[i];
|
comp.label = $scope.newComp.label[i];
|
||||||
|
|
||||||
console.log(comp);
|
console.log(comp);
|
||||||
$scope.task.components.push(comp);
|
$scope.task.components.push(comp);
|
||||||
|
@ -46,6 +112,7 @@ angular.module('SeHub').controller('newTasksController', ['$scope',
|
||||||
$scope.newComp.isMandatory = false;
|
$scope.newComp.isMandatory = false;
|
||||||
$scope.compDetails = [];
|
$scope.compDetails = [];
|
||||||
$scope.isRadioButton = false;
|
$scope.isRadioButton = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.ComponentType = function(type) {
|
$scope.ComponentType = function(type) {
|
||||||
|
@ -86,28 +153,31 @@ angular.module('SeHub').controller('newTasksController', ['$scope',
|
||||||
$scope.dueTimeFromNow = moment(d).fromNow();
|
$scope.dueTimeFromNow = moment(d).fromNow();
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.initLinkComp = function(component){
|
$scope.initLinkComp = function(component) {
|
||||||
var arr = component.label.split("|");
|
var arr = component.label.split("|");
|
||||||
for (var i = 0; i < arr.length - 1; i++) {
|
for (var i = 0; i < arr.length - 1; i++) {
|
||||||
if(i == 0)
|
if (i == 0)
|
||||||
component.title = arr[i];
|
component.title = arr[i];
|
||||||
else
|
else
|
||||||
component.href = arr[i];
|
component.href = arr[i];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope.initRadioButtonsComp = function(component){
|
$scope.initRadioButtonsComp = function(component) {
|
||||||
var arr = component.label.split("|");
|
var arr = component.label.split("|");
|
||||||
component.values = [];
|
component.values = [];
|
||||||
for (var i = 0; i < arr.length - 1; i++) {
|
for (var i = 0; i < arr.length - 1; i++) {
|
||||||
if(i == 0)
|
if (i == 0)
|
||||||
component.title = arr[i];
|
component.title = arr[i];
|
||||||
else
|
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);
|
console.info(comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,15 @@ service.factory('apiService', ['$http', function($http) {
|
||||||
url: url
|
url: url
|
||||||
};
|
};
|
||||||
return $http(req);
|
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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
|
@ -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 layout="row">
|
||||||
<div flex="40" layout-padding>
|
<div flex="40" layout-padding>
|
||||||
<md-card layout-padding>
|
<md-card layout-padding>
|
||||||
|
@ -6,16 +10,21 @@
|
||||||
<i class="fa fa-info-circle"></i> Task Info:
|
<i class="fa fa-info-circle"></i> Task Info:
|
||||||
</h2>
|
</h2>
|
||||||
<div layout="column">
|
<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>
|
<div>
|
||||||
<md-input-container>
|
<md-input-container>
|
||||||
<label>Title</label>
|
<label>Title</label>
|
||||||
<input ng-model="task.task.title" required>
|
<input ng-model="task.title" required>
|
||||||
</md-input-container>
|
</md-input-container>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<md-input-container>
|
<md-input-container>
|
||||||
<label>Description</label>
|
<label>Description</label>
|
||||||
<textarea ng-model="task.task.description" required></textarea>
|
<textarea ng-model="task.description" required></textarea>
|
||||||
</md-input-container>
|
</md-input-container>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -32,7 +41,7 @@
|
||||||
<div layout="row">
|
<div layout="row">
|
||||||
<div flex="60"></div>
|
<div flex="60"></div>
|
||||||
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -84,10 +93,10 @@
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<md-card layout-padding>
|
<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>
|
<h4>Due At: {{ task.date }}</h4>
|
||||||
<p>{{ dueTimeFromNow }}</p>
|
<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>
|
<p>{{(task.isPersonal) ? "Personal" : "Project"}} Task</p>
|
||||||
|
|
||||||
<md-divider ng-if="!$last"></md-divider>
|
<md-divider ng-if="!$last"></md-divider>
|
||||||
|
|
Loading…
Reference in a new issue