diff --git a/SE_API/MessageRoutes.py b/SE_API/MessageRoutes.py index 272fb5c..a360da7 100644 --- a/SE_API/MessageRoutes.py +++ b/SE_API/MessageRoutes.py @@ -187,6 +187,98 @@ def getMessagesByGroup(token, groupId): status=200, mimetype="application/json") +@message_routes.route('/api/messages/getAllUserMessages/', methods=["GET"]) +@auto.doc() +def getAllUserMessages(token): + """ + >This Call will return an array of all messages (sorted by date),
+
+
+ Route Parameters
+ - SeToken: token
+ - groupId: 1234567890 +
+
+ Payload
+ - NONE +
+
+ Response +
+ 200 - JSON Example:
+ [
+ {
+ 'groupId' : 1234567890,
+ 'message' : 'hello all',
+ 'date' : {
+ 'year': 2015,
+ 'month': 5,
+ 'day': 5,
+ 'hour': 5,
+ 'minute': 5
+ },
+ 'id' : 1234567890,
+ 'master_id' : 1234567890,
+ 'isProject' : false,
+ 'user': {
+ 'username': 'DarkLord',
+ 'name': 'Darth Vader',
+ 'email': 'darkLord@death.planet,
+ 'isLecturer': 'True',
+ 'seToken': 'xxxxxx-xxxxx-xxxxx-xxxxxx',
+ 'avatar_url': 'http://location.git.com/somthing'
+ 'isFirstLogin': False,
+ 'campuses_id_list': [43243532532,5325325325,532532342],
+ 'courses_id_list': [53523,43432423,432432432432]
+ 'id': 1234567890
+ },
+ 'group': {The Group Object Project OR Campus (according to isProject)}

+ + }
+ ]
+
+
+ """ + user = get_user_by_token(token) + if user is None: + return bad_request("No such User") + + arr = [] + + query = Message.all() + query.filter('isProject =', False) + for m in query.run(): + if str(m.groupId) in user.courses_id_list: + msgDic = dict(json.loads(m.to_JSON())) + #add a key 'forSortDate' for sorting dates + msgTime = datetime.datetime(msgDic['date']['year'], msgDic['date']['month'], msgDic['date']['day'], msgDic['date']['hour'], msgDic['date']['minute']) + msgDic['forSortDate'] = msgTime + arr.append(msgDic) + + query = Message.all() + query.filter('isProject =', True) + for m in query.run(): + if str(m.groupId) in user.projects_id_list: + msgDic = dict(json.loads(m.to_JSON())) + #add a key 'forSortDate' for sorting dates + msgTime = datetime.datetime(msgDic['date']['year'], msgDic['date']['month'], msgDic['date']['day'], msgDic['date']['hour'], msgDic['date']['minute']) + msgDic['forSortDate'] = msgTime + arr.append(msgDic) + + arr = sorted(arr, key=itemgetter('forSortDate'), reverse=True) + for i in arr: + del i['forSortDate'] + print arr + + if len(arr) != 0: + return Response(response=json.dumps(arr), + status=200, + mimetype="application/json") + else: + return Response(response=[], + status=200, + mimetype="application/json") + #---------------------------------------------------------- # DELETE diff --git a/templates/js/controllers/classController.js b/templates/js/controllers/classController.js index 5bf3304..00c985f 100644 --- a/templates/js/controllers/classController.js +++ b/templates/js/controllers/classController.js @@ -1,77 +1,98 @@ angular.module('SeHub') -.controller('classController', ['$scope', '$routeParams', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function ($scope, $routeParams, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService ,$rootScope) -{ - var token = $cookies['com.sehub.www']; - var classId = $routeParams.classId; - $scope.project = {}; - $scope.project.courseName = $routeParams.className; - $scope.projectsEmpty = true; - $scope.isCreateProjectClicked = false; - $scope.submitNewCourseClicked = false; - $scope.loadingData = true; - $scope.isInCourse = false; - + .controller('classController', ['$scope', '$routeParams', '$cookies', '$cookieStore', '$window', '$location', '$mdToast', '$mdDialog', 'apiService', '$rootScope', function($scope, $routeParams, $cookies, $cookieStore, $window, $location, $mdToast, $mdDialog, apiService, $rootScope) { + var token = $cookies['com.sehub.www']; + var classId = $routeParams.classId; + $scope.project = {}; + $scope.project.courseName = $routeParams.className; + $scope.projectsEmpty = true; + $scope.isCreateProjectClicked = false; + $scope.submitNewCourseClicked = false; + $scope.loadingData = true; + $scope.isInCourse = false; + var startDate = null; + var endDate = null; + var nowDate = new Date(); + var one_day=1000*60*60*24; + var dayDeltaOfCourse; + var courseElapseTime; + $scope.isCourseOver = false; + $scope.createSctionStatus = "fa fa-angle-down"; - $scope.displayProjects = function() - { - apiService.getProjectsByCourse(token, classId).success(function(data) // Get all the campuses - { - $scope.loadingData = false; - $scope.projects = data; - if($scope.projects != null && $scope.projects.length > 0) - { - $scope.projectsEmpty = false; - } - init(); // Executing the function to initialize projects display - console.log("project created! not rly!! " + classId); - }).error(function(err) - { - console.log("Error: " + err); - }); - } - $scope.joinCourse = function() - { - apiService.joinCourse(token, classId).success(function(data) - { - $scope.isInCourse = true; - $mdDialog.show($mdDialog.alert().title('Joined Course').content('You have successfully joined course.') - .ariaLabel('Join course alert dialog').ok('Lets Start!').targetEvent()) - .then(function() { - $location.path('/class/' + classId); // TODO TODO TODO - }); // Pop-up alert - }).error(function(err) - { - $mdDialog.show($mdDialog.alert().title('Error Joining Course').content(err.message + '.') - .ariaLabel('Join course alert dialog').ok('Try Again!').targetEvent()); // Pop-up alert - // .then(function() { - // // $location.path('/newCourse'); // TODO TODO TODO - // }); - }); - } + $scope.displayProjects = function() { + apiService.getCourseById(token, classId) + .success(function(data) { + startDate = new Date(data.startDate.year, data.startDate.month-1, data.startDate.day); + endDate = new Date(data.endDate.year, data.endDate.month-1, data.endDate.day) + $scope.course = data; + $scope.course.startDate = startDate.toDateString(); + $scope.course.endDate = endDate.toDateString(); + dayDeltaOfCourse = (endDate.getTime() - startDate.getTime()) / one_day; + courseElapseTime = (nowDate.getTime() - startDate.getTime()) / one_day; + if(courseElapseTime < 0) + courseElapseTime = 0; + else if(courseElapseTime > dayDeltaOfCourse){ + $scope.isCourseOver = true; + courseElapseTime = dayDeltaOfCourse; + } + $scope.courseTimePresentege = ((courseElapseTime/dayDeltaOfCourse) * 100).toString(); + console.log($scope.courseTimePresentege); - $scope.createProjectClicked = function() - { - // console.log("project created! is it ?!???! " + classId); - $scope.isCreateProjectClicked = !$scope.isCreateProjectClicked; - } + apiService.getProjectsByCourse(token, classId).success(function(data) // Get all the campuses + { + $scope.loadingData = false; + $scope.projects = data; + if ($scope.projects != null && $scope.projects.length > 0) { + $scope.projectsEmpty = false; + } + init(); // Executing the function to initialize projects display + }).error(function(err) { + console.error("Error: " + err); + }); + }) + .error(function(err) { + console.error("Error: " + err); + }) + } + $scope.joinCourse = function() { + apiService.joinCourse(token, classId).success(function(data) { + $scope.isInCourse = true; + $mdDialog.show($mdDialog.alert().title('Joined Course').content('You have successfully joined course.') + .ariaLabel('Join course alert dialog').ok('Lets Start!').targetEvent()) + .then(function() { + $location.path('/class/' + classId); // TODO TODO TODO + }); // Pop-up alert + }).error(function(err) { + $mdDialog.show($mdDialog.alert().title('Error Joining Course').content(err.message + '.') + .ariaLabel('Join course alert dialog').ok('Try Again!').targetEvent()); // Pop-up alert + // .then(function() { + // // $location.path('/newCourse'); // TODO TODO TODO + // }); + }); + } - $scope.submitNewProject = function() - { - loadingData = true; - // debugger; - var intClassId = parseInt(classId); - // console.log($scope); - var jsonNewProj = - { - 'projectName': $scope.project.projectName, - 'courseId': intClassId, - 'gitRepository': $scope.project.repoOwner + '/' + $scope.project.gitRepoName - }; - console.log(jsonNewProj); + $scope.createProjectClicked = function() { + // console.log("project created! is it ?!???! " + classId); + $scope.isCreateProjectClicked = !$scope.isCreateProjectClicked; + if($scope.isCreateProjectClicked) + $scope.createSctionStatus = "fa fa-angle-up"; + else + $scope.createSctionStatus = "fa fa-angle-down"; + } - if($scope.project.logoUrl) - jsonNewProj.logo_url = $scope.project.logoUrl; + $scope.submitNewProject = function() { + loadingData = true; + // debugger; + var intClassId = parseInt(classId); + // console.log($scope); + var jsonNewProj = { + 'projectName': $scope.project.projectName, + 'courseId': intClassId, + 'gitRepository': $scope.project.repoOwner + '/' + $scope.project.gitRepoName + }; + console.log(jsonNewProj); + if ($scope.project.logoUrl) + jsonNewProj.logo_url = $scope.project.logoUrl; apiService.createProject(token, jsonNewProj).success(function(data) { @@ -124,4 +145,5 @@ angular.module('SeHub') $scope.displayProjects(); // Displaying all projects related to user + }]); \ No newline at end of file diff --git a/templates/js/controllers/myClassesController.js b/templates/js/controllers/myClassesController.js index 2591b3c..9fabe73 100644 --- a/templates/js/controllers/myClassesController.js +++ b/templates/js/controllers/myClassesController.js @@ -74,8 +74,6 @@ angular.module('SeHub') } }; - console.log("Json here: " + $scope.chosenCampus); - console.log(jsonNewCourse); apiService.createCourse(token, jsonNewCourse).success(function(data) { @@ -88,7 +86,8 @@ angular.module('SeHub') }); // Pop-up alert }).error(function(err) { - console.log(err); + $mdDialog.show($mdDialog.alert().title('Error Creating Class').content(err) + .ariaLabel('Create Class alert dialog').ok('Try Again!').targetEvent()); // Pop-up alert }); } else diff --git a/templates/js/services/apiService.js b/templates/js/services/apiService.js index 4537dfc..ee40112 100644 --- a/templates/js/services/apiService.js +++ b/templates/js/services/apiService.js @@ -181,8 +181,8 @@ service.factory('apiService', ['$http', function($http) { }; return $http(req); }, - getCampuseById: function(token, id){ - var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/getCoursesById/" + id; + getCourseById: function(token, id){ + var url = (DEBUG ? "http://localhost:8080" : "http://se-hub.appspot.com") + "/api/courses/getCoursesById/" + token + "/" + id; req = { method: "GET", url: url diff --git a/templates/views/class.html b/templates/views/class.html index 677d057..ef3fe11 100644 --- a/templates/views/class.html +++ b/templates/views/class.html @@ -1,43 +1,38 @@
-

Class {{project.courseName}}

-
- -
-
- You Are Not Related To Any Project. -
-
- -
-
-
- - {{project.projectName}} -
- -
- -
-
- - {{project.projectName}} - - - - -
-
-
-
+
+ +
+

+ Class {{project.courseName}} + - This Course Is Over +

+
+ +
+
+ {{course.startDate}}   +
+
+ +
+
+  {{course.endDate}} +
+
-
- Join Class + +
+
+ Join Class +
+
+ + Create Project + +
- - - Create Project - +
@@ -84,6 +79,47 @@
+
+
+ +
+
+ You Are Not Related To Any Project. +
+
+ +
+
+
+ +
+
+
+ + {{project.projectName}} +
+
+
+
+ +
+ +
+
+ + {{project.projectName}} + + + + +
+
+
+
+
+
+
diff --git a/templates/views/home.html b/templates/views/home.html index ebc3f1f..44820cf 100644 --- a/templates/views/home.html +++ b/templates/views/home.html @@ -62,7 +62,7 @@ {{user.name}}
- {{c.courseName}} + {{courseObj.courseName}}
@@ -142,8 +142,8 @@
-
- +
+