- Create course api -fixed

This commit is contained in:
Matan Bar Yosef 2015-06-24 14:01:08 +03:00
parent 38ae45aa95
commit ba5939c437
3 changed files with 56 additions and 22 deletions

View file

@ -5,8 +5,11 @@ angular.module('SeHub')
$scope.isCourse = false; $scope.isCourse = false;
$scope.isNewCourse = false; $scope.isNewCourse = false;
$scope.newClassName = false; $scope.newClassName = false;
$scope.user.createNewCourse = ''; // $scope.course.courseName = '';
$scope.course = {};
var token = $cookies['com.sehub.www'];
$scope.user.finalDate = ''; $scope.user.finalDate = '';
$scope.user.startDate = '';
$scope.showMyClass = false; $scope.showMyClass = false;
if($scope.user.isLecturer) if($scope.user.isLecturer)
@ -42,13 +45,38 @@ angular.module('SeHub')
$scope.submitNewClassClicked = function() $scope.submitNewClassClicked = function()
{ {
if($scope.user.createNewCourse != '' && $scope.user.finalDate != '') if($scope.course.courseName != '' && $scope.course.endDate != '' && $scope.course.startDate != '')
{ {
console.log("finalDate " + $scope.user.finalDate); var jsonNewCourse =
console.log($scope.user.createNewCourse); {
'courseName': $scope.course.courseName,
'campusName': $scope.course.campusName,
'startDate': {
'year' : $scope.course.startDate.getFullYear(),
'day' : $scope.course.startDate.getDate(),
'month': ($scope.course.startDate.getMonth() + 1)
},
'endDate': {
'year' : $scope.course.endDate.getFullYear(),
'day' : $scope.course.endDate.getDate(),
'month': ($scope.course.endDate.getMonth() + 1)
}
};
console.log("Json here:");
console.log(jsonNewCourse);
apiService.createCourse(token, jsonNewCourse).success(function(data)
{
console.log("createCourse API done");
}).error(function(err)
{
console.log(err);
});
$mdDialog.show($mdDialog.alert().title('Course Created').content('You have created course successfully.') $mdDialog.show($mdDialog.alert().title('Course Created').content('You have created course successfully.')
.ariaLabel('Email verification alert dialog').ok('Lets Start!').targetEvent()); .ariaLabel('Email verification alert dialog').ok('Lets Start!').targetEvent());
// $window.location.href = 'templates/views/newCourse.html'; // TODO TODO TODO // $window.location.href = 'templates/views/newCourse.html'; // TODO TODO TODO
} }
else else
{ {

View file

@ -71,7 +71,7 @@ service.factory('apiService', ['$http', function($http) {
return $http(req); return $http(req);
}, },
createMessage: function(token, payLoad){ createMessage: function(token, payLoad){
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/getCourseMessages/" + token; var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/createMessage/" + token;
req = { req = {
method : "POST", method : "POST",
url : url, url : url,
@ -80,12 +80,22 @@ service.factory('apiService', ['$http', function($http) {
}; };
return $http(req); return $http(req);
}, },
getCourseMessages: function(token, courseName){ getMessagesByCourseName: function(token, courseName){
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/getCourseMessages/" + token + '/' + courseName; var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/getMessagesByCourseName/" + token + '/' + courseName;
req = { req = {
method : "GET", method : "GET",
url : url url : url
};
return $http(req);
},
createCourse: function(token, payLoad){
var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/create/" + token;
req = {
method : "POST",
url : url,
data: payLoad
}; };
return $http(req); return $http(req);
} }

View file

@ -27,28 +27,24 @@
<form name="createNewCourseForm"> <form name="createNewCourseForm">
<div layout layout-sm="column"> <div layout layout-sm="column">
<md-input-container style="width:80%"> <md-input-container style="width:80%">
<label>Class Name</label> <label flex = "50">Class Name</label>
<input ng-model="user.createNewCourse" min-length="1" required> <input ng-model="course.courseName" min-length="1" required>
</md-input-container> </md-input-container>
<md-input-container flex> <md-input-container flex = "20">
<label>Course Start Date</label>
<input type="date" ng-model="course.startDate" required>
</md-input-container>
<md-input-container flex = "20">
<label>Course Finish Date</label> <label>Course Finish Date</label>
<input type="date" ng-model="user.finalDate" required> <input type="date" ng-model="course.endDate" required>
</md-input-container> </md-input-container>
</div> </div>
<div layout layout-sm="column"> <div layout layout-sm="column">
<md-input-container flex> <md-input-container flex = "50">
<label>First name</label> <label>Campus name</label>
<input ng-model="user.firstName"> <input ng-model="course.campusName">
</md-input-container>
<md-input-container flex>
<label>Last Name</label>
<input ng-model="theMax">
</md-input-container> </md-input-container>
</div> </div>
<md-input-container flex>
<label>General Info (optional)</label>
<textarea ng-model="user.courseInfo" columns="1" md-maxlength="150"></textarea>
</md-input-container>
</form> </form>
</md-content> </md-content>
<div layout-padding layout-margin> <div layout-padding layout-margin>