diff --git a/SE_API/API.py b/SE_API/API.py index 1f79300..340b5f8 100644 --- a/SE_API/API.py +++ b/SE_API/API.py @@ -185,10 +185,11 @@ def oauth(oauth_token): tempName = ";" - if user_data["email"] == "": - for email in userEmails: - if email["primary"] and email["verified"]: - tempEmail = email["email"] + if 'email' in user_data: + if user_data["email"] == "": + for email in userEmails: + if email["primary"] and email["verified"]: + tempEmail = email["email"] else: tempEmail = user_data["email"] diff --git a/models/User.py b/models/User.py index b413008..b2b2755 100644 --- a/models/User.py +++ b/models/User.py @@ -3,6 +3,7 @@ import json __author__ = 'Aran' from google.appengine.ext import db + class User(db.Model): username = db.StringProperty(required=True) name = db.StringProperty(required=False) @@ -26,6 +27,36 @@ class User(db.Model): 'campuses_id_list': self.campuses_id_list, 'courses_id_list': self.courses_id_list, 'projects_id_list': self.projects_id_list, - 'id' : self.key().id() + 'id' : self.key().id(), + 'stats': get_stats(self) } return json.dumps(data) + +def get_stats(user): + from models.Project import Project + from models.Message import Message + labels = ['Commits', 'Open Issues Assigned', 'Messages', 'Unfinished Tasks'] + data = [0, 0, 0, 0] + for pid in user.projects_id_list: + project = Project.get_by_id(int(pid)) + info = json.loads(project.info) + stats = info["stats"]['micro'] + p_data = stats['data'] + p_series = stats['series'] + try: + user_index = p_series.index(user.username) + #adding commits + data[0] = data[0] + p_data[user_index][0] + #adding open issues + data[1] = data[1] + p_data[user_index][1] + except Exception: + pass + messages = Message.all().filter('master_id =', user.key().id()) + for m in messages.run(): + data[2] = data[2] + 1 + + #need to do tasks + #### + + data = [data] + return {'data': data, 'labels': labels} \ No newline at end of file diff --git a/templates/js/app.js b/templates/js/app.js index 4940008..cb5558a 100644 --- a/templates/js/app.js +++ b/templates/js/app.js @@ -48,6 +48,14 @@ app.config(['$routeProvider', '$locationProvider', templateUrl: 'templates/views/newTask.html', controller: 'newTasksController' }) + .when('/tasks/overview/:taskId/:submitterId', { + templateUrl: 'templates/views/task.html', + controller: 'taskController' + }) + .when('/tasks/fill/:taskId', { + templateUrl: 'templates/views/task.html', + controller: 'taskController' + }) .when('/class/:classId/:className', { templateUrl: 'templates/views/class.html', controller: 'classController' @@ -71,3 +79,9 @@ app.config(['$routeProvider', '$locationProvider', } ]); +app.config(function($mdThemingProvider) { + $mdThemingProvider.theme('default') + .primaryPalette('teal') + .accentPalette('blue-grey'); + +}); \ No newline at end of file diff --git a/templates/js/controllers/mainController.js b/templates/js/controllers/mainController.js index 9fd22a2..b5e5632 100644 --- a/templates/js/controllers/mainController.js +++ b/templates/js/controllers/mainController.js @@ -10,9 +10,11 @@ angular.module('SeHub') $scope.loadingData = true; $scope.isInRegisterMode = false; - apiService.getUserByToken(token).success(function(data) { - if (data.message == 'No User Found') { + apiService.getUserByToken(token).success(function(data, status) { + if (status == 204) { console.error("No User Found!"); + $cookieStore.remove('com.sehub.www'); + window.location = 'http://se-hub.appstpot.com/'; } $scope.loadingData = false; $scope.user = data; @@ -60,6 +62,10 @@ angular.module('SeHub') $location.path('/home') } + }).error(function(err){ + console.error(err); + $cookieStore.remove('com.sehub.www'); + window.location = DEBUG ? 'http://localhost:8080' : 'http://se-hub.appstpot.com/'; }); diff --git a/templates/js/controllers/profileController.js b/templates/js/controllers/profileController.js index d07c0b8..670f604 100644 --- a/templates/js/controllers/profileController.js +++ b/templates/js/controllers/profileController.js @@ -8,6 +8,7 @@ angular.module('SeHub') $scope.loadingData = true; $scope.isInRegisterMode = false; $scope.userExists = false; + $scope.isUser = false; $scope.title = "Profile"; @@ -36,6 +37,13 @@ angular.module('SeHub') console.error("++++++++++++++++++++"); }); + $scope.labels = data.stats.labels; + //$scope.series = ['Project A', 'Project B']; + + $scope.data = data.stats.data; + + $scope.isUser = $scope.$parent.user.id.toString() /*The Actual User*/ === $routeParams.id /*The Profile User*/ ; + }); @@ -62,15 +70,7 @@ angular.module('SeHub') } } - $scope.labels = ['Commits', 'Issues Assigned', 'Messages', 'Open Tasks']; - //$scope.series = ['Project A', 'Project B']; - $scope.data = [ - [54, 3, 15, 3] //, - //[28, 48, 40, 3] - ]; - - $scope.isUser = $scope.$parent.user.id.toString() /*The Actual User*/ === $routeParams.id /*The Profile User*/ ; } ]); \ No newline at end of file diff --git a/templates/js/controllers/taskController.js b/templates/js/controllers/taskController.js new file mode 100644 index 0000000..4133f05 --- /dev/null +++ b/templates/js/controllers/taskController.js @@ -0,0 +1,126 @@ +angular.module('SeHub') + .controller('taskController', ['$scope', '$rootScope', 'dataService', 'apiService', + '$cookies', '$location', '$routeParams', '$mdDialog', + + function($scope, $rootScope, dataService, apiService, $cookies, $location, $routeParams, $mdDialog) { + + var taskId = $routeParams.taskId; + var submitterId = $routeParams.submitterId; + + + if (submitterId) { //In This Case we Only Want to show The Content of the Submitter + $scope.readOnly = true; + } else { //In This Case We Need An Empty Task To Be Able To Fill It + $scope.readOnly = false; + } + + $scope.dateInit = function(date) { + d = moment(new Date(date.year, date.month - 1, date.day)); + $scope.task.date = d.format("d MMMM YYYY"); + } + + + $scope.dueTime = function() { + if (!$scope.task.date || $scope.task.date === '') + $scope.dueTimeFromNow = ""; + var d = new Date($scope.task.date); + $scope.dueTimeFromNow = moment(d).fromNow(); + } + + $scope.initLinkComp = function(component) { + var arr = component.label.split("|"); + for (var i = 0; i < arr.length - 1; i++) { + if (i == 0) + component.title = arr[i]; + else + component.href = arr[i]; + }; + } + + $scope.initRadioButtonsComp = function(component) { + var arr = component.label.split("|"); + component.values = []; + for (var i = 0; i < arr.length - 1; i++) { + if (i == 0) + component.title = arr[i]; + else + component.values.push({ + text: arr[i], + id: i + }); + }; + } + + function validateComponents() { + for (var i = 0; i < $scope.task.components.length; i++) { + if ($scope.task.components[i].isMandatory && (!$scope.task.components[i].value || $scope.task.components[i].value == '')) + return false; + } + return true; + } + + $scope.submitTask = function(event) { //Dialog will pop-up if not all mandatory fields are filled + if (validateComponents()) { + alert('All Shit Are Filled'); + return; + } + $mdDialog.show( + $mdDialog.alert() + .title('Hey There...') + .content('You Must Fill All Mandatory Fields In Order To Submit The Task') + .ariaLabel('Not All Mandatory Are Filled') + .ok('Got it!') + .targetEvent(event) + ); + + } + + + + /*================================= + = Mock Data = + =================================*/ + + $scope.task = { + "title": "task1", + "courseId": 1234567890, + "description": "one line\nsecondline\nthirdline", + "dueDate": { + "year": 2010, + "month": 2, + "day": 4 + }, + "isPersonal": true, + "components": [{ + "type": "radiobuttons", + "label": "pick One|this|orthis|MaybeThis", + "isMandatory": true, + "order": 1 + }, { + "type": "checkbox", + "label": "tick Me", + "isMandatory": true, + "order": 2 + }, { + "type": "textarea", + "label": "fill shit", + "isMandatory": false, + "order": 3 + }] + }; + + $scope.dateInit($scope.task.dueDate); + + $scope.dueTime = function() { + if (!$scope.task.date || $scope.task.date === '') + $scope.dueTimeFromNow = ""; + var d = new Date($scope.task.date); + $scope.descriptionInit = function(desc) { + desc.replace('\n', '
'); + } + $scope.descriptionInit($scope.task.description); + $scope.dueTimeFromNow = moment(d).fromNow(); + } + + } + ]); //End Controller \ No newline at end of file diff --git a/templates/views/index.html b/templates/views/index.html index 0196f52..9c1d9bd 100644 --- a/templates/views/index.html +++ b/templates/views/index.html @@ -112,6 +112,7 @@ + diff --git a/templates/views/newTask.html b/templates/views/newTask.html index e9ae941..0a7a855 100644 --- a/templates/views/newTask.html +++ b/templates/views/newTask.html @@ -87,7 +87,7 @@

{{task.task.title}}

Due At: {{ task.date }}

{{ dueTimeFromNow }}

-

{{task.task.description}}

+

{{task.task.description}}

{{(task.isPersonal) ? "Personal" : "Project"}} Task

diff --git a/templates/views/profile.html b/templates/views/profile.html index a4b6769..78bb3e2 100644 --- a/templates/views/profile.html +++ b/templates/views/profile.html @@ -8,7 +8,7 @@

{{title}}

-
+
diff --git a/templates/views/task.html b/templates/views/task.html new file mode 100644 index 0000000..760a2fb --- /dev/null +++ b/templates/views/task.html @@ -0,0 +1,69 @@ +
+
+
+ +

{{task.title}}

+

Due At: {{ task.date }}

+

{{ dueTimeFromNow }}

+

{{task.description}}

+

{{(task.isPersonal) ? "Personal" : "Project"}} Task

+ + + +
+ +
+ + + +
+ +
+ + + + +
+ +
+ + + + +
+ +
+ + {{ component.label}} + +
+ +
+ + {{component.title}} + +
+ +
+ {{component.title}} + + {{option.text}} + +
+
+
+
+
+
+ Submit +
+
+
+
+ +
+ + +
+ + \ No newline at end of file