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
|
//PUT
|
||||||
exports.updateProject = function(req, res) {
|
exports.updateProject = function(req, res) {
|
||||||
ActivityModel.findById(req.params.id, function(err, tvshow) {
|
ActivityModel.findById(req.params.id, function(err, tvshow) {
|
||||||
|
|||||||
@@ -143,6 +143,7 @@ exports.login = function(req, res) {
|
|||||||
//console.log(user);
|
//console.log(user);
|
||||||
|
|
||||||
//update connected=true
|
//update connected=true
|
||||||
|
|
||||||
user.connected= true;
|
user.connected= true;
|
||||||
user.save(function(err) {
|
user.save(function(err) {
|
||||||
if(err) return res.send(500, err.message);
|
if(err) return res.send(500, err.message);
|
||||||
@@ -178,12 +179,14 @@ exports.logout = function(req, res) {
|
|||||||
user.connected= false;
|
user.connected= false;
|
||||||
user.save(function(err) {
|
user.save(function(err) {
|
||||||
if(err) return res.send(500, err.message);
|
if(err) return res.send(500, err.message);
|
||||||
});
|
|
||||||
// return the information including token as JSON
|
// return the information including token as JSON
|
||||||
res.json({
|
res.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: 'logged out'
|
message: 'logged out'
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,7 +7,16 @@ var projectSchema = new Schema({
|
|||||||
description: { type: String },
|
description: { type: String },
|
||||||
icon: { type: String },
|
icon: { type: String },
|
||||||
users: [{ 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 },
|
dateCreation: { type: Date },
|
||||||
github: { type: String },
|
github: { type: String },
|
||||||
refnum: { type: String }
|
refnum: { type: String }
|
||||||
|
|||||||
@@ -127,6 +127,11 @@ apiRoutes.route('/projects/:id')
|
|||||||
apiRoutes.route('/projects/:id/adduser')
|
apiRoutes.route('/projects/:id/adduser')
|
||||||
.put(projectCtrl.addUserToProject);
|
.put(projectCtrl.addUserToProject);
|
||||||
|
|
||||||
|
apiRoutes.route('/projects/:id/startworking')
|
||||||
|
.put(projectCtrl.userStartWorking);
|
||||||
|
apiRoutes.route('/projects/:id/stopworking')
|
||||||
|
.put(projectCtrl.userStopWorking);
|
||||||
|
|
||||||
app.use('/api', apiRoutes);
|
app.use('/api', apiRoutes);
|
||||||
// end of API routes -------------------------------------
|
// end of API routes -------------------------------------
|
||||||
|
|
||||||
|
|||||||
@@ -27,10 +27,10 @@ angular.module('workApp', ['chart.js'])
|
|||||||
$http.get(urlapi + 'users')
|
$http.get(urlapi + 'users')
|
||||||
.success(function(data, status, headers,config){
|
.success(function(data, status, headers,config){
|
||||||
if(data.success==false){
|
if(data.success==false){
|
||||||
/*localStorage.removeItem("owt_token");
|
localStorage.removeItem("owt_token");
|
||||||
localStorage.removeItem("owt_user");
|
localStorage.removeItem("owt_user");
|
||||||
$scope.currentInclude="login.html";
|
$scope.currentInclude="login.html";
|
||||||
console.log("token ended");*/
|
console.log("token ended");
|
||||||
}else{
|
}else{
|
||||||
console.log(data);
|
console.log(data);
|
||||||
$scope.users=data;
|
$scope.users=data;
|
||||||
@@ -48,8 +48,15 @@ angular.module('workApp', ['chart.js'])
|
|||||||
//getting projects
|
//getting projects
|
||||||
$http.get(urlapi + 'projects')
|
$http.get(urlapi + 'projects')
|
||||||
.success(function(data, status, headers,config){
|
.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);
|
console.log(data);
|
||||||
$scope.projects=data;
|
$scope.projects=data;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.error(function(data, status, headers,config){
|
.error(function(data, status, headers,config){
|
||||||
console.log("server not responding, data error");
|
console.log("server not responding, data error");
|
||||||
@@ -227,32 +234,33 @@ angular.module('workApp', ['chart.js'])
|
|||||||
var interval;
|
var interval;
|
||||||
$scope.currentStrike=0;
|
$scope.currentStrike=0;
|
||||||
$scope.btnWork = function(){
|
$scope.btnWork = function(){
|
||||||
$scope.editingProject=false;
|
//$scope.editingProject=false;
|
||||||
$scope.working=true;
|
$scope.working=true;
|
||||||
$scope.currentStrike=0;
|
|
||||||
interval = $interval(function(){
|
|
||||||
$scope.currentStrike++;
|
|
||||||
$scope.currentproject.totaltime++;
|
|
||||||
}, 1000);
|
|
||||||
$http({
|
$http({
|
||||||
url: urlapi + 'users',
|
url: urlapi + 'projects/' + $scope.currentproject._id + '/startworking',
|
||||||
method: "POST",
|
method: "PUT",
|
||||||
data: $scope.user
|
data: $scope.user
|
||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
$scope.currentInclude="login.html";
|
console.log(response);
|
||||||
|
$scope.projects=response.data;
|
||||||
},
|
},
|
||||||
function(response) {// failed
|
function(response) {// failed
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
$scope.btnStop = function(){
|
$scope.btnStop = function(){
|
||||||
$interval.cancel(interval);
|
|
||||||
if($scope.working==true)
|
if($scope.working==true)
|
||||||
{
|
{
|
||||||
$scope.working=false;
|
$scope.working=false;
|
||||||
$scope.currentproject.chart.labels.push("work strike " + $scope.currentproject.chart.labels.length);
|
$http({
|
||||||
$scope.currentproject.chart.data.push($scope.currentStrike);
|
url: urlapi + 'projects/' + $scope.currentproject._id + '/stopworking',
|
||||||
|
method: "PUT",
|
||||||
localStorage.setItem("w_l_projects", angular.toJson($scope.projects));
|
data: $scope.user
|
||||||
|
}).then(function(response) {
|
||||||
|
console.log(response);
|
||||||
|
$scope.projects=response.data;
|
||||||
|
},
|
||||||
|
function(response) {// failed
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user