mirror of
https://github.com/arnaucube/openworktime.git
synced 2026-02-07 03:36:44 +01:00
work and stopwork system done, project time data structure runs ok
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
//File: controllers/projectController.js
|
//File: controllers/projectController.js
|
||||||
var mongoose = require('mongoose');
|
var mongoose = require('mongoose');
|
||||||
|
var moment = require('moment');
|
||||||
var projectModel = mongoose.model('projectModel');
|
var projectModel = mongoose.model('projectModel');
|
||||||
|
|
||||||
var userModel = mongoose.model('userModel');
|
var userModel = mongoose.model('userModel');
|
||||||
@@ -75,7 +76,11 @@ exports.addUserToProject = function(req, res) {
|
|||||||
console.log(req.body);
|
console.log(req.body);
|
||||||
projectModel.findById(req.params.id, function(err, project) {
|
projectModel.findById(req.params.id, function(err, project) {
|
||||||
console.log(project);
|
console.log(project);
|
||||||
project.users.push(req.body.username);
|
var auxUser={
|
||||||
|
username: req.body.username,
|
||||||
|
time: 0
|
||||||
|
};
|
||||||
|
project.users.push(auxUser);
|
||||||
console.log(project.users);
|
console.log(project.users);
|
||||||
project.save(function(err) {
|
project.save(function(err) {
|
||||||
if(err) return res.send(500, err.message);
|
if(err) return res.send(500, err.message);
|
||||||
@@ -117,6 +122,14 @@ exports.userStopWorking = function(req, res) {
|
|||||||
if((project.workStrikes[i].username==req.body.username)&&(project.workStrikes[i].end==null))
|
if((project.workStrikes[i].username==req.body.username)&&(project.workStrikes[i].end==null))
|
||||||
{
|
{
|
||||||
project.workStrikes[i].end= new Date();
|
project.workStrikes[i].end= new Date();
|
||||||
|
project.workStrikes[i].time=moment(project.workStrikes[i].end).diff(project.workStrikes[i].start, 'seconds');
|
||||||
|
for(var j=0; j<project.users.length; j++)
|
||||||
|
{
|
||||||
|
if(project.users[j].username==req.body.username)
|
||||||
|
{
|
||||||
|
project.users[j].time+=project.workStrikes[i].time;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log(project);
|
console.log(project);
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ var projectSchema = new Schema({
|
|||||||
title: { type: String },
|
title: { type: String },
|
||||||
description: { type: String },
|
description: { type: String },
|
||||||
icon: { type: String },
|
icon: { type: String },
|
||||||
users: [{ type: String }],
|
users: [{
|
||||||
|
username: { type: String },
|
||||||
|
time: { type: Number }
|
||||||
|
}],
|
||||||
chart: [{
|
chart: [{
|
||||||
labels: [{ type: String }],
|
labels: [{ type: String }],
|
||||||
series: [{ type: String }],
|
series: [{ type: String }],
|
||||||
@@ -15,7 +18,8 @@ var projectSchema = new Schema({
|
|||||||
workStrikes: [{
|
workStrikes: [{
|
||||||
username: { type: String },
|
username: { type: String },
|
||||||
start: { type: Date },
|
start: { type: Date },
|
||||||
end: { type: Date }
|
end: { type: Date },
|
||||||
|
time: { type: Number }
|
||||||
}],
|
}],
|
||||||
dateCreation: { type: Date },
|
dateCreation: { type: Date },
|
||||||
github: { type: String },
|
github: { type: String },
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
"jsonwebtoken": "latest",
|
"jsonwebtoken": "latest",
|
||||||
"method-override": "^2.1.2",
|
"method-override": "^2.1.2",
|
||||||
"mongoose": "latest",
|
"mongoose": "latest",
|
||||||
"morgan": "latest"
|
"morgan": "latest",
|
||||||
|
"moment": "latest"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,10 @@ angular.module('workApp', ['chart.js'])
|
|||||||
$scope.currentInclude="login.html";
|
$scope.currentInclude="login.html";
|
||||||
console.log("token ended");
|
console.log("token ended");
|
||||||
}else{
|
}else{
|
||||||
|
for(var i=0; i<data.length; i++)
|
||||||
|
{
|
||||||
|
data[i].chart=translateWorkStrikes2Chart(data[i].workStrikes);
|
||||||
|
}
|
||||||
console.log(data);
|
console.log(data);
|
||||||
$scope.projects=data;
|
$scope.projects=data;
|
||||||
}
|
}
|
||||||
@@ -257,6 +261,11 @@ angular.module('workApp', ['chart.js'])
|
|||||||
data: $scope.user
|
data: $scope.user
|
||||||
}).then(function(response) {
|
}).then(function(response) {
|
||||||
console.log(response);
|
console.log(response);
|
||||||
|
|
||||||
|
for(var i=0; i<response.data.length; i++)
|
||||||
|
{
|
||||||
|
response.data[i].chart=translateWorkStrikes2Chart(response.data[i].workStrikes);
|
||||||
|
}
|
||||||
$scope.projects=response.data;
|
$scope.projects=response.data;
|
||||||
},
|
},
|
||||||
function(response) {// failed
|
function(response) {// failed
|
||||||
@@ -278,6 +287,19 @@ angular.module('workApp', ['chart.js'])
|
|||||||
window.open(urlCode);
|
window.open(urlCode);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
$scope.arrayObjectIndexOf = function(myArray, searchTerm, property) {
|
||||||
|
if(myArray)
|
||||||
|
{
|
||||||
|
for(var i = 0, len = myArray.length; i < len; i++) {
|
||||||
|
if (myArray[i][property] === searchTerm){
|
||||||
|
//console.log("i: " + i);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//console.log("i: -1");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
//chart
|
//chart
|
||||||
/*$scope.chart={
|
/*$scope.chart={
|
||||||
@@ -297,3 +319,22 @@ angular.module('workApp', ['chart.js'])
|
|||||||
return new Date(2016, 0, 1).setSeconds(seconds);
|
return new Date(2016, 0, 1).setSeconds(seconds);
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function translateWorkStrikes2Chart(workStrikes){
|
||||||
|
var auxChart={
|
||||||
|
labels: [],
|
||||||
|
series: ['working'],
|
||||||
|
data: []
|
||||||
|
};
|
||||||
|
if(workStrikes)
|
||||||
|
{
|
||||||
|
for(var i=0; i<workStrikes.length; i++)
|
||||||
|
{
|
||||||
|
auxChart.labels.push(workStrikes[i].username);
|
||||||
|
auxChart.data.push(workStrikes[i].time);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return(auxChart);
|
||||||
|
}
|
||||||
|
|||||||
@@ -79,7 +79,7 @@
|
|||||||
<p class="grey-text">{{project.description}}</p>
|
<p class="grey-text">{{project.description}}</p>
|
||||||
<p class="grey-text">{{project.totaltime | secondsToDateTime | date:'HH:mm:ss'}}</p>
|
<p class="grey-text">{{project.totaltime | secondsToDateTime | date:'HH:mm:ss'}}</p>
|
||||||
<p class="grey-text">
|
<p class="grey-text">
|
||||||
<div ng-repeat="user in project.users">{{user}}</div>
|
<div ng-repeat="user in project.users">{{user.username}}</div>
|
||||||
</p>
|
</p>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -122,17 +122,17 @@
|
|||||||
<p>
|
<p>
|
||||||
Total time: {{currentproject.totaltime | secondsToDateTime | date:'HH:mm:ss'}}
|
Total time: {{currentproject.totaltime | secondsToDateTime | date:'HH:mm:ss'}}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p ng-repeat="user in currentproject.users">
|
||||||
Current strike time: <b>{{currentStrike | secondsToDateTime | date:'HH:mm:ss'}}</b>
|
{{user.username}}: <b>{{user.time | secondsToDateTime | date:'HH:mm:ss'}}</b>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="card-action">
|
<div class="card-action">
|
||||||
<div ng-show="currentproject.users.indexOf(user.username)!=-1">
|
<div ng-show="arrayObjectIndexOf(currentproject.users, user.username, 'username')!=-1">
|
||||||
<a ng-click="btnWork()" ng-show="!working" class="waves-effect waves-light btn green lighten-2">Work!</a>
|
<a ng-click="btnWork()" ng-show="!working" class="waves-effect waves-light btn green lighten-2">Work!</a>
|
||||||
<a ng-click="btnStop()" ng-show="working" class="waves-effect waves-light btn red lighten-2">Stop!</a>
|
<a ng-click="btnStop()" ng-show="working" class="waves-effect waves-light btn red lighten-2">Stop!</a>
|
||||||
</div>
|
</div>
|
||||||
<div ng-show="currentproject.users.indexOf(user.username)==-1">
|
<div ng-show="arrayObjectIndexOf(currentproject.users, user.username, 'username')==-1">
|
||||||
<a ng-click="joinProject()" class="waves-effect waves-light btn blue lighten-2">Join!</a>
|
<a ng-click="joinProject()" class="waves-effect waves-light btn blue lighten-2">Join!</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user