In this week I was officially assigned tasks to do in the project. I was assigned 3 tasks all related to JointJS and Wt Wresources. However, I could only manage to finish one task which was handling saving and loading a Json file to and from the server.
The first part of the task was loading the file from the server to the client browser. This was a fairly simple task. To do that, I created a Witty function in the editor class to handle the loading. The function basically sends a GET request to the server to retrieve the specific file, then loads the file to the editor using the JointJS API.
The second part of the task is reversing this process; i.e. send the file (after doing some editing) from the client browser to the server to save the changes. Logically, I defined another function to send a PUT request to the server with the edited file being the body of this request. This part on the client browser was done using JQuery. However, not like loading a file, I did not rely on the default server handling request routine and I had to define my own Wresources to handle this PUT request. Wresources is in fact very simple. After defining a new class inherting from wresources, I added it to the server with server.addResource() function. Then, I modified handleRequest() function to extract the Json file from the put request and write to a file.
One of the problems I was facing in this task was to send the Json file using JQuery as a request body and not a parameter (as I was instructed by my supervisor, Dr. Shawn). After a lot of digging I found the solution is to send the Json file in the data field, and use HTTP::request.in() function to open the input stream to receive the body of the request.
Next week I will be working on the other two tasks. I hope I can finish them within the time frame given.
For any queries, feel free to leave a comment. I will be more than happy to answer.
Talk to you next time.
0 Comments