SWAMI Page 5 - End of Day
If you recall, we are making a sample that follows the "Day in the Life of...." a Restaurant Mobile Inspector, at the start of their day they synchronise their application to get the To Dos of the day.
Upon completing their days tasks they then need to synchronise the gathered data to a backend database.
The EndOfDay html file is very simple, it contains a button for the user to press and a status field to indicate the success code (or failure code and error message). The button press action uses the AngularJS declaration to call a specific function in the controller JavaScript file.
It's essentially the same setup as the StartofDay html and controller.
When the user presses the button, the sync function will be executed. This performs a check to see if the Worklight client can connect to the Worklight Server, if it can then it will then perform the tasks in the function called connected. The first task in that function is to invoke the Worklight Adapter that is running on the Worklight Server.
You have to specify the name of the adapter, the procedure name and any parameters that are required.
I couldn't figure out a way to send the whole array of JSON objects (if there are more than a single completed inspection), so I send them one at a time via the WLAdapter. This is not the most efficient way, I am sure, but it does work and allows for more granular control of the send and wipe procedure.
Once we receive back a positive result, we can then remove the completed inspection from the JSONStore.
Upon completing their days tasks they then need to synchronise the gathered data to a backend database.
The EndOfDay html file is very simple, it contains a button for the user to press and a status field to indicate the success code (or failure code and error message). The button press action uses the AngularJS declaration to call a specific function in the controller JavaScript file.
It's essentially the same setup as the StartofDay html and controller.
When the user presses the button, the sync function will be executed. This performs a check to see if the Worklight client can connect to the Worklight Server, if it can then it will then perform the tasks in the function called connected. The first task in that function is to invoke the Worklight Adapter that is running on the Worklight Server.
You have to specify the name of the adapter, the procedure name and any parameters that are required.
I couldn't figure out a way to send the whole array of JSON objects (if there are more than a single completed inspection), so I send them one at a time via the WLAdapter. This is not the most efficient way, I am sure, but it does work and allows for more granular control of the send and wipe procedure.
Once we receive back a positive result, we can then remove the completed inspection from the JSONStore.
Now that we've managed to execute the EndOfDay and post the data to the server we can hang up our coat, kick off our shoes, sit back and relax for the evening....until tomorrow morning, when we'll loop through the StartOfDay sync again. One extension to this task could be an automated native-coded scheduler that would perform an auto-sync in the morning and the evening. Again, another item for v2.0.
Now that we've walked through how all the code works under the bonnet let's walk through the app from an end users perspective. That is what we shall investigate on the next Page.
Comments
Post a Comment