++ hoursweeky_plannedtowork, endwork_estimate, totalphases , actualphase
This commit is contained in:
@@ -27,14 +27,6 @@ var ProjectSchema = new mongoose.Schema({
|
||||
longdescr: {
|
||||
type: String,
|
||||
},
|
||||
hoursplanned: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
hoursworked: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
id_parent: {
|
||||
type: String,
|
||||
},
|
||||
@@ -64,10 +56,6 @@ var ProjectSchema = new mongoose.Schema({
|
||||
id_prev: {
|
||||
type: String,
|
||||
},
|
||||
progressCalc: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
modified: {
|
||||
type: Boolean,
|
||||
},
|
||||
@@ -77,12 +65,39 @@ var ProjectSchema = new mongoose.Schema({
|
||||
test_url: {
|
||||
type: String,
|
||||
},
|
||||
totalphases: {
|
||||
type: Number,
|
||||
default: 1
|
||||
},
|
||||
actualphase: {
|
||||
type: Number,
|
||||
default: 1
|
||||
},
|
||||
hoursplanned: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
hoursworked: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
progressCalc: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
begin_development: {
|
||||
type: Date,
|
||||
},
|
||||
begin_test: {
|
||||
type: Date,
|
||||
},
|
||||
hoursweeky_plannedtowork: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
endwork_estimate: {
|
||||
type: Date
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -176,7 +191,6 @@ ProjectSchema.statics.getAllProjects = async function (userId) {
|
||||
|
||||
ProjectSchema.statics.updateCalc = async function (userId, idproj, objdatacalc, recIn) {
|
||||
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!!recIn) {
|
||||
return resolve(recIn);
|
||||
@@ -185,21 +199,22 @@ ProjectSchema.statics.updateCalc = async function (userId, idproj, objdatacalc,
|
||||
}
|
||||
}).then((myproj) => {
|
||||
if (!!myproj) {
|
||||
// console.log('myproj', myproj);
|
||||
console.log('objdatacalc progressCalc', objdatacalc.mydata.progressCalc);
|
||||
|
||||
objdatacalc.setValuesToRecord(myproj);
|
||||
|
||||
console.log('updateCalc', myproj._id, objdatacalc);
|
||||
// console.log('updateCalc', myproj._id, myproj.progressCalc);
|
||||
|
||||
myproj.save()
|
||||
return myproj.save()
|
||||
.then(() => {
|
||||
// console.log('salvato proj!');
|
||||
return true;
|
||||
})
|
||||
.catch(err => {
|
||||
console.log("Error updateCalc", err.message);
|
||||
});
|
||||
}
|
||||
return true;
|
||||
return false;
|
||||
}).catch(e => {
|
||||
console.log('Error: ', e);
|
||||
return false;
|
||||
|
||||
@@ -88,19 +88,23 @@ TodoSchema.methods.toJSON = function () {
|
||||
};
|
||||
|
||||
|
||||
TodoSchema.statics.findByUserIdAndIdParent = function (userId, category) {
|
||||
TodoSchema.statics.findByUserIdAndIdParent = function (userId, category, phase = '') {
|
||||
var Todo = this;
|
||||
|
||||
if (userId === '') {
|
||||
return Todo.find({
|
||||
'category': category,
|
||||
});
|
||||
} else {
|
||||
return Todo.find({
|
||||
'userId': userId,
|
||||
'category': category,
|
||||
});
|
||||
let tofind = {
|
||||
'category': category,
|
||||
};
|
||||
|
||||
if (userId !== '') {
|
||||
tofind['userId'] = userId;
|
||||
}
|
||||
|
||||
if (!!phase) {
|
||||
tofind['phase'] = phase;
|
||||
}
|
||||
|
||||
return Todo.find(tofind);
|
||||
|
||||
};
|
||||
|
||||
TodoSchema.statics.findAllByUserIdAndCat = function (userId, category = '') {
|
||||
@@ -158,71 +162,102 @@ TodoSchema.statics.getAllTodo = async function (userId) {
|
||||
};
|
||||
|
||||
class CalcTodo {
|
||||
constructor() {
|
||||
constructor(phase) {
|
||||
|
||||
this.mydata = {
|
||||
hoursworked: 0,
|
||||
hoursplanned: 0,
|
||||
progressCalc: 0,
|
||||
phase: phase,
|
||||
numitem: 0
|
||||
};
|
||||
this.clean()
|
||||
}
|
||||
|
||||
clean() {
|
||||
this.mydata.hoursplanned = 0;
|
||||
this.mydata.hoursworked = 0;
|
||||
this.mydata.progressCalc = 0;
|
||||
}
|
||||
|
||||
addDataProj(datain) {
|
||||
if (!!datain) {
|
||||
if (datain.actualphase === this.mydata.phase) {
|
||||
CalcTodo.addFields(this.mydata, datain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
addData(datain) {
|
||||
addDataTodo(datain) {
|
||||
if (!!datain) {
|
||||
this.mydata.hoursworked += datain.hoursworked;
|
||||
this.mydata.hoursplanned += datain.hoursplanned;
|
||||
if (!!datain.progressCalc)
|
||||
this.mydata.progressCalc += datain.progressCalc;
|
||||
else if (!!datain.progress)
|
||||
this.mydata.progressCalc += datain.progress;
|
||||
|
||||
this.mydata.numitem++;
|
||||
if (datain.phase === this.mydata.phase) {
|
||||
CalcTodo.addFields(this.mydata, datain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static addFields(recout, recin) {
|
||||
// console.log('addFields', recin);
|
||||
recout.hoursworked += recin.hoursworked;
|
||||
recout.hoursplanned += recin.hoursplanned;
|
||||
if (!!recin.progressCalc)
|
||||
recout.progressCalc += recin.progressCalc;
|
||||
else
|
||||
recout.progressCalc += recin.progress;
|
||||
|
||||
recout.numitem++;
|
||||
}
|
||||
|
||||
static copyFields(recout, recin) {
|
||||
recout.hoursworked = recin.hoursworked;
|
||||
recout.hoursplanned = recin.hoursplanned;
|
||||
if (!!recin.progressCalc)
|
||||
recout.progressCalc = recin.progressCalc;
|
||||
else
|
||||
recout.progressCalc = 0;
|
||||
}
|
||||
|
||||
setValuesToRecord(objout) {
|
||||
CalcTodo.copyFields(objout, this.mydata)
|
||||
}
|
||||
|
||||
endDataCalc() {
|
||||
if (this.mydata.numitem > 0) {
|
||||
this.mydata.progressCalc = Math.round(this.mydata.progressCalc / this.mydata.numitem);
|
||||
}
|
||||
}
|
||||
|
||||
setValuesToRecord(objout) {
|
||||
objout.hoursworked = this.mydata.hoursworked;
|
||||
objout.hoursplanned = this.mydata.hoursplanned;
|
||||
objout.progressCalc = this.mydata.progressCalc;
|
||||
}
|
||||
|
||||
getData() {
|
||||
// return tools.jsonCopy(this.mydata);
|
||||
return { ...this.mydata }
|
||||
}
|
||||
}
|
||||
|
||||
TodoSchema.statics.calculateTreeTodo = async function (actualphase, userId, idproj, calcalsoUpper, masterproj, nocalcDown) {
|
||||
// console.log('calculateTreeTodo', 'actualphase', actualphase, idproj);
|
||||
|
||||
TodoSchema.statics.calculateTreeTodo = async function (userId, idproj, calcalsoUpper, masterproj, nocalcDown) {
|
||||
console.log('calculateTreeTodo', idproj);
|
||||
const myrecproj = await Project.findProjectByUserId(userId, idproj);
|
||||
// const id_parent = await Project.getIdParentByIdProj(idproj);
|
||||
|
||||
let objdata = new CalcTodo();
|
||||
let objdata = new CalcTodo(actualphase);
|
||||
|
||||
let promiseChain = Promise.resolve();
|
||||
|
||||
return await Project.findByUserIdAndIdParent(userId, idproj)
|
||||
.then(arrsubproj => {
|
||||
console.log('arrsubproj', 'userId', userId, 'idproj', idproj, arrsubproj.length);
|
||||
// console.log(' ', arrsubproj.length, 'SubProjects trovati');
|
||||
// console.log('arrsubproj', 'userId', userId, 'idproj', idproj, arrsubproj.length);
|
||||
|
||||
if (!nocalcDown) {
|
||||
// 1) Calculate the SubProjects of this project Main
|
||||
for (const subproj of arrsubproj) {
|
||||
if (!calcalsoUpper) { // not include the first Project because it was already calculated before
|
||||
promiseChain = promiseChain.then(() => {
|
||||
return Todo.calculateTreeTodo(userId, subproj._id, calcalsoUpper, masterproj, true)
|
||||
return Todo.calculateTreeTodo(actualphase, userId, subproj._id, calcalsoUpper, masterproj, true)
|
||||
.then((subobjdata) => {
|
||||
objdata.addData(subobjdata);
|
||||
objdata.addDataProj(subobjdata);
|
||||
});
|
||||
});
|
||||
} else {
|
||||
promiseChain = promiseChain.then(() => {
|
||||
objdata.addData(subproj);
|
||||
objdata.addDataProj(subproj);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -231,39 +266,44 @@ TodoSchema.statics.calculateTreeTodo = async function (userId, idproj, calcalsoU
|
||||
return promiseChain;
|
||||
})
|
||||
.then(() => {
|
||||
console.log('objdata', objdata);
|
||||
// console.log('objdata', objdata);
|
||||
// 2) Calculate the Todos of this project
|
||||
return Todo.calculateTodoHoursAndProgress(userId, idproj);
|
||||
return Todo.calculateTodoHoursAndProgress(userId, idproj, myrecproj.actualphase);
|
||||
})
|
||||
.then((objdatatodos) => {
|
||||
objdata.addData(objdatatodos);
|
||||
|
||||
// End Calculate
|
||||
objdata.endDataCalc();
|
||||
if (myrecproj.actualphase === actualphase) {
|
||||
// console.log('objdatatodos', objdatatodos);
|
||||
objdata.addDataTodo(objdatatodos);
|
||||
|
||||
// Update into the DB:
|
||||
return Project.updateCalc(userId, idproj, objdata, null)
|
||||
.then(() => {
|
||||
return objdata.getData();
|
||||
});
|
||||
// End Calculate
|
||||
objdata.endDataCalc();
|
||||
|
||||
// Update into the DB:
|
||||
return Project.updateCalc(userId, idproj, objdata, null)
|
||||
.then((ris) => {
|
||||
if (ris)
|
||||
return objdata.getData();
|
||||
else
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
})
|
||||
.then((ris) => {
|
||||
if (calcalsoUpper) {
|
||||
return Project.getIdParentByIdProj(idproj)
|
||||
.then(idparent => {
|
||||
console.log('idparent', idparent);
|
||||
if (!!idparent) {
|
||||
// Calculate also the upper Projects !
|
||||
return new Promise((resolve, reject) => {
|
||||
Todo.calculateTreeTodo(userId, idparent, true, masterproj, false);
|
||||
resolve(ris)
|
||||
});
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve()
|
||||
});
|
||||
}
|
||||
if (!!myrecproj.id_parent) {
|
||||
// Calculate also the upper Projects !
|
||||
return new Promise((resolve, reject) => {
|
||||
Todo.calculateTreeTodo(actualphase, userId, myrecproj.id_parent, true, masterproj, false);
|
||||
resolve(ris)
|
||||
});
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve()
|
||||
});
|
||||
}
|
||||
} else {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve()
|
||||
@@ -272,16 +312,16 @@ TodoSchema.statics.calculateTreeTodo = async function (userId, idproj, calcalsoU
|
||||
})
|
||||
};
|
||||
|
||||
|
||||
TodoSchema.statics.calculateTodoHoursAndProgress = async function (userId, idproj) {
|
||||
TodoSchema.statics.calculateTodoHoursAndProgress = async function (userId, idproj, actualphase) {
|
||||
var Todo = this;
|
||||
|
||||
let objdata = new CalcTodo();
|
||||
let objdata = new CalcTodo(actualphase);
|
||||
|
||||
return await Todo.findByUserIdAndIdParent(userId, idproj)
|
||||
return await Todo.findByUserIdAndIdParent(userId, idproj, actualphase)
|
||||
.then(arrtodo => {
|
||||
// console.log(' calculateTodo *', arrtodo.length, '* FOUND');
|
||||
for (let itemtodo of arrtodo) {
|
||||
objdata.addData(itemtodo);
|
||||
objdata.addDataTodo(itemtodo);
|
||||
}
|
||||
|
||||
objdata.endDataCalc();
|
||||
|
||||
Reference in New Issue
Block a user