[Bast-commits] r3451 - in trunk/Anything: docs lib lib/Anything
lib/Anything/Controller/Test lib/Anything/InterfaceModel
lib/Anything/InterfaceModel/Items
lib/Anything/InterfaceModel/Items/Action
lib/Anything/InterfaceModel/Items/Role
lib/Anything/UI/ActionForm root/base
castaway at dev.catalyst.perl.org
castaway at dev.catalyst.perl.org
Thu May 31 23:18:07 GMT 2007
Author: castaway
Date: 2007-05-31 23:18:06 +0100 (Thu, 31 May 2007)
New Revision: 3451
Added:
trunk/Anything/lib/Anything/InterfaceModel/Items/Role/
trunk/Anything/lib/Anything/InterfaceModel/Items/Role/Typefields.pm
trunk/Anything/root/base/header
Modified:
trunk/Anything/docs/Installing
trunk/Anything/lib/Anything.pm
trunk/Anything/lib/Anything/Controller/Test/Item.pm
trunk/Anything/lib/Anything/InterfaceModel/Items.pm
trunk/Anything/lib/Anything/InterfaceModel/Items/Action/Create.pm
trunk/Anything/lib/Anything/Types.pm
trunk/Anything/lib/Anything/UI/ActionForm/Item.pm
trunk/Anything/root/base/header.tt
Log:
Add Role to do the attribute twiddling, used in Create and Update actions
Split header into one for ttoolkit view, one for XHTML
Add NumberField to Types and ActionForm
Modified: trunk/Anything/docs/Installing
===================================================================
--- trunk/Anything/docs/Installing 2007-05-31 20:48:31 UTC (rev 3450)
+++ trunk/Anything/docs/Installing 2007-05-31 22:18:06 UTC (rev 3451)
@@ -23,9 +23,9 @@
- sqlite3 db/mydatabase.db < db/anything.sql
(currently the only SQL supplied is for SQLite3)
8) Apply the dataset update:
- - perl bin/import_dataset.pl --dataset data/<datasetname>.xml --dsn dbi:SQLite:db/mydatabase.db
+ - perl -Ilib bin/import_dataset.pl --dataset data/<datasetname>.xml --dsn dbi:SQLite:db/mydatabase.db
9) Create an inital Xapian database for your search indexing:
- - perl bin/anything_xapian.pl dbi:SQLite:db/mydatabase.db
+ - perl -Ilib bin/anything_xapian.pl dbi:SQLite:db/mydatabase.db
9) Start the application:
- script/anything_server.pl [--port NNNN]
Modified: trunk/Anything/lib/Anything/Controller/Test/Item.pm
===================================================================
--- trunk/Anything/lib/Anything/Controller/Test/Item.pm 2007-05-31 20:48:31 UTC (rev 3450)
+++ trunk/Anything/lib/Anything/Controller/Test/Item.pm 2007-05-31 22:18:06 UTC (rev 3451)
@@ -28,35 +28,39 @@
sub get_model_action {
my ($self, $c, $name, $target, $typeid) = @_;
+ my $type :Stashed;
$c->log->debug("Target: $target, " . ref($target));
+# $c->log->debug("Target: $target, " . $target->TypeID);
# $c->log->debug("DM: " . ref $target->_items_store);
## this attempts to inflate our type object into an items obj, oops
+ $type ||= $target->TypeID;
# my $target_type = $target->_items_store->related_resultset('TypeID')->find({ID => $typeid});
- my $target_type = $target->related_resultset('TypeID')->find({ID => $typeid});
- my $target_type = $c->model('Anything::Type')->find({ID => $typeid});
- my $rel_rs = $target->related_resultset('TypeID');
- $c->log->debug("Rel result_class " . $rel_rs->result_source->result_class);
- $c->log->debug("Rel: " . ref($rel_rs));
- use MRO::Compat;
- my $linear_isa = mro::get_linear_isa(ref $rel_rs);
- $c->log->debug("ISA $_") for @$linear_isa;
+# my $target_type = $target->related_resultset('TypeID')->find({ID => $typeid});
+# my $target_type = $c->model('Anything::Type')->find({ID => $typeid});
+# my $rel_rs = $target->related_resultset('TypeID');
+# $c->log->debug("Rel result_class " . $rel_rs->result_source->result_class);
+# $c->log->debug("Rel: " . ref($rel_rs));
+# use MRO::Compat;
+# my $linear_isa = mro::get_linear_isa(ref $rel_rs);
+# $c->log->debug("ISA $_") for @$linear_isa;
- my $target_type = $rel_rs->find({ID => $typeid});
- $c->log->debug("Target ID: $typeid");
- $c->log->debug("Target ID: $target_type");
+# my $target_type = $rel_rs->find({ID => $typeid});
+# $c->log->debug("Target ID: $typeid");
+# $c->log->debug("Target ID: $target_type");
if ($target->can('action_for')) {
return $target->action_for($name,
ctx => $c,
- target_type => $target_type,
- target_model => $target);
+# target_type => $target_type,
+# target_model => $target
+ );
}
my $model_name = "Action::${name}".$self->model_name;
my $model = $c->model($model_name);
confess "no such Model $model_name" unless $model;
return $model->new(target_model => $target,
- target_type => $target_type,
+# target_type => $target_type,
ctx => $c);
}
@@ -71,8 +75,21 @@
# );
# }
-sub create :Chained('base') :PathPart('create') :Args() {
+## Base list and create off type, which captures the typeid and stashes the type object ??
+
+sub type :Chained('base') :PathPart('type') :CaptureArgs(1)
+{
my ($self, $c, $typeid) = @_;
+ my $type :Stashed = $self->get_collection($c)->related_resultset('TypeID')->find({ID => $typeid});
+ print STDERR "Type found: $type\n";
+}
+
+sub create :Chained('type') :PathPart('create') :Args() {
+ my ($self, $c, $typeid) = @_;
+## Atempt to use an empty Item object for create instead of the collection, fails as Anything::InterfaceModel::Items cant be instantiated with no _items_store attribute.
+# my $coll = $self->get_collection($c);
+# my $new_object = $coll->new_result({_items_store => $coll->_items_store});
+# my $action = $self->get_model_action($c, 'Create', $new_object, $typeid);
my $action = $self->get_model_action($c, 'Create', $self->get_collection($c), $typeid);
# print STDERR $action->dump, "\n";
# print STDERR $_->blessed for $action->meta->compute_all_applicable_attributes;
Modified: trunk/Anything/lib/Anything/InterfaceModel/Items/Action/Create.pm
===================================================================
--- trunk/Anything/lib/Anything/InterfaceModel/Items/Action/Create.pm 2007-05-31 20:48:31 UTC (rev 3450)
+++ trunk/Anything/lib/Anything/InterfaceModel/Items/Action/Create.pm 2007-05-31 22:18:06 UTC (rev 3451)
@@ -2,62 +2,13 @@
use Reaction::Class;
use aliased 'Reaction::InterfaceModel::Action::DBIC::ResultSet::Create' => 'DBIC_Create';
+use Anything::InterfaceModel::Items::Role::Typefields;
use Anything::Types;
class Create is DBIC_Create, which {
- has delayed_fields =>
- (is => 'rw', isa => 'HashRef', required => 1,
- default => sub{{}}, metaclass => 'Reaction::Meta::Attribute');
+ does 'Anything::InterfaceModel::Items::Role::Typefields';
- around 'new' => sub {
- my $super = shift;
- my $self = shift;
- my $class = ref $self || $self;
- my %args = @_;
-
- return $super->($self, @_) if $self->meta->is_anon_class;
- print STDERR "Inherits from $class\n";
- my $action_meta = $self->meta->create_anon_class(superclasses => [$class]);
-
-# print STDERR "Self: $self\n";
- # this one errors
-# $self->delayed_fields({});
- my %delayed_fields;
- for my $val ($args{target_type}->typefields->all){
- my $attr_name = $val->FieldID->Name;
- $DB::single=1;
- print STDERR "Typefield: $attr_name " if($ENV{REACTION_DEBUG});
- $attr_name =~ s/ /_/g; #TODO FIX FOR POSSIBLE COLLISIONS WHEN USING UNDERSCORES
-# {
-# local $SIG{__DIE__} = sub {
-# print STDERR Carp::longmess;
-# print STDERR join " // ", @_;
-# exit;
- # this one doesnt
-# $self->delayed_fields->{$attr_name} = $val->FieldID->Name;
- $delayed_fields{$attr_name} = $val->FieldID->Name;
-
- $action_meta->add_attribute
- ($attr_name,
- reader => 'get_field_{$attr_name}',
- writer => 'set_field_{$attr_name}',
- is => 'rw',
- isa => $val->FieldID->TypeID->Name, #this will need fixing still
- predicate => "has_field_${attr_name}",
- required => 0
- );
-# };
-# }
- print STDERR "Done Typefield: $attr_name " if($ENV{REACTION_DEBUG});
- print STDERR "Field: $attr_name, Type: ", $val->FieldID->TypeID->Name, "\n" if $ENV{REACTION_DEBUG};
- }
-
- my $obj = $action_meta->new_object(@_, delayed_fields => \%delayed_fields);
- $obj->{__keep_metaclass_alive__} = $action_meta;
- return $obj;
- };
-
around do_apply => sub {
my $super = shift;
my $row = $super->(@_);
Added: trunk/Anything/lib/Anything/InterfaceModel/Items/Role/Typefields.pm
===================================================================
--- trunk/Anything/lib/Anything/InterfaceModel/Items/Role/Typefields.pm (rev 0)
+++ trunk/Anything/lib/Anything/InterfaceModel/Items/Role/Typefields.pm 2007-05-31 22:18:06 UTC (rev 3451)
@@ -0,0 +1,49 @@
+package Anything::InterfaceModel::Items::Role::Typefields;
+
+use Reaction::Role;
+use Anything::Types;
+
+role Typefields which {
+
+ has delayed_fields =>
+ (is => 'rw', isa => 'HashRef', required => 1,
+ default => sub{{}}, metaclass => 'Reaction::Meta::Attribute');
+
+ around 'new' => sub {
+ my $super = shift;
+ my $self = shift;
+ my $class = ref $self || $self;
+ my %args = @_;
+
+ return $super->($self, @_) if $self->meta->is_anon_class;
+ my $action_meta = $self->meta->create_anon_class(superclasses => [$class]);
+
+ my %delayed_fields;
+ die "No ctx passed to " . ref $self if(!exists $args{ctx});
+ die "No type passed to " . ref $self if(!exists $args{ctx}->stash->{type});
+
+ for my $val ($args{ctx}->stash->{type}->typefields->all)
+ {
+ my $attr_name = $val->FieldID->Name;
+ $attr_name =~ s/ /_/g; #TODO FIX FOR POSSIBLE COLLISIONS WHEN USING UNDERSCORES
+ $delayed_fields{$attr_name} = $val->FieldID->Name;
+
+ $action_meta->add_attribute
+ ($attr_name,
+ reader => 'get_field_{$attr_name}',
+ writer => 'set_field_{$attr_name}',
+ is => 'rw',
+ isa => $val->FieldID->TypeID->Name, #this will need fixing still
+ predicate => "has_field_${attr_name}",
+ required => 0
+ );
+ }
+
+ my $obj = $action_meta->new_object(@_, delayed_fields => \%delayed_fields);
+ $obj->{__keep_metaclass_alive__} = $action_meta;
+ return $obj;
+ };
+
+};
+
+1;
Modified: trunk/Anything/lib/Anything/InterfaceModel/Items.pm
===================================================================
--- trunk/Anything/lib/Anything/InterfaceModel/Items.pm 2007-05-31 20:48:31 UTC (rev 3450)
+++ trunk/Anything/lib/Anything/InterfaceModel/Items.pm 2007-05-31 22:18:06 UTC (rev 3451)
@@ -17,6 +17,15 @@
Delete => {},
);
+ around 'action_for' => sub {
+ my $super = shift;
+ my ($self, $action, %args) = @_;
+
+ print STDERR "Running IM action_for\n";
+
+ $super->(@_);
+ }
+
# implements 'action_for' => as {
# my ($self, $action, %args) = @_;
# my $super = $self->_action_class_for($action);
Modified: trunk/Anything/lib/Anything/Types.pm
===================================================================
--- trunk/Anything/lib/Anything/Types.pm 2007-05-31 20:48:31 UTC (rev 3450)
+++ trunk/Anything/lib/Anything/Types.pm 2007-05-31 22:18:06 UTC (rev 3451)
@@ -6,10 +6,17 @@
subtype 'TextField'
=> as 'Str'
+ => where {1}
;
subtype 'DateField'
=> as 'DateTime'
+ => where {1}
;
+subtype 'NumberField'
+ => as 'Int'
+ => where {1}
+ ;
+
1;
Modified: trunk/Anything/lib/Anything/UI/ActionForm/Item.pm
===================================================================
--- trunk/Anything/lib/Anything/UI/ActionForm/Item.pm 2007-05-31 20:48:31 UTC (rev 3450)
+++ trunk/Anything/lib/Anything/UI/ActionForm/Item.pm 2007-05-31 22:18:06 UTC (rev 3451)
@@ -7,6 +7,9 @@
class Item is 'Reaction::UI::ViewPort::ActionForm', which {
+ has +layout => (default => 'actionform');
+ ## default is the end of the class name, eg "item" here.. !
+
implements build_fields_for_type_TextField => as {
my ($self, $attr, $args) = @_;
return $self->build_simple_field(Text, $attr, $args);
Modified: trunk/Anything/lib/Anything.pm
===================================================================
--- trunk/Anything/lib/Anything.pm 2007-05-31 20:48:31 UTC (rev 3450)
+++ trunk/Anything/lib/Anything.pm 2007-05-31 22:18:06 UTC (rev 3451)
@@ -40,7 +40,7 @@
DSN => 'dbi:mysql:stuff',
DBUSER => 'root',
DBPASS => '',
- default_view => 'TToolkit',
+# default_view => 'TToolkit',
stacktrace => { verbose => 1 },
static => { dirs => [
'static',
Added: trunk/Anything/root/base/header
===================================================================
--- trunk/Anything/root/base/header (rev 0)
+++ trunk/Anything/root/base/header 2007-05-31 22:18:06 UTC (rev 3451)
@@ -0,0 +1,41 @@
+[%# NOTE: This leaves an open div/body/html, which *MUST* be closed in footer.tt.
+ # FIXME: This should wrap, instead of having a top/bottom template
+%]
+
+[% PROCESS "header_macros.tt" %]
+
+ <div id="navcontainer" class="menu">
+ <ul class="navlist" style="margin: 0">
+ [% IF app_navigation;
+ app_navigation;
+ END; %]
+ <li class="typelist-top">[% create_menu(types) %]</li>
+ [% IF c.user_exists && c.check_user_roles('Admin') %]
+ <li style="border-top: 1px solid;">Admin</li>
+ <li>
+ <a href="[% c.uri_for('/import/add') %]">Import Data</a>
+ </li>
+ <li>
+ <a href="[% c.uri_for('/type/list/') %]">Types</a>
+ </li>
+ [% END %]
+ </ul>
+ </div>
+
+ <div class="content">
+ <div style="float:right">
+ <form action="/search" method="post">
+ <div>
+ <input type="text" name="search" />
+ <input type="submit" value="Search" />
+ </div>
+ </form>
+ </div>
+
+ [% IF message || c.flash.message %]
+ <div class="message">[% message || c.flash.message | html %]</div>
+ [% END %]
+ [% IF error %]
+ <div class="error">[% error | html %]</div>
+ [% END %]
+
Modified: trunk/Anything/root/base/header.tt
===================================================================
--- trunk/Anything/root/base/header.tt 2007-05-31 20:48:31 UTC (rev 3450)
+++ trunk/Anything/root/base/header.tt 2007-05-31 22:18:06 UTC (rev 3451)
@@ -3,17 +3,17 @@
%]
[% PROCESS "header_macros.tt" %]
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
- <script src="/static/js/dojo.js" type="text/javascript"></script>
- <title>[% name %] - [% page_title %]</title>
- <link title="[% name %]" href="/static/css/[% name | lower %].css" type="text/css" rel="stylesheet" />
- <base href="[%- c.req.base -%]" />
- </head>
- <body>
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
+ <html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <meta http-equiv="Content-Script-Type" content="text/javascript" />
+ <script src="/static/js/dojo.js" type="text/javascript"></script>
+ <title>[% name %] - [% page_title %]</title>
+ <link title="[% name %]" href="/static/css/[% name | lower %].css" type="text/css" rel="stylesheet" />
+ <base href="[%- c.req.base -%]" />
+ </head>
+ <body>
<div id="navcontainer" class="menu">
<ul class="navlist" style="margin: 0">
More information about the Bast-commits
mailing list