Ticket #463 (closed enhancement: fixed)

Opened 8 years ago

Last modified 7 years ago

CRUD enhancement for module generator

Reported by: demian Assigned to: demian
Priority: normal Milestone: 0.6.0
Component: module - default Severity: not categorised
Keywords: Cc:

Description (Last modified by demian)

submitted by Gerald Fischer

as mentioned yesterday on IRC I did some work on generating a more complete manager and templates for a given entity/database table. It's not complete especially in the template area, but I thought I'll send it over so you can have a look.

The accompaning zip contains:

1. a modified 'maintenance.html' that includes an additional option to generate the 'extended' version of mgr & templates (the one i've built). to go in /themes/default/default

2. a modified MaintenanceMgr?.php and a new sub-directory templates. MaintenanceMgr? does the following: * add the table to host.conf.ini if it doesn't exist * add the module to module table in database * generate a manager class for a database table with complete add, insert, edit, update, list and delete methods * generate stubs for Edit.html and List.html templates * generate language files with the basic key/value pairs already populated.

The code that is generated is taken from the various files in the templates directory, so it's easy to adapt

how to use it: 1. obviously you have to place the files in their respective diretories :-)

2. create a table in the database. something like this will do for a test:

CREATE TABLE `crud` (
  `crud_id` int(8) NOT NULL auto_increment,
  `name` varchar(255) character set latin1 collate latin1_german1_ci NOT NULL default '',
  `description` text character set latin1 collate latin1_german1_ci NOT NULL,
  PRIMARY KEY  (`crud_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

3. the maintenance panel and fill in the section Create a module with Module Name: crud, Manager Name: CrudMgr?, tick all options and hit 'Create Module now'

4. copy the generated templates from the crud/templates directory to /www/default/crud and modify them to display something reasonable.

5. Go to the modules panel and start the 'Crud manager', add a record, modify a record, delete it.

i hope all goes well, i did some testing already but that's not completly done.

please have a look if the generated code is reasonable, it's based on the tutorial examples, but as you know i'm pretty new to Seagull. maybe you'll have some ideas how to improve it -that l'll appreciate :-)

Attachments

moduleGeneration.diff (11.6 kB) - added by gfischer on 05/18/06 06:46:45.
missingTmplsForModuleGenerator.patch (0.7 kB) - added by aj on 05/28/06 21:04:15.
missingTmplsForModuleGenerator2.patch (1.0 kB) - added by aj on 05/28/06 22:10:21.

Change History

02/07/06 15:22:34 changed by demian

  • description changed.

02/21/06 17:07:33 changed by demian

  • status changed from new to closed.
  • resolution set to fixed.

Hi Gerald

at long last I've been able to get to your module generator patch, i've first refactored the existing code, moved it to its own mgr, then added what i could of your patch.

i stumbled at bit at the CRUD stuff, the idea is great with the templates, but if the enduser is only looking at the GUI, there is no indication that they have to create a model/entity/table first. i think we could get around this in 2 stages:

1) for FooMgr?: use your existing code as is, put put in validation "if (!$table->exists('foo')) {$msg = 'you must creat this table first'}

2) for phase two, create a entity form as part of the module generator, when CRUD is ticked, reveal form to build entity, using dynamic approach shown here: http://trac.seagullproject.org/query, then in mgr create table, add to tableAliases, etc.

everything else in your patch was fine, just watch the "if ($foo)" instead of "if($foo)". and call 'templates' something different like 'mgrTemplates'. you also need to enable admin_gui in Config to see CRUD option.

please reopen this ticket if you're able to patch in the fixes as suggested.

cheers

demian

03/13/06 04:30:47 changed by gfischer

  • status changed from closed to reopened.
  • resolution deleted.
  • milestone changed from 0.5.6 to 0.6.0.

reopened to supply patch

03/13/06 04:35:13 changed by gfischer

  • owner changed from somebody to demian.
  • status changed from reopened to new.

OK so I: 1. added some sanity check if the table (i.e. module to be generated) exists in the database and 2. added list, create, insert,edit, update, delete method functionality to the generated manager.

what's left to do is to generate reasonable templates on the fly. cheers gerald

03/13/06 05:53:10 changed by demian

  • owner changed from demian to gfischer.

hi Gerald - this code looks good but it's not a valid patch - please patch from the root of your Seagull install, as per instruction here: Code/SubmittingPatches

03/13/06 06:16:57 changed by gfischer

  • owner changed from gfischer to demian.

see, that's what you get when using windows tools instead of command line clients. sorry.

03/13/06 06:26:57 changed by demian

actually the majority of our patches are submitted by windows users (omniton and juliencasanova) it's just a matter of setting up correctly

03/13/06 08:04:55 changed by gfischer

i know. the difference is using svn command line tools instead of the turtoiseSVN built in patch function.

03/13/06 14:25:34 changed by demian

  • status changed from new to assigned.

03/14/06 20:09:32 changed by demian

  • status changed from assigned to closed.
  • resolution set to invalid.

Hi Gerald

thanks for fixing the paths, patch looks interesting but you are very far away from our coding standards (which, by the way, are identical to Zend Framework coding standards so they really will become a PHP standard sooner or later).

http://framework.zend.com/manual/coding-standard.html

Here are a few pointers:

  • indent with 4 spaces, not 8
  • ternary operators need to be indented on 2nd line
  • comma separated args always need 1 space after comma
  • line length max 80 chars
  • array elems on next line need to be indented
  • else if -> elseif

Also, the str_pad("\t' ... stuff would be more manageable if you did

$out = <<<EOT

... your data here with {ucfirst($output->moduleName)} escaped

EOT;

And for ever new data manipulation you do, please create a new method to keep code modular.

cheers

demian

03/15/06 09:42:44 changed by gfischer

  • status changed from closed to reopened.
  • resolution deleted.

Hi Demian, your absolutly right to enforce those :-) Although there are a couple of reasons for some of the violations:

* indent with 4 spaces, not 8

true, but in case of the *.tmpl pieces they have to be indented 8 chars because they get mixed in the source of the generated manager class and that class itself wouldn't be formated correctly otherwise.

* ternary operators need to be indented on 2nd line

yep, didn't write those, but indented them anyway. Might have been Zend Studio and it's code formating feature as well

* comma separated args always need 1 space after comma

yep

* line length max 80 chars

yeah back in the old days when we had the 80x24 green/black monsters... in general your right, in practice sometimes it becomes more an obfuscating feature than a readability enhancement.

* array elems on next line need to be indented

yep

* else if -> elseif

yep

Also, the str_pad("\t' ... stuff would be more manageable if you did...

i know that's kind of strange, but was the best solution to produce an evenly formated language file, as the meanger name that's embedded in a couple of lines is of different length for each module.

And for ever new data manipulation you do, please create a new method to keep code modular.

sure, didn't spot any though.

i hope that cleans it up reasonably well,let me know otherwise - i'll persist on getting it ready.

03/15/06 09:43:04 changed by gfischer

  • status changed from reopened to new.

03/17/06 21:27:38 changed by demian

  • status changed from new to assigned.

Hi Gerald - good stuff, coding standards much better, patch committed. I've spent quite a bit of time ironing out bugs, basically you had the concept of managers and modules reversed, now it's generating the code correctly.

Am leaving the ticket open as a few more things are still needed:

  • add entity to tableAliases.ini
  • fix html templates
  • add a 'view your new manager' button on generation completion

I liked your template generation, it's true it's quite powerful the amount of code you can automate.

cheers

Demian

03/24/06 16:50:32 changed by demian

  • owner deleted.
  • status changed from assigned to new.

05/18/06 06:46:45 changed by gfischer

  • attachment moduleGeneration.diff added.

05/18/06 06:49:33 changed by gfischer

  • owner set to demian.

finaly got around to complete the enhancements. i didn't figure out how to add the 'view your new manager' button, but added directions in the success message.

The functionality is still: throw in database table and get a complete maintenance module for it.

Give it a try if you have time (I know, I know nobody has enough of that) and let me know.

05/22/06 18:42:06 changed by demian

  • status changed from new to closed.
  • resolution set to fixed.

Hiya Gerald

thanks for this update, some interesting stuff, i like the DB_DATAOBJECT_* bit, a few probs though:

1) writing tableAliases.ini doesn't work

2) the edit template is not created correctly

Let me know if you have any ideas on this, otherwise I will try debug it at the weekend.

committed in bugfix branch.

cheers

Demian

05/28/06 21:03:56 changed by aj

  • status changed from closed to reopened.
  • resolution deleted.

05/28/06 21:04:15 changed by aj

  • attachment missingTmplsForModuleGenerator.patch added.

05/28/06 21:04:28 changed by aj

  • status changed from reopened to new.

05/28/06 21:45:56 changed by demian

  • status changed from new to closed.
  • resolution set to fixed.

(In [2068]) add missing templates, fixes #463

05/28/06 22:10:21 changed by aj

  • attachment missingTmplsForModuleGenerator2.patch added.

05/28/06 22:10:44 changed by aj

  • status changed from closed to reopened.
  • resolution deleted.

05/28/06 22:10:52 changed by aj

  • status changed from reopened to new.

05/28/06 22:15:59 changed by demian

  • status changed from new to closed.
  • resolution set to fixed.

(In [2070]) template improvements, fixes #463