From c8fbb8ad6185f3f14717138aaf8bb95d6b2d27b2 Mon Sep 17 00:00:00 2001 From: groditi Date: Wed, 2 Jan 2008 18:49:19 +0000 Subject: work in progress, listview still broken --- lib/Reaction/UI/Controller/Collection.pm | 6 +-- lib/Reaction/UI/Controller/Collection/CRUD.pm | 8 +-- lib/Reaction/UI/LayoutSet.pm | 1 - lib/Reaction/UI/ViewPort/Action.pm | 3 +- lib/Reaction/UI/ViewPort/Action/Link.pm | 2 +- lib/Reaction/UI/ViewPort/Collection.pm | 11 +++-- lib/Reaction/UI/ViewPort/Collection/Grid.pm | 5 +- lib/Reaction/UI/ViewPort/Collection/Grid/Member.pm | 4 +- lib/Reaction/UI/ViewPort/Field/Mutable/Array.pm | 2 +- .../UI/ViewPort/Field/Mutable/ChooseOne.pm | 4 +- lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm | 7 +-- lib/Reaction/UI/ViewPort/Field/Mutable/Number.pm | 2 +- lib/Reaction/UI/ViewPort/Field/Role/Choices.pm | 2 +- lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm | 4 ++ lib/Reaction/UI/ViewPort/ListView.pm | 14 +++--- lib/Reaction/UI/ViewPort/Object.pm | 8 +-- lib/Reaction/UI/ViewPort/Role/Actions.pm | 5 +- lib/Reaction/UI/Widget/Field/Array.pm | 57 ++++++++++++++++++++++ lib/Reaction/UI/Widget/Field/List.pm | 57 ---------------------- lib/Reaction/UI/Widget/ListView.pm | 2 +- 20 files changed, 105 insertions(+), 99 deletions(-) create mode 100644 lib/Reaction/UI/Widget/Field/Array.pm delete mode 100644 lib/Reaction/UI/Widget/Field/List.pm (limited to 'lib/Reaction/UI') diff --git a/lib/Reaction/UI/Controller/Collection.pm b/lib/Reaction/UI/Controller/Collection.pm index d7d727b..2aff23e 100644 --- a/lib/Reaction/UI/Controller/Collection.pm +++ b/lib/Reaction/UI/Controller/Collection.pm @@ -6,7 +6,7 @@ use base 'Reaction::UI::Controller'; use Reaction::Class; use aliased 'Reaction::UI::ViewPort::ListView'; -use aliased 'Reaction::UI::ViewPort::ObjectView'; +use aliased 'Reaction::UI::ViewPort::Object'; has 'model_name' => (isa => 'Str', is => 'rw', required => 1); has 'collection_name' => (isa => 'Str', is => 'rw', required => 1); @@ -17,7 +17,7 @@ has action_viewport_args => (isa => 'HashRef', is => 'rw', lazy_build => 1); sub _build_action_viewport_map { return { list => ListView, - view => ObjectView, + view => Object, }; } @@ -52,7 +52,7 @@ sub object :Chained('base') :PathPart('id') :CaptureArgs(1) { sub view :Chained('object') :Args(0) { my ($self, $c) = @_; my $object :Stashed; - $c->forward(basic_page => [{object => $object}]); + $c->forward(basic_page => [{model => $object}]); } sub basic_page : Private { diff --git a/lib/Reaction/UI/Controller/Collection/CRUD.pm b/lib/Reaction/UI/Controller/Collection/CRUD.pm index 8a2dcd0..3d04c1f 100644 --- a/lib/Reaction/UI/Controller/Collection/CRUD.pm +++ b/lib/Reaction/UI/Controller/Collection/CRUD.pm @@ -5,11 +5,11 @@ use warnings; use base 'Reaction::UI::Controller::Collection'; use Reaction::Class; -use aliased 'Reaction::UI::ViewPort::ActionForm'; +use aliased 'Reaction::UI::ViewPort::Action'; sub _build_action_viewport_map { my $map = shift->next::method(@_); - map{ $map->{$_} = ActionForm } qw/create update delete delete_all/; + map{ $map->{$_} = Action } qw/create update delete delete_all/; return $map; } @@ -22,7 +22,7 @@ sub _build_action_viewport_args { { label => 'Delete all', action => sub { [ '', 'delete_all', $_[1]->req->captures ] } }, ], - Entity => + Member => { action_prototypes => [ { label => 'View', action => sub { [ '', 'view', [ @{$_[1]->req->captures}, $_[0]->__id ] ] } }, @@ -102,7 +102,7 @@ sub basic_model_action :Private { return $self->push_viewport ( $self->action_viewport_map->{$cat_action_name}, - action => $self->get_model_action($c, $im_action_name, $target), + model => $self->get_model_action($c, $im_action_name, $target), %{ $vp_args || {} }, %{ $self->action_viewport_args->{$cat_action_name} || {} }, ); diff --git a/lib/Reaction/UI/LayoutSet.pm b/lib/Reaction/UI/LayoutSet.pm index 4a9c533..da4ecdc 100644 --- a/lib/Reaction/UI/LayoutSet.pm +++ b/lib/Reaction/UI/LayoutSet.pm @@ -78,7 +78,6 @@ class LayoutSet which { # doesn't have the match pos go past the latter = and lose name2 while ($data =~ m/=(.*?)\n(.*?)(?:\n(?==)|$)/sg) { my ($data, $text) = ($1, $2); - if ($data =~ /^for layout (\S+)/) { my $fname = $1; $layouts->{$fname} = $text; diff --git a/lib/Reaction/UI/ViewPort/Action.pm b/lib/Reaction/UI/ViewPort/Action.pm index e7a21a5..9da7191 100644 --- a/lib/Reaction/UI/ViewPort/Action.pm +++ b/lib/Reaction/UI/ViewPort/Action.pm @@ -17,7 +17,8 @@ use aliased 'Reaction::UI::ViewPort::Field::Mutable::ChooseMany'; #use aliased 'Reaction::UI::ViewPort::InterfaceModel::Field::Mutable::TimeRange'; class Action is 'Reaction::UI::ViewPort::Object', which { - has '+model' => (isa => 'Reaction::InterfaceModel::Action'); + has model => (is => 'ro', isa => 'Reaction::InterfaceModel::Action', required => 1); + #has '+model' => (isa => 'Reaction::InterfaceModel::Action'); has next_action => (is => 'rw', isa => 'ArrayRef'); has on_apply_callback => (is => 'rw', isa => 'CodeRef'); diff --git a/lib/Reaction/UI/ViewPort/Action/Link.pm b/lib/Reaction/UI/ViewPort/Action/Link.pm index 314c6a3..8bc8da8 100644 --- a/lib/Reaction/UI/ViewPort/Action/Link.pm +++ b/lib/Reaction/UI/ViewPort/Action/Link.pm @@ -1,4 +1,4 @@ -package Reaction::UI::ViewPort::InterfaceModel::Action::Link; +package Reaction::UI::ViewPort::Action::Link; use Reaction::Class; diff --git a/lib/Reaction/UI/ViewPort/Collection.pm b/lib/Reaction/UI/ViewPort/Collection.pm index c728f8e..a260bd7 100644 --- a/lib/Reaction/UI/ViewPort/Collection.pm +++ b/lib/Reaction/UI/ViewPort/Collection.pm @@ -17,21 +17,24 @@ class Collection is 'Reaction::UI::ViewPort', which { implements BUILD => as { my ($self, $args) = @_; - my $entity_args = delete $args->{Member}; + my $member_args = delete $args->{Member}; $self->member_args( $member_args ) if ref $member_args; }; + implements _build_member_args => as{ {} }; + implements _build_member_class => as{ Object }; after clear_current_collection => sub{ - shift->clear_entities; #clear the entitiesis the current collection changes, duh + shift->clear_members; #clear the members the current collection changes, duh }; implements _build_current_collection => as { shift->collection; }; - implements model + #I'm not really sure why this is here all of a sudden. + implements model => as { shift->current_collection }; implements _build_members => as { my ($self) = @_; @@ -50,7 +53,7 @@ class Collection is 'Reaction::UI::ViewPort', which { my $builder_cache = $builders->{$type} ||= {}; my $member = $class->new( ctx => $ctx, - object => $obj, + model => $obj, location => join('-', $loc, $i++), builder_cache => $builder_cache, %$args diff --git a/lib/Reaction/UI/ViewPort/Collection/Grid.pm b/lib/Reaction/UI/ViewPort/Collection/Grid.pm index 3314039..bc81a0c 100644 --- a/lib/Reaction/UI/ViewPort/Collection/Grid.pm +++ b/lib/Reaction/UI/ViewPort/Collection/Grid.pm @@ -25,13 +25,16 @@ class Grid is 'Reaction::UI::ViewPort::Collection', which { return \%labels; }; + implements _build_field_order => as { []; }; + implements _build_excluded_fields => as { []; }; + implements _build_ordered_fields => as { my ($self) = @_; confess("current_collection lacks a value for 'member_type' attribute") unless $self->current_collection->has_member_type; my %excluded = map { $_ => undef } @{ $self->excluded_fields }; #treat _$field_name as private and exclude fields with no reader - my @names = grep { $_ !~ /^_/ && !exists($exclude{$_})} map { $_->name } + my @names = grep { $_ !~ /^_/ && !exists($excluded{$_})} map { $_->name } grep { defined $_->get_read_method } $self->current_collection->member_type->meta->parameter_attributes; return $self->sort_by_spec($self->field_order, \@names); diff --git a/lib/Reaction/UI/ViewPort/Collection/Grid/Member.pm b/lib/Reaction/UI/ViewPort/Collection/Grid/Member.pm index 0aa5e1d..c37e10e 100644 --- a/lib/Reaction/UI/ViewPort/Collection/Grid/Member.pm +++ b/lib/Reaction/UI/ViewPort/Collection/Grid/Member.pm @@ -2,7 +2,7 @@ package Reaction::UI::ViewPort::Collection::Grid::Member; use Reaction::Class; -Class Member is 'Reaction::UI::ViewPort::Object', which { +class Member is 'Reaction::UI::ViewPort::Object', which { around _build_fields_for_type_Num => sub { $_[0]->(@_[1..3], { layout => 'value/number', %{ $_[4] } }) @@ -41,3 +41,5 @@ Class Member is 'Reaction::UI::ViewPort::Object', which { around _build_fields_for_type_Reaction_InterfaceModel_Collection => sub { return }; }; + +1; diff --git a/lib/Reaction/UI/ViewPort/Field/Mutable/Array.pm b/lib/Reaction/UI/ViewPort/Field/Mutable/Array.pm index 7fa3118..49e629b 100644 --- a/lib/Reaction/UI/ViewPort/Field/Mutable/Array.pm +++ b/lib/Reaction/UI/ViewPort/Field/Mutable/Array.pm @@ -9,7 +9,7 @@ class Array is 'Reaction::UI::ViewPort::Field::Array', which { my $orig = shift; my $self = shift; return $orig->($self) unless @_; - my $value = defined $_[0] ? $_[0] || []; + my $value = defined $_[0] ? $_[0] : []; $orig->($self, (ref $value eq 'ARRAY' ? $value : [ $value ])); $self->sync_to_action; }; diff --git a/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm b/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm index 3ab97b6..12d6d11 100644 --- a/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm +++ b/lib/Reaction/UI/ViewPort/Field/Mutable/ChooseOne.pm @@ -4,8 +4,8 @@ use Reaction::Class; class ChooseOne is 'Reaction::UI::ViewPort::Field', which { - does 'Reaction::UI::ViewPort::Object::Field::Role::Mutable'; - does 'Reaction::UI::ViewPort::Object::Field::Role::Choices'; + does 'Reaction::UI::ViewPort::Field::Role::Mutable'; + does 'Reaction::UI::ViewPort::Field::Role::Choices'; around value => sub { my $orig = shift; diff --git a/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm b/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm index f792e5c..4950aa1 100644 --- a/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm +++ b/lib/Reaction/UI/ViewPort/Field/Mutable/DateTime.pm @@ -4,8 +4,7 @@ use Reaction::Class; use Time::ParseDate; use DateTime; -class 'Reaction::UI::ViewPort::Field::Mutable::DateTime' - is 'Reaction::UI::ViewPort::Field::DateTime', which { +class 'Reaction::UI::ViewPort::Field::Mutable::DateTime', is 'Reaction::UI::ViewPort::Field::DateTime', which { does 'Reaction::UI::ViewPort::Field::Role::Mutable'; @@ -26,9 +25,7 @@ class 'Reaction::UI::ViewPort::Field::Mutable::DateTime' } }; - override accept_events => sub { - ('value_string', super()); - }; + around accept_events => sub { ('value_string', shift->(@_)) }; }; diff --git a/lib/Reaction/UI/ViewPort/Field/Mutable/Number.pm b/lib/Reaction/UI/ViewPort/Field/Mutable/Number.pm index d52121b..41308f3 100644 --- a/lib/Reaction/UI/ViewPort/Field/Mutable/Number.pm +++ b/lib/Reaction/UI/ViewPort/Field/Mutable/Number.pm @@ -2,7 +2,7 @@ package Reaction::UI::ViewPort::Field::Mutable::Number; use Reaction::Class; -class Number 'Reaction::UI::ViewPort::Field::Number', which { +class Number is 'Reaction::UI::ViewPort::Field::Number', which { does 'Reaction::UI::ViewPort::Field::Role::Mutable'; }; diff --git a/lib/Reaction/UI/ViewPort/Field/Role/Choices.pm b/lib/Reaction/UI/ViewPort/Field/Role/Choices.pm index db1c3af..326dc54 100644 --- a/lib/Reaction/UI/ViewPort/Field/Role/Choices.pm +++ b/lib/Reaction/UI/ViewPort/Field/Role/Choices.pm @@ -1,6 +1,6 @@ package Reaction::UI::ViewPort::Field::Role::Choices; -use Reaction::Class; +use Reaction::Role; use URI; use Scalar::Util 'blessed'; diff --git a/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm b/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm index 62191ca..db6c4f3 100644 --- a/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm +++ b/lib/Reaction/UI/ViewPort/Field/Role/Mutable.pm @@ -1,5 +1,7 @@ package Reaction::UI::ViewPort::Field::Role::Mutable; +use Reaction::Role; + use aliased 'Reaction::InterfaceModel::Action'; use aliased 'Reaction::Meta::InterfaceModel::Action::ParameterAttribute'; @@ -44,3 +46,5 @@ role Mutable, which { around accept_events => sub { ('value', shift->(@_)) }; }; + +1; diff --git a/lib/Reaction/UI/ViewPort/ListView.pm b/lib/Reaction/UI/ViewPort/ListView.pm index 5d90c76..1c2247d 100644 --- a/lib/Reaction/UI/ViewPort/ListView.pm +++ b/lib/Reaction/UI/ViewPort/ListView.pm @@ -1,24 +1,24 @@ package Reaction::UI::ViewPort::ListView; use Reaction::Class; -use aliased 'Reaction::UI::ViewPort::GridView::Entity::WithActions'; +use aliased 'Reaction::UI::ViewPort::Collection::Grid::Member::WithActions'; -class ListView is 'Reaction::UI::ViewPort::GridView', which { +class ListView is 'Reaction::UI::ViewPort::Collection::Grid', which { - does 'Reaction::UI::ViewPort::GridView::Role::Order'; - does 'Reaction::UI::ViewPort::GridView::Role::Pager'; - does 'Reaction::UI::ViewPort::GridView::Role::Actions'; + does 'Reaction::UI::ViewPort::Collection::Role::Order'; + does 'Reaction::UI::ViewPort::Collection::Role::Pager'; + does 'Reaction::UI::ViewPort::Role::Actions'; #If I decide that object actions and collection actions should be #lumped together i oculd move these into the collection action role #ooor we could create a third role that does this, but gah, no? - implements _build_entity_class => as { WithActions }; + implements _build_member_class => as { WithActions }; #You'se has to goes aways. sorry. #if i saved the args as an attribute i could probably get around this.... implements object_action_count => as { my $self = shift; - for ( @{ $self->entities } ) { + for ( @{ $self->members } ) { #pickup here, and of to the widget for listview return scalar @{ $_->action_prototypes }; } diff --git a/lib/Reaction/UI/ViewPort/Object.pm b/lib/Reaction/UI/ViewPort/Object.pm index d7a70c1..8a40fbf 100644 --- a/lib/Reaction/UI/ViewPort/Object.pm +++ b/lib/Reaction/UI/ViewPort/Object.pm @@ -9,7 +9,7 @@ use aliased 'Reaction::UI::ViewPort::Field::Boolean'; use aliased 'Reaction::UI::ViewPort::Field::String'; use aliased 'Reaction::UI::ViewPort::Field::DateTime'; use aliased 'Reaction::UI::ViewPort::Field::RelatedObject'; -use aliased 'Reaction::UI::ViewPort::Field::List'; +use aliased 'Reaction::UI::ViewPort::Field::Array'; use aliased 'Reaction::UI::ViewPort::Field::Collection'; use aliased 'Reaction::InterfaceModel::Object' => 'IM_Object'; @@ -48,14 +48,14 @@ class Object is 'Reaction::UI::ViewPort', which { my $field = $self->$meth($obj, $attr, ($args->{$field_name} || {})); push(@fields, $field) if $field; } - return \@field; + return \@fields; }; implements _build_ordered_fields => as { my ($self) = @_; my %excluded = map { $_ => undef } @{ $self->excluded_fields }; #treat _$field_name as private and exclude fields with no reader - my @names = grep { $_ !~ /^_/ && !exists($exclude{$_})} map { $_->name } + my @names = grep { $_ !~ /^_/ && !exists($excluded{$_})} map { $_->name } grep { defined $_->get_read_method } $self->model->meta->parameter_attributes; return $self->sort_by_spec($self->field_order, \@names); }; @@ -164,7 +164,7 @@ class Object is 'Reaction::UI::ViewPort', which { implements _build_fields_for_type_ArrayRef => as { my ($self, $attr, $args) = @_; - $self->_build_simple_field(attribute => $attr, class => List, %$args); + $self->_build_simple_field(attribute => $attr, class => Array, %$args); }; implements _build_fields_for_type_Reaction_InterfaceModel_Object => as { diff --git a/lib/Reaction/UI/ViewPort/Role/Actions.pm b/lib/Reaction/UI/ViewPort/Role/Actions.pm index d7641be..9c99077 100644 --- a/lib/Reaction/UI/ViewPort/Role/Actions.pm +++ b/lib/Reaction/UI/ViewPort/Role/Actions.pm @@ -13,15 +13,12 @@ role Actions, which { my ($self) = @_; my (@act, $i); my $ctx = $self->ctx; - #if i could abstract this vs ->object for row we could eliminate the entity - #version of this role and just use one for both things. that would be cool. - my $obj = $self->current_collection; my $loc = $self->location; foreach my $proto (@{ $self->action_prototypes }) { my $action = Reaction::UI::ViewPort::Action::Link->new ( ctx => $ctx, - target => $obj, + target => $self->model, location => join ('-', $loc, 'action', $i++), %$proto, ); diff --git a/lib/Reaction/UI/Widget/Field/Array.pm b/lib/Reaction/UI/Widget/Field/Array.pm new file mode 100644 index 0000000..cf318c9 --- /dev/null +++ b/lib/Reaction/UI/Widget/Field/Array.pm @@ -0,0 +1,57 @@ +package Reaction::UI::Widget::Field::Array; + +use Reaction::UI::WidgetClass; + +class Array, which { + + before fragment widget { + arg 'label' => $_{viewport}->label; + }; + + implements fragment list { + render 'item' => over $_{viewport}->value_names; + }; + + implements fragment item { + arg 'name' => $_; + }; + +}; + +1; + +__END__; + +=head1 NAME + +Reaction::UI::Widget::DisplayField::Array + +=head1 DESCRIPTION + +=head1 FRAGMENTS + +=head2 widget + +renders C