[Catalyst-commits] r7274 - in trunk/examples/ExtJS: . conf lib lib/ExtJS/Controller lib/ExtJS/Model root/lib/site root/src script t

peterdragon at dev.catalyst.perl.org peterdragon at dev.catalyst.perl.org
Wed Dec 12 00:24:53 GMT 2007


Author: peterdragon
Date: 2007-12-12 00:24:53 +0000 (Wed, 12 Dec 2007)
New Revision: 7274

Added:
   trunk/examples/ExtJS/conf/extjs_local.pl
   trunk/examples/ExtJS/conf/extjs_model.pl
   trunk/examples/ExtJS/script/dump_bookings.pl
   trunk/examples/ExtJS/t/10_schema.t
Modified:
   trunk/examples/ExtJS/Makefile.PL
   trunk/examples/ExtJS/README
   trunk/examples/ExtJS/conf/extjs.pl
   trunk/examples/ExtJS/extjs.db
   trunk/examples/ExtJS/extjs.sql
   trunk/examples/ExtJS/lib/ExtJS.pm
   trunk/examples/ExtJS/lib/ExtJS/Controller/ExtJS.pm
   trunk/examples/ExtJS/lib/ExtJS/Model/ExtJSModel.pm
   trunk/examples/ExtJS/root/lib/site/header
   trunk/examples/ExtJS/root/src/booking.tt2
Log:
Change to pick up booking data from SQLite database.
Split schema config to separate config file.
Incorporate use of Catalyst::Plugin::ConfigLoader::Multi
for Catalyst Advent calendar day 14 example.
Add script to demonstrate access to Catalyst model
from external script and test case.
Add dependencies.



Modified: trunk/examples/ExtJS/Makefile.PL
===================================================================
--- trunk/examples/ExtJS/Makefile.PL	2007-12-11 14:17:58 UTC (rev 7273)
+++ trunk/examples/ExtJS/Makefile.PL	2007-12-12 00:24:53 UTC (rev 7274)
@@ -8,8 +8,11 @@
 requires 'Catalyst::Plugin::Static::Simple';
 requires 'Catalyst::Action::RenderView';
 requires 'Data::Dump';
-requires 'YAML'; # This should reflect the config file format you've chosen
-                 # See Catalyst::Plugin::ConfigLoader for supported formats
+requires 'Path::Class::File';
+requires 'Catalyst::Plugin::ConfigLoader::Multi';
+requires 'Config::Any::Perl';
+requires 'YAML';
+requires 'Test::More';
 catalyst;
 
 install_script glob('script/*.pl');

Modified: trunk/examples/ExtJS/README
===================================================================
--- trunk/examples/ExtJS/README	2007-12-11 14:17:58 UTC (rev 7273)
+++ trunk/examples/ExtJS/README	2007-12-12 00:24:53 UTC (rev 7274)
@@ -1,6 +1,6 @@
-Catalyst Advent Calendar 2007 day 1 supporting
-Catalyst ExtJS sample application.
-Please read that article in association with this code.
+Catalyst Advent Calendar 2007 day 1 and day 14.
+This is the supporting Catalyst ExtJS sample application.
+Please read those articles in association with this code.
 
 Run script/extjs_server.pl to test the application.
 
@@ -8,12 +8,6 @@
 of the ext-1.1.1 library so this app will work if the reader
 forgets to install ExtJS. A lot of the examples and the manuals
 have been removed so you'd be better off downloading it from
-the extjs.com site as described in the article.
+the extjs.com site as described in the day 1 article.
 
-TODO: add in code to ExtJS/lib/ExtJS/Controller/ExtJS.pm
-to read a booking record from the database and pass it to
-Template Toolkit via the stash, then change root/src/booking.tt2
-to pick up the booking field data from there. It's hard coded
-for now (ran out of time, but all the db hooks are in place).
-
 Peter Edwards / peterdragon <peter at dragonstaff.co.uk>

Modified: trunk/examples/ExtJS/conf/extjs.pl
===================================================================
--- trunk/examples/ExtJS/conf/extjs.pl	2007-12-11 14:17:58 UTC (rev 7273)
+++ trunk/examples/ExtJS/conf/extjs.pl	2007-12-12 00:24:53 UTC (rev 7274)
@@ -5,8 +5,5 @@
   static => {
     include_path => [ '__path_to(root/static)__' ],
   },
-  'Model::ExtJSModel' => {
-    schema_class => 'ExtJS::Schema',
-    connect_info => [ 'dbi:SQLite:extjs.db', '', '', { AutoCommit => 1 } ],
-  },
+  overrideme => 'first value',
 }

Added: trunk/examples/ExtJS/conf/extjs_local.pl
===================================================================
--- trunk/examples/ExtJS/conf/extjs_local.pl	                        (rev 0)
+++ trunk/examples/ExtJS/conf/extjs_local.pl	2007-12-12 00:24:53 UTC (rev 7274)
@@ -0,0 +1,5 @@
+# extjs_local.pl
+{
+	dummy => 'someval',
+  overrideme => 'second value',
+}

Added: trunk/examples/ExtJS/conf/extjs_model.pl
===================================================================
--- trunk/examples/ExtJS/conf/extjs_model.pl	                        (rev 0)
+++ trunk/examples/ExtJS/conf/extjs_model.pl	2007-12-12 00:24:53 UTC (rev 7274)
@@ -0,0 +1,9 @@
+# extjs_model.pl
+{
+  # model DBI connection data
+  'Model::ExtJSModel' => {
+    schema_class => 'ExtJS::Schema',
+    connect_info => [ 'dbi:SQLite:extjs.db', '', '', { AutoCommit => 1 } ],
+   #connect_info => [ 'DBI:mysql:database=extjs;host=localhost', 'username', 'password', {} ], # mysql connection string sample
+  },
+}


Property changes on: trunk/examples/ExtJS/conf/extjs_model.pl
___________________________________________________________________
Name: svn:executable
   + *

Modified: trunk/examples/ExtJS/extjs.db
===================================================================
(Binary files differ)

Modified: trunk/examples/ExtJS/extjs.sql
===================================================================
--- trunk/examples/ExtJS/extjs.sql	2007-12-11 14:17:58 UTC (rev 7273)
+++ trunk/examples/ExtJS/extjs.sql	2007-12-12 00:24:53 UTC (rev 7274)
@@ -3,14 +3,42 @@
 CREATE TABLE booking (
   id            INTEGER PRIMARY KEY,
   po_ref        TEXT NOT NULL,
-  client_name   TEXT NOT NULL DEFAULT '',
-  description   TEXT NOT NULL DEFAULT '',
+  resource      INTEGER NOT NULL,
+  resource_name TEXT NOT NULL DEFAULT '',
+  start_date    TEXT NOT NULL DEFAULT '',
+  end_date      TEXT NOT NULL DEFAULT '',
+  customer_code TEXT NOT NULL,
+  customer_name TEXT NOT NULL DEFAULT '',
+  assignment    TEXT NOT NULL DEFAULT '',
+  order_no      INTEGER NOT NULL,
+  department    TEXT NOT NULL DEFAULT '',
+  comments      TEXT NOT NULL DEFAULT '',
+  work_tel      TEXT NOT NULL DEFAULT '',
+  report_to     TEXT NOT NULL DEFAULT '',
+  report_address  TEXT NOT NULL DEFAULT '',
+  report_postcode TEXT NOT NULL DEFAULT '',
+  type          TEXT NOT NULL DEFAULT '',
+  status        TEXT NOT NULL DEFAULT '',
+  cost_code     TEXT NOT NULL DEFAULT '',
+  cost_centre   TEXT NOT NULL DEFAULT '',
+  customer_tel  TEXT NOT NULL DEFAULT '',
+  project       TEXT NOT NULL DEFAULT '',
+  skill_codes   TEXT NOT NULL DEFAULT '',
   charge        REAL NOT NULL DEFAULT 0.0
 );
 
-INSERT INTO booking VALUES (1, 'ABC000001', 'A.B. Contractors', 'Fit worktops to kitchen', 150.0);
-INSERT INTO booking VALUES (2, 'ABC000002', 'A.B. Contractors', 'Install plumbing for sink and appliances', 500.50);
-INSERT INTO booking VALUES (3, 'CAR 12/95', 'Carillon Gmbh', 'General duties', 220.0);
-INSERT INTO booking VALUES (4, 'ABC000003', 'A.B. Contractors', 'Remove waste', 85.0);
-INSERT INTO booking VALUES (5, 'CAR A/B1', 'Carillon Gmbh', 'Callout cover', 240);
-INSERT INTO booking VALUES (6, 'BART PROD', 'Bart Spices', 'Production control', 70.0);
+INSERT INTO booking VALUES (1, 'ABC000001', 1040, 'Fred Bloggs', '2007/12/01',
+  '2008/01/25', 'ABC', 'A.B. Contractors', 'Fit worktops to kitchen', 
+  1052, '', '', '01234 567890', 'Site Manager', "Some address, Sometown",
+  'SO1 ME23', 'Temporary', 'Live', 'AC 1001', 'ABC01', '', 'Catalyst',
+  'PERL KITCHEN', 150.0);
+INSERT INTO booking VALUES (2, 'ABC000002', 1055, 'Simone de Beauvoir', '2007/08/20',
+  '2007/08/31', 'ABC', 'A.B. Contractors', 'Install plumbing for sink and appliances',
+  549, 'Kitchens', 'ASAP please', '01234 567890', 'A. Manager', "Some address, Sometown",
+  'SO1 ME23', 'Contract', 'Complete', 'AC 2051', 'ABC02', '01234 987654', 'Catalyst',
+  'KITCHEN PLUMBING', 150.0);
+INSERT INTO booking VALUES (4001, 'ABC/123', 13066, 'Joe Tester', '2007/06/01',
+  '2007/09/27', 'ABC000001', 'A.B. Contractors', 'PCB Assembly Test',
+  4, 'Mech/Hemel', '', '0555923534', 'Alice Davies', "1 One Street, Twotown, Threesdale",
+  'TH1 1AA', 'Temporary', 'Complete', 'AC 1001 / ABH', 'HEM01', '0131 5232 4121', 'Catalyst',
+  'DWIM DRY', 150.0);

Modified: trunk/examples/ExtJS/lib/ExtJS/Controller/ExtJS.pm
===================================================================
--- trunk/examples/ExtJS/lib/ExtJS/Controller/ExtJS.pm	2007-12-11 14:17:58 UTC (rev 7273)
+++ trunk/examples/ExtJS/lib/ExtJS/Controller/ExtJS.pm	2007-12-12 00:24:53 UTC (rev 7274)
@@ -48,19 +48,22 @@
 
 =head2 booking - a database record view
 
-The data is hard-coded in the template for now.
-
-TODO: read the booking record data through $c->model('ExtJS::Booking')
+Read the booking record data through $c->model('ExtJSModel::Booking')
 and pass the data object in the stash so the template can display field data from it.
-The class ExtJS::Model::ExtJSModel::Booking is already set up by lib/ExtJS/Schema.pm 
-using DBIx::Class::Schema::Loader ready for you.
+The class ExtJS::Model::ExtJSModel::Booking is automatically set up by lib/ExtJS/Schema.pm 
+using DBIx::Class::Schema::Loader.
 
 =cut
 
 sub booking :Path('/booking') {
     my ( $self, $c, $arg ) = @_;
+    my $booking_id = $arg; # a path like /booking/4001 gives $arg == 4001
     $c->stash->{template} = 'booking.tt2';
-    $c->stash->{page}->{title} = 'Booking View - 4001';
+    $c->stash->{page}->{title} = 'Booking View - ' . $booking_id;
+    my $rs = $c->model('ExtJSModel::Booking')->search({ id => $booking_id }, {})->single;
+    # normally you'd handle inconsistent data with an error screen rather than dying
+    defined $rs || die "cannot find booking '${booking_id}'";
+    $c->stash->{booking} = $rs; # pass into Template Toolkit where the object is accessible as 'booking', e.g. [% booking.id %]
 }
 
 =head1 AUTHOR

Modified: trunk/examples/ExtJS/lib/ExtJS/Model/ExtJSModel.pm
===================================================================
--- trunk/examples/ExtJS/lib/ExtJS/Model/ExtJSModel.pm	2007-12-11 14:17:58 UTC (rev 7273)
+++ trunk/examples/ExtJS/lib/ExtJS/Model/ExtJSModel.pm	2007-12-12 00:24:53 UTC (rev 7274)
@@ -1,6 +1,7 @@
 package ExtJS::Model::ExtJSModel;
 
 use strict;
+use warnings;
 use base 'Catalyst::Model::DBIC::Schema';
 
 #__PACKAGE__->config(
@@ -11,18 +12,33 @@
 #    ],
 #);
 
-use Catalyst qw/ ConfigLoader /;
-use Config::Any::Perl;
+use Catalyst qw/ ConfigLoader /; # gives us __PACKAGE__->config->{'home'}
+use Config::Any::Perl; # to load .pl config files
+use Path::Class;
 
 my $cfg;
 eval { $cfg = ExtJS->config; }; # this succeeds if running inside Catalyst
-if ($@) # otherwise if called from outside Catalyst try manual load
+if ($@) # otherwise if called from outside Catalyst try manual load of model configuration
 {
-	my $cfgpath = __PACKAGE__->config->{'home'} . '/conf/extjs.pl';
-	-r $cfgpath || die "cannot read config file $cfgpath";
+  # TODO use File::Path
+  my $cfgpath1 = Path::Class::File->new( __PACKAGE__->config->{'home'},
+    'conf', 'extjs_model_local.pl' )->stringify;
+  my $cfgpath2 = Path::Class::File->new( __PACKAGE__->config->{'home'},
+    'conf', 'extjs_model.pl' )->stringify;
+  my $cfgpath = -r $cfgpath1 ? $cfgpath1 
+              : -r $cfgpath2 ? $cfgpath2
+              : die "cannot read $cfgpath1 or $cfgpath2";
+  delete $INC{$cfgpath}; # workaround so older Config::Any::Perl will work when reloading config file
   $cfg = Config::Any::Perl->load( $cfgpath );
 }
 
+# test we have got our model config in
+defined $cfg->{'Model::ExtJSModel'} || die "Catalyst config not found";
+
+# put model parameters into main configuration
+__PACKAGE__->config( $cfg->{'Model::ExtJSModel'} );
+
+
 =head1 NAME
 
 ExtJS::Model::ExtJSModel - Catalyst DBIC Schema Model

Modified: trunk/examples/ExtJS/lib/ExtJS.pm
===================================================================
--- trunk/examples/ExtJS/lib/ExtJS.pm	2007-12-11 14:17:58 UTC (rev 7273)
+++ trunk/examples/ExtJS/lib/ExtJS.pm	2007-12-12 00:24:53 UTC (rev 7274)
@@ -13,9 +13,10 @@
 # Static::Simple: will serve static files from the application's root 
 #                 directory
 
-use Catalyst qw/-Debug ConfigLoader Static::Simple/;
+use Catalyst qw/-Debug ConfigLoader::Multi Static::Simple/;
 
 use Data::Dump qw(dump);
+use Config::Any::Perl;
 
 our $VERSION = '0.01';
 
@@ -30,16 +31,16 @@
 
 __PACKAGE__->config( name => 'ExtJS' );
 
-# this app's configuration is in conf/extjs.pl
+# this app's configuration is in conf/extjs.pl, conf/extjs_local.pl, conf/extjs_model.pl
 __PACKAGE__->config( file => __PACKAGE__->path_to('conf') );
 
 # Start the application
 __PACKAGE__->setup;
 
 # use
-#   $ CATALYST_DEBUG=1 perl script/extjs_test.pl /
+#   $ CATALYST_DEBUG_CONFIG=1 perl script/extjs_test.pl /
 # to check what's in your configuration after loading
-$ENV{CATALYST_DEBUG} && print STDERR 'cat config looks like: '. dump(__PACKAGE__->config) . "\n";# . dump(%INC)."\n";
+$ENV{CATALYST_DEBUG_CONFIG} && print STDERR 'cat config looks like: '. dump(__PACKAGE__->config) . "\n";# . dump(%INC)."\n";
 
 
 =head1 NAME

Modified: trunk/examples/ExtJS/root/lib/site/header
===================================================================
--- trunk/examples/ExtJS/root/lib/site/header	2007-12-11 14:17:58 UTC (rev 7273)
+++ trunk/examples/ExtJS/root/lib/site/header	2007-12-12 00:24:53 UTC (rev 7274)
@@ -13,7 +13,8 @@
  <ul>
    <li><a href="[% Catalyst.uri_for('/home') %]">Home</a>
    <li><a href="[% Catalyst.uri_for('/hello') %]">Hello</a>
-   <li><a href="[% Catalyst.uri_for('/booking') %]">Booking</a>
+   <li><a href="[% Catalyst.uri_for('/booking/2') %]">Booking 2</a>
+   <li><a href="[% Catalyst.uri_for('/booking/4001') %]">Booking 4001</a>
    <li><a href="http://www.google.com" target="_blank">Google</a>
  </ul>
 </div>

Modified: trunk/examples/ExtJS/root/src/booking.tt2
===================================================================
--- trunk/examples/ExtJS/root/src/booking.tt2	2007-12-11 14:17:58 UTC (rev 7273)
+++ trunk/examples/ExtJS/root/src/booking.tt2	2007-12-12 00:24:53 UTC (rev 7274)
@@ -20,6 +20,7 @@
 
 <p>A simple record view with two tabs. ExtJS has lots of options for tab layouts,
 tabs that can be closed and so on.</p>
+<p>The booking data here has been passed in as a DBIx::Class resultset row object.</p>
 <p>Well, that's it for today folks, I hope you enjoyed
 the article and it encourages you to have a play with Catalyst and ExtJS.<br />--peterdragon</p>
 
@@ -32,44 +33,47 @@
 <tbody>
 <tr>
     <td>
+<!-- normally you would use a TT macro to lookup the field label and generate
+     the HTML it is wrapped in but we use straight HTML here for clarity -->
     <strong>Booking</strong>
-    4001
+    [% booking.id %]
     </td>
     <td>
     <strong>Start Date</strong>
-    01/06/2007
+    [% booking.start_date %]
     </td>
     <td>
     <strong>End Date</strong>
-    27/09/2007
+    [% booking.end_date %]
     </td>
     <td>
     <strong>Customer Code</strong>
-    ABC000001
+    [% booking.customer_code %]
     </td>
 </tr>
 <tr>
     <td>
     <strong>Resource</strong>
-    13066
+     [% booking.resource %]
     </td>
     <td>
     <strong>Resource Name</strong>
-    Joe Tester
+    [% booking.resource_name %]
     </td>
     <td>
     <strong>PO Ref</strong>
-    ABC/123
+    [% booking.po_ref %]
     </td>
     <td>
     <strong>Customer Name</strong>
-    A.B. Contractors
+    [% booking.customer_name %]
     </td>    
 </tr>
 </tbody>
 </table>
    
 
+<!-- define tab 1 -->
 <div id="bkpg1">
 
 <table border="2" class="boxdata" id="infobox_booking">
@@ -77,42 +81,42 @@
 <tr><td class="boxdataheading" colspan=2>Booking</td></tr>
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Assignment</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">PCB Assembly Test</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.assignment %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Order No.</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">4</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.order_no %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Department</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">Mech/Hemel</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.department %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Comments</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue"></span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.comments %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Work Telephone</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">0555923534</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.work_tel %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Report To</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">Alice Davies</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.report_to %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Address</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">1 One Street<br>Twotown<br>Threesdale<br><br></span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.report_address %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Postcode</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">TH1 1AA</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.report_postcode %]</span></td>
     </tr>
 
 </tbody>
@@ -124,12 +128,12 @@
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Booking Type</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">Temporary</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.type %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Status</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">Complete</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.status %]</span></td>
     </tr>
 
 </tbody>
@@ -138,6 +142,7 @@
 </div>
 
 
+<!-- define tab 2 -->
 <div id="bkpg2">
 
 <table border="2" class="boxdata" id="infobox_customer">
@@ -146,27 +151,27 @@
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Cost code</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">AC 1001 / ABH</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.cost_code %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Cost centre</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">HEM01 </span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.cost_centre %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Telephone</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">0131 5232 4121</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.customer_tel %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Project</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">Catalyst</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.project %]</span></td>
     </tr>
 
     <tr>
     <td class="boxdatalabel"><span class="boxdatalabel">Skill Codes</span></td>
-    <td class="boxdatavalue"><span class="boxdatavalue">DWIM  DRY</span></td>
+    <td class="boxdatavalue"><span class="boxdatavalue">[% booking.skill_codes %]</span></td>
     </tr>
     
 </tbody>
@@ -175,6 +180,7 @@
 </div>
 
 
+<!-- ExtJS will attach tab1 and tab2 to this div and render them as a tab set -->
 <div id="tabs1" class="xp"></div>
 
      </div>

Added: trunk/examples/ExtJS/script/dump_bookings.pl
===================================================================
--- trunk/examples/ExtJS/script/dump_bookings.pl	                        (rev 0)
+++ trunk/examples/ExtJS/script/dump_bookings.pl	2007-12-12 00:24:53 UTC (rev 7274)
@@ -0,0 +1,37 @@
+#!/usr/bin/perl
+# script/dump_bookings.pl
+# a really simple example of accessing a Catalyst application's Model
+# from an external script
+# it lists all the booking records in the database
+
+use strict;
+use warnings;
+
+use lib qw( lib ../lib ); # allow for running from root directory or from script directory
+
+use ExtJS::Model::ExtJSModel;
+use ExtJS::Schema;
+
+# demonstrate picking up database connection info
+my $connect_info = ExtJS::Model::ExtJSModel->config->{connect_info};
+print "connecting schema to ".$connect_info->[0]."\n";
+
+# connect to the Catalyst schema
+my $schema = ExtJS::Schema->connect( @$connect_info );
+
+# show the model classes available
+my @sources = $schema->sources();
+print 'found schema model sources :-  ' . join(", ", at sources) . "\n";
+
+# list all bookings
+print "listing all bookings ordered by po_ref\n";
+my $rs = $schema->resultset('Booking')->search({}, { order_by => 'po_ref' });
+for my $row ( $rs->all )
+{
+  print "\nBooking ". $row->id ." - PO Ref " . $row->po_ref . "\n";
+  for my $col ( sort $row->columns )
+  {
+    next if $col eq 'id' || $col eq 'po_ref';
+    printf "  %-20s: %-50s\n", $col, $row->get_column($col);
+  }
+}


Property changes on: trunk/examples/ExtJS/script/dump_bookings.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: trunk/examples/ExtJS/t/10_schema.t
===================================================================
--- trunk/examples/ExtJS/t/10_schema.t	                        (rev 0)
+++ trunk/examples/ExtJS/t/10_schema.t	2007-12-12 00:24:53 UTC (rev 7274)
@@ -0,0 +1,23 @@
+# t/10_schema.t
+
+use strict;
+use warnings;
+use Test::More tests => 5;
+use Data::Dump qw(dump);
+
+BEGIN { use_ok 'ExtJS::Model::ExtJSModel' }
+BEGIN { use_ok 'ExtJS::Schema' }
+
+my $connect_info = ExtJS::Model::ExtJSModel->config->{connect_info};
+diag "connecting schema to ".$connect_info->[0]."\n";
+my $schema = ExtJS::Schema->connect( @$connect_info );
+
+my @sources = $schema->sources();
+ok( scalar @sources > 0, 'found schema sources :-  '.join(", ", at sources) );
+
+my $b;
+ok( $b = $schema->resultset('Booking')->find(1),
+    'find booking with id 1' );
+ok( $b->po_ref eq 'ABC000001',
+    'booking 1 po_ref is ABC000001' );
+1;


Property changes on: trunk/examples/ExtJS/t/10_schema.t
___________________________________________________________________
Name: svn:executable
   + *




More information about the Catalyst-commits mailing list