views:

58

answers:

1

Hey guys,

I'm trying to figure out the logic for creating tasks that have dependencies. In short I'm building a dynamic task management system and each tasks has several options one of them is to have the task start after a predecessor.

Users can add/remove/re-order (by drag&drop) tasks so I'm wondering how can I make the predecessors dynamic, here's an example of what I mean

  • Task 1
  • Task 2
  • Task 3 -> dependent of task 2
  • Task 4 -> dependent of task 2

Tasks get renamed on delete and/or re-order. If task 1 gets deleted then 3 and 4 should become dependent of task 1 (which is the old task 2). I've been banging my head for the past few hours trying to figure out how to do that.

I'm using jQuery right now and each task is contained in a div with an incremental id (ie id="task1") that gets renamed whenever a task is removed or re-ordered and I'm using a dynamically populated drop down for selecting a predecessor.

What would be the easiest way to get this done??

by the way, I'm not necessarily asking for code, just trying to figure out the best way to tackle this

A: 

Make the order separate from the task id.

  • Order 1: Task 1
  • Order 2: Task 2
  • Order 3: Task 3 -> dependent on task 2
  • Order 4: Task 4 -> dependent on task 2

After deleting task 1, it becomes...

  • Order 1: Task 2
  • Order 2: Task 3 -> dependent on task 2
  • Order 3: Task 4 -> dependent on task 2
Robert Wohlfarth
That's what I had in mind but I'm trying to figure out an efficient way to storing the order (since the order doesn't really matter during the creationDo you mean storing the order in an array?
Serge
Do you mean efficient storage in the database or in memory? In memory, an array works perfectly. In a database, you might use two tables: one for the task, and one that puts the tasks in order.
Robert Wohlfarth
I meant in memory. I might be wrong but I don't think storing it in an array would be efficient. If a task has a predecessor then on every delete or sort I'll need to search the array for the task id and return it's order and repopulate the dropdown... right?
Serge