Our state of the art Gantt chart


Post by jhughesoneplan »

I am trying to either write critical or totalSlack back to the database. It appears that when totalSlack changes it does not trigger a change in turn it doesn't sync back to the database. I have done a model with name: 'totalSlack', dataSource: 'totalSlack', persist: true, alwaysWrite: true and it does write but only for the task you directly edit. If you edit a task and some other tasks change their totalSlack those other tasks will not be flagged as changed.


Post by marcio »

Hey jhughesoneplan,

Could you please share how is your custom model coded (the full code)??

Best regards,
Márcio


Post by jhughesoneplan »

class WorkPlanTaskModel extends bryntum.gantt.TaskModel {
			get isLate() {
				return false;
			}
			get planIndex() {
				var index = this.wbsValue._value.split('.').reduce((a, b) => parseInt(a) + parseInt(b));
				if(this.parent.isRoot)
					return index;

			var pIndex = this.parent.wbsValue._value.split('.').reduce((a, b) => parseInt(a) + parseInt(b));
			
			return index - pIndex;
		}
		get isReadOnly() {
			return this.get("ReadOnly") == true || this.get("ReadOnly") == "True";
		}
		get style() {
			var c = "";
			try {
				c = "background-color: #" + ColorValues[this.get(ColorField)]
			} catch (e) { }

			return c;
		}
		get WBS() {
			return this.wbsValue._value.substr(2);
		}
		set WBS(a) {
			
		}
		static get fields() {
			var a = [
				{
					name: 'name', dataSource: 'Name'
				},
				{
					name: 'Id'
				},
				{
					name: 'percentDone', dataSource: 'PercentDone'
				},
				{
					name: 'startDate', dataSource: 'StartDate', format: 'YYYY-MM-DD HH:mm:ss'
				},
				{
					name: 'totalSlack', dataSource: 'totalSlack', persist: true, alwaysWrite: true
				},
				{
					name: 'endDate', dataSource: 'EndDate',  format: 'YYYY-MM-DD HH:mm:ss'
				},
				{
					name: 'effort', dataSource: 'Effort'
				},
				{
					name: 'duration', dataSource: 'Duration'
				},
				{
					name: 'milestone', dataSource: 'Milestone', persist: true, alwaysWrite: true
				},
				{
					name: 'calendar', dataSource: 'CalendarId'
				},
				{
					name: 'wbsValue', dataSource: 'wbsValue', alwaysWrite: true
				},
				{
					name: 'WBS', dataSource: 'WBS', alwaysWrite: true
				},
				{
					name: 'taskorder', dataSource: 'taskorder'
				},
				{
					name: 'Note', dataSource: 'Note'
				},
				{
					name: 'WorkPlanIndex', dataSource: 'WorkPlanIndex'
				},
				{
					name: 'showInTimeline', dataSource: 'ShowInTimeline'
				},
				{
					name: 'WorkPlanId', dataSource: 'WorkPlanId', alwaysWrite: true
				},
				{
					name: 'WorkTypeId', dataSource: 'WorkTypeId', alwaysWrite: true
				},
				{
					name: 'RowType', dataSource: 'RowType', alwaysWrite: true
				},
				{
					name: 'index', persist: true, alwaysWrite: true
				},
				{
					name: 'leaf', persist: true, alwaysWrite: true
				},
				{
					name: 'Iteration', dataSource: 'Iteration'
				},
				{
					name: 'schedulingMode', dataSource: 'SchedulingMode'
				},
				{
					name: 'manuallyScheduled', dataSource: 'ManuallyScheduled'
				},
				{
					name: 'TaskScheduleType', dataSource: 'TaskScheduleType', persist: true
				},
				{
					name: 'ScheduleItemId', dataSource: 'ScheduleItemId'
				},
				{
					name: 'constraintDate', dataSource: 'constraintDate', format: 'YYYY-MM-DD HH:mm:ss'
				},
				{
					name: 'RateTableId', dataSource: 'RateTableId'
				},
				{
					name: 'note', dataSource: 'Note'
				},
				{
					name: 'IsScheduled', dataSource: 'IsScheduled'
				},
				{
					name: 'Author', dataSource: 'Author', persist: false
				},
				{
					name: 'Editor', dataSource: 'Editor', persist: false
				},
				{
					name: 'Created', dataSource: 'Created', format: 'YYYY-MM-DDTHH:mm:ssz', persist: false
				},
				{
					name: 'Modified', dataSource: 'Modified', format: 'YYYY-MM-DDTHH:mm:ssz', persist: false
				},
				{
					name: 'earlyStartDate', persist: false,
				}
			]

			return a;
		}

	}

Post by arcady »

Hello,
The reason behind this is totalSlack field is a so called "lazy" field.
Such fields are not calculated until we actually try to read their values. So they are not updated when you change some other data.
The field is lazy out of the box since calculation of slack is quite expensive on large projects.

You can try disabling that mode by using this code:

// custom task model
class Task extends TaskModel {

    static $name = 'Task';

    static get fields() {
        return [
            // make totalSlack persistable
            { name : 'totalSlack', persist : true }
        ];
    }
}

// disable totalSlack lazy mode
Task.$entity.allFields.get('totalSlack').lazy = false;

And I've made a ticket to explain that in the docs: https://github.com/bryntum/support/issues/5365


Post Reply