mirror of
https://github.com/arnaucube/openworktime.git
synced 2026-02-07 11:46:40 +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
|
||||
var mongoose = require('mongoose');
|
||||
var moment = require('moment');
|
||||
var projectModel = mongoose.model('projectModel');
|
||||
|
||||
var userModel = mongoose.model('userModel');
|
||||
@@ -75,7 +76,11 @@ exports.addUserToProject = function(req, res) {
|
||||
console.log(req.body);
|
||||
projectModel.findById(req.params.id, function(err, 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);
|
||||
project.save(function(err) {
|
||||
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))
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -6,7 +6,10 @@ var projectSchema = new Schema({
|
||||
title: { type: String },
|
||||
description: { type: String },
|
||||
icon: { type: String },
|
||||
users: [{ type: String }],
|
||||
users: [{
|
||||
username: { type: String },
|
||||
time: { type: Number }
|
||||
}],
|
||||
chart: [{
|
||||
labels: [{ type: String }],
|
||||
series: [{ type: String }],
|
||||
@@ -15,7 +18,8 @@ var projectSchema = new Schema({
|
||||
workStrikes: [{
|
||||
username: { type: String },
|
||||
start: { type: Date },
|
||||
end: { type: Date }
|
||||
end: { type: Date },
|
||||
time: { type: Number }
|
||||
}],
|
||||
dateCreation: { type: Date },
|
||||
github: { type: String },
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
"jsonwebtoken": "latest",
|
||||
"method-override": "^2.1.2",
|
||||
"mongoose": "latest",
|
||||
"morgan": "latest"
|
||||
"morgan": "latest",
|
||||
"moment": "latest"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,6 +54,10 @@ angular.module('workApp', ['chart.js'])
|
||||
$scope.currentInclude="login.html";
|
||||
console.log("token ended");
|
||||
}else{
|
||||
for(var i=0; i<data.length; i++)
|
||||
{
|
||||
data[i].chart=translateWorkStrikes2Chart(data[i].workStrikes);
|
||||
}
|
||||
console.log(data);
|
||||
$scope.projects=data;
|
||||
}
|
||||
@@ -257,6 +261,11 @@ angular.module('workApp', ['chart.js'])
|
||||
data: $scope.user
|
||||
}).then(function(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;
|
||||
},
|
||||
function(response) {// failed
|
||||
@@ -278,6 +287,19 @@ angular.module('workApp', ['chart.js'])
|
||||
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
|
||||
/*$scope.chart={
|
||||
@@ -297,3 +319,22 @@ angular.module('workApp', ['chart.js'])
|
||||
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.totaltime | secondsToDateTime | date:'HH:mm:ss'}}</p>
|
||||
<p class="grey-text">
|
||||
<div ng-repeat="user in project.users">{{user}}</div>
|
||||
<div ng-repeat="user in project.users">{{user.username}}</div>
|
||||
</p>
|
||||
</a>
|
||||
</div>
|
||||
@@ -122,17 +122,17 @@
|
||||
<p>
|
||||
Total time: {{currentproject.totaltime | secondsToDateTime | date:'HH:mm:ss'}}
|
||||
</p>
|
||||
<p>
|
||||
Current strike time: <b>{{currentStrike | secondsToDateTime | date:'HH:mm:ss'}}</b>
|
||||
<p ng-repeat="user in currentproject.users">
|
||||
{{user.username}}: <b>{{user.time | secondsToDateTime | date:'HH:mm:ss'}}</b>
|
||||
</p>
|
||||
|
||||
</div>
|
||||
<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="btnStop()" ng-show="working" class="waves-effect waves-light btn red lighten-2">Stop!</a>
|
||||
</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>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user