From fd5abae31fec6cf404077eb6041f44bd6435688f Mon Sep 17 00:00:00 2001 From: nau Date: Fri, 9 Sep 2016 21:58:51 +0200 Subject: [PATCH] user working parameter added --- controllers/projectController.js | 21 +++++++++++++++++ models/userModel.js | 3 ++- server.js | 2 +- webapp/controllers.js | 39 ++++++++++++++++++++++++++++---- webapp/dashboard.html | 4 ++-- 5 files changed, 60 insertions(+), 9 deletions(-) diff --git a/controllers/projectController.js b/controllers/projectController.js index c88f606..e3e1106 100644 --- a/controllers/projectController.js +++ b/controllers/projectController.js @@ -112,7 +112,19 @@ exports.userStartWorking = function(req, res) { res.status(200).jsonp(projects); }); }); + + userModel.findById(req.body._id, function(err, user) { + user.working=true; + + user.save(function(err) { + if(err) return res.send(500, err.message); + console.log("user working=true"); + }); + }); + }); + + }; exports.userStopWorking = function(req, res) { console.log("userStopWorking"); @@ -142,6 +154,15 @@ exports.userStopWorking = function(req, res) { res.status(200).jsonp(projects); }); }); + + userModel.findById(req.body._id, function(err, user) { + user.working=false; + + user.save(function(err) { + if(err) return res.send(500, err.message); + console.log("user working=false"); + }); + }); }); }; //PUT diff --git a/models/userModel.js b/models/userModel.js index 9eb2892..3de4c25 100644 --- a/models/userModel.js +++ b/models/userModel.js @@ -11,6 +11,7 @@ var userSchema = new Schema({ github: { type: String }, web: { type: String }, projects: { type: String }, - connected: { type: Boolean } + connected: { type: Boolean }, + working: { type: Boolean } }) module.exports = mongoose.model('userModel', userSchema); diff --git a/server.js b/server.js index da9b57c..3495d8c 100755 --- a/server.js +++ b/server.js @@ -136,6 +136,6 @@ app.use('/api', apiRoutes); // end of API routes ------------------------------------- // Start server -app.listen(config.port, function() { +app.listen(config.port, "localhost", function() { console.log("Node server running on http://localhost:3000"); }); diff --git a/webapp/controllers.js b/webapp/controllers.js index ccc9e6f..0f0b5b3 100644 --- a/webapp/controllers.js +++ b/webapp/controllers.js @@ -1,3 +1,4 @@ +var urlapi = "http://192.168.1.41:3000/api/"; var urlapi = "http://localhost:3000/api/"; angular.module('workApp', ['chart.js']) @@ -10,6 +11,22 @@ angular.module('workApp', ['chart.js']) $scope.projects={}; $scope.currentInclude='login.html'; var refreshTime=20000; + $scope.getLoggedUser = function(){ + //get logged user + $http.get(urlapi + 'users/byusername/' + $scope.user.username) + .success(function(data, status, headers,config){ + console.log(data); + $scope.user=data; + }) + .error(function(data, status, headers,config){ + console.log("server not responding, data error"); + toastr.error("server not responding"); + $scope.$broadcast('scroll.refreshComplete');//refresher stop + }) + .then(function(result){ + users = result.data; + }); + }; /* DASHBOARD initialization */ $scope.dashboardInit = function(){ if(localStorage.getItem('owt_token')){// adding token to the headers @@ -23,6 +40,7 @@ angular.module('workApp', ['chart.js']) $scope.currentInclude="login.html"; } + $scope.getLoggedUser(); //getting users $http.get(urlapi + 'users') .success(function(data, status, headers,config){ @@ -76,9 +94,17 @@ angular.module('workApp', ['chart.js']) $scope.user={}; + + $http.defaults.headers.post['Content-Type'] = 'application/json'; if(localStorage.getItem("owt_user")){ + if(localStorage.getItem('owt_token')){// adding token to the headers + $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('owt_token'); + $http.defaults.headers.post['Content-Type'] = 'application/json'; + $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('owt_token'); + } $scope.user=JSON.parse(localStorage.getItem("owt_user")); $scope.currentInclude="dashboard.html"; + $scope.getLoggedUser(); $scope.dashboardInit(); intervalGetData = $interval(function(){ $scope.dashboardInit(); @@ -153,7 +179,7 @@ angular.module('workApp', ['chart.js']) //localStorage.clear(); - $scope.working=false; + //$scope.working=false; $scope.currentproject={}; $scope.newproject={}; @@ -214,7 +240,8 @@ angular.module('workApp', ['chart.js']) }; $scope.currentprojectIndex; $scope.projectSelect = function(index){ - $scope.btnStop(); + //$scope.btnStop(); + console.log(index); $scope.currentprojectIndex=index; $scope.currentproject=$scope.projects[index]; }; @@ -239,7 +266,7 @@ angular.module('workApp', ['chart.js']) $scope.currentStrike=0; $scope.btnWork = function(){ //$scope.editingProject=false; - $scope.working=true; + $scope.user.working=true; $http({ url: urlapi + 'projects/' + $scope.currentproject._id + '/startworking', method: "PUT", @@ -247,14 +274,15 @@ angular.module('workApp', ['chart.js']) }).then(function(response) { console.log(response); $scope.projects=response.data; + $scope.getLoggedUser(); }, function(response) {// failed }); }; $scope.btnStop = function(){ - if($scope.working==true) + if($scope.user.working==true) { - $scope.working=false; + //$scope.user.working=false; $http({ url: urlapi + 'projects/' + $scope.currentproject._id + '/stopworking', method: "PUT", @@ -267,6 +295,7 @@ angular.module('workApp', ['chart.js']) response.data[i].chart=translateWorkStrikes2Chart(response.data[i].workStrikes); } $scope.projects=response.data; + $scope.getLoggedUser(); }, function(response) {// failed }); diff --git a/webapp/dashboard.html b/webapp/dashboard.html index cc3ac66..dbb3bff 100644 --- a/webapp/dashboard.html +++ b/webapp/dashboard.html @@ -129,8 +129,8 @@
- Work! - Stop! + Work! + Stop!
Join!