Slide 1

Slide 1 text

REALLY RAPID ADMIN APPLICATION DEVELOPMENT

Slide 2

Slide 2 text

~WHOAMI • Jose Diaz-Gonzalez • Resident IRC Troll (savant) • Rants at http://josediazgonzalez.com • Harasses as @savant • Codes as josegonzalez on github • Works at @seatgeek ➘ me ➘ not me

Slide 3

Slide 3 text

WHO IS THIS TALK FOR? • Anyone building CMS’ for a living • Those needing quick, extensible CRUD applications • Anyone looking for a boring challenge

Slide 4

Slide 4 text

WHAT THE HELL IS THIS? • var $scaffold = true; • ../cake/console/cake bake • cake bake skeletons • admin generation

Slide 5

Slide 5 text

SCAFFOLD

Slide 6

Slide 6 text

SCAFFOLDING • Generic application auto-generation • In CakePHP, introspects the Model::schema() and relationships to pull in data • Dumb, never recommended for production, not easy to manipulate

Slide 7

Slide 7 text

Slide 8

Slide 8 text

EXTENDING THIS? • Introspects model; add callbacks/validation rules/behaviors • _*Scaffold() Callbacks • Custom app/controller/scaffold.php class • Customize app/views/scaffolds/* views • 2.0 gets cooler scaffold

Slide 9

Slide 9 text

FIN

Slide 10

Slide 10 text

SCAFFOLD DRAWBACKS • Little to no usage documentation • Hard to customize • Easier to add generic methods in AppController

Slide 11

Slide 11 text

GENERIC METHODS

Slide 12

Slide 12 text

GENERIC METHODS • Create index()/view()/add()/edit()/delete() methods in your AppController • Have callbacks to disable in specific Controllers • Able to override in child Controllers

Slide 13

Slide 13 text

/**  *  Handles  index  requests.  *  *  @return  void  *  @access  public  */ public  function  index()  {        //  Only  do  this  work  if  our  concrete  controller  has  not.        if  (!isset($this-­‐>viewVars[Inflector::pluralize($this-­‐>modelClass)]))  {                $this-­‐>set(array(                        Inflector::pluralize($this-­‐>modelClass)  =>  $this-­‐>paginate(                                $this-­‐>modelClass,                                /**                                  *  Here  we  toss  in  any  conditions  that  were  found  as  named                                  *  parameters  and  which  match  up  to  a  column  in  the  model                                  *  schema.                                  */                                array_intersect_key(                                        $this-­‐>params['named'],                                        $this-­‐>{$this-­‐>modelClass}-­‐>schema()                                )                        )                ));        } } From https://github.com/joebeeson/crumbs/blob/develop/app_controller.php

Slide 14

Slide 14 text

class  PostsController  extends  AppController  {        protected  $disabledActions  =  array('index',  'add',  'edit',  'changelog');        public  function  beforeFilter()  {                if  (in_array($this-­‐>params['action'],  $this-­‐>disabledActions))  {                        $this-­‐>cakeError('404');                }        } } disabling mocked methods

Slide 15

Slide 15 text

CAVEATS • Has to be generic enough to use across controllers • Only portable if built as a plugin library (ie. LazyModel) • Must remember to build disabling code

Slide 16

Slide 16 text

BAKE

Slide 17

Slide 17 text

CAKE BAKE • You can now view the generated code and modify at will • Have to re-bake constantly • Everyone uses it; No one customizes it • Same issues as Scaffold • NOT === var $scaffold

Slide 18

Slide 18 text

BAD CAKE BAKE • Lets use Model::scaffold = -­‐1 please • Generated view() can result in an empty page • Generated delete() lets crawlers potentially auto-delete site • Model::read() usage is evil • Asks too many questions; Can’t I just answer once and rebake?

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

EXTENDING THIS? • Templates: app/vendors/shells/templates • Models are simple to access in templates • Do you follow “conventions” or allow configuration? • May need custom shell for extra configuration

Slide 21

Slide 21 text

CAKE SKELETONS • ../cake/console/cake bake project • Multiple skeletons available • Application Bootstrap • More or less portable

Slide 22

Slide 22 text

CAKE SKELETONS • Can’t use in existing applications • Assume you’ll always follow the same conventions • Hard to upgrade bootstrapped apps in automated fashion • Good for “chop-shops” and freelancers on new apps

Slide 23

Slide 23 text

EXTENDING THIS? • Copy cake/console/templates/skel to app/ vendors/templates/skeletor • Add plugins, create migrations/schema files • Generate generic models/controllers/views • Customize the HTML/CSS • GITHUB

Slide 24

Slide 24 text

EXISTING CAKE BAKE SKELETONS • Andy Dawson’s Skel • Jon Bradley’s cake-skel • Dean Soffer’s BakingPlate • Jose Gonzalez’s AppSkellington

Slide 25

Slide 25 text

IS THAT ALL?

Slide 26

Slide 26 text

RAILS GENERATORS

Slide 27

Slide 27 text

ESSENTIALLY CAKE BAKE+SKELETONS • Generators generate generators • Scaffolding similar to bake • Heavy community use • http://railswizard.org/ ^ Someone make this for CakePHP ^

Slide 28

Slide 28 text

RAILS ADMIN

Slide 29

Slide 29 text

• Port of MerbAdmin • Ruby DSL Configuration • Similar to var $scaffold • Works with existing applications • Actively Developed, Unofficial https://github.com/sferik/rails_admin

Slide 30

Slide 30 text

SYMFONY ADMIN

Slide 31

Slide 31 text

http://chetzit.com/uploads/images/00/00/04/2010/09/10/4ef9840c2e.png • var $scaffold on crack • supports custom fields • weird templating language • Symfony win? PROGRESSIVE ENHANCEMENT

Slide 32

Slide 32 text

YAML YAML YAML

Slide 33

Slide 33 text

NO GENERATION STEP save and go

Slide 34

Slide 34 text

DJANGO ADMIN

Slide 35

Slide 35 text

DJANGO PONY • Very customizable • Lots of available plugins • Lots of “themes” • Official Support

Slide 36

Slide 36 text

CAKE ADMIN

Slide 37

Slide 37 text

WHY • Need custom admin interface on top of phpmyadmin • Can’t use Croogo/Infinitas/etc. • Need to replicate similar admin interfaces across projects • Let less technical developers create their own interfaces

Slide 38

Slide 38 text

THE GOOD

Slide 39

Slide 39 text

CLASS BASED //  Access  via  /admin/posts class  PostCakeAdmin  extends  CakeAdmin  { }

Slide 40

Slide 40 text

PHP-BASED CONFIGURATION class  CategoryCakeAdmin  extends  CakeAdmin  { /**  *  Where  do  I  “scaffold”  this?  *  *  @var  string  */        public  $plugin                  =  'dashboard'; }

Slide 41

Slide 41 text

LOOKS EFFIN AMAZING

Slide 42

Slide 42 text

BETTER BASE METHODS public  function  delete($id  =  null)  {        if  (!empty($this-­‐>data['Category']['id']))  {                if  ($this-­‐>Category-­‐>delete($this-­‐>data['Category']['id']))  {                        $this-­‐>Session-­‐>setFlash(__d('admin',  'Category  deleted',  true),  'flash/success');                        $this-­‐>redirect(array('action'  =>  'index'));                }                $this-­‐>Session-­‐>setFlash(__d('admin',  'Category  was  not  deleted',  true),  'flash/error');                $id  =  $this-­‐>data['Category']['id'];        }        $this-­‐>data  =  $this-­‐>Category-­‐>find('delete',  compact('id'));        if  (!$this-­‐>data)  {                $this-­‐>Session-­‐>setFlash(__d('admin',  'Category  unspecified',  true),  'flash/error');                $this-­‐>redirect(array('action'  =>  'index'));        } }

Slide 43

Slide 43 text

THE BAD

Slide 44

Slide 44 text

NO TESTS

Slide 45

Slide 45 text

HIGH LEARNING CURVE

Slide 46

Slide 46 text

AND THE REST

Slide 47

Slide 47 text

CREATING NEW ACTIONS • Needs an *ActionConfig class • Templates for Controller/View - Model optional • Similar to Cake Bake Templates • Access to a model and the Admin class config

Slide 48

Slide 48 text

WHATS IN AN ACTION

Slide 49

Slide 49 text

CAKE ADMIN GENERATE

Slide 50

Slide 50 text

TODO • More actions (galleries, TreeBehavior) • Ajax and other UI enhancements • Web interface for customization • Scaffold-like interface in 2.0

Slide 51

Slide 51 text

LINKS • CakeAdmin: http://github.com/josegonzalez/cake_admin • Baking Master Class: http://www.neilcrookes.com/2009/07/11/baking-master-class-cakefest-jul-09/ • AppSkellington: http://github.com/josegonzalez/app_skellington • Skel: http://github.com/ad7six/skel • Cake-Skel: https://github.com/jonbradley/cake-skel • BakingPlate: http://github.com/proloser/bakingplate • RailsAdmin: http://github.com/sferik/rails_admin • DjangoAdmin: https://docs.djangoproject.com/en/1.3/ref/contrib/admin/