Consuming existing backend API

Hi there, I’m discovering this application that seems really well done and useful.

I’m seeing the examples of how the backend can be implemented in many ways.
But I’m wondering how easy would be to plug this application to an existing backend that already has concepts such as tasks, links & resources.
I’m talking about Redmine.

I saw we can hook the DataProcesssor, but do you think it would be customizable enough to communicate with the Redmine API ?

Hi,

It should be customizable enough.
However, we didn’t test our gantt with this particular api, so I don’t know if the data model of that app is compatible with what we have in gantt.

In order to load the data from the existing api, you’ll need a call api in some format and then convert the result in the format that can be loaded into the gantt

gantt.ajax.get({
    url: "/api",
    headers: {
        "Authorization": "Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b"
    }
}).then(function (xhr) {
    const data = JSON.parse(xhr.responseText);
    // convert `data` into something that can be loaded into the gantt https://docs.dhtmlx.com/gantt/desktop__supported_data_formats.html#json
    gantt.parse(convertedData);
});

https://docs.dhtmlx.com/gantt/desktop__server_side.html#customrequestheadersandparameters

And in order to save the changes via the dataProcessor, you can define your custom ‘router’, which will give you a hook for all updates that needed to be sent to the backend.
Then you’ll be able to manually call the external API in whatever format it accepts:

gantt.createDataProcessor(function(entity, action, data, id){
    // entity - "task"|"link"
    // action - "update"|"create"|"delete"
    // data - task or link object
    // id - task or link id

    return new gantt.Promise(function(resolve, reject){
         // send the update and resolve on completion
         //
         resolve();

         // if your create a new record - resolve with a database id of that record
         resolve({tid: databaseId});

    });
});

https://docs.dhtmlx.com/gantt/desktop__server_side.html#customrouting

1 Like

Thank you for your detailed answer.
It seems perfect.

1 Like