Browse Source

work traking and stopping functionallity semi implemented

master
nau 8 years ago
parent
commit
a0f6d4abba
5 changed files with 96 additions and 29 deletions
  1. +42
    -0
      controllers/projectController.js
  2. +13
    -10
      controllers/userController.js
  3. +10
    -1
      models/projectModel.js
  4. +5
    -0
      server.js
  5. +26
    -18
      webapp/controllers.js

+ 42
- 0
controllers/projectController.js

@ -88,7 +88,49 @@ exports.addUserToProject = function(req, res) {
});
});
};
exports.userStartWorking = function(req, res) {
console.log("userStartWorking");
projectModel.findById(req.params.id, function(err, project) {
var workstrike={
username: req.body.username,
start: new Date(),
end: "",
};
project.workStrikes.push(workstrike);
console.log(project);
project.save(function(err) {
if(err) return res.send(500, err.message);
projectModel.find(function(err, projects) {
if(err) res.send(500, err.message);
res.status(200).jsonp(projects);
});
});
});
};
exports.userStopWorking = function(req, res) {
console.log("userStopWorking");
projectModel.findById(req.params.id, function(err, project) {
for(var i=0; i<project.workStrikes.length; i++)
{
if((project.workStrikes[i].username==req.body.username)&&(project.workStrikes[i].end==null))
{
project.workStrikes[i].end= new Date();
}
}
console.log(project);
project.save(function(err) {
if(err) return res.send(500, err.message);
projectModel.find(function(err, projects) {
if(err) res.send(500, err.message);
res.status(200).jsonp(projects);
});
});
});
};
//PUT
exports.updateProject = function(req, res) {
ActivityModel.findById(req.params.id, function(err, tvshow) {

+ 13
- 10
controllers/userController.js

@ -143,6 +143,7 @@ exports.login = function(req, res) {
//console.log(user);
//update connected=true
user.connected= true;
user.save(function(err) {
if(err) return res.send(500, err.message);
@ -174,16 +175,18 @@ exports.logout = function(req, res) {
} else if (user) {
//update connected=true
user.connected= false;
user.save(function(err) {
if(err) return res.send(500, err.message);
});
// return the information including token as JSON
res.json({
success: true,
message: 'logged out'
});
//update connected=true
user.connected= false;
user.save(function(err) {
if(err) return res.send(500, err.message);
// return the information including token as JSON
res.json({
success: true,
message: 'logged out'
});
});
}
});

+ 10
- 1
models/projectModel.js

@ -7,7 +7,16 @@ var projectSchema = new Schema({
description: { type: String },
icon: { type: String },
users: [{ type: String }],
chart: { type: String },
chart: [{
labels: [{ type: String }],
series: [{ type: String }],
data: [{type: String }]
}],
workStrikes: [{
username: { type: String },
start: { type: Date },
end: { type: Date }
}],
dateCreation: { type: Date },
github: { type: String },
refnum: { type: String }

+ 5
- 0
server.js

@ -127,6 +127,11 @@ apiRoutes.route('/projects/:id')
apiRoutes.route('/projects/:id/adduser')
.put(projectCtrl.addUserToProject);
apiRoutes.route('/projects/:id/startworking')
.put(projectCtrl.userStartWorking);
apiRoutes.route('/projects/:id/stopworking')
.put(projectCtrl.userStopWorking);
app.use('/api', apiRoutes);
// end of API routes -------------------------------------

+ 26
- 18
webapp/controllers.js

@ -27,10 +27,10 @@ angular.module('workApp', ['chart.js'])
$http.get(urlapi + 'users')
.success(function(data, status, headers,config){
if(data.success==false){
/*localStorage.removeItem("owt_token");
localStorage.removeItem("owt_token");
localStorage.removeItem("owt_user");
$scope.currentInclude="login.html";
console.log("token ended");*/
console.log("token ended");
}else{
console.log(data);
$scope.users=data;
@ -48,8 +48,15 @@ angular.module('workApp', ['chart.js'])
//getting projects
$http.get(urlapi + 'projects')
.success(function(data, status, headers,config){
console.log(data);
$scope.projects=data;
if(data.success==false){
localStorage.removeItem("owt_token");
localStorage.removeItem("owt_user");
$scope.currentInclude="login.html";
console.log("token ended");
}else{
console.log(data);
$scope.projects=data;
}
})
.error(function(data, status, headers,config){
console.log("server not responding, data error");
@ -227,32 +234,33 @@ angular.module('workApp', ['chart.js'])
var interval;
$scope.currentStrike=0;
$scope.btnWork = function(){
$scope.editingProject=false;
//$scope.editingProject=false;
$scope.working=true;
$scope.currentStrike=0;
interval = $interval(function(){
$scope.currentStrike++;
$scope.currentproject.totaltime++;
}, 1000);
$http({
url: urlapi + 'users',
method: "POST",
url: urlapi + 'projects/' + $scope.currentproject._id + '/startworking',
method: "PUT",
data: $scope.user
}).then(function(response) {
$scope.currentInclude="login.html";
console.log(response);
$scope.projects=response.data;
},
function(response) {// failed
});
};
$scope.btnStop = function(){
$interval.cancel(interval);
if($scope.working==true)
{
$scope.working=false;
$scope.currentproject.chart.labels.push("work strike " + $scope.currentproject.chart.labels.length);
$scope.currentproject.chart.data.push($scope.currentStrike);
localStorage.setItem("w_l_projects", angular.toJson($scope.projects));
$http({
url: urlapi + 'projects/' + $scope.currentproject._id + '/stopworking',
method: "PUT",
data: $scope.user
}).then(function(response) {
console.log(response);
$scope.projects=response.data;
},
function(response) {// failed
});
}

Loading…
Cancel
Save