Our state of the art Gantt chart


Post by hien.nguyen »

Hi team,

When I delete task => it deleted already, but after sync (failed to delete on server). Now I want to restore this task again. Please share me the way to do it.

Best regards.


Post by tasnim »

You can use the undoRedo to achieve that.

Here are the steps that you need to follow

  1. Inside of your projectConfig add this
            stm : {
                disabled : false,
                autoRecord : true
            },
    
    So that it will enable state tracking manager

Docs :
https://bryntum.com/products/gantt/docs/api/Core/data/stm/StateTrackingManager#config-autoRecord
https://bryntum.com/products/gantt/docs/api/Core/data/stm/StateTrackingManager#config-disabled

  1. You need to listen for the sync fail with the syncFail listener https://bryntum.com/products/gantt/docs/api/Gantt/model/ProjectModel#event-syncFail
            listeners : {
                syncFail() {
                    // undo the change
                    this.stm.undo();
                }
            }
    

Good Luck :),
Tasnim


Post by hien.nguyen »

Thanks,

It's OK but have error when edit task (delete task not have)

1.png
1.png (181.85 KiB) Viewed 359 times

And my code for event as

gantt.project.on("syncFail", ( response ) => {           
gantt.project.stm.undo(); });

Best regards.


Post by tasnim »

Hello,
I'm getting an error every time I make a sync request and when it fails. Maybe your edit task didn't fail to sync. you can check it by giving an invalid sync URL.


Post by hien.nguyen »

Yes,

My edit task can call sync correct, but server (sync url) return error for case can't edit task in server. I return

success = false

in api.

Best regards.


Post by tasnim »

Thanks for reporting. I've reproduced it. And created a ticket to fix that. Here it is https://github.com/bryntum/support/issues/5678

If you have any other questions please don't hesitate to ask

Good Luck :),
Tasnim


Post by Animal »

None of this should be necessary.

If using a CrudManager, the server should send back a response which indicates that it could not perform the deletion and the CrudManager should restore it. This is what a CrudManager is for.

It will take me some time to examine the CrudManager source code or tests to find out exactly what this should look like. I will post an update when I have more info.


Post by Animal »

So if your request packet to the server contained

"events" : { "removed" : [{ "id" : 2 }]}

Then if the server could not perform that operation, the response should be

{
    success   : true,
    type      : 'sync',
    events  : {
        rows : [{
            id : 2,
            ...the rest of the data
        }],
        removed : []
    }
}

That is basically adding event 2 back as if it were new.


Post by Animal »

You should just be able to send back the removed block as [] to indicate that the remove failed and the CrdManager should restore it.

Here's a ticket about that: https://github.com/bryntum/support/issues/5684


Post Reply