mirror of
https://github.com/arnaucube/openworktime.git
synced 2026-02-07 03:36:44 +01:00
work traking and stopping functionallity semi implemented
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
@@ -178,12 +179,14 @@ exports.logout = function(req, res) {
|
||||
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'
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -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 -------------------------------------
|
||||
|
||||
|
||||
@@ -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){
|
||||
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
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user