This should be a simple logic problem but for some reason I’ve been struggling with it for hours trying to come up with a semi-clean algorithm to implement this. I’m using MVC3 with a SQL Server background, but even if you don’t know about MVC you might still be able to help me with the algorithm.
I’m writing an application that makes use of a wizard-like interface. For now, the navigation between those wizard screens is very linear (the next button goes to the page immediately after, previous button goes to page immediately before). Due to scope change (fun, I know) I’ve now been told to make this less linear.
For the first run-through, the user has to visit all pages in linear order, like so:
Step 1
Step 2
Step 3
SubStep 1
Sub-SubStep 1
Sub-SubStep 2
SubStep 2
Sub-SubStep 1
Sub-SubStep 2
...
SubStep *n*
Sub-SubStep 1
Sub-SubStep 2
Submission
Where n is variable based on something that was entered in Step 2.
After the wizard is submitted it is reviewed by an administrator. If they find information missing they can unlock certain pages. When the user goes back to enter that information they should only be able to view those certain pages. For example, navigation might be like so:
Step 2
Step 3
SubStep 1
Sub-SubStep2
Submission
My current implementation consists of a table in the database that keeps track of the unlocked pages. When the “Next” button is clicked it calls a method to determine what the next page is. Because of the strange and variable navigation that takes place in Step 3 this method is an if-else branching nightmare which is easily broken.
Any suggestions on simplifying this would be greatly appreciated.
If you create a tree structure that represents the navigation hierarchy, a preorder traversal of the tree will hit the pages in the desired linear order. You can run such a traversal, and when you hit the current page, you can continue the traversal until you find an unlocked page, which will be the desired next page.
Pseudocode:
Note that you need a root node, whose children must be Step 1, Step 2, and Step 3. Pass this root node to the last
findNextPage()function.