Subject: | possible generic solution to choosing subsets of columns intelligently |
In your normal CRUD database application, columns fall into at least three discrete groups:
-- displayable, those that can be displayed in the interface (presumably most columns but not all)
-- editable, those that can be specified in adds and edits
-- required, those that must be specified in adds and edits (not necessarily the same as "not null" columns, because some of those may be primary keys that are auto-generated but not editable, although they may still be displayable)
This model no doubt still a simplification of what is necessary in "real" situations, but is still an improvement on the current Maypole and Maypole + FormBuilder model. It's actually not very difficult to implement consistently. I was able to do so in about five minutes by making use of Class::DBI's column grouper (incidentally, I have no idea why Maypole bothered with the display_columns sub, which seems rather ugly given CDBI's column grouper is sitting right there). Here's an example:
__PACKAGE__->columns(Display => qw/ table_id item_id ref description num_values /);
__PACKAGE__->columns(Required => qw/ ref description /);
__PACKAGE__->columns(Editable => qw/ ref description compound /);
I wrote a small thing to automatically create a display_columns sub returning the Display group of columns. It's then quite a simple matter making the Maypole::FB templates aware of this. For addnew, you add these args:
fields => [ $request->model_class->columns('Editable') ],
required => [ $request->model_class->columns('Required') ],
For search, you add:
fields => [ $request->model_class->display_columns ],
Ditto for editlist. Unfortunately, there's not yet a way to combine forms with uneditable fields in a table row, but I'm working on that. :-)
I suppose one argument for the display_columns sub over the CBDI column grouper is that the former supports dynamic changes in column display. Perhaps, then, it would be preferably to add editable_columns and required_columns subs. Now, I understand that this is arguably simply a template-level issue, but it seems to me that given the tedium involved in this sort of thing, and the frequency with which it's bound to come up, it would be worthwhile to add some generic functionality of this sort to Maypole and/or Maypole::FB. Perhaps I will submit a proposal to the Maypole mailing list. In the meantime, these ramblings will have to do.