ForumsDevelopersHow should clone with subtasks be implemented?


How should clone with subtasks be implemented?
Author Message
ykphuah

Posted: Aug 10, 2013
Score: 0 Reference
In order to properly clone a task with subtask, I need to do the following:
1. clone the parent
2. sync the new parent to the cloud
3. get the id that is assigned by toodledo
4. clone all the subtasks to be under this parent

Steps #2 and #3 is problematic, as network connection is needed, and its a very "async" task. Is there any way to accomplish this cloning of subtasks without making a roundtrip to the web?
Jake

Toodledo Admin
Posted: Aug 11, 2013
Score: 0 Reference
Here is what our iOS app does for duplicating parents with subtasks:

1) Clone the parent and give it a temporary id
2) Clone all the subtasks and give them temporary ids and set their parent id to be the new parent's temporary id.

At this point, the user can continue to use your app offline, making any changes to the parent/subtasks as needed. Then, when ready to sync:

3) Sync the parent and get the new id
4) Update the parent's temporary id with the real id
5) Update all the subtask's temporary parent id to the real parent id
6) Sync the subtasks
7) Update the subtasks's temporary ids with the real ids.

hope that helps,
Jake
ykphuah

Posted: Aug 12, 2013
Score: 0 Reference
How do I generate a random id and make sure it won't crash with the other task's id that I have on the list?
Jake

Toodledo Admin
Posted: Aug 12, 2013
Score: 0 Reference
Just use a really big random number and you should be fine.
ykphuah

Posted: Aug 13, 2013
Score: 0 Reference
Is it possible for you to share out the snipplet of code to generate this really big random number?
Jake

Toodledo Admin
Posted: Aug 13, 2013
Score: 0 Reference
Its not special code. Just use your languages built in random number generator. Or concatenate several small random numbers together into a long string. It doesn't really matter as long as it is unique.
ykphuah

Posted: Aug 14, 2013
Score: 0 Reference
Thanks a lot.
safire

Posted: Aug 15, 2013
Score: 0 Reference
In my app, I just use a negative number. Makes it easy to identify tasks which are not yet synced with the server. ;-)
Jake

Toodledo Admin
Posted: Aug 15, 2013
Score: 0 Reference
Good idea. You could also append a letter or set a flag inside the task that it has a temporary id.
ykphuah

Posted: Aug 16, 2013
Score: 0 Reference
I have thought about a random negative number, but after that I realize it basically reduce the random space in half. I think I am better off with the while random space, together with a flag.
You cannot reply yet

U Back to topic home

R Post a reply

To participate in these forums, you must be signed in.