Working with Socket.io using dataProcessor


#1

Hi,

Does dataProcessor work when using websocket (Socket.io) with a node/mongodb backend? As it currently only works using REST API AFAIK.

Or what are the alternative available?

Thanks.


#2

Hello Joseph,
The Data Processor uses only RESTful API. It has several transaction methods like "POST" and "REST" but it doesn’t work in a different way:
https://docs.dhtmlx.com/gantt/desktop__server_side.html#technique
I don’t specialize in node.js and MongoDB and we didn’t check node.js with MongoDB so I cannot tell you if it works correctly there or if you need to apply an additional configuration to make it work.

But it should work correctly in a node.js application with an SQL database:
https://docs.dhtmlx.com/gantt/desktop__howtostart_nodejs.html


#3

Hi @ramil,

Thanks. As I have tried to use dataProcessor with REST but seem to have some issue when I tested it awhile back. Currently, am using my own way to update the data to store in backend through web-socket implementation. It’s working fine.

I was only trying out to see if I could tap onto dataProcessor to do it through WS.

Regards,


#4

Hi,

I came across data processor and I should be able to use custom routing to push CUD event through websocket right?

For the sample list with the following…

var dp = gantt.createDataProcessor(function(mode, taskState, data, rowId) {
		var workData = [];

		if (localStorage[mode]) {
			workData = JSON.parse(localStorage[mode]);
		}

		switch(taskState) {
			case "create":
				workData.push(data);
			break;
			case "update":
				var itemIndex = workData.findIndex(function(entry, index) {
					return entry.id == rowId;
				});
				workData[itemIndex] = data;
			break;
			break;
			case "delete":
				var itemIndex = workData.findIndex(function(entry, index) {
					return entry.id == rowId;
				});
				workData.splice(itemIndex, 1);
			break;
		}
		
		localStorage[mode] = JSON.stringify(workData);
	});

Is this automatically triggered whenever I make a call to gantt.addTask, gantt.updateTask and gantt.deleteTask? Meaning to say, if I do a gantt.addTask, workData.push(data); will be triggered automatically as it’s a create action.

Thanks.


#5

Hello Joseph,
Yes, you can use custom routing, sorry that I didn’t tell you that it is possible to use that option.

If you use the Data Processor, it will always try to send changes to the server side when you create, modify(update) and delete tasks and links.
Here is the sample with your code, which shows the output in the web console:
http://snippet.dhtmlx.com/217e34d6e
And here are other snippets, where Gantt sends the changes to the server side with custom routing:
https://snippet.dhtmlx.com/0763f65c2


https://snippet.dhtmlx.com/87d4edc67


#6

Thanks @ramil. May be useful for my case. Will try it out.