On my current project we are in need of a dynamic query-building user interface. In non-geek terms, that means a web page that allows a user to specify fields, constraints, and values that evaluate to some kind of query or expression. Alright that was still a geeky explanation... but if you're reading this then the geek-speak is probably appropriate for you. But I digress...
This little UI is all about the data structure you want the UI to represent. If you can plan the data structure, you can throw the UI on top of it. There may be specific theories and methods on how to properly represent a logical query like this, but I'm not following any particular approach here.
My data structure is as follows:
* Condition - a unit of logic that defines a field, comparison operator, and value (e.g. Color equals 'Black', Quantity is greater than two, etc).
* Group - contains an array of Conditions and Groups, and specifies whether to perform a logical-AND or a logical-OR on all items in the array.