Is there a way I can get a project % done/complete value from the gantt or project model?
What I mean is lets say there is a project with two tasks first have percentageDone=50 and second have 0, then the project level % done value should be 25.
Is there also a way to be notify whenever this value change?
I know I can calculate it myself, but in case we have many tasks it would be more efficient to read the value from the property rather than manually calculate it every time the data changes.
Unlike TaskModel class that has HasPercentDoneMixin mixin applied ProjectModel class does not have it onboard. So it doesn't have that field. Yet you can subclass ProjectModel and add that mixin:
// extend standard ProjectModel w/ HasPercentDoneMixin mixin
class MyProject extends HasPercentDoneMixin.derive(ProjectModel) {}
const gantt = new Gantt({
// tell the Gantt it should use MyProject class to instantiate project model
projectModelClass : MyProject,
project : {
...
After that the project will have percentDone field that will calculate its value based on contained tasks.
Is there also a way to be notify whenever this value change?
Yes you can use the Engine API for this:
project.getGraph().observe(
function * () {
// yield identifiers we react on changes of
return yield project.$.percentDone;
},
(percentDone) => {
// some code to run on percentDone change
console.log(`Percent done is: ${percentDone}%`)
}
);
Thanks for rapid answer.
Could you advise how can I get reference to HasPercentDoneMixin.
I installed scheduler pro and react wrapper, but it's not there.
Could you let me know which package I need to install to get access to this?
HasPercentDoneMixin class is shipped in the same bundle you export Gantt class from.
The only thing if you write your app in TypeScript then the class could be not represented in the shipped TS interface files. But the class should be in the bundle.
If you have access to the customerzone you can try my solution w/ the upcoming Gantt v5.0.0 (it's on alpha-2 stage at the moment). It should export that class.
We had this working in version 5.3.0 but since moving to version 5.6.0 of the Gantt, we can't find HasPercentDoneMixIn ?
Please can you advise
Thanks
Paul